cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From simonetrip...@apache.org
Subject svn commit: r907774 - in /cocoon/cocoon3/trunk/cocoon-sax/src: main/java/org/apache/cocoon/sax/component/XIncludeTransformer.java test/java/org/apache/cocoon/sax/component/XIncludeTransformerTest.java test/resources/multiple-prefixes.xml
Date Mon, 08 Feb 2010 19:49:59 GMT
Author: simonetripodi
Date: Mon Feb  8 19:49:59 2010
New Revision: 907774

URL: http://svn.apache.org/viewvc?rev=907774&view=rev
Log:
COCOON3-51
XIncludeTransformer sends extra startDocument and endDocument events by Charles Yates

Added:
    cocoon/cocoon3/trunk/cocoon-sax/src/test/resources/multiple-prefixes.xml   (with props)
Modified:
    cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/component/XIncludeTransformer.java
    cocoon/cocoon3/trunk/cocoon-sax/src/test/java/org/apache/cocoon/sax/component/XIncludeTransformerTest.java

Modified: cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/component/XIncludeTransformer.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/component/XIncludeTransformer.java?rev=907774&r1=907773&r2=907774&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/component/XIncludeTransformer.java
(original)
+++ cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/component/XIncludeTransformer.java
Mon Feb  8 19:49:59 2010
@@ -102,11 +102,20 @@
     private int fallbackElementLevel;
 
     /**
+     * The nesting level of document events.
+     */
+    private int documentLevel = 0;
+
+    /**
      * Locator of the current stream, stored here so that it can be restored after
      * another document send its content to the consumer.
      */
     private Locator locator;
 
+    /**
+     * The base URL from which document will be included, if XInclude element
+     * points to a relative path.
+     */
     private URL baseUrl;
 
     /**
@@ -187,7 +196,7 @@
      */
     @Override
     public void startDocument() throws SAXException {
-        if (this.xIncludeElementLevel == 0) {
+        if (this.documentLevel++ == 0) {
             this.getSAXConsumer().startDocument();
         }
     }
@@ -197,7 +206,7 @@
      */
     @Override
     public void endDocument() throws SAXException {
-        if (this.xIncludeElementLevel == 0) {
+        if (--this.documentLevel == 0) {
             this.getSAXConsumer().endDocument();
         }
     }

Modified: cocoon/cocoon3/trunk/cocoon-sax/src/test/java/org/apache/cocoon/sax/component/XIncludeTransformerTest.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-sax/src/test/java/org/apache/cocoon/sax/component/XIncludeTransformerTest.java?rev=907774&r1=907773&r2=907774&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-sax/src/test/java/org/apache/cocoon/sax/component/XIncludeTransformerTest.java
(original)
+++ cocoon/cocoon3/trunk/cocoon-sax/src/test/java/org/apache/cocoon/sax/component/XIncludeTransformerTest.java
Mon Feb  8 19:49:59 2010
@@ -16,13 +16,17 @@
  */
 package org.apache.cocoon.sax.component;
 
-import static junit.framework.Assert.*;
+import static junit.framework.Assert.assertEquals;
+import static junit.framework.Assert.assertTrue;
 
 import java.io.ByteArrayOutputStream;
 import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
 
 import org.apache.cocoon.pipeline.NonCachingPipeline;
 import org.apache.cocoon.pipeline.Pipeline;
+import org.apache.cocoon.sax.AbstractSAXTransformer;
 import org.apache.cocoon.sax.SAXPipelineComponent;
 import org.custommonkey.xmlunit.Diff;
 import org.custommonkey.xmlunit.XMLUnit;
@@ -106,6 +110,69 @@
                 + "<url id=\"url\">http://www.opensource.org/licenses/W3C.php</url></x>");
     }
 
+    /**
+     * Test that the number of startPrefixMapping and endPrefixMapping events is the same.
+     */
+    @Test
+    public void testForPrefixMappingSymmetry() throws Exception {
+        URL base = this.getClass().getResource("/");
+        URL source = new URL(base, "multiple-prefixes.xml");
+
+        final List<Integer> countCollector = new ArrayList<Integer>(1);
+        countCollector.add(0);
+
+        Pipeline<SAXPipelineComponent> pipeline = new NonCachingPipeline<SAXPipelineComponent>();
+        pipeline.addComponent(new XMLGenerator(source));
+        pipeline.addComponent(new XIncludeTransformer(base));
+        pipeline.addComponent(new AbstractSAXTransformer(){
+            public void startPrefixMapping(String prefix, String url) {
+                countCollector.add(countCollector.remove(0).intValue() + 1);
+            }
+
+            public void endPrefixMapping(String prefix) {
+                countCollector.add(countCollector.remove(0).intValue() - 1);
+            }
+        });
+        pipeline.addComponent(new XMLSerializer());
+        pipeline.setup(new ByteArrayOutputStream());
+        pipeline.execute();
+        assertEquals("startPrefixMapping and endPrefixMapping not symmetric: ", 0, countCollector.get(0).intValue());
+    }
+
+    /**
+     * Test that only one each of startDocument and endDocument events are produced.
+     */
+    @Test
+    public void testExtraDocumentEvents() throws Exception {
+        URL base = this.getClass().getResource("/");
+        URL source = new URL(base, "multiple-prefixes.xml");
+
+        final List<Integer> startCollector = new ArrayList<Integer>(1);
+        startCollector.add(0);
+
+        final List<Integer> endCollector = new ArrayList<Integer>(1);
+        endCollector.add(0);
+
+        Pipeline<SAXPipelineComponent> pipeline = new NonCachingPipeline<SAXPipelineComponent>();
+        pipeline.addComponent(new XMLGenerator(source));
+        pipeline.addComponent(new XIncludeTransformer(base));
+        pipeline.addComponent(new AbstractSAXTransformer(){
+
+            public void startDocument() {
+                startCollector.add(startCollector.remove(0).intValue() + 1);
+            }
+
+            public void endDocument() {
+                endCollector.add(endCollector.remove(0).intValue() + 1);
+            }
+        });
+        pipeline.addComponent(new XMLSerializer());
+        pipeline.setup(new ByteArrayOutputStream());
+        pipeline.execute();
+        assertEquals("extra startDocument event: ", 1, startCollector.get(0).intValue());
+        assertEquals("extra endDocument event: ", 1, endCollector.get(0).intValue());
+    }
+
    /**
     *
     */

Added: cocoon/cocoon3/trunk/cocoon-sax/src/test/resources/multiple-prefixes.xml
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-sax/src/test/resources/multiple-prefixes.xml?rev=907774&view=auto
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-sax/src/test/resources/multiple-prefixes.xml (added)
+++ cocoon/cocoon3/trunk/cocoon-sax/src/test/resources/multiple-prefixes.xml Mon Feb  8 19:49:59
2010
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  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.
+-->
+<!-- $Id$ -->
+<xml xmlns="ns1" xmlns:x="ns2">
+    <xml xmlns:y="ns3">
+        <xml xmlns="ns4"> </xml>
+        <xml>
+            <x xmlns:xi="http://www.w3.org/2001/XInclude">
+                <xi:include href="document-not-found.txt" parse="text">
+                    <xi:fallback>
+                        <error>the linked document has not found</error>
+                    </xi:fallback>
+                </xi:include>
+            </x>
+        </xml>
+        <xml xmlns:z="ns5">
+            <x xmlns:xi="http://www.w3.org/2001/XInclude">
+                <xi:include href="test.xml">
+                    <xi:fallback>
+                        <error>the linked document has not found</error>
+                    </xi:fallback>
+                </xi:include>
+            </x>
+        </xml>
+    </xml>
+</xml>

Propchange: cocoon/cocoon3/trunk/cocoon-sax/src/test/resources/multiple-prefixes.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/cocoon3/trunk/cocoon-sax/src/test/resources/multiple-prefixes.xml
------------------------------------------------------------------------------
    svn:keywords = Date Revision Author HeadURL Id

Propchange: cocoon/cocoon3/trunk/cocoon-sax/src/test/resources/multiple-prefixes.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml



Mime
View raw message