Bug 4029 - StyleTag.getSource(Object)
Summary: StyleTag.getSource(Object)
Status: CLOSED FIXED
Alias: None
Product: Taglibs
Classification: Unclassified
Component: XTags Taglib (show other bugs)
Version: unspecified
Hardware: PC All
: P3 normal (vote)
Target Milestone: ---
Assignee: Tomcat Developers Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2001-10-08 14:30 UTC by margaret.lu
Modified: 2005-03-20 17:06 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description margaret.lu 2001-10-08 14:30:11 UTC
I originally used ApplyTag for xml/xslt transformation on VisualAge test 
environment and it worked fine.  After I changed to StyleTag, I have to add the 
whole path, starting from c: drive root, to the file parameters, as "/Program 
Files/IBM/VisualAge for Java/ide/project_resources/IBM WebSphere Test 
Environment/hosts/default_host/default_app/web/header.xslt" instead 
of "header.xslt", otherwise, it won't find the file.

I tried to change the code like ApplyTag, and it works fine.  So, I wonder why 
you change the code on StyleTag.  Do you have any reason for the change?

The change I made on StyleTag is as follows (in StyleTag.getSource(Object):
/*	        
 try {	            
    URL url = URLHelper.createURL( (String) source, pageContext );
    //return new StreamSource(url.toExternalForm());
    return new StreamSource(url.openStream(), url.toExternalForm());
*/

 ServletContext context =pageContext.getServletContext();
 InputStream stream=context.getResourceAsStream((String)source);
 return new StreamSource(stream);

/* 				
 }
           
  catch (IOException e) {
  throw new JspException("Bad URL:"+source + ". Exception: " + e.getMessage() 
  );
 }
*/ 

The part I comment out is the original code.

I appreciate if you can take a look and let me know your thoughts.

Margaret
Comment 1 James Strachan 2001-10-08 14:36:41 UTC
Is ../default_host/default_app/web the directory that contains the WEB-INF 
directory and the WEB-INF/web.xml file?

If so, try changing your XSLT document to "/header.xslt". All web-context 
relative URIs should start with "/" if they are meant to be relative to the web 
root.

Let me know if that fixes it or if there is still a problem.

James
Comment 2 margaret.lu 2001-10-08 15:45:00 UTC
James,
Thanks for the prompt response.  
I don't have web.xml file and I put xtags.tld file under 
../default_host/default_app/web/jakarta-taglibs/Web-inf/ and I specify 
the file location as 
<%@taglib uri="/jakarta-taglibs/Web-inf/xtags.tld" prefix="xsl" %> on the first 
line of my jsp file.  I hope the setting is OK.  Actually it runs well, only 
thing is that I need specify the whole physical path.
 
I run the code as you suggested, I got NullPointerException at 
StyleTag.getSource(java.lang.Object).  It can not find the file specified.

Do you have a reason for changing the code as mentioned earlier?

Thanks
Margaret
Comment 3 James Strachan 2001-10-08 16:45:17 UTC
Because if your URL starts with a '/' then the code should use

pageContext.getServletContext().getResource( uri );.

Look at the implementation of URLHelper.getResourceURL() which is called via 
the getSource() method;
Comment 4 James Strachan 2001-11-09 10:23:13 UTC
I'm assuming that the resolution was to prefix your stylesheet or XML source 
file with "/".

<xtags:style xsl="/foo.xsl">

So I'm marking this bug as resolved.