cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r122636 - in cocoon/branches/BRANCH_2_1_X/src/blocks/portal: java/org/apache/cocoon/portal/transformation samples/coplets/html
Date Fri, 17 Dec 2004 11:28:56 GMT
Author: cziegeler
Date: Fri Dec 17 03:28:53 2004
New Revision: 122636

URL: http://svn.apache.org/viewcvs?view=rev&rev=122636
Log:
Add remove mode to html root transformer and make it cacheable
Removed:
   cocoon/branches/BRANCH_2_1_X/src/blocks/portal/samples/coplets/html/cleanhtml.xsl
Modified:
   cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/transformation/HTMLRootTransformer.java
   cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/transformation/RSSTransformer.java
   cocoon/branches/BRANCH_2_1_X/src/blocks/portal/samples/coplets/html/sitemap.xmap

Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/transformation/HTMLRootTransformer.java
Url: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/transformation/HTMLRootTransformer.java?view=diff&rev=122636&p1=cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/transformation/HTMLRootTransformer.java&r1=122635&p2=cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/transformation/HTMLRootTransformer.java&r2=122636
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/transformation/HTMLRootTransformer.java
(original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/transformation/HTMLRootTransformer.java
Fri Dec 17 03:28:53 2004
@@ -16,44 +16,71 @@
 package org.apache.cocoon.portal.transformation;
 
 import java.io.IOException;
+import java.io.Serializable;
 import java.util.Map;
 
 import org.apache.avalon.framework.parameters.Parameters;
 import org.apache.cocoon.ProcessingException;
+import org.apache.cocoon.caching.CacheableProcessingComponent;
 import org.apache.cocoon.environment.SourceResolver;
 import org.apache.cocoon.transformation.AbstractTransformer;
 import org.apache.cocoon.xml.XMLUtils;
+import org.apache.excalibur.source.SourceValidity;
+import org.apache.excalibur.source.impl.validity.NOPValidity;
+import org.xml.sax.Attributes;
 import org.xml.sax.SAXException;
 
 /**
- * This transformer simply adds an html and a body element
+ * This transformer is an utility transformer for dealing with (x)html content.
+ * It has two operating modes:
+ * 
+ * Add Mode (default): The transformer simply adds an html and a body element
  * around the sax stream.
  * 
+ * Remove Mode: The transformer removes all surrounding elements like html and body
+ * and only passes everything on to the next pipeline component that's contained
+ * in a body element.
+ * 
  * @author <a href="mailto:cziegeler@s-und-n.de">Carsten Ziegeler</a>
  * @author <a href="mailto:volker.schmitt@basf-it-services.com">Volker Schmitt</a>
  * 
- * @version CVS $Id: HTMLRootTransformer.java,v 1.2 2004/03/05 13:02:16 bdelacretaz Exp $
+ * @version CVS $Id$
  */
-public class HTMLRootTransformer extends AbstractTransformer {
+public class HTMLRootTransformer 
+    extends AbstractTransformer 
+    implements CacheableProcessingComponent{
+
+    /** the operating mode: true means adding the root elements, false means removing them
*/
+    protected boolean addMode;
+        
+    /** do we remove the root tag? */
+    protected boolean ignoreRootElement;
+    protected int     ignoreRootElementCount;
 
+    protected boolean insideBodyTag;
+    
     /* (non-Javadoc)
      * @see org.apache.cocoon.sitemap.SitemapModelComponent#setup(org.apache.cocoon.environment.SourceResolver,
java.util.Map, java.lang.String, org.apache.avalon.framework.parameters.Parameters)
      */
     public void setup(SourceResolver resolver,
-                       Map objectModel,
-                       String src,
-                       Parameters par)
+                      Map objectModel,
+                      String src,
+                      Parameters par)
     throws ProcessingException, SAXException, IOException {
-        // do nothing
-
+        this.addMode = par.getParameterAsBoolean("add-mode", true);
+        this.ignoreRootElement = par.getParameterAsBoolean("ignore-root", false);
+        this.ignoreRootElementCount = 0;
+        this.insideBodyTag = false;
     }
 
     /* (non-Javadoc)
      * @see org.xml.sax.ContentHandler#endDocument()
      */
     public void endDocument() throws SAXException {
-        XMLUtils.endElement(this.xmlConsumer, "body");
-        XMLUtils.endElement(this.xmlConsumer, "html");
+        if ( this.addMode ) {
+            XMLUtils.endElement(this.xmlConsumer, "body");
+            XMLUtils.endElement(this.xmlConsumer, "html");
+        }
         super.endDocument();
     }
 
@@ -62,8 +89,62 @@
      */
     public void startDocument() throws SAXException {
         super.startDocument();
-        XMLUtils.startElement(this.xmlConsumer, "html");
-        XMLUtils.startElement(this.xmlConsumer, "body");
+        if ( this.addMode ) {
+            XMLUtils.startElement(this.xmlConsumer, "html");
+            XMLUtils.startElement(this.xmlConsumer, "body");
+        }
+    }
+
+    /* (non-Javadoc)
+     * @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) throws
SAXException {
+        if ( !this.ignoreRootElement || this.ignoreRootElementCount > 0) {
+            if ( this.addMode || this.insideBodyTag ) {
+                this.contentHandler.startElement(uri,local,qName,attr);
+            }
+        }
+        if ( "body".equals(local) ) {
+            this.insideBodyTag = true;
+        }
+        this.ignoreRootElementCount++;
+    }
+
+    /* (non-Javadoc)
+     * @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 ( "body".equals(local) ) {
+            this.insideBodyTag = false;
+        }
+        this.ignoreRootElementCount--;
+        if (!this.ignoreRootElement || this.ignoreRootElementCount > 0) {
+            if ( this.addMode || this.insideBodyTag ) {
+                this.contentHandler.endElement(uri, local, qName);
+            }
+        }
+    }
+    
+    /* (non-Javadoc)
+     * @see org.xml.sax.ContentHandler#characters(char[], int, int)
+     */
+    public void characters(char[] c, int start, int len) throws SAXException {
+        if ( this.addMode || this.insideBodyTag ) {
+            super.characters(c, start, len);
+        }
+    }
+    
+    /* (non-Javadoc)
+     * @see org.apache.cocoon.caching.CacheableProcessingComponent#getKey()
+     */
+    public Serializable getKey() {
+        return new Boolean[] { new Boolean(this.addMode), new Boolean(this.ignoreRootElement)};
     }
 
+    /* (non-Javadoc)
+     * @see org.apache.cocoon.caching.CacheableProcessingComponent#getValidity()
+     */
+    public SourceValidity getValidity() {
+        return NOPValidity.SHARED_INSTANCE;
+    }
 }

Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/transformation/RSSTransformer.java
Url: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/transformation/RSSTransformer.java?view=diff&rev=122636&p1=cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/transformation/RSSTransformer.java&r1=122635&p2=cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/transformation/RSSTransformer.java&r2=122636
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/transformation/RSSTransformer.java
(original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/transformation/RSSTransformer.java
Fri Dec 17 03:28:53 2004
@@ -43,7 +43,7 @@
  * It's actually a quick hack...
  *
  * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
- * @version CVS $Id: RSSTransformer.java,v 1.6 2004/03/05 13:02:16 bdelacretaz Exp $
+ * @version CVS $Id$
  */
 public final class RSSTransformer
 extends AbstractSAXTransformer
@@ -90,6 +90,7 @@
                 // if no exception occurs, everything is fine!
                 parsed = serializer.getSAXFragment();
             } catch (Exception ignore) {
+                // just ignore all exceptions
             } finally {
                 this.manager.release( serializer );
             }

Deleted: /cocoon/branches/BRANCH_2_1_X/src/blocks/portal/samples/coplets/html/cleanhtml.xsl
Url: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/portal/samples/coplets/html/cleanhtml.xsl?view=auto&rev=122635
==============================================================================

Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/portal/samples/coplets/html/sitemap.xmap
Url: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/portal/samples/coplets/html/sitemap.xmap?view=diff&rev=122636&p1=cocoon/branches/BRANCH_2_1_X/src/blocks/portal/samples/coplets/html/sitemap.xmap&r1=122635&p2=cocoon/branches/BRANCH_2_1_X/src/blocks/portal/samples/coplets/html/sitemap.xmap&r2=122636
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/portal/samples/coplets/html/sitemap.xmap	(original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/portal/samples/coplets/html/sitemap.xmap	Fri Dec
17 03:28:53 2004
@@ -24,14 +24,18 @@
             <map:transform type="portal-proxy">
               <map:parameter name="envelope-tag" value="envelope"/>
             </map:transform>
-            <map:transform type="xslt" src="cleanhtml.xsl"/>
+            <map:transform type="htmlroot">
+              <map:parameter name="add-mode" value="false"/>
+            </map:transform>
             <map:transform type="portal-html-linktoeventlink"/>
             <map:serialize type="xml"/>
         </map:match>
 
         <map:match pattern="application">
             <map:generate src="{coplet:temporaryAttributes/application-uri}?copletid={coplet:#}"/>
-            <map:transform type="xslt" src="cleanhtml.xsl"/>
+            <map:transform type="htmlroot">
+              <map:parameter name="add-mode" value="false"/>
+            </map:transform>
             <map:transform type="portal-html-eventlink">
                 <map:parameter name="attribute-name" value="application-uri"/>
             </map:transform>
@@ -40,7 +44,9 @@
 <!--
         <map:match pattern="live.html">
             <map:generate type="html" src="{request-param:feed}"/>
-            <map:transform type="xslt" src="cleanhtml.xsl"/>
+            <map:transform type="htmlroot">
+              <map:parameter name="add-mode" value="false"/>
+            </map:transform>
             <map:serialize type="xml"/>
         </map:match>
 -->

Mime
View raw message