cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r171102 - in /cocoon/branches/BRANCH_2_1_X/src: java/org/apache/cocoon/components/treeprocessor/ test/htmlunit/org/apache/cocoon/ webapp/samples/test/sitemap-annotations/
Date Fri, 20 May 2005 11:29:09 GMT
Author: bdelacretaz
Date: Fri May 20 04:29:08 2005
New Revision: 171102

URL: http://svn.apache.org/viewcvs?rev=171102&view=rev
Log:
ignore sitemap annotations in the http://apache.org/cocoon/sitemap/annotations/1.0 namespace,
backported from trunk, see bugzilla 25352

Added:
    cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/treeprocessor/AnnotationsFilter.java
    cocoon/branches/BRANCH_2_1_X/src/test/htmlunit/org/apache/cocoon/SitemapAnnotationsTestCase.java
    cocoon/branches/BRANCH_2_1_X/src/webapp/samples/test/sitemap-annotations/
    cocoon/branches/BRANCH_2_1_X/src/webapp/samples/test/sitemap-annotations/explain-test.xml
    cocoon/branches/BRANCH_2_1_X/src/webapp/samples/test/sitemap-annotations/get-annotations.xsl
    cocoon/branches/BRANCH_2_1_X/src/webapp/samples/test/sitemap-annotations/sitemap.xmap
Modified:
    cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/treeprocessor/DefaultTreeBuilder.java

Added: cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/treeprocessor/AnnotationsFilter.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/treeprocessor/AnnotationsFilter.java?rev=171102&view=auto
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/treeprocessor/AnnotationsFilter.java
(added)
+++ cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/treeprocessor/AnnotationsFilter.java
Fri May 20 04:29:08 2005
@@ -0,0 +1,108 @@
+/*
+ * Copyright 1999-2004 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.components.treeprocessor;
+
+import org.xml.sax.Attributes;
+import org.xml.sax.ContentHandler;
+import org.xml.sax.Locator;
+import org.xml.sax.SAXException;
+
+/** Filter out annotations in the sitemap
+ *  (bugzilla 25352)
+ *  $Id$
+ */
+class AnnotationsFilter implements ContentHandler {
+    public static final String ANNOTATIONS_NAMESPACE = "http://apache.org/cocoon/sitemap/annotations/1.0";
+
+    private ContentHandler delegate;
+
+    private int nestingLevel;
+
+    private boolean isOutsideAnnotation()
+    {
+        return nestingLevel == 0;
+    }
+
+    public AnnotationsFilter(ContentHandler delegate) {
+        this.delegate = delegate;
+    }
+
+    public void setDocumentLocator(Locator locator) {
+        delegate.setDocumentLocator(locator);
+    }
+
+    public void startDocument() throws SAXException {
+        delegate.startDocument();
+    }
+
+    public void endDocument() throws SAXException {
+        delegate.endDocument();
+    }
+
+    public void startPrefixMapping(String prefix, String namespaceURI) throws SAXException
{
+        if (isOutsideAnnotation()) {
+            delegate.startPrefixMapping(prefix, namespaceURI);
+        }
+    }
+
+    public void endPrefixMapping(String prefix) throws SAXException {
+        if (isOutsideAnnotation()) {
+            delegate.endPrefixMapping(prefix);
+        }
+    }
+
+    public void startElement(String namespaceURI, String localName, String qName, Attributes
attributes) throws SAXException {
+        if (namespaceURI !=  null && namespaceURI.equals(ANNOTATIONS_NAMESPACE))
{
+            nestingLevel++;
+        }
+        if (isOutsideAnnotation()) {
+            delegate.startElement(namespaceURI, localName, qName, attributes);
+        }
+    }
+
+    public void endElement(String namespaceURI, String localName, String qName) throws SAXException
{
+        if (isOutsideAnnotation()) {
+            delegate.endElement(namespaceURI, localName, qName);
+        }
+        if (namespaceURI !=  null && namespaceURI.equals(ANNOTATIONS_NAMESPACE))
{
+            nestingLevel--;
+        }
+    }
+
+    public void characters(char[] ch, int start, int len) throws SAXException {
+        if (isOutsideAnnotation()) {
+            delegate.characters(ch, start, len);
+        }
+    }
+
+    public void ignorableWhitespace(char[] ch, int start, int len) throws SAXException {
+        if (isOutsideAnnotation()) {
+            delegate.ignorableWhitespace(ch, start, len);
+        }
+    }
+
+    public void processingInstruction(String target, String data) throws SAXException {
+        if (isOutsideAnnotation()) {
+            delegate.processingInstruction(target, data);
+        }
+    }
+
+    public void skippedEntity(String name) throws SAXException {
+        if (isOutsideAnnotation()) {
+            delegate.skippedEntity(name);
+        }
+    }
+}

Modified: cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/treeprocessor/DefaultTreeBuilder.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/treeprocessor/DefaultTreeBuilder.java?rev=171102&r1=171101&r2=171102&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/treeprocessor/DefaultTreeBuilder.java
(original)
+++ cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/treeprocessor/DefaultTreeBuilder.java
Fri May 20 04:29:08 2005
@@ -351,7 +351,8 @@
         try {
             // Build a namespace-aware configuration object
             NamespacedSAXConfigurationHandler handler = new NamespacedSAXConfigurationHandler();
-            SourceUtil.toSAX( source, handler );
+            AnnotationsFilter annotationsFilter = new AnnotationsFilter(handler);
+            SourceUtil.toSAX( source, annotationsFilter );
             Configuration treeConfig = handler.getConfiguration();
 
             return build(treeConfig);

Added: cocoon/branches/BRANCH_2_1_X/src/test/htmlunit/org/apache/cocoon/SitemapAnnotationsTestCase.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/test/htmlunit/org/apache/cocoon/SitemapAnnotationsTestCase.java?rev=171102&view=auto
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/test/htmlunit/org/apache/cocoon/SitemapAnnotationsTestCase.java
(added)
+++ cocoon/branches/BRANCH_2_1_X/src/test/htmlunit/org/apache/cocoon/SitemapAnnotationsTestCase.java
Fri May 20 04:29:08 2005
@@ -0,0 +1,40 @@
+/*
+ * 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;
+
+/**
+ *  Verify that sitemap annotations (bugzilla 25352) are ignored.
+ *  In the (2.2) trunk this test is done using anteater,
+ *  as the HtmlUnit-based tests were not ported to 2.2 yet
+ *  when this feature was implemented.
+ *
+ * @version $Id: $
+ */
+public class SitemapAnnotationsTestCase
+    extends HtmlUnitTestCase
+{
+    public void testSitemapAnnotations()
+        throws Exception
+    {
+        final String pageurl = "samples/test/sitemap-annotations/annotations";
+
+        // Just check that the annotated sitemap works
+        loadXmlPage(pageurl);
+        final String author = evalXPath("/sitemap-annotations/info/author");
+        assertEquals("The Cocoon team",author);
+    }
+}

Added: cocoon/branches/BRANCH_2_1_X/src/webapp/samples/test/sitemap-annotations/explain-test.xml
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/webapp/samples/test/sitemap-annotations/explain-test.xml?rev=171102&view=auto
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/webapp/samples/test/sitemap-annotations/explain-test.xml
(added)
+++ cocoon/branches/BRANCH_2_1_X/src/webapp/samples/test/sitemap-annotations/explain-test.xml
Fri May 20 04:29:08 2005
@@ -0,0 +1,35 @@
+<?xml version="1.0"?>
+<!--
+  Copyright 1999-2004 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.
+-->
+
+<!-- CVS $Id: explain-test.xml 30932 2004-07-29 17:35:38Z vgritsenko $ -->
+
+<page>
+    <title>Sitemap annotations test</title>
+    <content>
+        <para>
+            Test sitemap annotations and their extraction
+            <ul>
+                <li>
+                  The <link href="annotations">annotations</link>
+                  page contains a copy of the annotations found in sitemap.xmap
+                  (with namespaces removed as I haven't been able to get the
+                  anteater-based tests to work with namespaces)
+                </li>
+            </ul>
+        </para>
+    </content>
+</page>
\ No newline at end of file

Added: cocoon/branches/BRANCH_2_1_X/src/webapp/samples/test/sitemap-annotations/get-annotations.xsl
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/webapp/samples/test/sitemap-annotations/get-annotations.xsl?rev=171102&view=auto
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/webapp/samples/test/sitemap-annotations/get-annotations.xsl
(added)
+++ cocoon/branches/BRANCH_2_1_X/src/webapp/samples/test/sitemap-annotations/get-annotations.xsl
Fri May 20 04:29:08 2005
@@ -0,0 +1,44 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  Copyright 1999-2004 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.
+-->
+
+<!--
+  Extract annotations from sitemap
+  $Id: dir-links.xsl 36225 2004-08-11 14:36:46Z vgritsenko $
+ -->
+
+<xsl:stylesheet
+  version="1.0"
+  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+  xmlns:fyi="http://apache.org/cocoon/sitemap/annotations/1.0"
+  exclude-element-prefixes="fyi"
+  >
+
+  <xsl:template match="/">
+    <sitemap-annotations>
+      <xsl:apply-templates/>
+    </sitemap-annotations>
+  </xsl:template>
+
+  <!-- copy fyi elements, without namespace -->
+  <xsl:template match="fyi:*">
+    <xsl:element name="{local-name()}">
+      <xsl:copy-of select="@*"/>
+      <xsl:apply-templates/>
+    </xsl:element>
+  </xsl:template>
+
+</xsl:stylesheet>

Added: cocoon/branches/BRANCH_2_1_X/src/webapp/samples/test/sitemap-annotations/sitemap.xmap
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/webapp/samples/test/sitemap-annotations/sitemap.xmap?rev=171102&view=auto
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/webapp/samples/test/sitemap-annotations/sitemap.xmap
(added)
+++ cocoon/branches/BRANCH_2_1_X/src/webapp/samples/test/sitemap-annotations/sitemap.xmap
Fri May 20 04:29:08 2005
@@ -0,0 +1,44 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  Copyright 1999-2004 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.
+-->
+<map:sitemap
+  xmlns:map="http://apache.org/cocoon/sitemap/1.0"
+  xmlns:fyi="http://apache.org/cocoon/sitemap/annotations/1.0"
+  >
+  <fyi:info>
+    <fyi:author>The Cocoon team</fyi:author>
+    <fyi:text>
+      This sitemap contains notes which are ignored
+      by the tree processor, but could be used to create
+      self-documenting samples, for example.
+      See bugzilla issue 25352.
+    </fyi:text>
+  </fyi:info>
+
+  <map:pipelines>
+    
+    <map:pipeline>
+
+      <fyi:note>filter out sitemap to keep annotations only</fyi:note>
+      <map:match pattern="annotations">
+        <map:generate src="sitemap.xmap"/>
+        <map:transform src="get-annotations.xsl"/>
+        <map:serialize type="xml"/>
+      </map:match>
+      
+    </map:pipeline>
+  </map:pipelines>
+</map:sitemap>
\ No newline at end of file



Mime
View raw message