cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From reinh...@apache.org
Subject svn commit: r705653 - in /cocoon/cocoon3/trunk: cocoon-docs/src/changes/ cocoon-optional/ cocoon-optional/src/main/java/org/apache/cocoon/optional/pipeline/components/sax/neko/ cocoon-optional/src/test/java/org/apache/cocoon/optional/pipeline/component...
Date Fri, 17 Oct 2008 16:04:00 GMT
Author: reinhard
Date: Fri Oct 17 09:03:58 2008
New Revision: 705653

URL: http://svn.apache.org/viewvc?rev=705653&view=rev
Log:
COCOON3-5 Add an HTML to XHTML converter based on NekoHtml.

Added:
    cocoon/cocoon3/trunk/cocoon-optional/src/main/java/org/apache/cocoon/optional/pipeline/components/sax/neko/
    cocoon/cocoon3/trunk/cocoon-optional/src/main/java/org/apache/cocoon/optional/pipeline/components/sax/neko/NekoGenerator.java
  (with props)
    cocoon/cocoon3/trunk/cocoon-optional/src/test/java/org/apache/cocoon/optional/pipeline/components/sax/neko/
    cocoon/cocoon3/trunk/cocoon-optional/src/test/java/org/apache/cocoon/optional/pipeline/components/sax/neko/NekoGeneratorTestCase.java
  (with props)
    cocoon/cocoon3/trunk/cocoon-optional/src/test/resources/org/
    cocoon/cocoon3/trunk/cocoon-optional/src/test/resources/org/apache/
    cocoon/cocoon3/trunk/cocoon-optional/src/test/resources/org/apache/cocoon/
    cocoon/cocoon3/trunk/cocoon-optional/src/test/resources/org/apache/cocoon/optional/
    cocoon/cocoon3/trunk/cocoon-optional/src/test/resources/org/apache/cocoon/optional/pipeline/
    cocoon/cocoon3/trunk/cocoon-optional/src/test/resources/org/apache/cocoon/optional/pipeline/components/
    cocoon/cocoon3/trunk/cocoon-optional/src/test/resources/org/apache/cocoon/optional/pipeline/components/sax/
    cocoon/cocoon3/trunk/cocoon-optional/src/test/resources/org/apache/cocoon/optional/pipeline/components/sax/neko/
    cocoon/cocoon3/trunk/cocoon-optional/src/test/resources/org/apache/cocoon/optional/pipeline/components/sax/neko/sample.html
  (with props)
Modified:
    cocoon/cocoon3/trunk/cocoon-docs/src/changes/changes.xml
    cocoon/cocoon3/trunk/cocoon-optional/pom.xml

Modified: cocoon/cocoon3/trunk/cocoon-docs/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-docs/src/changes/changes.xml?rev=705653&r1=705652&r2=705653&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-docs/src/changes/changes.xml (original)
+++ cocoon/cocoon3/trunk/cocoon-docs/src/changes/changes.xml Fri Oct 17 09:03:58 2008
@@ -25,6 +25,12 @@
 <document>
   <body>
     <release version="3.0.0-alpha-2" date="2008-00-00" description="unreleased">
+      <action dev="steven" type="add" issue="COCOON3-5" due-to="Simone Tripodi">
+        [cocoon-optional] Add an HTML to XHTML converter based on NekoHtml.
+      </action>
+      <action dev="steven" type="add">[cocoon-pipeline] Introduce an exception hierarchy
for pipeline components 
+        (ProcessingException and SetupException extend both PipelineException).
+      </action>
       <action dev="reinhard" type="add" issue="COCOON3-2" due-to="Simone Tripodi">[cocoon-pipeline]
Add a SchemaProcessorTransformer that validates the SAX event 
         stream against an XML schema.    
       </action>

Modified: cocoon/cocoon3/trunk/cocoon-optional/pom.xml
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-optional/pom.xml?rev=705653&r1=705652&r2=705653&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-optional/pom.xml (original)
+++ cocoon/cocoon3/trunk/cocoon-optional/pom.xml Fri Oct 17 09:03:58 2008
@@ -63,7 +63,13 @@
           <artifactId>commons-beanutils</artifactId>
         </exclusion>
       </exclusions>
-    </dependency>    
+    </dependency>
+    <dependency>
+      <groupId>net.sourceforge.nekohtml</groupId>
+      <artifactId>nekohtml</artifactId>
+      <version>1.9.9</version>
+      <optional>true</optional>
+    </dependency>
     <!-- Test libraries -->
     <dependency>
       <groupId>junit</groupId>
@@ -74,6 +80,6 @@
       <groupId>xmlunit</groupId>
       <artifactId>xmlunit</artifactId>
       <scope>test</scope>
-    </dependency>    
+    </dependency>
   </dependencies>
 </project>

Added: cocoon/cocoon3/trunk/cocoon-optional/src/main/java/org/apache/cocoon/optional/pipeline/components/sax/neko/NekoGenerator.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-optional/src/main/java/org/apache/cocoon/optional/pipeline/components/sax/neko/NekoGenerator.java?rev=705653&view=auto
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-optional/src/main/java/org/apache/cocoon/optional/pipeline/components/sax/neko/NekoGenerator.java
(added)
+++ cocoon/cocoon3/trunk/cocoon-optional/src/main/java/org/apache/cocoon/optional/pipeline/components/sax/neko/NekoGenerator.java
Fri Oct 17 09:03:58 2008
@@ -0,0 +1,94 @@
+/*
+ * 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.optional.pipeline.components.sax.neko;
+
+import java.io.IOException;
+import java.net.URL;
+import java.util.Map;
+
+import org.apache.cocoon.pipeline.ProcessingException;
+import org.apache.cocoon.pipeline.SetupException;
+import org.apache.cocoon.pipeline.component.sax.AbstractGenerator;
+import org.apache.cocoon.pipeline.util.StringRepresentation;
+import org.cyberneko.html.parsers.SAXParser;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXNotRecognizedException;
+import org.xml.sax.SAXNotSupportedException;
+
+public final class NekoGenerator extends AbstractGenerator {
+
+    private URL htmlSource;
+
+    private SAXParser saxParser;
+
+    public NekoGenerator() {
+        super();
+    }
+
+    public NekoGenerator(URL htmlSource) {
+        super();
+
+        this.setHtmlSource(htmlSource);
+    }
+
+    public void execute() {
+        this.saxParser.setContentHandler(this.getXMLConsumer());
+
+        try {
+            this.saxParser.parse(this.htmlSource.toExternalForm());
+        } catch (SAXException e) {
+            throw new ProcessingException("Fatal XML error", e);
+        } catch (IOException e) {
+            throw new ProcessingException("Fatal protocol violation", e);
+        }
+    }
+
+    @Override
+    public void setConfiguration(Map<String, ? extends Object> configuration) {
+        super.setConfiguration(configuration);
+
+        this.setHtmlSource((URL) configuration.get("source"));
+    }
+
+    public void setHtmlSource(URL htmlSource) {
+        this.htmlSource = htmlSource;
+    }
+
+    @Override
+    public void setup(Map<String, Object> parameters) {
+        super.setup(parameters);
+
+        this.saxParser = new SAXParser();
+        try {
+            this.saxParser.setFeature("http://cyberneko.org/html/features/balance-tags",
true);
+            this.saxParser.setProperty("http://cyberneko.org/html/properties/names/elems",
"lower");
+            this.saxParser.setFeature("http://cyberneko.org/html/features/override-namespaces",
true);
+            this.saxParser.setFeature("http://cyberneko.org/html/features/insert-namespaces",
true);
+            this.saxParser.setProperty("http://cyberneko.org/html/properties/namespaces-uri",
+                    "http://www.w3.org/1999/xhtml");
+        } catch (SAXNotRecognizedException e) {
+            throw new SetupException("Impossible to set property to HTML Parser", e);
+        } catch (SAXNotSupportedException e) {
+            throw new SetupException("Property not supported by the HTML Parser", e);
+        }
+    }
+
+    @Override
+    public String toString() {
+        return StringRepresentation.buildString(this, "htmlSource=" + this.htmlSource);
+    }
+}

Propchange: cocoon/cocoon3/trunk/cocoon-optional/src/main/java/org/apache/cocoon/optional/pipeline/components/sax/neko/NekoGenerator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/cocoon3/trunk/cocoon-optional/src/main/java/org/apache/cocoon/optional/pipeline/components/sax/neko/NekoGenerator.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cocoon/cocoon3/trunk/cocoon-optional/src/main/java/org/apache/cocoon/optional/pipeline/components/sax/neko/NekoGenerator.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: cocoon/cocoon3/trunk/cocoon-optional/src/test/java/org/apache/cocoon/optional/pipeline/components/sax/neko/NekoGeneratorTestCase.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-optional/src/test/java/org/apache/cocoon/optional/pipeline/components/sax/neko/NekoGeneratorTestCase.java?rev=705653&view=auto
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-optional/src/test/java/org/apache/cocoon/optional/pipeline/components/sax/neko/NekoGeneratorTestCase.java
(added)
+++ cocoon/cocoon3/trunk/cocoon-optional/src/test/java/org/apache/cocoon/optional/pipeline/components/sax/neko/NekoGeneratorTestCase.java
Fri Oct 17 09:03:58 2008
@@ -0,0 +1,46 @@
+/*
+ * 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.optional.pipeline.components.sax.neko;
+
+import static org.custommonkey.xmlunit.XMLAssert.*;
+
+import java.io.ByteArrayOutputStream;
+
+import org.apache.cocoon.pipeline.NonCachingPipeline;
+import org.apache.cocoon.pipeline.Pipeline;
+import org.apache.cocoon.pipeline.component.sax.XMLSerializer;
+import org.custommonkey.xmlunit.examples.CountingNodeTester;
+import org.junit.Test;
+import org.w3c.dom.Node;
+
+public final class NekoGeneratorTestCase {
+
+    @Test
+    public void testPipelineWithNekoGenerator() throws Exception {
+        Pipeline pipeline = new NonCachingPipeline();
+        pipeline.addComponent(new NekoGenerator(this.getClass().getResource("sample.html")));
+        pipeline.addComponent(new XMLSerializer());
+
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        pipeline.setup(baos);
+        pipeline.execute();
+
+        CountingNodeTester countingNodeTester = new CountingNodeTester(11);
+
+        assertNodeTestPasses(new String(baos.toByteArray()), countingNodeTester, Node.TEXT_NODE);
+    }
+}

Propchange: cocoon/cocoon3/trunk/cocoon-optional/src/test/java/org/apache/cocoon/optional/pipeline/components/sax/neko/NekoGeneratorTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/cocoon3/trunk/cocoon-optional/src/test/java/org/apache/cocoon/optional/pipeline/components/sax/neko/NekoGeneratorTestCase.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cocoon/cocoon3/trunk/cocoon-optional/src/test/java/org/apache/cocoon/optional/pipeline/components/sax/neko/NekoGeneratorTestCase.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: cocoon/cocoon3/trunk/cocoon-optional/src/test/resources/org/apache/cocoon/optional/pipeline/components/sax/neko/sample.html
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-optional/src/test/resources/org/apache/cocoon/optional/pipeline/components/sax/neko/sample.html?rev=705653&view=auto
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-optional/src/test/resources/org/apache/cocoon/optional/pipeline/components/sax/neko/sample.html
(added)
+++ cocoon/cocoon3/trunk/cocoon-optional/src/test/resources/org/apache/cocoon/optional/pipeline/components/sax/neko/sample.html
Fri Oct 17 09:03:58 2008
@@ -0,0 +1,28 @@
+<!--
+  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.
+-->
+<html>
+    <head>
+        <title>Sample HTML</title>
+    </head>
+    <body>
+        <p>
+            <ul>
+                <li>test item
+            </ul>
+        </p>
+    </body>
+</html>

Propchange: cocoon/cocoon3/trunk/cocoon-optional/src/test/resources/org/apache/cocoon/optional/pipeline/components/sax/neko/sample.html
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/cocoon3/trunk/cocoon-optional/src/test/resources/org/apache/cocoon/optional/pipeline/components/sax/neko/sample.html
------------------------------------------------------------------------------
    svn:mime-type = text/html



Mime
View raw message