You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Pedro Salazar <pe...@ptinovacao.pt> on 2001/06/26 15:23:44 UTC

open xml/xsl files inside classpath

Greetings,

I have a servlet which read some properties (using the ResourceBundle) 
from a properties file in a package PT.teste.props where exists a 
relation like this:

"
fileA.xml = file1.xsl
fileB.xml = file2.xsl
...
"

Of course getting the properties file is simple task because I just use 
the location in classpath, ex:

rb=ResourceBundle.getBundle("PT.teste.props."+properties_file);

But, now I would like to open both files, the xml and the xsl file, 
which are in a package PT.teste.xml. I tested using the absolute path to 
them, but is not very recommendable because tomorrow I probably will put 
it in another location or in another machine...

"
Source xmlSource = new javax.xml.transform.stream.StreamSource (new 
java.net.URL("file:///opt/jakarta-tomcat-3.2.1/webapps/servlet_teste/WEB-INF/classes/PT/teste/xml/fileA.xml").openStream());
Source xslSource = new javax.xml.transform.stream.StreamSource (new 
java.net.URL("file:///opt/jakarta-tomcat-3.2.1/webapps/servlet_teste/WEB-INF/classes/PT/teste/xml/file1.xsl").openStream());
"

Is there a easy way to open a file in a classpath directly? Or at least 
a way where the path is relative to the web application? A not very 
recommendable way just to solve my problem is use a path in a properties 
file which I would read in the init() of servlet... but, I wouldn't like 
to do it!

thanks,
Pedro Salazar.


RE: open xml/xsl files inside classpath

Posted by Stefan Neumann <st...@netgrafics.de>.
>>Or at least a way where the path is relative to the web application?

You can use getResourceAsStream() of the ServletContext.

Stefan

-----Original Message-----
From: Pedro Salazar [mailto:pedro-b-salazar@ptinovacao.pt]
Sent: Dienstag, 26. Juni 2001 15:24
To: tomcat-user@jakarta.apache.org
Subject: open xml/xsl files inside classpath


Greetings,

I have a servlet which read some properties (using the ResourceBundle)
from a properties file in a package PT.teste.props where exists a
relation like this:

"
fileA.xml = file1.xsl
fileB.xml = file2.xsl
...
"

Of course getting the properties file is simple task because I just use
the location in classpath, ex:

rb=ResourceBundle.getBundle("PT.teste.props."+properties_file);

But, now I would like to open both files, the xml and the xsl file,
which are in a package PT.teste.xml. I tested using the absolute path to
them, but is not very recommendable because tomorrow I probably will put
it in another location or in another machine...

"
Source xmlSource = new javax.xml.transform.stream.StreamSource (new
java.net.URL("file:///opt/jakarta-tomcat-3.2.1/webapps/servlet_teste/WEB-INF
/classes/PT/teste/xml/fileA.xml").openStream());
Source xslSource = new javax.xml.transform.stream.StreamSource (new
java.net.URL("file:///opt/jakarta-tomcat-3.2.1/webapps/servlet_teste/WEB-INF
/classes/PT/teste/xml/file1.xsl").openStream());
"

Is there a easy way to open a file in a classpath directly? Or at least
a way where the path is relative to the web application? A not very
recommendable way just to solve my problem is use a path in a properties
file which I would read in the init() of servlet... but, I wouldn't like
to do it!

thanks,
Pedro Salazar.