RE: Servlets and relative paths
Title: RE: Servlets and relative paths Hi, here is how I get the document root in the init method of my servlet, "index.html"being the first page of my application, I know it shall always be at the root context of my web application. I then use this document root to initialise my implementation of URIResolver. The latter then use this document root in its resolve method instead of the base path. ServletContext servletContext = servletConfig.getServletContext(); String documentRoot = servletContext.getResource("/index.html").toString();documentRoot = documentRoot.substring(0, documentRoot.indexOf("index.html") - 1); Cheers, Viksen. -Original Message-From: Jeff Gaer [mailto:[EMAIL PROTECTED]]Sent: Tuesday, June 05, 2001 00:39To: '[EMAIL PROTECTED]'Subject: RE: Servlets and relative paths How do you specify the base path in a installation independent way, I.e. as relative to the document root. Assuming you install your xsl fragments in webapps/myapplication/xslfrags/ , can you give an example? Thanks in advance Jeff Gaer -Original Message-From: Viksen Pillay Narrainen [mailto:[EMAIL PROTECTED]]Sent: Monday, June 04, 2001 1:04 AMTo: [EMAIL PROTECTED]Subject: RE: Servlets and relative paths Hi, take a look at the URIResolver interface and at the method setURIResolver of TransformerFactory, both in package javax.xml.transform. What I did was to create my own implementation of the URIResolver, initialize it with correct parameters, andset it for my instance of TransformerFactory. The transformers instantiated by this factory then rely on my URIResolver implentation to resolve xsl:include Hope that helps, Viksen. PS: Here is the implementation of my URIResolver import java.net.URL;import javax.xml.transform.URIResolver;import javax.xml.transform.TransformerException;import javax.xml.transform.Source;import javax.xml.transform.stream.StreamSource; public class URIResolverImpl implements URIResolver{ private String _documentRoot; /** Creates new URIResolverImpl */ public URIResolverImpl(String documentRoot) { _documentRoot = documentRoot; } public Source resolve(String href, String base) throws TransformerException {try{ return new StreamSource(new URL(_documentRoot + href).openStream());} catch (Exception e){ throw new TransformerException(e);} } } -Original Message-From: Cox, Charlie [mailto:[EMAIL PROTECTED]]Sent: Friday, June 01, 2001 16:45To: '[EMAIL PROTECTED]'Subject: RE: Servlets and relative paths What I had to do was put the xsl files in the root directory for my webapp where I could make the href the full url (http://localhost/webapp/sections.xsl) This was the only way I could get it to work correctly. Obviously this exposes your stylesheet to anyone who requests that url. I finally gave up on the include since I was only sharing with 2 stylesheets, but I still use it for my dtd, which has the same problem when processed by a stylesheet. I didn't think that I would get it to work as I wanted since Xalan(library I'm using) doesn't know about tomcat, and I couldn't find anywhere in xalan to set a default path to look for include files/dtd's. Therefore it always assumes the 'working dir' for the application when looking for includes. The ugly option is that you could make the include path = "../webapps/MyContext/sections.xsl" assuming your context is under webapps. Of course this is inconsistant with other paths in your application(i.e. getResourceAsStream()) and is a pain to maintain if you move your context. The other ugly option being chucking the includes into the bin directory, but that defeats the purpose of separating contexts. Charlie -Original Message- From: Chris McNeilly [mailto:[EMAIL PROTECTED]] Sent: Wednesday, May 30, 2001 2:22 PM To: [EMAIL PROTECTED] Subject: RE: Servlets and relative paths No, my problem is that I can use this method to read the xsl file just fine. It's the includes inside the xsl file that aren't working. For example, inside the xsl file (which I read into the servlet using your pointer from the earlier email) there is the line xsl:include href='sections.xsl'/ and I get an error saying that it cannot find file tomcat/bin/sections.xsl. Which, of course, it cannot, since the file is located in Meta-Inf/. Chris -Original Message- From: Bo Xu [mailto:[EMAIL PROTECTED]] Sent: Wednesday, May 30, 2001 10:45 AM To:
RE: Servlets and relative paths
Title: RE: Servlets and relative paths Hi, take a look at the URIResolver interface and at the method setURIResolver of TransformerFactory, both in package javax.xml.transform. What I did was to create my own implementation of the URIResolver, initialize it with correct parameters, andset it for my instance of TransformerFactory. The transformers instantiated by this factory then rely on my URIResolver implentation to resolve xsl:include Hope that helps, Viksen. PS: Here is the implementation of my URIResolver import java.net.URL;import javax.xml.transform.URIResolver;import javax.xml.transform.TransformerException;import javax.xml.transform.Source;import javax.xml.transform.stream.StreamSource; public class URIResolverImpl implements URIResolver{ private String _documentRoot; /** Creates new URIResolverImpl */ public URIResolverImpl(String documentRoot) { _documentRoot = documentRoot; } public Source resolve(String href, String base) throws TransformerException {try{ return new StreamSource(new URL(_documentRoot + href).openStream());} catch (Exception e){ throw new TransformerException(e);} } } -Original Message-From: Cox, Charlie [mailto:[EMAIL PROTECTED]]Sent: Friday, June 01, 2001 16:45To: '[EMAIL PROTECTED]'Subject: RE: Servlets and relative paths What I had to do was put the xsl files in the root directory for my webapp where I could make the href the full url (http://localhost/webapp/sections.xsl) This was the only way I could get it to work correctly. Obviously this exposes your stylesheet to anyone who requests that url. I finally gave up on the include since I was only sharing with 2 stylesheets, but I still use it for my dtd, which has the same problem when processed by a stylesheet. I didn't think that I would get it to work as I wanted since Xalan(library I'm using) doesn't know about tomcat, and I couldn't find anywhere in xalan to set a default path to look for include files/dtd's. Therefore it always assumes the 'working dir' for the application when looking for includes. The ugly option is that you could make the include path = "../webapps/MyContext/sections.xsl" assuming your context is under webapps. Of course this is inconsistant with other paths in your application(i.e. getResourceAsStream()) and is a pain to maintain if you move your context. The other ugly option being chucking the includes into the bin directory, but that defeats the purpose of separating contexts. Charlie -Original Message- From: Chris McNeilly [mailto:[EMAIL PROTECTED]] Sent: Wednesday, May 30, 2001 2:22 PM To: [EMAIL PROTECTED] Subject: RE: Servlets and relative paths No, my problem is that I can use this method to read the xsl file just fine. It's the includes inside the xsl file that aren't working. For example, inside the xsl file (which I read into the servlet using your pointer from the earlier email) there is the line xsl:include href='sections.xsl'/ and I get an error saying that it cannot find file tomcat/bin/sections.xsl. Which, of course, it cannot, since the file is located in Meta-Inf/. Chris -Original Message- From: Bo Xu [mailto:[EMAIL PROTECTED]] Sent: Wednesday, May 30, 2001 10:45 AM To: [EMAIL PROTECTED] Subject: Re: Servlets and relative paths Chris McNeilly wrote:Thanks Bo. This is certainly a step in the right direction. I can now include the xml file and xsl file using relative paths. My only problem now is that there are xsl includes inside the xsl files and they are still being loaded incorrectly (using the tomcat/bin directory as root, not the servlet context). Any ideas? Thanks, Chris Chris McNeilly wrote:I've got a servlet and am trying to open files. Theproblem is that its defaulting to the tomcat/bin directory whenever I attempt to refer to them. How can I change this? Hardcoding the path isn'tsuch a good idea as my dev environment is different from production.These are xml and xsl files and they are located on the webroot. Thanks, Chris Hi :-) from several emails in Servlet-List and this List: * InputStream is = this.getServletContext(). getResourceAsStream("/WEB-INF/testApp.properties"); now testApp.properties is in myapp/WEB-INF/ *- InputStream is = this.getClass().getResourceAsStream("testApp.properties");- InputStream is = Thread.currentThread().getContextClassLoader(). getResourceAsStream("myservlet.conf"); now, (normally), myservlet.conf/testApp.properties is inmyapp/WEB-INF/classes BoMay.29, 2001 [...] Hello Chris :-) I am not sure, do you want to read a file i
RE: Servlets and relative paths
Title: RE: Servlets and relative paths What I had to do was put the xsl files in the root directory for my webapp where I could make the href the full url (http://localhost/webapp/sections.xsl) This was the only way I could get it to work correctly. Obviously this exposes your stylesheet to anyone who requests that url. I finally gave up on the include since I was only sharing with 2 stylesheets, but I still use it for my dtd, which has the same problem when processed by a stylesheet. I didn't think that I would get it to work as I wanted since Xalan(library I'm using) doesn't know about tomcat, and I couldn't find anywhere in xalan to set a default path to look for include files/dtd's. Therefore it always assumes the 'working dir' for the application when looking for includes. The ugly option is that you could make the include path = ../webapps/MyContext/sections.xsl assuming your context is under webapps. Of course this is inconsistant with other paths in your application(i.e. getResourceAsStream()) and is a pain to maintain if you move your context. The other ugly option being chucking the includes into the bin directory, but that defeats the purpose of separating contexts. Charlie -Original Message- From: Chris McNeilly [mailto:[EMAIL PROTECTED]] Sent: Wednesday, May 30, 2001 2:22 PM To: [EMAIL PROTECTED] Subject: RE: Servlets and relative paths No, my problem is that I can use this method to read the xsl file just fine. It's the includes inside the xsl file that aren't working. For example, inside the xsl file (which I read into the servlet using your pointer from the earlier email) there is the line xsl:include href='sections.xsl'/ and I get an error saying that it cannot find file tomcat/bin/sections.xsl. Which, of course, it cannot, since the file is located in Meta-Inf/. Chris -Original Message- From: Bo Xu [mailto:[EMAIL PROTECTED]] Sent: Wednesday, May 30, 2001 10:45 AM To: [EMAIL PROTECTED] Subject: Re: Servlets and relative paths Chris McNeilly wrote: Thanks Bo. This is certainly a step in the right direction. I can now include the xml file and xsl file using relative paths. My only problem now is that there are xsl includes inside the xsl files and they are still being loaded incorrectly (using the tomcat/bin directory as root, not the servlet context). Any ideas? Thanks, Chris Chris McNeilly wrote: I've got a servlet and am trying to open files. The problem is that its defaulting to the tomcat/bin directory whenever I attempt to refer to them. How can I change this? Hardcoding the path isn't such a good idea as my dev environment is different from production. These are xml and xsl files and they are located on the webroot. Thanks, Chris Hi :-) from several emails in Servlet-List and this List: * InputStream is = this.getServletContext(). getResourceAsStream(/WEB-INF/testApp.properties); now testApp.properties is in myapp/WEB-INF/ * - InputStream is = this.getClass().getResourceAsStream(testApp.properties); - InputStream is = Thread.currentThread().getContextClassLoader(). getResourceAsStream(myservlet.conf); now, (normally), myservlet.conf/testApp.properties is in myapp/WEB-INF/classes Bo May.29, 2001 [...] Hello Chris :-) I am not sure, do you want to read a file in TOMCAT_HOME/bin? is the following possible? - put MyUtil.class in TOMCAT_HOME/bin - include TOMCAT_HOME/bin/MyUtil.class into CLASSPATH - put testApp.properties into TOMCAT_HOME/bin - in MyServlet, write the following code: ... MyUtil myobject=new MyUtil(); InputStream is = myobject.getClass().getResourceAsStream(testApp.properties); ... I don't test it, if it is not right, please correct it, thanks! :-) Bo May.30, 2001
RE: Servlets and relative paths
Title: RE: Servlets and relative paths That's eventually what I did. I now have two top xsl pages, one includes with fully qualified urls and the other uses the relative includes. One for the xsl designer and the other for testing/prod. It's not ideal, but isn't too much of a pain. Chris -Original Message-From: Cox, Charlie [mailto:[EMAIL PROTECTED]]Sent: Friday, June 01, 2001 8:45 AMTo: '[EMAIL PROTECTED]'Subject: RE: Servlets and relative paths What I had to do was put the xsl files in the root directory for my webapp where I could make the href the full url (http://localhost/webapp/sections.xsl) This was the only way I could get it to work correctly. Obviously this exposes your stylesheet to anyone who requests that url. I finally gave up on the include since I was only sharing with 2 stylesheets, but I still use it for my dtd, which has the same problem when processed by a stylesheet. I didn't think that I would get it to work as I wanted since Xalan(library I'm using) doesn't know about tomcat, and I couldn't find anywhere in xalan to set a default path to look for include files/dtd's. Therefore it always assumes the 'working dir' for the application when looking for includes. The ugly option is that you could make the include path = "../webapps/MyContext/sections.xsl" assuming your context is under webapps. Of course this is inconsistant with other paths in your application(i.e. getResourceAsStream()) and is a pain to maintain if you move your context. The other ugly option being chucking the includes into the bin directory, but that defeats the purpose of separating contexts. Charlie -Original Message- From: Chris McNeilly [mailto:[EMAIL PROTECTED]] Sent: Wednesday, May 30, 2001 2:22 PM To: [EMAIL PROTECTED] Subject: RE: Servlets and relative paths No, my problem is that I can use this method to read the xsl file just fine. It's the includes inside the xsl file that aren't working. For example, inside the xsl file (which I read into the servlet using your pointer from the earlier email) there is the line xsl:include href='sections.xsl'/ and I get an error saying that it cannot find file tomcat/bin/sections.xsl. Which, of course, it cannot, since the file is located in Meta-Inf/. Chris -Original Message- From: Bo Xu [mailto:[EMAIL PROTECTED]] Sent: Wednesday, May 30, 2001 10:45 AM To: [EMAIL PROTECTED] Subject: Re: Servlets and relative paths Chris McNeilly wrote:Thanks Bo. This is certainly a step in the right direction. I can now include the xml file and xsl file using relative paths. My only problem now is that there are xsl includes inside the xsl files and they are still being loaded incorrectly (using the tomcat/bin directory as root, not the servlet context). Any ideas? Thanks, Chris Chris McNeilly wrote:I've got a servlet and am trying to open files. Theproblem is that its defaulting to the tomcat/bin directory whenever I attempt to refer to them. How can I change this? Hardcoding the path isn'tsuch a good idea as my dev environment is different from production.These are xml and xsl files and they are located on the webroot. Thanks, Chris Hi :-) from several emails in Servlet-List and this List: * InputStream is = this.getServletContext(). getResourceAsStream("/WEB-INF/testApp.properties"); now testApp.properties is in myapp/WEB-INF/ *- InputStream is = this.getClass().getResourceAsStream("testApp.properties");- InputStream is = Thread.currentThread().getContextClassLoader(). getResourceAsStream("myservlet.conf"); now, (normally), myservlet.conf/testApp.properties is inmyapp/WEB-INF/classes BoMay.29, 2001 [...] Hello Chris :-) I am not sure, do you want to read a file in TOMCAT_HOME/bin? is the following possible? - put MyUtil.class in TOMCAT_HOME/bin - include TOMCAT_HOME/bin/MyUtil.class into CLASSPATH - put testApp.properties into TOMCAT_HOME/bin - in MyServlet, write the following code: ... MyUtil myobject=new MyUtil(); InputStream is = myobject.getClass().getResourceAsStream("testApp.properties"); ... I don't test it, if it is not right, please correct it, thanks! :-)Bo May.30, 2001
RE: Servlets and relative paths
Set the SystemID for xsl includes: this line is part of the setup for some SAX-driven XSL processing I've used in servlets: StreamSource source = new StreamSource(stream, getSystemID()); // set system id for xsl includes where getSystemID() returns the URI to use as a base location for xsl includes. See the xalan javadoc. Hope that helps. SteveM -Original Message- From: Chris McNeilly [mailto:[EMAIL PROTECTED]] Sent: Friday, June 01, 2001 2:18 PM To: [EMAIL PROTECTED] Subject: RE: Servlets and relative paths That's eventually what I did. I now have two top xsl pages, one includes with fully qualified urls and the other uses the relative includes. One for the xsl designer and the other for testing/prod. It's not ideal, but isn't too much of a pain. Chris -Original Message- From: Cox, Charlie [mailto:[EMAIL PROTECTED]] Sent: Friday, June 01, 2001 8:45 AM To: '[EMAIL PROTECTED]' Subject: RE: Servlets and relative paths What I had to do was put the xsl files in the root directory for my webapp where I could make the href the full url (http://localhost/webapp/sections.xsl) This was the only way I could get it to work correctly. Obviously this exposes your stylesheet to anyone who requests that url. I finally gave up on the include since I was only sharing with 2 stylesheets, but I still use it for my dtd, which has the same problem when processed by a stylesheet. I didn't think that I would get it to work as I wanted since Xalan(library I'm using) doesn't know about tomcat, and I couldn't find anywhere in xalan to set a default path to look for include files/dtd's. Therefore it always assumes the 'working dir' for the application when looking for includes. The ugly option is that you could make the include path = ../webapps/MyContext/sections.xsl assuming your context is under webapps. Of course this is inconsistant with other paths in your application(i.e. getResourceAsStream()) and is a pain to maintain if you move your context. The other ugly option being chucking the includes into the bin directory, but that defeats the purpose of separating contexts. Charlie -Original Message- From: Chris McNeilly [mailto:[EMAIL PROTECTED]] Sent: Wednesday, May 30, 2001 2:22 PM To: [EMAIL PROTECTED] Subject: RE: Servlets and relative paths No, my problem is that I can use this method to read the xsl file just fine. It's the includes inside the xsl file that aren't working. For example, inside the xsl file (which I read into the servlet using your pointer from the earlier email) there is the line xsl:include href='sections.xsl'/ and I get an error saying that it cannot find file tomcat/bin/sections.xsl. Which, of course, it cannot, since the file is located in Meta-Inf/. Chris -Original Message- From: Bo Xu [mailto:[EMAIL PROTECTED]] Sent: Wednesday, May 30, 2001 10:45 AM To: [EMAIL PROTECTED] Subject: Re: Servlets and relative paths Chris McNeilly wrote: Thanks Bo. This is certainly a step in the right direction. I can now include the xml file and xsl file using relative paths. My only problem now is that there are xsl includes inside the xsl files and they are still being loaded incorrectly (using the tomcat/bin directory as root, not the servlet context). Any ideas? Thanks, Chris Chris McNeilly wrote: I've got a servlet and am trying to open files. The problem is that its defaulting to the tomcat/bin directory whenever I attempt to refer to them. How can I change this? Hardcoding the path isn't such a good idea as my dev environment is different from production. These are xml and xsl files and they are located on the webroot. Thanks, Chris Hi :-) from several emails in Servlet-List and this List: * InputStream is = this.getServletContext(). getResourceAsStream(/WEB-INF/testApp.properties); now testApp.properties is in myapp/WEB-INF/ * - InputStream is = this.getClass().getResourceAsStream(testApp.properties); - InputStream is = Thread.currentThread().getContextClassLoader(). getResourceAsStream(myservlet.conf); now, (normally), myservlet.conf/testApp.properties is in myapp/WEB-INF/classes Bo May.29, 2001 [...] Hello Chris :-) I am not sure, do you want to read a file in TOMCAT_HOME/bin? is the following possible? - put MyUtil.class in TOMCAT_HOME/bin - include TOMCAT_HOME/bin/MyUtil.class into CLASSPATH - put testApp.properties into TOMCAT_HOME/bin - in MyServlet, write the following code: ... MyUtil myobject=new MyUtil(); InputStream is = myobject.getClass().getResourceAsStream(testApp.properties); ... I don't test it, if it is not right, please correct it, thanks! :-) Bo May.30, 2001
RE: Servlets and relative paths
That's an improvement, although not quite it. Now I have the full path portion hardcoded in the java and not the xsl. Ideally, I'd like it all to be a relative path, but if I don't fully qualify the systemID portion, the include still tries to prepend the tomcat/bin directory. This helps, though. Thanks, Chris -Original Message- From: Steve Meyfroidt [mailto:[EMAIL PROTECTED]] Sent: Friday, June 01, 2001 9:40 AM To: '[EMAIL PROTECTED]' Subject: RE: Servlets and relative paths Set the SystemID for xsl includes: this line is part of the setup for some SAX-driven XSL processing I've used in servlets: StreamSource source = new StreamSource(stream, getSystemID()); // set system id for xsl includes where getSystemID() returns the URI to use as a base location for xsl includes. See the xalan javadoc. Hope that helps. SteveM -Original Message- From: Chris McNeilly [mailto:[EMAIL PROTECTED]] Sent: Friday, June 01, 2001 2:18 PM To: [EMAIL PROTECTED] Subject: RE: Servlets and relative paths That's eventually what I did. I now have two top xsl pages, one includes with fully qualified urls and the other uses the relative includes. One for the xsl designer and the other for testing/prod. It's not ideal, but isn't too much of a pain. Chris -Original Message- From: Cox, Charlie [mailto:[EMAIL PROTECTED]] Sent: Friday, June 01, 2001 8:45 AM To: '[EMAIL PROTECTED]' Subject: RE: Servlets and relative paths What I had to do was put the xsl files in the root directory for my webapp where I could make the href the full url (http://localhost/webapp/sections.xsl) This was the only way I could get it to work correctly. Obviously this exposes your stylesheet to anyone who requests that url. I finally gave up on the include since I was only sharing with 2 stylesheets, but I still use it for my dtd, which has the same problem when processed by a stylesheet. I didn't think that I would get it to work as I wanted since Xalan(library I'm using) doesn't know about tomcat, and I couldn't find anywhere in xalan to set a default path to look for include files/dtd's. Therefore it always assumes the 'working dir' for the application when looking for includes. The ugly option is that you could make the include path = ../webapps/MyContext/sections.xsl assuming your context is under webapps. Of course this is inconsistant with other paths in your application(i.e. getResourceAsStream()) and is a pain to maintain if you move your context. The other ugly option being chucking the includes into the bin directory, but that defeats the purpose of separating contexts. Charlie -Original Message- From: Chris McNeilly [mailto:[EMAIL PROTECTED]] Sent: Wednesday, May 30, 2001 2:22 PM To: [EMAIL PROTECTED] Subject: RE: Servlets and relative paths No, my problem is that I can use this method to read the xsl file just fine. It's the includes inside the xsl file that aren't working. For example, inside the xsl file (which I read into the servlet using your pointer from the earlier email) there is the line xsl:include href='sections.xsl'/ and I get an error saying that it cannot find file tomcat/bin/sections.xsl. Which, of course, it cannot, since the file is located in Meta-Inf/. Chris -Original Message- From: Bo Xu [mailto:[EMAIL PROTECTED]] Sent: Wednesday, May 30, 2001 10:45 AM To: [EMAIL PROTECTED] Subject: Re: Servlets and relative paths Chris McNeilly wrote: Thanks Bo. This is certainly a step in the right direction. I can now include the xml file and xsl file using relative paths. My only problem now is that there are xsl includes inside the xsl files and they are still being loaded incorrectly (using the tomcat/bin directory as root, not the servlet context). Any ideas? Thanks, Chris Chris McNeilly wrote: I've got a servlet and am trying to open files. The problem is that its defaulting to the tomcat/bin directory whenever I attempt to refer to them. How can I change this? Hardcoding the path isn't such a good idea as my dev environment is different from production. These are xml and xsl files and they are located on the webroot. Thanks, Chris Hi :-) from several emails in Servlet-List and this List: * InputStream is = this.getServletContext(). getResourceAsStream(/WEB-INF/testApp.properties); now testApp.properties is in myapp/WEB-INF/ * - InputStream is = this.getClass().getResourceAsStream(testApp.properties); - InputStream is = Thread.currentThread().getContextClassLoader(). getResourceAsStream(myservlet.conf); now, (normally), myservlet.conf/testApp.properties is in myapp/WEB-INF/classes Bo May.29, 2001 [...] Hello Chris :-) I am not sure, do you
RE: Servlets and relative paths
True. We ended up pulling a full path from config file and had the XSL pull from a known place on the filesystem. You're right... not ideal! Untidy deployment. You could (I imagine) make a URL resolver that will work from the classpath. Say it could resolve classpath://blah/foo. Would that help? Are URL resolvers created by a factory somewhere? Is there a xalan resolver... I bet there is somewhere. SteveM -Original Message- From: Chris McNeilly [mailto:[EMAIL PROTECTED]] Sent: Friday, June 01, 2001 3:41 PM To: [EMAIL PROTECTED] Subject: RE: Servlets and relative paths That's an improvement, although not quite it. Now I have the full path portion hardcoded in the java and not the xsl. Ideally, I'd like it all to be a relative path, but if I don't fully qualify the systemID portion, the include still tries to prepend the tomcat/bin directory. This helps, though. Thanks, Chris -Original Message- From: Steve Meyfroidt [mailto:[EMAIL PROTECTED]] Sent: Friday, June 01, 2001 9:40 AM To: '[EMAIL PROTECTED]' Subject: RE: Servlets and relative paths Set the SystemID for xsl includes: this line is part of the setup for some SAX-driven XSL processing I've used in servlets: StreamSource source = new StreamSource(stream, getSystemID()); // set system id for xsl includes where getSystemID() returns the URI to use as a base location for xsl includes. See the xalan javadoc. Hope that helps. SteveM -Original Message- From: Chris McNeilly [mailto:[EMAIL PROTECTED]] Sent: Friday, June 01, 2001 2:18 PM To: [EMAIL PROTECTED] Subject: RE: Servlets and relative paths That's eventually what I did. I now have two top xsl pages, one includes with fully qualified urls and the other uses the relative includes. One for the xsl designer and the other for testing/prod. It's not ideal, but isn't too much of a pain. Chris -Original Message- From: Cox, Charlie [mailto:[EMAIL PROTECTED]] Sent: Friday, June 01, 2001 8:45 AM To: '[EMAIL PROTECTED]' Subject: RE: Servlets and relative paths What I had to do was put the xsl files in the root directory for my webapp where I could make the href the full url (http://localhost/webapp/sections.xsl) This was the only way I could get it to work correctly. Obviously this exposes your stylesheet to anyone who requests that url. I finally gave up on the include since I was only sharing with 2 stylesheets, but I still use it for my dtd, which has the same problem when processed by a stylesheet. I didn't think that I would get it to work as I wanted since Xalan(library I'm using) doesn't know about tomcat, and I couldn't find anywhere in xalan to set a default path to look for include files/dtd's. Therefore it always assumes the 'working dir' for the application when looking for includes. The ugly option is that you could make the include path = ../webapps/MyContext/sections.xsl assuming your context is under webapps. Of course this is inconsistant with other paths in your application(i.e. getResourceAsStream()) and is a pain to maintain if you move your context. The other ugly option being chucking the includes into the bin directory, but that defeats the purpose of separating contexts. Charlie -Original Message- From: Chris McNeilly [mailto:[EMAIL PROTECTED]] Sent: Wednesday, May 30, 2001 2:22 PM To: [EMAIL PROTECTED] Subject: RE: Servlets and relative paths No, my problem is that I can use this method to read the xsl file just fine. It's the includes inside the xsl file that aren't working. For example, inside the xsl file (which I read into the servlet using your pointer from the earlier email) there is the line xsl:include href='sections.xsl'/ and I get an error saying that it cannot find file tomcat/bin/sections.xsl. Which, of course, it cannot, since the file is located in Meta-Inf/. Chris -Original Message- From: Bo Xu [mailto:[EMAIL PROTECTED]] Sent: Wednesday, May 30, 2001 10:45 AM To: [EMAIL PROTECTED] Subject: Re: Servlets and relative paths Chris McNeilly wrote: Thanks Bo. This is certainly a step in the right direction. I can now include the xml file and xsl file using relative paths. My only problem now is that there are xsl includes inside the xsl files and they are still being loaded incorrectly (using the tomcat/bin directory as root, not the servlet context). Any ideas? Thanks, Chris Chris McNeilly wrote: I've got a servlet and am trying to open files. The problem is that its defaulting to the tomcat/bin directory whenever I attempt to refer to them. How can I change this? Hardcoding the path isn't such a good idea as my dev environment is different from production
RE: Servlets and relative paths
I found this in the archives (http://marc.theaimsgroup.com ). You might search them for more info if this doesn't work. If you put the file in your servlet's classpath, this code, which in this case is accessing a properties file, should allow you to access the file. - InputStream is = this.getClass().getResourceAsStream(myapp.properties); Properties p = new Properties(); try { p.load(is); } catch ( java.io.IOException e ) { // Can't load props file -Original Message- From: Chris McNeilly [mailto:[EMAIL PROTECTED]] Sent: Tuesday, May 29, 2001 11:32 AM To: [EMAIL PROTECTED] Subject: Servlets and relative paths I've got a servlet and am trying to open files. The problem is that its defaulting to the tomcat/bin directory whenever I attempt to refer to them. How can I change this? Hardcoding the path isn't such a good idea as my dev environment is different from production. These are xml and xsl files and they are located on the webroot. Thanks, Chris
RE: Re: Servlets and relative paths
Thanks Bo. This is certainly a step in the right direction. I can now include the xml file and xsl file using relative paths. My only problem now is that there are xsl includes inside the xsl files and they are still being loaded incorrectly (using the tomcat/bin directory as root, not the servlet context). Any ideas? Thanks, Chris Chris McNeilly wrote: I've got a servlet and am trying to open files. The problem is that its defaulting to the tomcat/bin directory whenever I attempt to refer to them. How can I change this? Hardcoding the path isn't such a good idea as my dev environment is different from production. These are xml and xsl files and they are located on the webroot. Thanks, Chris Hi :-) from several emails in Servlet-List and this List: * InputStream is = this.getServletContext(). getResourceAsStream(/WEB-INF/testApp.properties); now testApp.properties is in myapp/WEB-INF/ * - InputStream is = this.getClass().getResourceAsStream(testApp.properties); - InputStream is = Thread.currentThread().getContextClassLoader(). getResourceAsStream(myservlet.conf); now, (normally), myservlet.conf/testApp.properties is in myapp/WEB-INF/classes Bo May.29, 2001
Re: Servlets and relative paths
Chris McNeilly wrote: Thanks Bo. This is certainly a step in the right direction. I can now include the xml file and xsl file using relative paths. My only problem now is that there are xsl includes inside the xsl files and they are still being loaded incorrectly (using the tomcat/bin directory as root, not the servlet context). Any ideas? Thanks, Chris Chris McNeilly wrote: I've got a servlet and am trying to open files. The problem is that its defaulting to the tomcat/bin directory whenever I attempt to refer to them. How can I change this? Hardcoding the path isn't such a good idea as my dev environment is different from production. These are xml and xsl files and they are located on the webroot. Thanks, Chris Hi :-) from several emails in Servlet-List and this List: * InputStream is = this.getServletContext(). getResourceAsStream(/WEB-INF/testApp.properties); now testApp.properties is in myapp/WEB-INF/ * - InputStream is = this.getClass().getResourceAsStream(testApp.properties); - InputStream is = Thread.currentThread().getContextClassLoader(). getResourceAsStream(myservlet.conf); now, (normally), myservlet.conf/testApp.properties is in myapp/WEB-INF/classes Bo May.29, 2001 [...] Hello Chris :-) I am not sure, do you want to read a file in TOMCAT_HOME/bin? is the following possible? - put MyUtil.class in TOMCAT_HOME/bin - include TOMCAT_HOME/bin/MyUtil.class into CLASSPATH - put testApp.properties into TOMCAT_HOME/bin - in MyServlet, write the following code: ... MyUtil myobject=new MyUtil(); InputStream is = myobject.getClass().getResourceAsStream(testApp.properties); ... I don't test it, if it is not right, please correct it, thanks! :-) Bo May.30, 2001
RE: Servlets and relative paths
No, my problem is that I can use this method to read the xsl file just fine. It's the includes inside the xsl file that aren't working. For example, inside the xsl file (which I read into the servlet using your pointer from the earlier email) there is the line xsl:include href='sections.xsl'/ and I get an error saying that it cannot find file tomcat/bin/sections.xsl. Which, of course, it cannot, since the file is located in Meta-Inf/. Chris -Original Message- From: Bo Xu [mailto:[EMAIL PROTECTED]] Sent: Wednesday, May 30, 2001 10:45 AM To: [EMAIL PROTECTED] Subject: Re: Servlets and relative paths Chris McNeilly wrote: Thanks Bo. This is certainly a step in the right direction. I can now include the xml file and xsl file using relative paths. My only problem now is that there are xsl includes inside the xsl files and they are still being loaded incorrectly (using the tomcat/bin directory as root, not the servlet context). Any ideas? Thanks, Chris Chris McNeilly wrote: I've got a servlet and am trying to open files. The problem is that its defaulting to the tomcat/bin directory whenever I attempt to refer to them. How can I change this? Hardcoding the path isn't such a good idea as my dev environment is different from production. These are xml and xsl files and they are located on the webroot. Thanks, Chris Hi :-) from several emails in Servlet-List and this List: * InputStream is = this.getServletContext(). getResourceAsStream(/WEB-INF/testApp.properties); now testApp.properties is in myapp/WEB-INF/ * - InputStream is = this.getClass().getResourceAsStream(testApp.properties); - InputStream is = Thread.currentThread().getContextClassLoader(). getResourceAsStream(myservlet.conf); now, (normally), myservlet.conf/testApp.properties is in myapp/WEB-INF/classes Bo May.29, 2001 [...] Hello Chris :-) I am not sure, do you want to read a file in TOMCAT_HOME/bin? is the following possible? - put MyUtil.class in TOMCAT_HOME/bin - include TOMCAT_HOME/bin/MyUtil.class into CLASSPATH - put testApp.properties into TOMCAT_HOME/bin - in MyServlet, write the following code: ... MyUtil myobject=new MyUtil(); InputStream is = myobject.getClass().getResourceAsStream(testApp.properties); ... I don't test it, if it is not right, please correct it, thanks! :-) Bo May.30, 2001
RE: Servlets and relative paths
Just use a config file to point to the files / directories you want to load. You can put the file location of the config file in the web.xml. Mvgr, Martin -Original Message- From: Ronald G. Louzon [mailto:[EMAIL PROTECTED]] Sent: Wednesday, May 30, 2001 2:41 PM To: '[EMAIL PROTECTED]' Subject: RE: Servlets and relative paths I found this in the archives (http://marc.theaimsgroup.com ). You might search them for more info if this doesn't work. If you put the file in your servlet's classpath, this code, which in this case is accessing a properties file, should allow you to access the file. - InputStream is = this.getClass().getResourceAsStream(myapp.properties); Properties p = new Properties(); try p.load(is); } catch ( java.io.IOException e ) // Can't load props file -Original Message- From: Chris McNeilly [mailto:[EMAIL PROTECTED]] Sent: Tuesday, May 29, 2001 11:32 AM To: [EMAIL PROTECTED] Subject: Servlets and relative paths I've got a servlet and am trying to open files. The problem is that its defaulting to the tomcat/bin directory whenever I attempt to refer to them. How can I change this? Hardcoding the path isn't such a good idea as my dev environment is different from production. These are xml and xsl files and they are located on the webroot. Thanks, Chris
Re: Servlets and relative paths
Chris McNeilly wrote: I've got a servlet and am trying to open files. The problem is that its defaulting to the tomcat/bin directory whenever I attempt to refer to them. How can I change this? Hardcoding the path isn't such a good idea as my dev environment is different from production. These are xml and xsl files and they are located on the webroot. Thanks, Chris Hi :-) from several emails in Servlet-List and this List: * InputStream is = this.getServletContext(). getResourceAsStream(/WEB-INF/testApp.properties); now testApp.properties is in myapp/WEB-INF/ * - InputStream is = this.getClass().getResourceAsStream(testApp.properties); - InputStream is = Thread.currentThread().getContextClassLoader(). getResourceAsStream(myservlet.conf); now, (normally), myservlet.conf/testApp.properties is in myapp/WEB-INF/classes Bo May.29, 2001