[jdom-interest] caching JAXP Template from within an .ear archive
Crook, Charles
CrookC at tvratings.com
Thu Aug 1 06:19:21 PDT 2002
Using JDOM, I'm trying to cache Templates for xsl files contained within the
.ear file. The Source gets created as non-null, but I get an Exception on
the newTemplates call:
javax.xml.transform.TransformerConfigurationException: Did not find the
stylesheet root!
I know the stylesheets are valid, because they are used succesfully when we
just use a TransformerFactory instead of Templates on them:
This works:
TransformerFactory tFactory = TransformerFactory.newInstance();
StringReader xmlReader = new StringReader( xmlString );
StreamSource streamSource = new StreamSource( xmlReader ) ;
Transformer transformer = null ;
if ( xslStylesheet == null || xslStylesheet.equals( "" )) {
Source stylesheet = tFactory.getAssociatedStylesheet
( streamSource, media, title, charset);
transformer = tFactory.newTransformer(stylesheet);
}else{
String xslFileName = localHost + getStyleDir() +
xslStylesheet ;
// use direct transformer construction
transformer = tFactory.newTransformer(
new StreamSource( xslFileName ) );
...
This doesn't
// the ServletContext server_context was previously set by a calling
servlet
if ( server_context != null ){
try{
if ( !xsltFileName.startsWith( "/" ) ) {
xsltFileName = "/" + xsltFileName ;
}
xsltURL = server_context.getResource( xsltFileName )
;
Syslog.info( "StylesheetCache", "Locating xsl file
in archive: " + xsltURL.toExternalForm() ) ;
} catch ( MalformedURLException ex ){
Syslog.error( "StylesheetCache", "Unable to load: "
+ xsltFileName + " Exception: " + ex ) ;
}
}
Source xslSource = new StreamSource( xsltURL.toExternalForm() );
if ( xslSource == null ){
Syslog.warning( "StylesheetCache", "Null Source created" ) ;
}else{
Syslog.info( "StylesheetCache", "Source created" ) ;
}
TransformerFactory transFact = TransformerFactory.newInstance( );
Templates templates = transFact.newTemplates(xslSource);
if ( templates == null ){
Syslog.warning( "StylesheetCache", "Null templates created"
) ;
}else{
Syslog.warning( "StylesheetCache", "Templates created" ) ;
}
More information about the jdom-interest
mailing list