You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by re...@apache.org on 2008/04/25 19:27:44 UTC

svn commit: r651659 - in /cocoon/whiteboard/corona/trunk: corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/ corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/ corona-sitemap/src/main/resources/META-INF/cocoon/spring/

Author: reinhard
Date: Fri Apr 25 10:27:43 2008
New Revision: 651659

URL: http://svn.apache.org/viewvc?rev=651659&view=rev
Log:
introduce a cleaning transformer that strips all namespaces, comments and unnecessary white space (should be made configureable some time ...)

done together with Steven

Added:
    cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/CleaningTransformer.java   (with props)
Modified:
    cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/AbstractPipeline.java
    cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/FileGenerator.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/AbstractPipeline.java
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/AbstractPipeline.java?rev=651659&r1=651658&r2=651659&view=diff
==============================================================================
--- cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/AbstractPipeline.java (original)
+++ cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/AbstractPipeline.java Fri Apr 25 10:27:43 2008
@@ -134,7 +134,6 @@
 
     public String getContentType() {
         Finisher last = (Finisher) this.components.getLast();
-        System.out.println("Retrieving mime-type from component " + last);
         return last.getContentType();
     }
 }

Added: cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/CleaningTransformer.java
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/CleaningTransformer.java?rev=651659&view=auto
==============================================================================
--- cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/CleaningTransformer.java (added)
+++ cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/CleaningTransformer.java Fri Apr 25 10:27:43 2008
@@ -0,0 +1,95 @@
+/*
+ * 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.component;
+
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
+
+public class CleaningTransformer extends AbstractTransformer {
+
+    private static final String EMPTY_NS = "";
+
+    private char[] characters = new char[8192];
+    private int position;
+
+    @Override
+    public void startPrefixMapping(String prefix, String uri) {
+        // no prefix
+    }
+
+    @Override
+    public void endPrefixMapping(String prefix) throws SAXException {
+        // no prefix
+    }
+
+    @Override
+    public void comment(char[] ch, int start, int length) throws SAXException {
+        // no comment
+    }
+
+    @Override
+    public void startElement(String uri, String localName, String name, Attributes atts) throws SAXException {
+        this.maybeWriteCharacters();
+
+        super.startElement(EMPTY_NS, localName, localName, atts);
+    }
+
+    @Override
+    public void endElement(String uri, String localName, String name) throws SAXException {
+        this.maybeWriteCharacters();
+
+        super.endElement(EMPTY_NS, localName, localName);
+    }
+
+    @Override
+    public void characters(char[] c, int start, int len) throws SAXException {
+        int remaining = this.characters.length - this.position;
+        if (len > remaining) {
+            // not enough capacity remaining, allocate a new array and copy the
+            // current contents
+            int newCapacity = this.characters.length + len + 1000;
+            char[] nextCharacters = new char[newCapacity];
+            System.arraycopy(this.characters, 0, nextCharacters, 0, this.position);
+            this.characters = nextCharacters;
+        }
+
+        // simply append at the current position (the check above ensures
+        // there's enough space)
+        System.arraycopy(c, start, this.characters, this.position, len);
+        // update current position
+        this.position += len;
+    }
+
+    private void maybeWriteCharacters() throws SAXException {
+        if (this.position == 0) {
+            // no characters pending
+            return;
+        }
+
+        for (int i = 0; i < this.position; i++) {
+            if (!Character.isWhitespace(this.characters[i])) {
+                super.characters(this.characters, 0, this.position);
+                break;
+            }
+        }
+
+        this.position = 0;
+    }
+
+}

Propchange: cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/CleaningTransformer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/CleaningTransformer.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/CleaningTransformer.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/FileGenerator.java
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/FileGenerator.java?rev=651659&r1=651658&r2=651659&view=diff
==============================================================================
--- cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/FileGenerator.java (original)
+++ cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/FileGenerator.java Fri Apr 25 10:27:43 2008
@@ -66,8 +66,7 @@
      */
     public void execute() {
         if (this.source == null) {
-            // failed to resolve
-            throw new IllegalArgumentException("FileGenerator cannot resolve source '" + this.source + "'");
+            throw new IllegalArgumentException("FileGenerator has no source.");
         }
 
         try {

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=651659&r1=651658&r2=651659&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 Fri Apr 25 10:27:43 2008
@@ -53,5 +53,7 @@
   <bean name="reader:file" class="org.apache.cocoon.corona.pipeline.component.FileReaderComponent" scope="prototype" />
 
   <bean name="transformer:xslt" class="org.apache.cocoon.corona.pipeline.component.XSLTTransformer" scope="prototype" />
+  
+  <bean name="transformer:cleaning" class="org.apache.cocoon.corona.pipeline.component.CleaningTransformer" scope="prototype" />
 
 </beans>