PDA

View Full Version : Add XSLT system ID to support realitive xsl:import paths


msqr
08-12-2004, 12:48 AM
I'm using the AbstractXsltView and I'd like to use relative paths in my xsl:import. In the past I've accomplished this by setting a system ID to StreamSource objects upon their construction. Here's a patch to AbstractXsltView that accomplishes this (I've only tested running within a web container (Tomcat)):


Index: AbstractXsltView.java
================================================== =================
RCS file: /cvsroot/springframework/spring/src/org/springframework/web/servlet/view/xslt/AbstractXsltView.java,v
retrieving revision 1.12
diff -u -r1.12 AbstractXsltView.java
--- AbstractXsltView.java 29 Jun 2004 12:09:43 -0000 1.12
+++ AbstractXsltView.java 12 Aug 2004 05:34:52 -0000
@@ -18,6 +18,7 @@

import java.io.BufferedOutputStream;
import java.io.IOException;
+import java.net.URL;
import java.util.Iterator;
import java.util.Map;

@@ -168,7 +169,10 @@
logger.debug("Loading XSLT stylesheet from " + stylesheetLocation);
}
try {
- return new StreamSource(stylesheetLocation.getInputStream());
+ URL url = stylesheetLocation.getURL();
+ String urlPath = url.toString();
+ String systemId = urlPath.substring(0,urlPath.lastIndexOf('/')+1);
+ return new StreamSource(url.openStream(),systemId);
}
catch (IOException ex) {
throw new ApplicationContextException("Can't load XSLT stylesheet from " + stylesheetLocation, ex);


(Are these new forums the place for patch submissions now?)

davison
08-12-2004, 03:30 AM
I think JIRA is more appropriate for patches..
http://opensource.atlassian.com/projects/spring/

msqr
08-12-2004, 10:09 AM
Ah yes, thank you, I'll post it there!

jmakeig
08-13-2004, 01:55 AM
If this works, it's certainly easier than implementing a custom UriResolver as I did.

msqr
08-13-2004, 12:04 PM
I created a report in JIRA on this issue:

http://opensource.atlassian.com/projects/spring/browse/SPR-261

This does work, so that you don't need to create a custom UriResolver. You can test this out by extending AbstractXsltView and overriding the getStylesheetSource() method to implement this patch:


/**
* Load the stylesheet. Subclasses can override this.
*/
protected Source getStylesheetSource(Resource stylesheetLocation) throws ApplicationContextException {
if (logger.isDebugEnabled()) {
logger.debug("Loading XSLT stylesheet from " + stylesheetLocation);
}
try {
URL url = stylesheetLocation.getURL();
String urlPath = url.toString();
String systemId = urlPath.substring(0,urlPath.lastIndexOf('/')+1);
return new StreamSource(url.openStream(),systemId);
}
catch (IOException ex) {
throw new ApplicationContextException("Can't load XSLT stylesheet from " + stylesheetLocation, ex);
}
}