cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From reinh...@apache.org
Subject svn commit: r677192 - in /cocoon/whiteboard/corona/trunk: corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/ corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/util/ corona-pipeline/src/test/java/org/apache/cocoon/c...
Date Wed, 16 Jul 2008 08:31:02 GMT
Author: reinhard
Date: Wed Jul 16 01:31:01 2008
New Revision: 677192

URL: http://svn.apache.org/viewvc?rev=677192&view=rev
Log:
. if there are no output format properties set, at least set the "method" property (otherwise
some transformer implementations run into NPEs)
. add another simple pipeline example (+ unit test)
. move StringTransformer tests into it's own class

Added:
    cocoon/whiteboard/corona/trunk/corona-pipeline/src/test/java/org/apache/cocoon/corona/pipeline/util/
    cocoon/whiteboard/corona/trunk/corona-pipeline/src/test/java/org/apache/cocoon/corona/pipeline/util/StringTransformationTest.java
  (with props)
Modified:
    cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/XMLSerializer.java
    cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/util/StringTransformation.java
    cocoon/whiteboard/corona/trunk/corona-pipeline/src/test/java/org/apache/cocoon/corona/pipeline/PipelineTest.java
    cocoon/whiteboard/corona/trunk/corona-sitemap/src/main/resources/META-INF/cocoon/spring/corona-pipeline-component.xml

Modified: cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/XMLSerializer.java
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/XMLSerializer.java?rev=677192&r1=677191&r2=677192&view=diff
==============================================================================
--- cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/XMLSerializer.java
(original)
+++ cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/XMLSerializer.java
Wed Jul 16 01:31:01 2008
@@ -19,6 +19,7 @@
 package org.apache.cocoon.corona.pipeline.component;
 
 import java.io.OutputStream;
+import java.util.Map;
 import java.util.Properties;
 
 import javax.xml.transform.TransformerConfigurationException;
@@ -48,7 +49,8 @@
         this.format = format;
     }
 
-    public void init() {
+    @Override
+    public void setup(Map<String, Object> inputParameters) {
         try {
             this.transformerHandler = SAX_TRANSFORMER_FACTORY.newTransformerHandler();
         } catch (TransformerConfigurationException e) {
@@ -57,6 +59,13 @@
         this.transformerHandler.getTransformer().setOutputProperties(this.format);
         this.setContentHandler(this.transformerHandler);
         this.setLexicalHandler(this.transformerHandler);
+
+        // set a default format because some transformer implementations run
+        // into NPEs if it is missing
+        if (this.format == null) {
+            this.format = new Properties();
+            this.format.put("method", "xml");
+        }
     }
 
     public CacheKey constructCacheKey() {

Modified: cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/util/StringTransformation.java
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/util/StringTransformation.java?rev=677192&r1=677191&r2=677192&view=diff
==============================================================================
--- cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/util/StringTransformation.java
(original)
+++ cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/util/StringTransformation.java
Wed Jul 16 01:31:01 2008
@@ -32,19 +32,19 @@
  * This class contains utility methods to transform an XML string by using XSLT. It hides
all the details of the Java
  * TRaX API by using SAX pipeline components that are linked to each other. This means that
the SAX events stream
  * through through the pipeline and are serialized at the end.
- *
+ * 
  * NOTE: Exception handling needs to be discussed and will probably change.
  */
 public abstract class StringTransformation {
 
     /**
      * Transform an XML string by using XSLT.
-     *
+     * 
      * @param xmlString The String to be transformed.
      * @param xsltUrls The {@link URL}s of all XSLT stylesheets that are used in the order
they are passed to transform
      *            the passed XML string.
      * @return The transformed result as {@link String}.
-     *
+     * 
      * @throws Exception
      */
     public static String transform(String xmlString, URL... xsltUrls) throws Exception {
@@ -53,7 +53,7 @@
 
     /**
      * Transform an XML string by using XSLT. This method also allows passing parameters
to the stylesheets.
-     *
+     * 
      * @param xmlString The String to be transformed.
      * @param xsltParameters Parameters that are available in all XSLT stylesheets.
      * @param xsltUrls The {@link URL}s of all XSLT stylesheets that are used in the order
they are passed to transform
@@ -68,7 +68,7 @@
 
     /**
      * Transform an XML string by using XSLT. This method allows defining the output properties.
-     *
+     * 
      * @param xmlString The String to be transformed.
      * @param outputProperties XML output properties. See {@link http://www.w3.org/TR/xslt#output}.
      * @param xsltUrls The {@link URL}s of all XSLT stylesheets that are used in the order
they are passed to transform
@@ -83,7 +83,7 @@
     /**
      * Transform an XML string by using XSLT. This method allows defining the output properties
and also allows passing
      * parameters to the stylesheets.
-     *
+     * 
      * @param xmlString The String to be transformed.
      * @param xsltParameters Parameters that are available in all XSLT stylesheets.
      * @param outputProperties XML output properties. See {@link http://www.w3.org/TR/xslt#output}.
@@ -101,7 +101,7 @@
 
     /**
      * Transform an XML string by using XSLT and write the result into an {@link OutputStream}.
-     *
+     * 
      * @param xmlString The String to be transformed.
      * @param outputStream The result is written into this {@link OutputStream}.
      * @param xsltUrls The {@link URL}s of all XSLT stylesheets that are used in the order
they are passed to transform
@@ -115,7 +115,7 @@
     /**
      * Transform an XML string by using XSLT and write the result into an {@link OutputStream}.
This method also allows
      * passing parameters to the stylesheets.
-     *
+     * 
      * @param xmlString The String to be transformed.
      * @param outputStream The result is written into this {@link OutputStream}.
      * @param xsltParameters Parameters that are available in all XSLT stylesheets.
@@ -131,7 +131,7 @@
     /**
      * Transform an XML string by using XSLT and write the result into an {@link OutputStream}.
This method allows
      * defining the output properties.
-     *
+     * 
      * @param xmlString The String to be transformed.
      * @param outputStream The result is written into this {@link OutputStream}.
      * @param outputProperties XML output properties. See {@link http://www.w3.org/TR/xslt#output}.
@@ -146,14 +146,14 @@
 
     /**
      * Transform an XML string and write the result into an {@link OutputStream}.
-     *
+     * 
      * @param xmlString The String to be transformed.
      * @param xsltParameters Parameters that are available in all XSLT stylesheets.
      * @param outputProperties XML output properties. See {@link http://www.w3.org/TR/xslt#output}.
      * @param outputStream The result is written into this {@link OutputStream}.
      * @param xsltUrls The {@link URL}s of all XSLT stylesheets that are used in the order
they are passed to transform
      *            the passed XML string.
-     *
+     * 
      * @throws Exception
      */
     public static void transform(String xmlString, Map<String, Object> xsltParameters,
Properties outputProperties,
@@ -164,14 +164,7 @@
         for (URL xsltUrl : xsltUrls) {
             pipeline.addComponent(new XSLTTransformer(xsltUrl, xsltParameters));
         }
-
-        if (outputProperties == null) {
-            outputProperties = new Properties();
-            outputProperties.put("method", "xml");
-        }
-        XMLSerializer xmlSerializer = new XMLSerializer(outputProperties);
-        xmlSerializer.init();
-        pipeline.addComponent(xmlSerializer);
+        pipeline.addComponent(new XMLSerializer(outputProperties));
 
         pipeline.setup(null, outputStream);
         pipeline.execute();

Modified: cocoon/whiteboard/corona/trunk/corona-pipeline/src/test/java/org/apache/cocoon/corona/pipeline/PipelineTest.java
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/corona/trunk/corona-pipeline/src/test/java/org/apache/cocoon/corona/pipeline/PipelineTest.java?rev=677192&r1=677191&r2=677192&view=diff
==============================================================================
--- cocoon/whiteboard/corona/trunk/corona-pipeline/src/test/java/org/apache/cocoon/corona/pipeline/PipelineTest.java
(original)
+++ cocoon/whiteboard/corona/trunk/corona-pipeline/src/test/java/org/apache/cocoon/corona/pipeline/PipelineTest.java
Wed Jul 16 01:31:01 2008
@@ -18,14 +18,14 @@
  */
 package org.apache.cocoon.corona.pipeline;
 
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Properties;
+import java.io.ByteArrayOutputStream;
 
 import junit.framework.TestCase;
 
 import org.apache.cocoon.corona.pipeline.component.FileReaderComponent;
-import org.apache.cocoon.corona.pipeline.util.StringTransformation;
+import org.apache.cocoon.corona.pipeline.component.StringGenerator;
+import org.apache.cocoon.corona.pipeline.component.XMLSerializer;
+import org.apache.cocoon.corona.pipeline.component.XSLTTransformer;
 import org.custommonkey.xmlunit.Diff;
 
 public class PipelineTest extends TestCase {
@@ -33,49 +33,24 @@
     /**
      * Demonstration of how to use the pipeline API. Currently it hasn't been optimized for
this purpose though!
      */
-    public void testPipeline() throws Exception {
+    public void testPipelineWithReader() throws Exception {
         Pipeline pipeline = new NonCachingPipeline();
-
         pipeline.addComponent(new FileReaderComponent(PipelineTest.class.getResource("/test.xml")));
         pipeline.setup(null, System.out);
         pipeline.execute();
     }
 
-    public void testStringTransformation() throws Exception {
-        String result = StringTransformation.transform("<x>test</x>", PipelineTest.class.getClassLoader().getResource(
-                "test.xslt"));
-        Diff diff = new Diff("<?xml version=\"1.0\" encoding=\"UTF-8\"?><p></p>",
result);
-        assertTrue("XSL transformation didn't work as expected " + diff, diff.identical());
-    }
-
-    public void testStringTransformationWithParameter() throws Exception {
-        Map<String, Object> params = new HashMap<String, Object>();
-        params.put("myParam", "abc");
-        String result = StringTransformation.transform("<x>test</x>", params,
PipelineTest.class.getClassLoader()
-                .getResource("test.xslt"));
-        Diff diff = new Diff("<?xml version=\"1.0\" encoding=\"UTF-8\"?><p>abc</p>",
result);
-        assertTrue("XSL transformation didn't work as expected " + diff, diff.identical());
-        assertTrue(result.startsWith("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"));
-    }
+    public void testPipelineWithTransformer() throws Exception {
+        Pipeline pipeline = new NonCachingPipeline();
+        pipeline.addComponent(new StringGenerator("<x></x>"));
+        pipeline.addComponent(new XSLTTransformer(PipelineTest.class.getClassLoader().getResource("test.xslt")));
+        pipeline.addComponent(new XMLSerializer());
 
-    public void testStringTransformationWithProperties() throws Exception {
-        Properties props = new Properties();
-        props.put("encoding", "iso-8859-1");
-        String result = StringTransformation.transform("<x>test</x>", props,
PipelineTest.class.getClassLoader()
-                .getResource("test.xslt"));
-        Diff diff = new Diff("<?xml version=\"1.0\" encoding=\"iso-8859-1\"?><p/>",
result);
-        assertTrue("XSL transformation didn't work as expected " + diff, diff.identical());
-        assertTrue(result.startsWith("<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>"));
-    }
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        pipeline.setup(null, baos);
+        pipeline.execute();
 
-    public void testStringTransformationWithPropertiesAndParameters() throws Exception {
-        Properties props = new Properties();
-        props.put("encoding", "iso-8859-1");
-        Map<String, Object> params = new HashMap<String, Object>();
-        params.put("myParam", "abc");
-        String result = StringTransformation.transform("<x>test</x>", params,
props, PipelineTest.class
-                .getClassLoader().getResource("test.xslt"));
-        Diff diff = new Diff("<?xml version=\"1.0\" encoding=\"iso-8859-1\"?><p>abc</p>",
result);
+        Diff diff = new Diff("<?xml version=\"1.0\" encoding=\"UTF-8\"?><p></p>",
new String(baos.toByteArray()));
         assertTrue("XSL transformation didn't work as expected " + diff, diff.identical());
     }
 }

Added: cocoon/whiteboard/corona/trunk/corona-pipeline/src/test/java/org/apache/cocoon/corona/pipeline/util/StringTransformationTest.java
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/corona/trunk/corona-pipeline/src/test/java/org/apache/cocoon/corona/pipeline/util/StringTransformationTest.java?rev=677192&view=auto
==============================================================================
--- cocoon/whiteboard/corona/trunk/corona-pipeline/src/test/java/org/apache/cocoon/corona/pipeline/util/StringTransformationTest.java
(added)
+++ cocoon/whiteboard/corona/trunk/corona-pipeline/src/test/java/org/apache/cocoon/corona/pipeline/util/StringTransformationTest.java
Wed Jul 16 01:31:01 2008
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.corona.pipeline.util;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+
+import junit.framework.TestCase;
+
+import org.apache.cocoon.corona.pipeline.PipelineTest;
+import org.custommonkey.xmlunit.Diff;
+
+public class StringTransformationTest extends TestCase {
+
+    public void testStringTransformation() throws Exception {
+        String result = StringTransformation.transform("<x>test</x>", PipelineTest.class.getClassLoader().getResource(
+                "test.xslt"));
+        Diff diff = new Diff("<?xml version=\"1.0\" encoding=\"UTF-8\"?><p></p>",
result);
+        assertTrue("XSL transformation didn't work as expected " + diff, diff.identical());
+    }
+
+    public void testStringTransformationWithParameter() throws Exception {
+        Map<String, Object> params = new HashMap<String, Object>();
+        params.put("myParam", "abc");
+        String result = StringTransformation.transform("<x>test</x>", params,
PipelineTest.class.getClassLoader()
+                .getResource("test.xslt"));
+        Diff diff = new Diff("<?xml version=\"1.0\" encoding=\"UTF-8\"?><p>abc</p>",
result);
+        assertTrue("XSL transformation didn't work as expected " + diff, diff.identical());
+        assertTrue(result.startsWith("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"));
+    }
+
+    public void testStringTransformationWithProperties() throws Exception {
+        Properties props = new Properties();
+        props.put("encoding", "iso-8859-1");
+        String result = StringTransformation.transform("<x>test</x>", props,
PipelineTest.class.getClassLoader()
+                .getResource("test.xslt"));
+        Diff diff = new Diff("<?xml version=\"1.0\" encoding=\"iso-8859-1\"?><p/>",
result);
+        assertTrue("XSL transformation didn't work as expected " + diff, diff.identical());
+        assertTrue(result.startsWith("<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>"));
+    }
+
+    public void testStringTransformationWithPropertiesAndParameters() throws Exception {
+        Properties props = new Properties();
+        props.put("encoding", "iso-8859-1");
+        Map<String, Object> params = new HashMap<String, Object>();
+        params.put("myParam", "abc");
+        String result = StringTransformation.transform("<x>test</x>", params,
props, PipelineTest.class
+                .getClassLoader().getResource("test.xslt"));
+        Diff diff = new Diff("<?xml version=\"1.0\" encoding=\"iso-8859-1\"?><p>abc</p>",
result);
+        assertTrue("XSL transformation didn't work as expected " + diff, diff.identical());
+    }
+}

Propchange: cocoon/whiteboard/corona/trunk/corona-pipeline/src/test/java/org/apache/cocoon/corona/pipeline/util/StringTransformationTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/whiteboard/corona/trunk/corona-pipeline/src/test/java/org/apache/cocoon/corona/pipeline/util/StringTransformationTest.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cocoon/whiteboard/corona/trunk/corona-pipeline/src/test/java/org/apache/cocoon/corona/pipeline/util/StringTransformationTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: cocoon/whiteboard/corona/trunk/corona-sitemap/src/main/resources/META-INF/cocoon/spring/corona-pipeline-component.xml
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/corona/trunk/corona-sitemap/src/main/resources/META-INF/cocoon/spring/corona-pipeline-component.xml?rev=677192&r1=677191&r2=677192&view=diff
==============================================================================
--- cocoon/whiteboard/corona/trunk/corona-sitemap/src/main/resources/META-INF/cocoon/spring/corona-pipeline-component.xml
(original)
+++ cocoon/whiteboard/corona/trunk/corona-sitemap/src/main/resources/META-INF/cocoon/spring/corona-pipeline-component.xml
Wed Jul 16 01:31:01 2008
@@ -25,7 +25,7 @@
     class="org.apache.cocoon.corona.sitemap.spring.PrototypePipelineComponentFactory">
   </bean>
 
-  <bean name="serializer:xhtml" class="org.apache.cocoon.corona.pipeline.component.XMLSerializer"
scope="prototype" init-method="init">
+  <bean name="serializer:xhtml" class="org.apache.cocoon.corona.pipeline.component.XMLSerializer"
scope="prototype">
     <property name="contentType" value="text/html;charset=utf-8" />
     <property name="format">
       <props>
@@ -37,7 +37,7 @@
     </property>
   </bean>
 
-  <bean name="serializer:xml" class="org.apache.cocoon.corona.pipeline.component.XMLSerializer"
scope="prototype" init-method="init">
+  <bean name="serializer:xml" class="org.apache.cocoon.corona.pipeline.component.XMLSerializer"
scope="prototype">
     <property name="contentType" value="text/xml" />
     <property name="format">
       <props>



Mime
View raw message