forrest-svn mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thors...@apache.org
Subject svn commit: r703429 - in /forrest/branches/dispatcher_rewrite/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher: factories/ impl/ impl/helper/ transformation/
Date Fri, 10 Oct 2008 12:05:50 GMT
Author: thorsten
Date: Fri Oct 10 05:05:50 2008
New Revision: 703429

URL: http://svn.apache.org/viewvc?rev=703429&view=rev
Log:
Sliming down the code and enhance performance.

Before we created a new instance for the xsl factory every time we prepared the transformation.
I extracted now the factory, so we make one instance for all contracts. 

Using the writable config bean to inject the needed properties and later on the read only
one. 

Dropping the uriResolver since it is part of the transfactory now.

Modified:
    forrest/branches/dispatcher_rewrite/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/factories/ContractFactory.java
    forrest/branches/dispatcher_rewrite/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/impl/XSLContract.java
    forrest/branches/dispatcher_rewrite/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/impl/helper/XSLContractHelper.java
    forrest/branches/dispatcher_rewrite/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/transformation/DispatcherTransformer.java

Modified: forrest/branches/dispatcher_rewrite/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/factories/ContractFactory.java
URL: http://svn.apache.org/viewvc/forrest/branches/dispatcher_rewrite/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/factories/ContractFactory.java?rev=703429&r1=703428&r2=703429&view=diff
==============================================================================
--- forrest/branches/dispatcher_rewrite/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/factories/ContractFactory.java
(original)
+++ forrest/branches/dispatcher_rewrite/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/factories/ContractFactory.java
Fri Oct 10 05:05:50 2008
@@ -68,7 +68,7 @@
        * requested contract does not exist. Otherwise it is a xsl based
        * contract.
        */
-      contract = new XSLContract(config.isAllowXmlProperties(),config.getUriResolver(),config.getStaxHelper());
+      contract = new XSLContract(config.isAllowXmlProperties(),config.getTransFact(),config.getStaxHelper());
       String uri = config.getContractUriPrefix() + name + config.getContractUriSufix();
       InputStream xslStream = config.getResolver().resolve(uri);
       contract.initializeFromStream(xslStream);

Modified: forrest/branches/dispatcher_rewrite/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/impl/XSLContract.java
URL: http://svn.apache.org/viewvc/forrest/branches/dispatcher_rewrite/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/impl/XSLContract.java?rev=703429&r1=703428&r2=703429&view=diff
==============================================================================
--- forrest/branches/dispatcher_rewrite/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/impl/XSLContract.java
(original)
+++ forrest/branches/dispatcher_rewrite/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/impl/XSLContract.java
Fri Oct 10 05:05:50 2008
@@ -27,12 +27,11 @@
 import javax.xml.transform.Result;
 import javax.xml.transform.Source;
 import javax.xml.transform.TransformerConfigurationException;
-import javax.xml.transform.URIResolver;
+import javax.xml.transform.TransformerFactory;
 import javax.xml.transform.stream.StreamResult;
 
 import org.apache.forrest.dispatcher.api.Contract;
 import org.apache.forrest.dispatcher.exception.ContractException;
-
 import org.apache.forrest.dispatcher.impl.helper.Loggable;
 import org.apache.forrest.dispatcher.impl.helper.StAX;
 import org.apache.forrest.dispatcher.impl.helper.XSLContractHelper;
@@ -45,13 +44,13 @@
 
   private boolean allowXmlProperties = false;
 
-  public XSLContract(boolean allowXmlProperties, URIResolver uriResolver,StAX stax) throws
ContractException {
+  public XSLContract(boolean allowXmlProperties, TransformerFactory transformerFactory,StAX
stax) throws ContractException {
     this.allowXmlProperties = allowXmlProperties;
     /*
      * get a new instance of the corresponding helper class since the helper is
      * doing the actual work
      */
-    helper = new XSLContractHelper(uriResolver,stax);
+    helper = new XSLContractHelper(transformerFactory,stax);
   }
 
   public BufferedInputStream execute(InputStream dataStream,

Modified: forrest/branches/dispatcher_rewrite/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/impl/helper/XSLContractHelper.java
URL: http://svn.apache.org/viewvc/forrest/branches/dispatcher_rewrite/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/impl/helper/XSLContractHelper.java?rev=703429&r1=703428&r2=703429&view=diff
==============================================================================
--- forrest/branches/dispatcher_rewrite/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/impl/helper/XSLContractHelper.java
(original)
+++ forrest/branches/dispatcher_rewrite/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/impl/helper/XSLContractHelper.java
Fri Oct 10 05:05:50 2008
@@ -33,14 +33,12 @@
 import javax.xml.stream.XMLStreamReader;
 import javax.xml.stream.XMLStreamWriter;
 import javax.xml.stream.util.XMLEventAllocator;
-import javax.xml.transform.ErrorListener;
 import javax.xml.transform.OutputKeys;
 import javax.xml.transform.Result;
 import javax.xml.transform.Source;
 import javax.xml.transform.Transformer;
 import javax.xml.transform.TransformerConfigurationException;
 import javax.xml.transform.TransformerFactory;
-import javax.xml.transform.URIResolver;
 import javax.xml.transform.stream.StreamSource;
 
 import org.apache.forrest.dispatcher.exception.ContractException;
@@ -50,11 +48,11 @@
 public class XSLContractHelper extends Loggable{
 
   private Transformer transformer = null;
-  private URIResolver uriResolver = null;
+  private TransformerFactory transFact = null;
   private StAX stax = null;
 
-  public XSLContractHelper(URIResolver uriResolver,StAX stax) {
-    this.uriResolver = uriResolver;
+  public XSLContractHelper(TransformerFactory transformerFactory,StAX stax) {
+    this.transFact = transformerFactory;
     this.stax = stax;
   }
 
@@ -73,19 +71,13 @@
    */
   public void prepareTransformation(Source xslSource, boolean allowXmlProperties, Map<String,
Object> params)
       throws TransformerConfigurationException, ParserConfigurationException, SAXException,
IOException {
-    TransformerFactory transFact = TransformerFactory.newInstance();
-    ErrorListener listener = new LoggingErrorListener(log);
-   // transFact.setErrorListener(listener);
-    if(null != uriResolver){
-      transFact.setURIResolver(uriResolver);
-    }
     // prepare transformation
     transformer = transFact.newTransformer(xslSource);
     transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
     transformer.setOutputProperty(OutputKeys.INDENT, "yes");
     transformer.setOutputProperty(OutputKeys.METHOD, "xml");
     // set errorListener
-    transformer.setErrorListener(listener);
+    transformer.setErrorListener(transFact.getErrorListener());
     // do we allow xml properties?
     if(allowXmlProperties){
       DocumentBuilder builder = DocumentBuilderFactory.newInstance()

Modified: forrest/branches/dispatcher_rewrite/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/transformation/DispatcherTransformer.java
URL: http://svn.apache.org/viewvc/forrest/branches/dispatcher_rewrite/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/transformation/DispatcherTransformer.java?rev=703429&r1=703428&r2=703429&view=diff
==============================================================================
--- forrest/branches/dispatcher_rewrite/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/transformation/DispatcherTransformer.java
(original)
+++ forrest/branches/dispatcher_rewrite/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/transformation/DispatcherTransformer.java
Fri Oct 10 05:05:50 2008
@@ -26,6 +26,7 @@
 import java.util.Map;
 
 import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
 import javax.xml.transform.URIResolver;
 import javax.xml.transform.stream.StreamSource;
 
@@ -41,12 +42,14 @@
 import org.apache.cocoon.caching.CacheableProcessingComponent;
 import org.apache.cocoon.environment.SourceResolver;
 import org.apache.cocoon.transformation.AbstractSAXTransformer;
+import org.apache.cocoon.util.TraxErrorHandler;
 import org.apache.excalibur.source.Source;
 import org.apache.excalibur.source.SourceException;
 import org.apache.excalibur.source.SourceValidity;
 import org.apache.excalibur.xml.sax.SAXParser;
 import org.apache.forrest.dispatcher.api.Structurer;
 import org.apache.forrest.dispatcher.config.DispatcherBean;
+import org.apache.forrest.dispatcher.config.WritableDispatcherBean;
 import org.apache.forrest.dispatcher.exception.DispatcherException;
 import org.apache.forrest.dispatcher.impl.CocoonResolver;
 import org.apache.forrest.dispatcher.impl.XMLStructurer;
@@ -142,7 +145,7 @@
    * This config will control things like <li>contract prefixes/suffixes <li>
    * resolver to use
    */
-  private DispatcherBean config;
+  private WritableDispatcherBean config;
 
   /**
    * The level of xpath support we need.
@@ -179,7 +182,7 @@
       throws ConfigurationException {
     // creating a new config and store the general not request specific
     // parameters here
-    config = new DispatcherBean();
+    config = new WritableDispatcherBean();
     config.setStaxHelper(new StAX());
     boolean allowXml = configuration.getChild("allowXml").getValueAsBoolean(
         false);
@@ -190,7 +193,11 @@
     xpathSupport = configuration.getChild("xpathSupport").getValue("basic");
     boolean shrink = configuration.getChild("shrink").getValueAsBoolean(true);
     config.setShrink(shrink);
-    config.setUriResolver(this);
+    // FIXME: is this the best way to get an instance in cocoon?
+    TransformerFactory tfactory = TransformerFactory.newInstance();
+    tfactory.setURIResolver(this);
+    tfactory.setErrorListener(new TraxErrorHandler(getLogger()));
+    config.setTransFact(tfactory);
   }
 
   // we do all the heavy stuff later and only prepare the basics here,
@@ -223,7 +230,7 @@
       throw new ProcessingException(error);
     }
     this.cacheKey += requestedFormat;
-    if (null == m_resolver)
+    if (null == m_resolver){
       try {
         m_resolver = (org.apache.excalibur.source.SourceResolver) manager
             .lookup(SourceResolver.ROLE);
@@ -231,7 +238,7 @@
       } catch (ServiceException e) {
         throw new ProcessingException(e);
       }
-
+    }
   }
   
 /*
@@ -315,14 +322,14 @@
        * (allocate xpath nodes), adding of child elements in
        * this xpath statement and many more. 
        */
-      structurer = new XMLStructurerAxiom(config, map);
+      structurer = new XMLStructurerAxiom((DispatcherBean)config, map);
     } else {
       /*
        * The stax implementationis 100% StAX even the generation 
        * of the resulting document is done with StAX.
        * However it does not offer real support of xpath expressions.
        */
-      structurer = new XMLStructurer(config, map);
+      structurer = new XMLStructurer((DispatcherBean)config, map);
     }
     /*
      * preparing the parser that will pick up the result and



Mime
View raw message