cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r234443 - in /cocoon: blocks/portal/trunk/java/org/apache/cocoon/portal/coplet/adapter/impl/PortletAdapter.java blocks/portal/trunk/java/org/apache/cocoon/portal/util/HtmlSaxParser.java trunk/gump.xml trunk/status.xml
Date Mon, 22 Aug 2005 06:51:12 GMT
Author: cziegeler
Date: Sun Aug 21 23:50:44 2005
New Revision: 234443

URL: http://svn.apache.org/viewcvs?rev=234443&view=rev
Log:
Allow portlet adapter to stream html content through the pipeline using the NekoHTML parser.

Added:
    cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/util/HtmlSaxParser.java   (with
props)
Modified:
    cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/coplet/adapter/impl/PortletAdapter.java
    cocoon/trunk/gump.xml
    cocoon/trunk/status.xml

Modified: cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/coplet/adapter/impl/PortletAdapter.java
URL: http://svn.apache.org/viewcvs/cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/coplet/adapter/impl/PortletAdapter.java?rev=234443&r1=234442&r2=234443&view=diff
==============================================================================
--- cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/coplet/adapter/impl/PortletAdapter.java
(original)
+++ cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/coplet/adapter/impl/PortletAdapter.java
Sun Aug 21 23:50:44 2005
@@ -52,6 +52,7 @@
 import org.apache.cocoon.portal.pluto.servlet.ServletRequestImpl;
 import org.apache.cocoon.portal.pluto.servlet.ServletResponseImpl;
 import org.apache.cocoon.portal.serialization.IncludingHTMLSerializer;
+import org.apache.cocoon.portal.util.HtmlSaxParser;
 import org.apache.cocoon.servlet.CocoonServlet;
 import org.apache.cocoon.xml.AttributesImpl;
 import org.apache.pluto.PortletContainer;
@@ -166,7 +167,7 @@
         }
     }
 
-    /* (non-Javadoc)
+    /**
      * @see org.apache.cocoon.portal.coplet.adapter.impl.AbstractCopletAdapter#streamContent(org.apache.cocoon.portal.coplet.CopletInstanceData,
org.xml.sax.ContentHandler)
      */
     public void streamContent(CopletInstanceData coplet,
@@ -193,17 +194,22 @@
             // TODO - for parallel processing we have to clone the response!
             this.portletContainer.renderPortlet(window, req.getRequest(window), res);
             final String value = res.toString();
-            
-            // stream out the include for the serializer
-            IncludingHTMLSerializer.addPortlet(portlet, value);
-            contentHandler.startPrefixMapping("portal", IncludingHTMLSerializer.NAMESPACE);
-            AttributesImpl attr = new AttributesImpl();
-            attr.addCDATAAttribute("portlet", portlet);
-            contentHandler.startElement(IncludingHTMLSerializer.NAMESPACE, 
-                                        "include", "portal:include", attr);
-            contentHandler.endElement(IncludingHTMLSerializer.NAMESPACE, 
-                                      "include", "portal:include");
-            contentHandler.endPrefixMapping("portal");
+
+            final Boolean usePipeline = (Boolean)this.getConfiguration(coplet, "use-pipeline",
Boolean.FALSE);
+            if ( usePipeline.booleanValue() ) {
+                HtmlSaxParser.parseString(value, contentHandler);
+            } else {
+                // stream out the include for the serializer
+                IncludingHTMLSerializer.addPortlet(portlet, value);
+                contentHandler.startPrefixMapping("portal", IncludingHTMLSerializer.NAMESPACE);
+                AttributesImpl attr = new AttributesImpl();
+                attr.addCDATAAttribute("portlet", portlet);
+                contentHandler.startElement(IncludingHTMLSerializer.NAMESPACE, 
+                                            "include", "portal:include", attr);
+                contentHandler.endElement(IncludingHTMLSerializer.NAMESPACE, 
+                                          "include", "portal:include");
+                contentHandler.endPrefixMapping("portal");
+            }
         } catch (SAXException se) {
             throw se;
         } catch (Exception e) {

Added: cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/util/HtmlSaxParser.java
URL: http://svn.apache.org/viewcvs/cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/util/HtmlSaxParser.java?rev=234443&view=auto
==============================================================================
--- cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/util/HtmlSaxParser.java (added)
+++ cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/util/HtmlSaxParser.java Sun Aug
21 23:50:44 2005
@@ -0,0 +1,71 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed 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.portal.util;
+
+import java.io.IOException;
+import java.io.StringReader;
+import java.util.Iterator;
+import java.util.Properties;
+
+import org.apache.xerces.parsers.AbstractSAXParser;
+import org.cyberneko.html.HTMLConfiguration;
+import org.xml.sax.ContentHandler;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+import org.xml.sax.ext.LexicalHandler;
+
+/**
+ * This parser uses the nekohtml parser to parse html and generate sax streams.
+ *
+ * @version $Id$
+ */
+public class HtmlSaxParser extends AbstractSAXParser {
+
+    public HtmlSaxParser(Properties properties) {
+        super(getConfig(properties));
+    }
+
+    protected static HTMLConfiguration getConfig(Properties properties) {
+        HTMLConfiguration config = new HTMLConfiguration();
+        config.setProperty("http://cyberneko.org/html/properties/names/elems", "lower");
+        if (properties != null) {
+            for (Iterator i = properties.keySet().iterator();i.hasNext();) {
+                String name = (String) i.next();
+                config.setProperty(name, properties.getProperty(name));
+            }
+        }
+        return config;
+    }
+
+    /**
+     * Parse html stored in the string.
+     */
+    public static void parseString(String content, ContentHandler ch)
+    throws SAXException {
+        final HtmlSaxParser parser = new HtmlSaxParser(null);
+        parser.setContentHandler(ch);
+        if ( ch instanceof LexicalHandler ) {
+            parser.setLexicalHandler((LexicalHandler)ch);
+        }
+        final InputSource is = new InputSource(new StringReader(content));
+        try {
+            parser.parse(is);
+        } catch (IOException ioe) {
+            throw new SAXException("Error during parsing of html markup.", ioe);
+        }
+        
+    }
+}

Propchange: cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/util/HtmlSaxParser.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/util/HtmlSaxParser.java
------------------------------------------------------------------------------
    svn:keywords = Id

Modified: cocoon/trunk/gump.xml
URL: http://svn.apache.org/viewcvs/cocoon/trunk/gump.xml?rev=234443&r1=234442&r2=234443&view=diff
==============================================================================
--- cocoon/trunk/gump.xml (original)
+++ cocoon/trunk/gump.xml Sun Aug 21 23:50:44 2005
@@ -922,6 +922,7 @@
     <depend project="cocoon-block-ojb"/>
     <depend project="cocoon-block-template" type="samples"/>
     <depend project="jtidy"/>
+    <depend project="nekohtml"/>
     <depend project="castor"/>
     <depend project="commons-collections"/>
     <depend project="portals-pluto" inherit="runtime"/>
@@ -929,6 +930,7 @@
     <depend project="cowarp"/>
 
     <library name="jtidy"/>
+    <library name="nekohtml"/>
     <library name="castor"/>
     <library name="commons-collections"/>
     <library name="pluto"/>

Modified: cocoon/trunk/status.xml
URL: http://svn.apache.org/viewcvs/cocoon/trunk/status.xml?rev=234443&r1=234442&r2=234443&view=diff
==============================================================================
--- cocoon/trunk/status.xml (original)
+++ cocoon/trunk/status.xml Sun Aug 21 23:50:44 2005
@@ -530,6 +530,9 @@
    </action>
   </release>
   <release version="2.1.8" date="TBD">
+    <action dev="CZ" type="add">
+      Portal block: Allow portlet adapter to stream html content through the pipeline using
the NekoHTML parser.
+    </action>
    <action dev="CZ" type="add" fixes-bug="36240" due-to="Jens Maukisch" due-to-email="jmaukisch@s-und-n.de">
       Portal block: Use OJB and the HSQLDB for authentication of the portal sample.
     </action>



Mime
View raw message