You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@turbine.apache.org by Eric J Altman <ea...@speakeasy.org> on 2001/03/05 12:09:26 UTC
Patch to TurbineXSLTService
Hello,
I thought it might be a good idea to update the xalan jar checked into
cvs to xalan-2.0.0.jar, so I patched the TurbineXSLTService to use
TrAX. Leon, could you or someone else review and check in the patch +
a newer xalan jar
(http://xml.apache.org/dist/xalan-j/xalan-j_2_0_0.tar.gz) if
appropriate? Are there any other dependencies on the old xalan
(documentation for instance)?
Regards,
~Eric
--
Eric J Altman
ealtman@studiotan.com
In the creative leap, history waits outside.
--Guitar Craft aphorism
? jakarta-turbine/lib/xalan-2.0.0.jar
Index: jakarta-turbine/src/java/org/apache/turbine/services/xslt/TurbineXSLTService.java
===================================================================
RCS file: /home/cvspublic/jakarta-turbine/src/java/org/apache/turbine/services/xslt/TurbineXSLTService.java,v
retrieving revision 1.3
diff -u -r1.3 TurbineXSLTService.java
--- jakarta-turbine/src/java/org/apache/turbine/services/xslt/TurbineXSLTService.java 2001/02/08 23:55:46 1.3
+++ jakarta-turbine/src/java/org/apache/turbine/services/xslt/TurbineXSLTService.java 2001/03/05 10:26:17
@@ -64,13 +64,13 @@
//import org.apache.turbine.services.Service;
import org.apache.turbine.services.*;
import org.apache.turbine.services.resources.TurbineResources;
-import org.apache.turbine.util.*;
-import org.apache.turbine.modules.*;
-import org.apache.turbine.util.assemblerbroker.*;
// Xalan classes
-import org.xml.sax.SAXException;
-import org.apache.xalan.xslt.*;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.Templates;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.stream.StreamResult;
+import javax.xml.transform.stream.StreamSource;
/**
@@ -155,50 +155,48 @@
}
/**
- * Compile a new StylesheetRoot from an input file.
+ * Compile a new Templates object from an input file.
*/
- protected StylesheetRoot compileStylesheetRoot (String source) throws Exception
+ protected Templates compileTemplates (String source) throws Exception
{
- XSLTProcessor processor = XSLTProcessorFactory.getProcessor();
-
- XSLTInputSource xslin = new XSLTInputSource("file:///"+source);
- StylesheetRoot root = processor.processStylesheet(xslin);
-
- return root;
+ TransformerFactory transformerfactory = TransformerFactory.newInstance();
+ Templates templates =
+ transformerfactory.newTemplates(new StreamSource("file:///"+source));
+ return templates;
}
/**
- * Retrieves a StylesheetRoot. If caching is switched on the
- * first attempt is to load the StylesheetRoot from the cache.
+ * Retrieves a Templates object. If caching is switched on the
+ * first attempt is to load the Templates object from the cache.
* If caching is switched of or if the Stylesheet is not found
- * in the cache a new StyleSheetRoot is compiled from an input
+ * in the cache a new Templates object is compiled from an input
* file.
* <p>
* This method is synchronized on the xsl cache so that a thread
- * does not attempt to load a StyleSheetRoot from the cache while
+ * does not attempt to load a Templates object from the cache while
* it is still being compiled.
*/
- protected StylesheetRoot getStylesheetRoot(String xslName) throws Exception
+ protected Templates getTemplates(String xslName) throws Exception
{
synchronized (cache)
{
if (caching && cache.containsKey (xslName))
{
- return (StylesheetRoot)cache.get(xslName);
+ return (Templates)cache.get(xslName);
}
String fn = getFileName (xslName);
if (fn == null) return null;
- StylesheetRoot sr = compileStylesheetRoot (fn);
+ Templates templates = compileTemplates (fn);
if (caching)
{
- cache.put (xslName,sr);
+ cache.put (xslName,templates);
}
- return sr;
+ return templates;
}
}
@@ -208,14 +206,10 @@
*/
public void transform (String xslName, Reader in, Writer out) throws Exception
{
- XSLTProcessor processor = XSLTProcessorFactory.getProcessor();
- XSLTInputSource xmlin = new XSLTInputSource(in);
- XSLTResultTarget xmlout = new XSLTResultTarget(out);
-
- StylesheetRoot sr = getStylesheetRoot(xslName);
+ Templates templates = getTemplates(xslName);
// If there is no stylesheet we just echo the xml
- if (sr == null)
+ if (templates == null)
{
String line;
BufferedReader br = new BufferedReader (in);
@@ -229,8 +223,8 @@
}
else
{
- processor.setStylesheet (sr);
- processor.process(xmlin, null, xmlout);
+ Transformer transformer = templates.newTransformer();
+ transformer.transform(new StreamSource(in), new StreamResult(out));
}
}