You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by vg...@apache.org on 2002/01/23 01:29:16 UTC
cvs commit: xml-cocoon2/src/java/org/apache/cocoon/components/xslt XSLTProcessor.java XSLTProcessorImpl.java
vgritsenko 02/01/22 16:29:16
Modified: src/java/org/apache/cocoon/components/xslt
XSLTProcessor.java XSLTProcessorImpl.java
Log:
- Do not serialize SAX source and parse again, use toSAX method directly.
- No need for entity resolver here. Source already have entity resolver.
Revision Changes Path
1.2 +2 -2 xml-cocoon2/src/java/org/apache/cocoon/components/xslt/XSLTProcessor.java
Index: XSLTProcessor.java
===================================================================
RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/xslt/XSLTProcessor.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- XSLTProcessor.java 3 Jan 2002 12:31:15 -0000 1.1
+++ XSLTProcessor.java 23 Jan 2002 00:29:16 -0000 1.2
@@ -59,7 +59,7 @@
* @exception ProcessingException if an error occurs
*/
TransformerHandler getTransformerHandler(Source stylesheet,
- XMLFilter filter)
+ XMLFilter filter)
throws ProcessingException;
/**
@@ -89,6 +89,6 @@
* @exception ProcessingException if an error occurs
*/
void transform(Source source, Source stylesheet, Parameters params,
- Result result)
+ Result result)
throws ProcessingException;
}
1.5 +33 -64 xml-cocoon2/src/java/org/apache/cocoon/components/xslt/XSLTProcessorImpl.java
Index: XSLTProcessorImpl.java
===================================================================
RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/xslt/XSLTProcessorImpl.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- XSLTProcessorImpl.java 22 Jan 2002 00:17:12 -0000 1.4
+++ XSLTProcessorImpl.java 23 Jan 2002 00:29:16 -0000 1.5
@@ -12,14 +12,12 @@
import org.apache.avalon.framework.component.ComponentException;
import org.apache.avalon.framework.component.ComponentManager;
import org.apache.avalon.framework.component.Composable;
-import org.apache.avalon.framework.configuration.Configurable;
-import org.apache.avalon.framework.configuration.Configuration;
-import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.avalon.framework.logger.AbstractLoggable;
import org.apache.avalon.framework.parameters.Parameters;
+import org.apache.avalon.framework.parameters.Parameterizable;
+import org.apache.avalon.framework.parameters.ParameterException;
import org.apache.cocoon.ResourceNotFoundException;
import org.apache.cocoon.ProcessingException;
-import org.apache.cocoon.components.resolver.Resolver;
import org.apache.cocoon.components.store.Store;
import org.apache.cocoon.environment.Source;
import org.apache.cocoon.environment.SourceResolver;
@@ -28,6 +26,7 @@
import org.xml.sax.InputSource;
import org.xml.sax.XMLFilter;
import org.xml.sax.XMLReader;
+import org.xml.sax.ContentHandler;
import org.xml.sax.helpers.XMLReaderFactory;
import javax.xml.transform.URIResolver;
@@ -78,7 +77,7 @@
*/
public class XSLTProcessorImpl
extends AbstractLoggable
- implements XSLTProcessor, Composable, Disposable, Configurable, URIResolver, Component
+ implements XSLTProcessor, Composable, Disposable, Parameterizable, URIResolver, Component
{
protected ComponentManager manager;
@@ -93,14 +92,12 @@
/** Is the store turned on? (default is on) */
boolean useStore = true;
+
/** Is incremental processing turned on? (default for Xalan: no) */
boolean incrementalProcessing = false;
SourceResolver resolver;
- /** the Entity Resolver */
- protected Resolver entityResolver;
-
/**
* Compose.
* Try to get the store and the entity resolver (optional)
@@ -110,10 +107,6 @@
this.manager = manager;
getLogger().debug("XSLTProcessorImpl component initialized.");
store = (Store)manager.lookup(Store.ROLE);
- if ( manager.hasComponent( Resolver.ROLE ) ) {
- getLogger().debug("Looking up " + Resolver.ROLE);
- this.entityResolver = (Resolver)manager.lookup(Resolver.ROLE);
- }
}
/**
@@ -122,22 +115,19 @@
public void dispose() {
if (this.manager != null) {
this.manager.release((Component)store);
- this.manager.release((Component)entityResolver);
}
}
/**
* Configure the component
*/
- public void configure(Configuration conf)
- throws ConfigurationException
+ public void parameterize(Parameters params)
+ throws ParameterException
{
- Parameters params = Parameters.fromConfiguration(conf);
useStore = params.getParameterAsBoolean("use-store", true);
incrementalProcessing = params.getParameterAsBoolean("incremental-processing", false);
String factoryName = params.getParameter("transformer-factory", null);
-
if (factoryName == null) {
// Will use default TRAX mechanism
this.tfactoryClass = null;
@@ -148,11 +138,11 @@
try {
this.tfactoryClass = ClassUtils.loadClass(factoryName);
} catch(ClassNotFoundException cnfe) {
- throw new ConfigurationException("Cannot load TransformerFactory class", cnfe);
+ throw new ParameterException("Cannot load TransformerFactory class", cnfe);
}
if (! TransformerFactory.class.isAssignableFrom(tfactoryClass)) {
- throw new ConfigurationException("Class " + factoryName + " isn't a TransformerFactory");
+ throw new ParameterException("Class " + factoryName + " isn't a TransformerFactory");
}
}
}
@@ -168,44 +158,30 @@
throws ProcessingException
{
try {
- final InputSource is = stylesheet.getInputSource();
- final String id = is.getSystemId();
+ final String id = stylesheet.getSystemId();
Templates templates = getTemplates(stylesheet, id);
- if(templates == null) {
+ if (templates == null) {
if (this.getLogger().isDebugEnabled()) {
- getLogger().debug("Creating new Templates in " + this + " for " + is);
- if (id != null)
- getLogger().debug(" with system id " + id);
+ getLogger().debug("Creating new Templates for " + id);
}
- //templates = getTransformerFactory().newTemplates(new SAXSource(is));
-
// Create a Templates ContentHandler to handle parsing of the
// stylesheet.
TemplatesHandler templatesHandler
= getTransformerFactory().newTemplatesHandler();
- // Create an XMLReader and set its ContentHandler.
- XMLReader reader = XMLReaderFactory.createXMLReader();
- reader.setFeature("http://xml.org/sax/features/namespace-prefixes",
- true);
-
if (filter != null) {
- filter.setParent(reader);
filter.setContentHandler(templatesHandler);
- } else {
- reader.setContentHandler(templatesHandler);
}
- if (this.entityResolver != null)
- reader.setEntityResolver(this.entityResolver);
if (this.getLogger().isDebugEnabled()) {
- getLogger().debug("InputSource = " + is
- + ", templatesHandler = " + templatesHandler
- + ", reader = " + reader);
+ getLogger().debug("Source = " + stylesheet
+ + ", templatesHandler = " + templatesHandler);
}
- // Parse the stylesheet.
- reader.parse(is);
+
+ // Process the stylesheet.
+ stylesheet.toSAX(filter != null ?
+ (ContentHandler)filter : (ContentHandler)templatesHandler);
// Get the Templates object (generated during the parsing of
// the stylesheet) from the TemplatesHandler.
@@ -213,26 +189,30 @@
putTemplates (templates, stylesheet, id);
} else {
if (this.getLogger().isDebugEnabled()) {
- getLogger().debug("Reusing Templates in " + this + " for " + is);
- if (id != null)
- getLogger().debug(" with system id " + id);
+ getLogger().debug("Reusing Templates for " + id);
}
}
TransformerHandler handler
= getTransformerFactory().newTransformerHandler(templates);
+
+ /* (VG)
+ From http://java.sun.com/j2se/1.4/docs/api/javax/xml/transform/TransformerFactory.html#newTemplates(javax.xml.transform.Source)
+ Or http://xml.apache.org/xalan-j/apidocs/javax/xml/transform/TransformerFactory.html#newTemplates(javax.xml.transform.Source)
+
+ "Returns: Templates object capable of being used for transformation
+ purposes, never null."
if (handler == null) {
- /* If there is a problem in getting the handler, try using a
- * brand new Templates object */
+
if (this.getLogger().isDebugEnabled()) {
- getLogger().debug("Re-creating new Templates in " + this + " for" + is);
- if (id != null)
- getLogger().debug(" with system id " + id);
+ getLogger().debug("Re-creating new Templates for " + id);
}
- templates = getTransformerFactory().newTemplates(new SAXSource(is));
+
+ templates = getTransformerFactory().newTemplates(new SAXSource(stylesheet.getInputSource()));
putTemplates (templates, stylesheet, id);
handler = getTransformerFactory().newTransformerHandler(templates);
}
+ */
handler.getTransformer()
.setErrorListener(new TraxErrorHandler(getLogger()));
@@ -268,25 +248,14 @@
InputSource is = source.getInputSource();
InputStream bs = is.getByteStream();
getLogger().debug("XSLTProcessorImpl: starting transform");
+ // FIXME (VG): Is it possible to use Source's toSAX method?
try {
transformer.transform(new StreamSource(bs, is.getSystemId()),
result);
} finally {
bs.close();
}
- if (this.getLogger().isDebugEnabled()) {
- getLogger().debug("XSLTProcessorImpl: transform done");
- if (result instanceof StreamResult) {
- Writer writer = ((StreamResult)result).getWriter();
- getLogger().debug("XSLTProcessorImpl: transform result = "
- + writer);
- if (writer instanceof StringWriter) {
- StringBuffer stringBuffer = ((StringWriter)writer).getBuffer();
- getLogger().debug("XSLTProcessorImpl: transform result = "
- + stringBuffer);
- }
- }
- }
+ getLogger().debug("XSLTProcessorImpl: transform done");
} catch (Exception e) {
throw new ProcessingException("Error in running Transformation", e);
}
----------------------------------------------------------------------
In case of troubles, e-mail: webmaster@xml.apache.org
To unsubscribe, e-mail: cocoon-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: cocoon-cvs-help@xml.apache.org