You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-dev@xerces.apache.org by Ben Sifuentes <bs...@cysive.com> on 2000/12/11 15:41:42 UTC

Question about path

Currently, I have a servlet that is using the Xalan to process XML from my
servlet.

Everything is working good, except that it's unable to find my XSL file when
it runs.

It trys to locate the file in my D:\Tomcat\bin directory instead of the
current working directory were I've store my servlet file
D:\Tomcat\webapps\airbank\web-inf\classes

How do I go about configuring Xalan to look into a specific path for
locating the XSL file? Is there some environment variable I can set or some
api I could call that will change this?

The following is a code snip from my servlet:

 	        XSLTProcessor processor = XSLTProcessorFactory.getProcessor();
	        XSLTInputSource xmlInput = null;
	        XSLTInputSource xslTemplate = null;

			.
			.

		    	// Create the InputSource needed for the parser
    		    	Reader in = new StringReader(b.toString());

                  xmlInput = new XSLTInputSource(in);
		    	String filename = null;
		    	if (isWML) {
				filename = new String("errorWML.xsl");
		    	}
		    	else {
				filename = new String("errorHDML.xsl");
                  }
                  xslTemplate = new XSLTInputSource(filename);

			.
			.

	       OutputStream byteStream = new ByteArrayOutputStream();
	       XSLTResultTarget result = new XSLTResultTarget(byteStream);
     	       processor.process(xmlInput, xslTemplate, result);


Current configuration is as follows:

Apache
Tomcat
Xalan

-Ben


Re: Question about path

Posted by Klaus Kiehne <ki...@struktur.de>.
Hi Ben,

Ben Sifuentes wrote:
> 
> Currently, I have a servlet that is using the Xalan to process XML from my
> servlet.
> 
> Everything is working good, except that it's unable to find my XSL file when
> it runs.
> 
> It trys to locate the file in my D:\Tomcat\bin directory instead of the
> current working directory were I've store my servlet file
> D:\Tomcat\webapps\airbank\web-inf\classes
> 
> How do I go about configuring Xalan to look into a specific path for
> locating the XSL file? Is there some environment variable I can set or some
> api I could call that will change this?

This is more a servlet topic than a xerces topic but I'll give it a try :

If you want to locate any resources associated to your servlet you should
use the methods from the servlet API. To get the URL of a ressource in a servlet
try using something like

   URL theURL = this.getServeltContext().getRessource("/xsl/errorWML.xsl")

or to get the InputStream of the ressource use

   InputStream theInputStream = this.getServeltContext().getRessourceAsStream("/xsl/errorWML.xsl")

in your case both of this would reference the file under
D:\Tomcat\webapps\airbank\xsl\errorWML.xsl 

Both methods expect an absolute path which is seen assolute to the root directory
of your web application. For further information see comments in javax.servelet.ServeltContext
and the servelet specs.

If you want to access ressources, which are stored local to your servlet class, you can also
use this.getClass().getRessource(...) or this.getClass().getRessourceAsStream(...) . 
 

Klaus
-- 
___    __________________________________             ______  ______   _____            
                                                     /     /|/     /| /    /|
       Klaus Kiehne [Software Architect]            /_____/ /_____/ /_____/ |
                                                   _|____ |_|____ |_|____ | |
       Dipl.-Informatiker                         /     /|/     /| /    /|| /
___                                              /_____/ /_____/ /_____/ ||/|
___    __________________________________       _|____ |_|____ |_|____ | |/ |
___                                            /     /|/     /|/     /|| /| |
         struktur AG                          /_____/ /_____/ /_____/ ||/|| /
                                              |     | |     | |     | |/ ||/|
         Junghansstrasse 5                    |     | |     | |     | /| |/ |
___    D-70469 Stuttgart                      |_____|/|_____|/|_____|/|| /| |
                                              /_____/ /_____/ /_____/ ||/|| /
       __________________________________     |     | |     | |     | |/ ||/
___                                           |     | |     | |     | /| | 
       Tel:   +49. 711. 89 66 56-61           |_____|/|_____|/|_____|/|| /
       Fax:   +49. 711. 89 66 56-10           /_____/ /_____/ /_____/ ||/
                                              |     | |     | |     | |
       website: www.struktur.de               |     | |     | |     | /
___    __________________________________     |_____|/|_____|/|_____|/