You are viewing a plain text version of this content. The canonical link for it is here.
Posted to svn@forrest.apache.org by th...@apache.org on 2008/10/02 14:31:16 UTC

svn commit: r701105 - /forrest/branches/dispatcher_rewrite/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/transformation/DispatcherTransformer.java

Author: thorsten
Date: Thu Oct  2 05:31:15 2008
New Revision: 701105

URL: http://svn.apache.org/viewvc?rev=701105&view=rev
Log:
FOR-1118
Parsing the resulting stream to the xmlconsumer. This way it is present in further processing.

Modified:
    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/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=701105&r1=701104&r2=701105&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 Thu Oct  2 05:31:15 2008
@@ -19,12 +19,14 @@
 import java.io.BufferedInputStream;
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
+import java.io.InputStream;
 import java.io.Serializable;
 import java.util.Map;
 
 import org.apache.avalon.framework.activity.Disposable;
 import org.apache.avalon.framework.configuration.Configuration;
 import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.avalon.framework.logger.Logger;
 import org.apache.avalon.framework.parameters.Parameters;
 import org.apache.avalon.framework.service.ServiceException;
 import org.apache.avalon.framework.service.ServiceManager;
@@ -35,14 +37,14 @@
 import org.apache.excalibur.source.Source;
 import org.apache.excalibur.source.SourceValidity;
 import org.apache.excalibur.source.impl.validity.AggregatedValidity;
-import org.apache.excalibur.xml.sax.XMLizable;
+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.exception.DispatcherException;
 import org.apache.forrest.dispatcher.impl.CocoonResolver;
 import org.apache.forrest.dispatcher.impl.XMLStructurer;
 import org.apache.forrest.dispatcher.impl.XMLStructurerAxiom;
 import org.apache.forrest.dispatcher.impl.helper.Captions;
+import org.xml.sax.InputSource;
 import org.xml.sax.SAXException;
 
 public class DispatcherTransformer extends AbstractSAXTransformer implements
@@ -71,6 +73,8 @@
    */
   private String xpathSupport;
 
+  private Logger log;
+
   public static final String PATH_PARAMETER = "path";
 
   public static final String DISPATCHER_REQUEST_ATTRIBUTE = "request";
@@ -111,10 +115,10 @@
     this.requestId = parameters
         .getParameter(DISPATCHER_REQUEST_ATTRIBUTE, null);
     this.cacheKey = parameters.getParameter(CACHE_PARAMETER, null);
+    log = getLogger();
     if (null == this.cacheKey)
-      getLogger().warn(
-          "Caching not activated! Declare the CACHE_KEY_PARAMETER="
-              + CACHE_PARAMETER + " in your sitemap.");
+      log.warn("Caching not activated! Declare the CACHE_KEY_PARAMETER="
+          + CACHE_PARAMETER + " in your sitemap.");
     this.validityFile = parameters.getParameter(VALIDITY_PARAMETER, null);
     this.validityOverride = parameters.getParameter(
         VALIDITY_OVERRIDE_PARAMETER, "");
@@ -123,14 +127,14 @@
     if (requestId == null) {
       String error = "dispatcherError:\n"
           + "You have to set the \"request\" parameter in the sitemap!";
-      getLogger().error(error);
+      log.error(error);
       throw new ProcessingException(error);
     }
     this.requestedFormat = parameters.getParameter(Captions.TYPE_ATT, null);
     if (requestedFormat == null) {
       String error = "dispatcherError:\n"
           + "You have to set the \"type\" parameter in the sitemap!";
-      getLogger().error(error);
+      log.error(error);
       throw new ProcessingException(error);
     }
     if (null == m_resolver)
@@ -145,12 +149,10 @@
   }
 
   public void startDocument() throws SAXException {
-    super.startDocument();
     startSerializedXMLRecording(null);
   }
 
   public void endDocument() throws SAXException {
-    super.endDocument();
     String document = null;
     try {
       document = super.endSerializedXMLRecording();
@@ -163,11 +165,19 @@
     } else {
       structurer = new XMLStructurer(config);
     }
+    SAXParser parser = null;
     try {
-      structurer.execute(new BufferedInputStream(new ByteArrayInputStream(
-          document.getBytes())), requestedFormat);
-    } catch (DispatcherException e) {
+      InputStream result = structurer.execute(new BufferedInputStream(
+          new ByteArrayInputStream(document.getBytes())), requestedFormat);
+      // adding the result to the consumer
+      parser = (SAXParser) manager.lookup(SAXParser.ROLE);
+      parser.parse(new InputSource(result), super.xmlConsumer);
+    } catch (Exception e) {
       throw new SAXException(e);
+    } finally {
+      if (null != parser) {
+        manager.release(parser);
+      }
     }
   }