You are viewing a plain text version of this content. The canonical link for it is here.
Posted to taglibs-dev@jakarta.apache.org by Brian Devries <bd...@intraware.com> on 2001/09/21 23:01:52 UTC
Adding URIResolver functionality to XTags StyleTag
I have run into a probelm using the style tag when trying to use
includes/imports. I would like to suggest that the StyleTag from xtags
configure the xslt transformer so that it resolves all included and
imported stylesheets in the same way the tag resolves a URI, for
example, through a URL, a relative URL, or a resource.
Here's the code I've added to my version of xtags:
public int doEndTag() throws JspException {
if ( xml == null || xsl == null ) {
throw new JspException( "Must specify both XML and an XSLT
to style" );
}
// Prepare an input source for the data
Source data = getSource(xml);
// Prepare an input source for the stylesheet
Source style = getSource(xsl);
// Prepare an output source for the outputs
Result result = getResult();
// Use JAXP to perform the stylesheet
try {
TransformerFactory factory =
TransformerFactory.newInstance();
factory.setURIResolver(new URIResolver() {
public Source resolve(String href, String base)
throws TransformerException {
try {
return getSource(href);
}
catch(javax.servlet.jsp.JspException e) {
return null;
}
}
});
Transformer transformer = factory.newTransformer(style);
configure(transformer);
transformer.transform( data, result );
if ( stringWriter != null ) {
pageContext.getOut().write( stringWriter.toString() );
}
}
catch (TransformerException e) {
handleException(e);
}
catch (IOException e) {
handleException(e);
}
finally {
stringWriter = null;
}
return EVAL_PAGE;
}
-Brian De Vries
--
Brian De Vries -- Sr. Software Engineer
mailto:bdevries@intraware.com http://www.intraware.com
Voice: 925.253.6516 Fax: 925.253.4542
-------------------------------------------------------
Intraware...Control Your Technology
Re: Adding URIResolver functionality to XTags StyleTag
Posted by James Strachan <ja...@yahoo.co.uk>.
Hi Brian
Sorry for the delay getting back to you, I've been on a short vacation and
it took a while to catch up.
Great idea, using a URIResolver. I've applied your patch, its now in CVS and
should make the next nightly build.
Thanks!
James
----- Original Message -----
From: "Brian Devries" <bd...@intraware.com>
To: <ta...@jakarta.apache.org>
Sent: Friday, September 21, 2001 10:01 PM
Subject: Adding URIResolver functionality to XTags StyleTag
> I have run into a probelm using the style tag when trying to use
> includes/imports. I would like to suggest that the StyleTag from xtags
> configure the xslt transformer so that it resolves all included and
> imported stylesheets in the same way the tag resolves a URI, for
> example, through a URL, a relative URL, or a resource.
>
> Here's the code I've added to my version of xtags:
>
> public int doEndTag() throws JspException {
> if ( xml == null || xsl == null ) {
> throw new JspException( "Must specify both XML and an XSLT
> to style" );
> }
>
> // Prepare an input source for the data
> Source data = getSource(xml);
>
> // Prepare an input source for the stylesheet
> Source style = getSource(xsl);
>
> // Prepare an output source for the outputs
> Result result = getResult();
>
> // Use JAXP to perform the stylesheet
> try {
> TransformerFactory factory =
> TransformerFactory.newInstance();
> factory.setURIResolver(new URIResolver() {
>
> public Source resolve(String href, String base)
> throws TransformerException {
> try {
> return getSource(href);
> }
> catch(javax.servlet.jsp.JspException e) {
> return null;
> }
> }
>
> });
> Transformer transformer = factory.newTransformer(style);
> configure(transformer);
> transformer.transform( data, result );
> if ( stringWriter != null ) {
> pageContext.getOut().write( stringWriter.toString() );
> }
> }
> catch (TransformerException e) {
> handleException(e);
> }
> catch (IOException e) {
> handleException(e);
> }
> finally {
> stringWriter = null;
> }
> return EVAL_PAGE;
> }
>
> -Brian De Vries
>
> --
> Brian De Vries -- Sr. Software Engineer
> mailto:bdevries@intraware.com http://www.intraware.com
> Voice: 925.253.6516 Fax: 925.253.4542
> -------------------------------------------------------
> Intraware...Control Your Technology
>
_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com