Return-Path: Delivered-To: apmail-jakarta-tomcat-user-archive@jakarta.apache.org Received: (qmail 66963 invoked by uid 500); 5 Jun 2001 05:51:21 -0000 Mailing-List: contact tomcat-user-help@jakarta.apache.org; run by ezmlm Precedence: bulk Reply-To: tomcat-user@jakarta.apache.org list-help: list-unsubscribe: list-post: Delivered-To: mailing list tomcat-user@jakarta.apache.org Received: (qmail 66872 invoked from network); 5 Jun 2001 05:51:16 -0000 Received: from hw.intnet.mu (HELO hwmg?nt.hw.intnet.mu) (202.123.30.75) by h31.sny.collab.net with SMTP; 5 Jun 2001 05:51:16 -0000 Received: by HWMG_NT with Internet Mail Service (5.5.2653.19) id ; Tue, 5 Jun 2001 09:52:41 +0400 Message-ID: <713BD7F3A60FD511AB4700805FFED9120C2A96@HWMG_NT> From: Viksen Pillay Narrainen To: tomcat-user@jakarta.apache.org Subject: RE: Servlets and relative paths Date: Tue, 5 Jun 2001 09:52:40 +0400 MIME-Version: 1.0 X-Mailer: Internet Mail Service (5.5.2653.19) Content-Type: multipart/alternative; boundary="----_=_NextPart_001_01C0ED83.BB8EA3C0" X-Spam-Rating: h31.sny.collab.net 1.6.2 0/1000/N This message is in MIME format. Since your mail reader does not understand this format, some or all of this message may not be legible. ------_=_NextPart_001_01C0ED83.BB8EA3C0 Content-Type: text/plain; charset="iso-8859-1" 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:jgaer@clearcommerce.com] Sent: Tuesday, June 05, 2001 00:39 To: 'tomcat-user@jakarta.apache.org' 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:v.narrainen@hw.intnet.mu] Sent: Monday, June 04, 2001 1:04 AM To: tomcat-user@jakarta.apache.org 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, and set it for my instance of TransformerFactory. The transformers instantiated by this factory then rely on my URIResolver implentation to resolve . 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:ccox@cincom.com] Sent: Friday, June 01, 2001 16:45 To: 'tomcat-user@jakarta.apache.org' 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:cmcneilly@smartbrief.com ] Sent: Wednesday, May 30, 2001 2:22 PM To: tomcat-user@jakarta.apache.org 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 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:bo@cybershop.ca ] > Sent: Wednesday, May 30, 2001 10:45 AM > To: tomcat-user@jakarta.apache.org > 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 > > > > ------_=_NextPart_001_01C0ED83.BB8EA3C0 Content-Type: text/html; charset="iso-8859-1" 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:jgaer@clearcommerce.com]
Sent: Tuesday, June 05, 2001 00:39
To: 'tomcat-user@jakarta.apache.org'
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:v.narrainen@hw.intnet.mu]
Sent: Monday, June 04, 2001 1:04 AM
To: tomcat-user@jakarta.apache.org
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, and set 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:ccox@cincom.com]
Sent: Friday, June 01, 2001 16:45
To: 'tomcat-user@jakarta.apache.org'
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:cmcneilly@smartbrief.com]
Sent: Wednesday, May 30, 2001 2:22 PM
To: tomcat-user@jakarta.apache.org
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:bo@cybershop.ca]
> Sent: Wednesday, May 30, 2001 10:45 AM
> To: tomcat-user@jakarta.apache.org
> 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
>
>
>
>

------_=_NextPart_001_01C0ED83.BB8EA3C0--