You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xalan.apache.org by Michael Engelhart <me...@earthtrip.com> on 2002/03/01 22:16:01 UTC

xalan extensions classpath

Hi,

I have a stylesheet with the following in it:

<xsl:variable name="language" select="/Document/@Language" />
<xsl:variable name="country" select="/Document/@Country" />
<xsl:variable name="locale" select="java:java.util.Locale.new($language, 
$country)" />
<xsl:variable name="i18nBundle" 
select="java:java.util.ResourceBundle.getBundle('clients.someclient.i18n', 
$locale)" />


This standalone application has the directory that contains 
"clients/someclient" in the classpath and I can easily call:
ResourceBundle bundle = 
ResourceBundle.getBundle("clients.someclient.i18n");
without throwing a MissingResourceException from anywhere in my java 
class files.  I can also do transforms with Xalan as well but when I 
include the above XSL extension code I get a MissingResourceException 
thrown.

So my question is how come Xalan isn't using the applications classpath 
in it's extension mechanism?   Also I tried jarring up that clients 
directory and sticking it my Java Extensions directory (which on Mac OS 
X gets added to the classpath automatically) and it found the file 
fine.    But I want these properties files to be editable and not 
wrapped up in a jar.   The clients directory is to sit in the 
applications top level directory.

Any help/advice would be apprectiated.

Thanks
Mike


Mixing SAXSource and StreamResult?

Posted by Thad Humphries <th...@mindwrap.com>.
I have an XML file and a stylesheet that work from the command line
using org.apache.xalan.xslt.Process.  Now I'm trying to put do the work
via a JSP and display the results in the browser.  To make things
interesting, my JSP is explicity ignoring the DTD in the XML document
because I can't count on it being around in all cases.  My code looks
like this:

<%!
public class DTDResolver implements EntityResolver
{
    public InputSource resolveEntity( String publicId, String systemId )
    {
        if ( systemId.toLowerCase().endsWith( "dtd" ) )
        {
            return new InputSource( new StringReader( "" ) );
        }
        return null;
    }
};
%>      
<%
    byte [] docBuffer = // my XML document
    byte [] xsltBuffer = // my XXL document
...
    TransformerFactory tFactory = TransformerFactory.newInstance();
    Transformer transformer = tFactory.newTransformer( new 
        StreamSource( new ByteArrayInputStream( xsltBuffer ) ) );

    SAXParserFactory factory = SAXParserFactory.newInstance();
    factory.setValidating( false );
    XMLReader reader = factory.newSAXParser().getXMLReader();
    reader.setEntityResolver( new DTDResolver() );
    SAXSource source = new SAXSource( reader, 
        new InputSource( new ByteArrayInputStream( docBuffer ) ) );

    transformer.transform( source,
       new StreamResult( out ) );
%>

My problem is that the output is *just* the XML docs' text data with
none of the XSL applied.  I have tested xstlBuffer and it contains my
XSL document.

What am I missing?  Can I mix a SAXSource and a StreamResult in my
transformer.transform()?  I've used Xalan 1 for a long while but just
got startd with Xalan 2 yesterday.  My other JSPs using StreamSource and
StreamResult (and following the example
http://xml.apache.org/xalan-j/usagepatterns.html#basic) works but this
one doesn't.

Thanks!

-- 
------------------------------------------------------------------------
Thad Humphries              "...no religious test shall ever be required
Web Development Manager      as a qualification to any office or public
Phone: 540/675-3015, x225    trust under the United States." -Article VI


Re: Extension: how to return java values from templates?

Posted by Brad Cox <bc...@virtualschool.edu>.
To rephrase my question in perhaps more familiar terms: how does one 
accomplish java-style subroutine return semantics in xslt/extensions. 
This table reflects my (possibly incorrect) understanding of how 
templates relate

	xslt				java
	call-template			subroutine()
	with-parameter			subroutine(argument)
	value-of			return ..
	apply-templates			no direct equivalent

That said, apparently some kind of conversion is imposed by xslt that 
coverts the return value from XMLFile to NODESET. My question is, how 
can this be avoided. Or is the above mental model the problem and 
things don't work this way at all?

At 5:03 PM -0500 3/6/02, Brad Cox wrote:
>Please pardon the newbie questions. Still rather new to this.
>
>This cut down example intends to compute instances of XMLFile in the 
>second template to be returned to the first template. However this 
>shows they being returned as #NODESETs, not java instances. How do I 
>get a plain old java-style return value from a xslt template?
>
>Exception:javax.xml.transform.TransformerException: 
>java.lang.NoSuchMethodException: For extension function, could not 
>find method 
>edu.virtualschool.jile.ctlr.SiteMap.addController([ExpressionContext,] 
>#UNKNOWN (java.util.ArrayList), #NODESET, #NODESET).
>
><xsl:template match="ile:page">
>	<xsl:variable name="content" select="ile:content"/>
>	<xsl:variable name="template" select="ile:template"/>
>	<xsl:variable name="this" select="java:addController(
>		$sitemap,
>		$content,
>		$template
>	)"/>
>	<xsl:apply-templates select="ile:page"/>
></xsl:template>
>
><xsl:template match="ile:content|ile:template">
>	<xsl:variable name="xsl" select="ile:xsl"/>
>	<xsl:variable name="xml" select="ile:xml"/>
>	<xsl:value-of select="java:edu.virtualschool.jile.ctlr.XMLFile.new(
>		string($xsl),
>		string($xml)
>)"/>
></xsl:template>
>
>PS: ile is my project's namespace.
>--
>Brad Cox, PhD; bcox@virtualschool.edu 703 361 4751
>o For industrial age goods there were checks and credit cards.
>    For everything else there is http://virtualschool.edu/mybank
>o Java Interactive Learning Environment http://virtualschool.edu/jile
>o Java Web Application Architecture: http://virtualschool.edu/jwaa


-- 
Brad Cox, PhD; bcox@virtualschool.edu 703 361 4751
o For industrial age goods there were checks and credit cards.
    For everything else there is http://virtualschool.edu/mybank
o Java Interactive Learning Environment http://virtualschool.edu/jile
o Java Web Application Architecture: http://virtualschool.edu/jwaa


Re: Extension: how to return java values from templates?

Posted by "Frank E. Weiss" <fr...@well.com>.
Oh man, am I ever embarassed. I just realized what's wrong with this. I mistakenly thought that the select attributes in
the xsl:variable elements in the first xsl:template would invoke the second xsl:template. Nope. These select attributes
merely get ile:content and ile:template nodes from the input document and assign them to variables. I was confusing them
with the select attribute of an xsl:apply-templates element. Only in that case is a template from the stylesheet applied
to the selected nodes from the input document. So your description "compute instances of XMLFile in the second template
to be returned to the first template" does not describe the behavior of the stylesheet snippet you gave in the example.

Brad Cox wrote:

> Please pardon the newbie questions. Still rather new to this.
>
> This cut down example intends to compute instances of XMLFile in the
> second template to be returned to the first template. However this
> shows they being returned as #NODESETs, not java instances. How do I
> get a plain old java-style return value from a xslt template?
>
> Exception:javax.xml.transform.TransformerException:
> java.lang.NoSuchMethodException: For extension function, could not
> find method
> edu.virtualschool.jile.ctlr.SiteMap.addController([ExpressionContext,]
> #UNKNOWN (java.util.ArrayList), #NODESET, #NODESET).
>
> <xsl:template match="ile:page">
>         <xsl:variable name="content" select="ile:content"/>
>         <xsl:variable name="template" select="ile:template"/>
>         <xsl:variable name="this" select="java:addController(
>                 $sitemap,
>                 $content,
>                 $template
>         )"/>
>         <xsl:apply-templates select="ile:page"/>
> </xsl:template>
>
> <xsl:template match="ile:content|ile:template">
>         <xsl:variable name="xsl" select="ile:xsl"/>
>         <xsl:variable name="xml" select="ile:xml"/>
>         <xsl:value-of select="java:edu.virtualschool.jile.ctlr.XMLFile.new(
>                 string($xsl),
>                 string($xml)
> )"/>
> </xsl:template>
>
> PS: ile is my project's namespace.
> --
> Brad Cox, PhD; bcox@virtualschool.edu 703 361 4751
> o For industrial age goods there were checks and credit cards.
>     For everything else there is http://virtualschool.edu/mybank
> o Java Interactive Learning Environment http://virtualschool.edu/jile
> o Java Web Application Architecture: http://virtualschool.edu/jwaa


Re: Extension: how to return java values from templates?

Posted by Brad Cox <bc...@virtualschool.edu>.
I'm still stuck on this one. Some further details I accidentally 
omitted are that $sitemap is passed in as a parameter. Its an 
instance of the java class $SiteMap. Also the #UNKNOWN 
(java.util.ArrayList) refers to a Java ArrayList instance that is 
constructed in the first template and passed as the second argument 
to addController; I omitted it in stripping this example down. The 
question concerns the last two arguments, $content and $template, 
which are instantiated in the second template. The question is, how 
do I return them from of the second template so that they remain 
XMLFile instances. The value-of statements converts them to #NODESET 
which is not what I want.

At 5:03 PM -0500 3/6/02, Brad Cox wrote:
>Please pardon the newbie questions. Still rather new to this.
>
>This cut down example intends to compute instances of XMLFile in the 
>second template to be returned to the first template. However this 
>shows they being returned as #NODESETs, not java instances. How do I 
>get a plain old java-style return value from a xslt template?
>
>Exception:javax.xml.transform.TransformerException: 
>java.lang.NoSuchMethodException: For extension function, could not 
>find method 
>edu.virtualschool.jile.ctlr.SiteMap.addController([ExpressionContext,] 
>#UNKNOWN (java.util.ArrayList), #NODESET, #NODESET).
>
><xsl:template match="ile:page">
>	<xsl:variable name="content" select="ile:content"/>
>	<xsl:variable name="template" select="ile:template"/>
>	<xsl:variable name="this" select="java:addController(
>		$sitemap,
>		$content,
>		$template
>	)"/>
>	<xsl:apply-templates select="ile:page"/>
></xsl:template>
>
><xsl:template match="ile:content|ile:template">
>	<xsl:variable name="xsl" select="ile:xsl"/>
>	<xsl:variable name="xml" select="ile:xml"/>
>	<xsl:value-of select="java:edu.virtualschool.jile.ctlr.XMLFile.new(
>		string($xsl),
>		string($xml)
>)"/>
></xsl:template>
>
>PS: ile is my project's namespace.
>--
>Brad Cox, PhD; bcox@virtualschool.edu 703 361 4751
>o For industrial age goods there were checks and credit cards.
>    For everything else there is http://virtualschool.edu/mybank
>o Java Interactive Learning Environment http://virtualschool.edu/jile
>o Java Web Application Architecture: http://virtualschool.edu/jwaa

-- 
Brad Cox, PhD; bcox@virtualschool.edu 703 361 4751
o For industrial age goods there were checks and credit cards.
    For everything else there is http://virtualschool.edu/mybank
o Java Interactive Learning Environment http://virtualschool.edu/jile
o Java Web Application Architecture: http://virtualschool.edu/jwaa



Extension: how to return java values from templates?

Posted by Brad Cox <bc...@virtualschool.edu>.
Please pardon the newbie questions. Still rather new to this.

This cut down example intends to compute instances of XMLFile in the 
second template to be returned to the first template. However this 
shows they being returned as #NODESETs, not java instances. How do I 
get a plain old java-style return value from a xslt template?

Exception:javax.xml.transform.TransformerException: 
java.lang.NoSuchMethodException: For extension function, could not 
find method 
edu.virtualschool.jile.ctlr.SiteMap.addController([ExpressionContext,] 
#UNKNOWN (java.util.ArrayList), #NODESET, #NODESET).

<xsl:template match="ile:page">
	<xsl:variable name="content" select="ile:content"/>
	<xsl:variable name="template" select="ile:template"/>
	<xsl:variable name="this" select="java:addController(
		$sitemap,
		$content,
		$template
	)"/>
	<xsl:apply-templates select="ile:page"/>
</xsl:template>

<xsl:template match="ile:content|ile:template">
	<xsl:variable name="xsl" select="ile:xsl"/>
	<xsl:variable name="xml" select="ile:xml"/>
	<xsl:value-of select="java:edu.virtualschool.jile.ctlr.XMLFile.new(
		string($xsl),
		string($xml)
)"/>
</xsl:template>

PS: ile is my project's namespace.
-- 
Brad Cox, PhD; bcox@virtualschool.edu 703 361 4751
o For industrial age goods there were checks and credit cards.
    For everything else there is http://virtualschool.edu/mybank
o Java Interactive Learning Environment http://virtualschool.edu/jile
o Java Web Application Architecture: http://virtualschool.edu/jwaa



Re: xalan extensions classpath

Posted by Michael Engelhart <me...@earthtrip.com>.
Hey Gary,

Thanks so much for helping with this.     Moving Xalan-J into an 
application defined directory worked like a charm.  I completely 
misunderstood how the extensions directory worked in the context of the 
java.util.ResourceBundle class.   Anyway the xalan extensions now work 
and I'm a very happy camper.

Thanks again
Mike


On Monday, March 4, 2002, at 07:50  PM, Gary L Peskin wrote:

> It would be helpful here if you logged the full stack trace when your
> MissingResourceException occurred.  Perhaps, for debugging purposes, you
> could include an
>
>   e.printStackTrace()
>
> call in your catch clause before the throw.  Of course, you could write
> this to a String and then log it but that would be more work.
>
> I think the problem has to do with how ResourceBundle.getBundle()
> determines which classloader (and hence which path) to use when loading
> a resource bundle for the one and two argument forms of getBundle().
>> From what I can tell, ResourceBundle uses the classloader of its
> caller's caller.  This is why I need the stack trace to determine what's
> going on.  It's also why I think that things worked when you placed the
> file in your extensions directory.
>
> Is XalanJ in your extensions directory?
>
> If so, the problem is not in how XalanJ uses the CLASSPATH but in how
> ResourceBundle uses the CLASSPATH.  I think it's going to use the same
> classloader that loaded the XalanJ class
> org.apache.xalan.extensions.ExtensionHandlerJavaClass which I think will
> be in the stack trace in the second spot from the top (but I'd like to
> verify it).
>
> If you're going to put XalanJ in the extensions directory, that's where
> ResourceBundle is going to look for any resources that it loads, I'm
> afraid.  ResourceBundle doesn't try to use the current thread class
> loader.
>
> If you don't want to move XalanJ out of the extensions directory, mu
> siggestion is that you write your own extension instead of using
> java.util.ResourceBundle directly.  Your extension could simply call
> ResourceBundle.getBundle as:
>
>   return ResourceBundle.getBundle(baseName, locale,
> Thread.getContextClassLoader());
>
> HTH,
> Gary
>
>> -----Original Message-----
>> From: Michael Engelhart [mailto:mengelhart@earthtrip.com]
>> Sent: Friday, March 01, 2002 5:26 PM
>> To: Gary L Peskin
>> Cc: xalan-j-users@xml.apache.org
>> Subject: Re: xalan extensions classpath
>>
>>
>> Hi Gary,
>>
>> Here's the error output in my Log4J file:
>> ERROR [earthtrip]: XSLT Transformation failed:
>> java.util.MissingResourceException: Can't find bundle for base name
>> clients.earthtrip.i18n, locale en_US 2002-02-28 16:37:51,259
>>
>> JDK 1.3.1 on  Mac OS X
>> Xalan 2.2.0
>>
>> I'm not executing from the command line.  Just programmatically from
>> within my code.   Here's the code that loads the stylesheet
>> and does the
>> transform (I'm using JDOM 1.0b7 for XML).    The reason I'm assuming
>> this is a Xalan problem is because it only happens from within the
>> stylesheet extension.
>>
>> try {
>> 	Transformer transformer =
>> TransformerFactory.newInstance().newTransformer(new
>> StreamSource(stylesheet));
>> 	StreamResult out = new StreamResult(new StringWriter());
>> 	transformer.transform(new JDOMSource(this.doc), out);
>> 	StringWriter writer =  (StringWriter) out.getWriter();
>> 	return writer.getBuffer();
>> }
>> catch (Exception e) {
>> 	throw new JDOMException("XSLT Transformation failed", e);
>> }
>>
>>
>> Also I'm not getting a JDOMException but a
>> java.util.MissingResourceException
>> I have the classpath set in the application launcher to point to the
>> directory that contains the "client" directory so the rest of my code
>> can call it fine.
>>
>> Thanks for your help.
>>
>> Mike
>>
>>
>> On Friday, March 1, 2002, at 04:21  PM, Gary L Peskin wrote:
>>
>>> Hi, Mike --
>>>
>>> What version of XalanJ are you using?  What is your JDK
>> version?  Can
>>> you include the full stack trace of the MissingResourceException,
>>> please (you may need to include the -edump command line switch).
>>>
>>> Also, if you're executing XalanJ from the command line, can
>> you please
>>> type
>>>
>>>   java org.apache.xalan.xslt.EnvironmentCheck
>>>
>>> and include the output?
>>>
>>> Thanks,
>>> Gary
>>>
>>>> -----Original Message-----
>>>> From: Michael Engelhart [mailto:mengelhart@earthtrip.com]
>>>> Sent: Friday, March 01, 2002 1:16 PM
>>>> To: xalan-j-users@xml.apache.org
>>>> Subject: xalan extensions classpath
>>>>
>>>>
>>>> Hi,
>>>>
>>>> I have a stylesheet with the following in it:
>>>>
>>>> <xsl:variable name="language" select="/Document/@Language" />
>>>> <xsl:variable name="country" select="/Document/@Country" />
>>>> <xsl:variable name="locale"
>>>> select="java:java.util.Locale.new($language,
>>>> $country)" />
>>>> <xsl:variable name="i18nBundle"
>>>> select="java:java.util.ResourceBundle.getBundle('clients.somec
>>>> lient.i18n',
>>>> $locale)" />
>>>>
>>>>
>>>> This standalone application has the directory that contains
>>>> "clients/someclient" in the classpath and I can easily call:
>>>> ResourceBundle bundle =
>>>> ResourceBundle.getBundle("clients.someclient.i18n");
>>>> without throwing a MissingResourceException from anywhere
>> in my java
>>>> class files.  I can also do transforms with Xalan as well
>> but when I
>>>> include the above XSL extension code I get a
>> MissingResourceException
>>>> thrown.
>>>>
>>>> So my question is how come Xalan isn't using the applications
>>>> classpath
>>>> in it's extension mechanism?   Also I tried jarring up that clients
>>>> directory and sticking it my Java Extensions directory
>> (which on Mac
>>>> OS X gets added to the classpath automatically) and it
>> found the file
>>>> fine.    But I want these properties files to be editable and not
>>>> wrapped up in a jar.   The clients directory is to sit in the
>>>> applications top level directory.
>>>>
>>>> Any help/advice would be apprectiated.
>>>>
>>>> Thanks
>>>> Mike
>>>>
>>


RE: xalan extensions classpath

Posted by Gary L Peskin <ga...@firstech.com>.
It would be helpful here if you logged the full stack trace when your
MissingResourceException occurred.  Perhaps, for debugging purposes, you
could include an

  e.printStackTrace()

call in your catch clause before the throw.  Of course, you could write
this to a String and then log it but that would be more work.

I think the problem has to do with how ResourceBundle.getBundle()
determines which classloader (and hence which path) to use when loading
a resource bundle for the one and two argument forms of getBundle().

Re: xalan extensions classpath

Posted by Michael Engelhart <me...@earthtrip.com>.
Hi Gary,

Here's the error output in my Log4J file:
ERROR [earthtrip]: XSLT Transformation failed: 
java.util.MissingResourceException: Can't find bundle for base name 
clients.earthtrip.i18n, locale en_US 2002-02-28 16:37:51,259

JDK 1.3.1 on  Mac OS X
Xalan 2.2.0

I'm not executing from the command line.  Just programmatically from 
within my code.   Here's the code that loads the stylesheet and does the 
transform (I'm using JDOM 1.0b7 for XML).    The reason I'm assuming 
this is a Xalan problem is because it only happens from within the 
stylesheet extension.

try {
	Transformer transformer = 
TransformerFactory.newInstance().newTransformer(new 
StreamSource(stylesheet));
	StreamResult out = new StreamResult(new StringWriter());
	transformer.transform(new JDOMSource(this.doc), out);
	StringWriter writer =  (StringWriter) out.getWriter();
	return writer.getBuffer();
}
catch (Exception e) {
	throw new JDOMException("XSLT Transformation failed", e);
}


Also I'm not getting a JDOMException but a 
java.util.MissingResourceException
I have the classpath set in the application launcher to point to the 
directory that contains the "client" directory so the rest of my code 
can call it fine.

Thanks for your help.

Mike


On Friday, March 1, 2002, at 04:21  PM, Gary L Peskin wrote:

> Hi, Mike --
>
> What version of XalanJ are you using?  What is your JDK version?  Can
> you include the full stack trace of the MissingResourceException, please
> (you may need to include the -edump command line switch).
>
> Also, if you're executing XalanJ from the command line, can you please
> type
>
>   java org.apache.xalan.xslt.EnvironmentCheck
>
> and include the output?
>
> Thanks,
> Gary
>
>> -----Original Message-----
>> From: Michael Engelhart [mailto:mengelhart@earthtrip.com]
>> Sent: Friday, March 01, 2002 1:16 PM
>> To: xalan-j-users@xml.apache.org
>> Subject: xalan extensions classpath
>>
>>
>> Hi,
>>
>> I have a stylesheet with the following in it:
>>
>> <xsl:variable name="language" select="/Document/@Language" />
>> <xsl:variable name="country" select="/Document/@Country" />
>> <xsl:variable name="locale"
>> select="java:java.util.Locale.new($language,
>> $country)" />
>> <xsl:variable name="i18nBundle"
>> select="java:java.util.ResourceBundle.getBundle('clients.somec
>> lient.i18n',
>> $locale)" />
>>
>>
>> This standalone application has the directory that contains
>> "clients/someclient" in the classpath and I can easily call:
>> ResourceBundle bundle =
>> ResourceBundle.getBundle("clients.someclient.i18n");
>> without throwing a MissingResourceException from anywhere in my java
>> class files.  I can also do transforms with Xalan as well but when I
>> include the above XSL extension code I get a MissingResourceException
>> thrown.
>>
>> So my question is how come Xalan isn't using the applications
>> classpath
>> in it's extension mechanism?   Also I tried jarring up that clients
>> directory and sticking it my Java Extensions directory (which
>> on Mac OS
>> X gets added to the classpath automatically) and it found the file
>> fine.    But I want these properties files to be editable and not
>> wrapped up in a jar.   The clients directory is to sit in the
>> applications top level directory.
>>
>> Any help/advice would be apprectiated.
>>
>> Thanks
>> Mike
>>


RE: xalan extensions classpath

Posted by Gary L Peskin <ga...@firstech.com>.
Hi, Mike --

What version of XalanJ are you using?  What is your JDK version?  Can
you include the full stack trace of the MissingResourceException, please
(you may need to include the -edump command line switch).

Also, if you're executing XalanJ from the command line, can you please
type

  java org.apache.xalan.xslt.EnvironmentCheck

and include the output?

Thanks,
Gary

> -----Original Message-----
> From: Michael Engelhart [mailto:mengelhart@earthtrip.com] 
> Sent: Friday, March 01, 2002 1:16 PM
> To: xalan-j-users@xml.apache.org
> Subject: xalan extensions classpath
> 
> 
> Hi,
> 
> I have a stylesheet with the following in it:
> 
> <xsl:variable name="language" select="/Document/@Language" /> 
> <xsl:variable name="country" select="/Document/@Country" /> 
> <xsl:variable name="locale" 
> select="java:java.util.Locale.new($language, 
> $country)" />
> <xsl:variable name="i18nBundle" 
> select="java:java.util.ResourceBundle.getBundle('clients.somec
> lient.i18n', 
> $locale)" />
> 
> 
> This standalone application has the directory that contains 
> "clients/someclient" in the classpath and I can easily call: 
> ResourceBundle bundle = 
> ResourceBundle.getBundle("clients.someclient.i18n");
> without throwing a MissingResourceException from anywhere in my java 
> class files.  I can also do transforms with Xalan as well but when I 
> include the above XSL extension code I get a MissingResourceException 
> thrown.
> 
> So my question is how come Xalan isn't using the applications 
> classpath 
> in it's extension mechanism?   Also I tried jarring up that clients 
> directory and sticking it my Java Extensions directory (which 
> on Mac OS 
> X gets added to the classpath automatically) and it found the file 
> fine.    But I want these properties files to be editable and not 
> wrapped up in a jar.   The clients directory is to sit in the 
> applications top level directory.
> 
> Any help/advice would be apprectiated.
> 
> Thanks
> Mike
>