cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From simonetrip...@apache.org
Subject svn commit: r1067706 - in /cocoon/cocoon3/trunk: cocoon-sample/src/main/resources/COB-INF/ cocoon-sax/src/main/java/org/apache/cocoon/sax/component/ cocoon-sitemap/src/main/resources/META-INF/cocoon/spring/
Date Sun, 06 Feb 2011 17:28:47 GMT
Author: simonetripodi
Date: Sun Feb  6 17:28:47 2011
New Revision: 1067706

URL: http://svn.apache.org/viewvc?rev=1067706&view=rev
Log:
COCOON3-60 The org.apache.cocoon.sax.component.LogAsXMLTransformer has to be integrated in
the sitemap - patch provided by Francesco Chicchiriccò

Modified:
    cocoon/cocoon3/trunk/cocoon-sample/src/main/resources/COB-INF/sitemap.xmap
    cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/component/LogAsXMLTransformer.java
    cocoon/cocoon3/trunk/cocoon-sitemap/src/main/resources/META-INF/cocoon/spring/cocoon-pipeline-component.xml

Modified: cocoon/cocoon3/trunk/cocoon-sample/src/main/resources/COB-INF/sitemap.xmap
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-sample/src/main/resources/COB-INF/sitemap.xmap?rev=1067706&r1=1067705&r2=1067706&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-sample/src/main/resources/COB-INF/sitemap.xmap (original)
+++ cocoon/cocoon3/trunk/cocoon-sample/src/main/resources/COB-INF/sitemap.xmap Sun Feb  6
17:28:47 2011
@@ -45,6 +45,9 @@
         <map:transform src="sax-pipeline/simple.xslt">
           <map:parameter name="myParam" value="1" />
         </map:transform>
+        <map:transform type="logasxml">
+          <map:parameter name="logfile" value="logasxml.log" />
+        </map:transform>
         <map:serialize />
       </map:match>
       <map:match equals="sax-pipeline/simple-1">

Modified: cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/component/LogAsXMLTransformer.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/component/LogAsXMLTransformer.java?rev=1067706&r1=1067705&r2=1067706&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/component/LogAsXMLTransformer.java
(original)
+++ cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/component/LogAsXMLTransformer.java
Sun Feb  6 17:28:47 2011
@@ -21,75 +21,100 @@ package org.apache.cocoon.sax.component;
 import java.io.File;
 import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
+import java.io.IOException;
 import java.io.OutputStream;
 import java.util.HashMap;
 import java.util.Map;
 
 import org.apache.cocoon.pipeline.SetupException;
 import org.apache.cocoon.sax.AbstractSAXTransformer;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.xml.sax.Attributes;
 import org.xml.sax.Locator;
 import org.xml.sax.SAXException;
 
 /**
- * 
- * This class is not thread-safety!
+ * Transformer that can be plugged into a pipeline to print as XML the SAX
+ * events which passes through this transformer in a readable form to a file
+ * or sysout.
+ *
+ * This class is not thread-safe!
  */
 public final class LogAsXMLTransformer extends AbstractSAXTransformer {
 
     private static final String LOG_FILE = "logfile";
 
+    /**
+     * This class log.
+     */
+    private static final Log LOG = LogFactory.getLog(LogAsXMLTransformer.class);
+
     private final XMLSerializer xmlSerializer = XMLSerializer.createXMLSerializer();
+    
+    private OutputStream outputStream;
 
     public LogAsXMLTransformer() {
-        this.init(System.out);
+        this(null);
     }
 
     public LogAsXMLTransformer(File logFile) {
         if (logFile == null) {
-            throw new IllegalArgumentException("Argument 'logFile' must not be null");
-        }
-
-        try {
-            this.init(new FileOutputStream(logFile));
-        } catch (FileNotFoundException e) {
-            throw new SetupException("Impossible to create an XML log file '"
-                    + logFile
-                    + "'");
+            this.init(System.out);
+        } else {
+            try {
+                this.init(new FileOutputStream(logFile));
+            } catch (FileNotFoundException e) {
+                throw new SetupException("Impossible to create an XML log file '"
+                        + logFile
+                        + "'");
+            }
         }
     }
 
     private void init(OutputStream outputStream) {
         this.xmlSerializer.setup(new HashMap<String, Object>());
         this.xmlSerializer.setOutputStream(outputStream);
+        this.xmlSerializer.setIndent(true);
+        this.outputStream = outputStream;
+    }
+
+    @Override
+    public void setConfiguration(Map<String, ? extends Object> configuration) {
+        this.setup((Map<String, Object>) configuration);
     }
 
     @Override
     public void setup(Map<String, Object> parameters) {
-        if (parameters == null) {
+        if (parameters == null || !parameters.containsKey(LOG_FILE)) {
             return;
         }
 
-        Object logFileString = parameters.get(LOG_FILE);
-
-        OutputStream outputStream = null;
-        if (logFileString != null) {
-            File logFile = new File(String.valueOf(logFileString));
+        String logFileName = String.valueOf(parameters.get(LOG_FILE));
+        if (logFileName != null) {
+            File logFile = new File(logFileName);
+            OutputStream os;
             try {
-                outputStream = new FileOutputStream(logFile);
+                os = new FileOutputStream(logFile);
+                this.init(os);
             } catch (FileNotFoundException e) {
-                throw new SetupException("Impossible to open log file '"
+                throw new SetupException("Impossible to open XML log file '"
                         + logFile
                         + "'", e);
             }
         }
-
-        this.xmlSerializer.setOutputStream(outputStream);
     }
 
     @Override
     public void finish() {
         this.xmlSerializer.finish();
+        if (this.outputStream != null) {
+            try {
+                this.outputStream.close();
+            } catch (IOException e) {
+                LOG.debug("Impossible to close the log writer", e);
+            }
+        }
     }
 
     @Override
@@ -206,5 +231,4 @@ public final class LogAsXMLTransformer e
         this.xmlSerializer.startPrefixMapping(prefix, uri);
         super.startPrefixMapping(prefix, uri);
     }
-
 }

Modified: cocoon/cocoon3/trunk/cocoon-sitemap/src/main/resources/META-INF/cocoon/spring/cocoon-pipeline-component.xml
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-sitemap/src/main/resources/META-INF/cocoon/spring/cocoon-pipeline-component.xml?rev=1067706&r1=1067705&r2=1067706&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-sitemap/src/main/resources/META-INF/cocoon/spring/cocoon-pipeline-component.xml
(original)
+++ cocoon/cocoon3/trunk/cocoon-sitemap/src/main/resources/META-INF/cocoon/spring/cocoon-pipeline-component.xml
Sun Feb  6 17:28:47 2011
@@ -48,5 +48,7 @@
 
   <bean name="transformer:cleaning" class="org.apache.cocoon.sax.component.CleaningTransformer"
scope="prototype" />
 
+  <bean name="transformer:logasxml" class="org.apache.cocoon.sax.component.LogAsXMLTransformer"
scope="prototype" />
+
   <bean name="reader:file" class="org.apache.cocoon.sitemap.component.FileReaderComponent"
scope="prototype" />
 </beans>



Mime
View raw message