cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r264123 - in /cocoon/trunk: src/java/org/apache/cocoon/serialization/AbstractTextSerializer.java src/java/org/apache/cocoon/transformation/CIncludeTransformer.java status.xml
Date Mon, 29 Aug 2005 12:15:54 GMT
Author: cziegeler
Date: Mon Aug 29 05:15:47 2005
New Revision: 264123

URL: http://svn.apache.org/viewcvs?rev=264123&view=rev
Log:
Add possibility to remove comments to all text based serializers and to cinclude transformer.

Modified:
    cocoon/trunk/src/java/org/apache/cocoon/serialization/AbstractTextSerializer.java
    cocoon/trunk/src/java/org/apache/cocoon/transformation/CIncludeTransformer.java
    cocoon/trunk/status.xml

Modified: cocoon/trunk/src/java/org/apache/cocoon/serialization/AbstractTextSerializer.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/serialization/AbstractTextSerializer.java?rev=264123&r1=264122&r2=264123&view=diff
==============================================================================
--- cocoon/trunk/src/java/org/apache/cocoon/serialization/AbstractTextSerializer.java (original)
+++ cocoon/trunk/src/java/org/apache/cocoon/serialization/AbstractTextSerializer.java Mon
Aug 29 05:15:47 2005
@@ -27,6 +27,7 @@
 import org.apache.cocoon.xml.XMLConsumer;
 import org.apache.cocoon.xml.XMLUtils;
 
+import org.apache.commons.lang.BooleanUtils;
 import org.apache.excalibur.source.SourceValidity;
 import org.apache.excalibur.source.impl.validity.NOPValidity;
 import org.xml.sax.Attributes;
@@ -86,6 +87,18 @@
      */
     private String cachingKey = "1";
 
+    /**
+     * Do we remove all comments?
+     */
+    private boolean removeComments = false;
+
+    /**
+     * If we remove comments, do we keep the document comment?
+     */
+    private boolean keepDocumentComment = true;
+
+    /** Did we get the root element already? */
+    private boolean gotRootElement = false;
 
     /**
      * Interpose namespace pipe if needed.
@@ -257,14 +270,25 @@
         } catch (Exception e) {
             getLogger().warn("Cannot know if transformer needs namespaces attributes - assuming
NO.", e);
         }
+
+        this.removeComments = conf.getChild("remove-comments").getValueAsBoolean(this.removeComments);
+        this.keepDocumentComment = conf.getChild("keep-document-comment").getValueAsBoolean(this.keepDocumentComment);
+        if ( this.getLogger().isDebugEnabled() ) {
+            this.getLogger().debug("Comment settings: remove comments: " + this.removeComments
+                                 + ", keep document comment: " + this.keepDocumentComment);
+        }
     }
 
+    /**
+     * @see org.apache.avalon.excalibur.pool.Recyclable#recycle()
+     */
     public void recycle() {
         super.recycle();
 
         if (this.namespacePipe != null) {
             this.namespacePipe.recycle();
         }
+        this.gotRootElement = false;
     }
 
     /**
@@ -335,7 +359,7 @@
 
             getLogger().debug("Trax handler " + handler.getClass().getName() + msg);
 
-            needsNamespaceCache.put(factory.getClass().getName(), new Boolean(needsIt));
+            needsNamespaceCache.put(factory.getClass().getName(), BooleanUtils.toBooleanObject(needsIt));
 
             return needsIt;
         }
@@ -554,6 +578,23 @@
         //       } catch (IOException ignored) {
         //       }
         //   }
+    }
+
+    /**
+     * @see org.xml.sax.ext.LexicalHandler#comment(char[], int, int)
+     */
+    public void comment(char[] ch, int start, int len) throws SAXException {
+        if ( !this.removeComments
+             || (!this.gotRootElement && this.keepDocumentComment)) {
+            super.comment(ch, start, len);
+        }
+    }
+    /**
+     * @see org.xml.sax.ContentHandler#startElement(java.lang.String, java.lang.String, java.lang.String,
org.xml.sax.Attributes)
+     */
+    public void startElement(String uri, String loc, String raw, Attributes a) throws SAXException
{
+        this.gotRootElement = true;
+        super.startElement(uri, loc, raw, a);
     }
 
 }

Modified: cocoon/trunk/src/java/org/apache/cocoon/transformation/CIncludeTransformer.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/transformation/CIncludeTransformer.java?rev=264123&r1=264122&r2=264123&view=diff
==============================================================================
--- cocoon/trunk/src/java/org/apache/cocoon/transformation/CIncludeTransformer.java (original)
+++ cocoon/trunk/src/java/org/apache/cocoon/transformation/CIncludeTransformer.java Mon Aug
29 05:15:47 2005
@@ -32,6 +32,7 @@
 import org.apache.cocoon.xml.XMLConsumer;
 import org.apache.cocoon.xml.XMLUtils;
 
+import org.apache.commons.lang.BooleanUtils;
 import org.apache.commons.lang.StringUtils;
 import org.apache.excalibur.source.Source;
 import org.apache.excalibur.source.SourceException;
@@ -182,7 +183,7 @@
      * Set the namespace
      */
     public CIncludeTransformer() {
-        super.defaultNamespaceURI = CINCLUDE_NAMESPACE_URI;
+        this.defaultNamespaceURI = CINCLUDE_NAMESPACE_URI;
     }
 
     /**
@@ -276,8 +277,8 @@
             if (ignoreErrors == null || ignoreErrors.length() == 0) {
                 ignoreErrors = "false";
             }
-            this.stack.push(new Boolean(this.ignoreEmptyCharacters));
-            this.stack.push(new Boolean(this.ignoreWhitespaces));
+            this.stack.push(BooleanUtils.toBooleanObject(this.ignoreEmptyCharacters));
+            this.stack.push(BooleanUtils.toBooleanObject(this.ignoreWhitespaces));
             this.stack.push(ignoreErrors);
 
             this.ignoreEmptyCharacters = false;
@@ -537,8 +538,8 @@
                     int length = list.getLength();
                     for (int i=0; i<length; i++) {
                           IncludeXMLConsumer.includeNode(list.item(i),
-                                               this,
-                                               this);
+                                               this.filter,
+                                               this.filter);
                     }
                 } finally {
                     this.manager.release(parser);
@@ -626,7 +627,9 @@
      * @see org.xml.sax.ContentHandler#startDocument()
      */
     public void startDocument() throws SAXException {
-        this.filter = new MyFilter(this.xmlConsumer, this);
+        this.filter = new MyFilter(this.xmlConsumer,
+                                   this, 
+                                   this.parameters.getParameterAsBoolean("remove-comments",
false));
         super.startDocument();
     }
 
@@ -679,18 +682,25 @@
 
 final class MyFilter extends IncludeXMLConsumer {
 
-    private CIncludeTransformer transformer;
+    private final CIncludeTransformer transformer;
+
+    private final boolean removeComments;
 
     /**
      * This filter class post-processes the parallel fetching
      * @param consumer
      */
-    public MyFilter(XMLConsumer consumer, CIncludeTransformer transformer) {
+    public MyFilter(XMLConsumer consumer,
+                    CIncludeTransformer transformer,
+                    boolean removeComments) {
         super(consumer);
         this.transformer = transformer;
+        this.removeComments = removeComments;
     }
 
-
+    /**
+     * @see org.xml.sax.ContentHandler#endElement(java.lang.String, java.lang.String, java.lang.String)
+     */
     public void endElement(String uri, String local, String qName)
     throws SAXException {
         if (uri != null
@@ -702,6 +712,9 @@
         }
     }
 
+    /**
+     * @see org.xml.sax.ContentHandler#startElement(java.lang.String, java.lang.String, java.lang.String,
org.xml.sax.Attributes)
+     */
     public void startElement(String uri,
                                 String local,
                                 String qName,
@@ -722,4 +735,12 @@
         }
     }
 
+    /**
+     * @see org.xml.sax.ext.LexicalHandler#comment(char[], int, int)
+     */
+    public void comment(char[] ary, int start, int length) throws SAXException {
+        if ( !this.removeComments ) {
+            super.comment(ary, start, length);
+        }
+    }
 }

Modified: cocoon/trunk/status.xml
URL: http://svn.apache.org/viewcvs/cocoon/trunk/status.xml?rev=264123&r1=264122&r2=264123&view=diff
==============================================================================
--- cocoon/trunk/status.xml (original)
+++ cocoon/trunk/status.xml Mon Aug 29 05:15:47 2005
@@ -530,6 +530,9 @@
    </action>
   </release>
   <release version="2.1.8" date="TBD">
+    <action dev="CZ" type="add">
+      Add possibility to remove comments to all text based serializers and to cinclude transformer.
+    </action>
     <action dev="AG" type="update">
       Updated hsqldb to 1.8.0.2.
     </action>



Mime
View raw message