cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r264119 - in /cocoon/branches/BRANCH_2_1_X: src/java/org/apache/cocoon/serialization/AbstractTextSerializer.java src/java/org/apache/cocoon/transformation/CIncludeTransformer.java status.xml
Date Mon, 29 Aug 2005 12:02:32 GMT
Author: cziegeler
Date: Mon Aug 29 05:02:27 2005
New Revision: 264119

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

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

Modified: cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/serialization/AbstractTextSerializer.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/serialization/AbstractTextSerializer.java?rev=264119&r1=264118&r2=264119&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/serialization/AbstractTextSerializer.java
(original)
+++ cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/serialization/AbstractTextSerializer.java
Mon Aug 29 05:02:27 2005
@@ -89,6 +89,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.
@@ -263,14 +275,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;
     }
 
     /**
@@ -560,6 +583,24 @@
         //       } 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/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/transformation/CIncludeTransformer.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/transformation/CIncludeTransformer.java?rev=264119&r1=264118&r2=264119&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/transformation/CIncludeTransformer.java
(original)
+++ cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/transformation/CIncludeTransformer.java
Mon Aug 29 05:02:27 2005
@@ -538,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);
@@ -627,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();
     }
 
@@ -680,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
@@ -703,10 +712,13 @@
         }
     }
 
+    /**
+     * @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,
-                                Attributes attr)
+                             String local,
+                             String qName,
+                             Attributes attr)
     throws SAXException {
         if (uri != null
             && uri.equals(CIncludeTransformer.CINCLUDE_NAMESPACE_URI)
@@ -720,6 +732,15 @@
             }
         } else {
             super.startElement(uri, local, qName, attr);
+        }
+    }
+
+    /**
+     * @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/branches/BRANCH_2_1_X/status.xml
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/status.xml?rev=264119&r1=264118&r2=264119&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/status.xml (original)
+++ cocoon/branches/BRANCH_2_1_X/status.xml Mon Aug 29 05:02:27 2005
@@ -196,6 +196,9 @@
 
   <changes>
   <release version="@version@" date="@date@">
+    <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