cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From reinh...@apache.org
Subject svn commit: r740557 [2/2] - in /cocoon/cocoon3/trunk: cocoon-sample/src/main/java/org/apache/cocoon/sample/rest/ cocoon-stax/ cocoon-stax/src/main/java/org/apache/cocoon/stax/ cocoon-stax/src/main/java/org/apache/cocoon/stax/converter/ cocoon-stax/src/...
Date Wed, 04 Feb 2009 01:13:32 GMT
Added: cocoon/cocoon3/trunk/cocoon-stax/src/main/java/org/apache/cocoon/stax/converter/util/XMLEventToContentHandler.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-stax/src/main/java/org/apache/cocoon/stax/converter/util/XMLEventToContentHandler.java?rev=740557&view=auto
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-stax/src/main/java/org/apache/cocoon/stax/converter/util/XMLEventToContentHandler.java
(added)
+++ cocoon/cocoon3/trunk/cocoon-stax/src/main/java/org/apache/cocoon/stax/converter/util/XMLEventToContentHandler.java
Wed Feb  4 01:13:31 2009
@@ -0,0 +1,361 @@
+/* Copyright (c) 2004, Sun Microsystems, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ *      notice, this list of conditions and the following disclaimer.
+ *
+ *     * Redistributions in binary form must reproduce the above
+ *      copyright notice, this list of conditions and the following
+ *       disclaimer in the documentation and/or other materials provided
+ *       with the distribution.
+ *
+ *     * Neither the name of Sun Microsystems, Inc. nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.apache.cocoon.stax.converter.util;
+
+import java.util.Iterator;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.Location;
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.events.Attribute;
+import javax.xml.stream.events.Characters;
+import javax.xml.stream.events.Comment;
+import javax.xml.stream.events.EndElement;
+import javax.xml.stream.events.Namespace;
+import javax.xml.stream.events.ProcessingInstruction;
+import javax.xml.stream.events.StartElement;
+import javax.xml.stream.events.XMLEvent;
+
+import org.xml.sax.Attributes;
+import org.xml.sax.Locator;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.AttributesImpl;
+
+/**
+ * This is a simple utility class that adapts StAX events from an
+ * {@link javax.xml.stream.XMLEventReader} to SAX events on a {@link org.xml.sax.ContentHandler},
+ * bridging between the two parser technologies.
+ * 
+ * @author Ryan.Shoemaker@Sun.COM
+ * @version 1.0
+ */
+public class XMLEventToContentHandler {
+
+    // SAX event sinks
+    private XMLFilterImplEx filter;
+
+    /**
+     * Construct a new StAX to SAX adapter that will convert a StAX event stream into a SAX
event
+     * stream.
+     * 
+     * @param staxCore StAX event source
+     * @param filter SAX event sink
+     */
+    public XMLEventToContentHandler(XMLFilterImplEx filter) {
+        this.filter = filter;
+    }
+
+    private int depth = 0;
+
+    /*
+     * @see StAXReaderToContentHandler#bridge()
+     */
+    public void convertEvent(XMLEvent event) throws XMLStreamException {
+        try {
+            if (event.isStartDocument()) {
+                this.handleStartDocument(event);
+            } else if (event.isEndDocument()) {
+                this.handleEndDocument();
+            } else {
+                // These are all of the events listed in the javadoc for
+                // XMLEvent.
+                // The spec only really describes 11 of them.
+                switch (event.getEventType()) {
+                case XMLStreamConstants.START_ELEMENT:
+                    this.depth++;
+                    this.handleStartElement(event.asStartElement());
+                    break;
+                case XMLStreamConstants.END_ELEMENT:
+                    this.handleEndElement(event.asEndElement());
+                    this.depth--;
+                    if (this.depth == 0) {
+                        break;
+                    }
+                    break;
+                case XMLStreamConstants.CHARACTERS:
+                    this.handleCharacters(event.asCharacters());
+                    break;
+                case XMLStreamConstants.ENTITY_REFERENCE:
+                    this.handleEntityReference();
+                    break;
+                case XMLStreamConstants.PROCESSING_INSTRUCTION:
+                    this.handlePI((ProcessingInstruction) event);
+                    break;
+                case XMLStreamConstants.COMMENT:
+                    this.handleComment((Comment) event);
+                    break;
+                case XMLStreamConstants.DTD:
+                    this.handleDTD();
+                    break;
+                case XMLStreamConstants.ATTRIBUTE:
+                    this.handleAttribute();
+                    break;
+                case XMLStreamConstants.NAMESPACE:
+                    this.handleNamespace();
+                    break;
+                case XMLStreamConstants.CDATA:
+                    this.handleCDATA();
+                    break;
+                case XMLStreamConstants.ENTITY_DECLARATION:
+                    this.handleEntityDecl();
+                    break;
+                case XMLStreamConstants.NOTATION_DECLARATION:
+                    this.handleNotationDecl();
+                    break;
+                case XMLStreamConstants.SPACE:
+                    this.handleSpace();
+                    break;
+                default:
+                    throw new InternalError("processing event: " + event);
+                }
+            }
+        } catch (SAXException e) {
+            throw new XMLStreamException(e);
+        }
+    }
+
+    private void handleEndDocument() throws SAXException {
+        this.filter.endDocument();
+    }
+
+    private void handleStartDocument(final XMLEvent event) throws SAXException {
+        final Location location = event.getLocation();
+        if (location != null) {
+            this.filter.setDocumentLocator(new Locator() {
+                public int getColumnNumber() {
+                    return location.getColumnNumber();
+                }
+
+                public int getLineNumber() {
+                    return location.getLineNumber();
+                }
+
+                public String getPublicId() {
+                    return location.getPublicId();
+                }
+
+                public String getSystemId() {
+                    return location.getSystemId();
+                }
+            });
+        } else {
+            this.filter.setDocumentLocator(new DummyLocator());
+        }
+        this.filter.startDocument();
+    }
+
+    private void handlePI(ProcessingInstruction event) throws XMLStreamException {
+        try {
+            this.filter.processingInstruction(event.getTarget(), event.getData());
+        } catch (SAXException e) {
+            throw new XMLStreamException(e);
+        }
+    }
+
+    private void handleCharacters(Characters event) throws XMLStreamException {
+        try {
+            this.filter.characters(event.getData().toCharArray(), 0, event.getData().length());
+        } catch (SAXException e) {
+            throw new XMLStreamException(e);
+        }
+    }
+
+    @SuppressWarnings("unchecked")
+    private void handleEndElement(EndElement event) throws XMLStreamException {
+        QName qName = event.getName();
+
+        try {
+            // fire endElement
+            String prefix = qName.getPrefix();
+            String rawname;
+            if (prefix == null || prefix.length() == 0) {
+                rawname = qName.getLocalPart();
+            } else {
+                rawname = prefix + ':' + qName.getLocalPart();
+            }
+
+            this.filter.endElement(qName.getNamespaceURI(), qName.getLocalPart(), rawname);
+
+            // end namespace bindings
+            for (Iterator i = event.getNamespaces(); i.hasNext();) {
+                String nsprefix = ((Namespace) i.next()).getPrefix();
+                if (nsprefix == null) { // true for default namespace
+                    nsprefix = "";
+                }
+                this.filter.endPrefixMapping(nsprefix);
+            }
+        } catch (SAXException e) {
+            throw new XMLStreamException(e);
+        }
+    }
+
+    @SuppressWarnings("unchecked")
+    private void handleStartElement(StartElement event) throws XMLStreamException {
+        try {
+            // start namespace bindings
+            for (Iterator i = event.getNamespaces(); i.hasNext();) {
+                String prefix = ((Namespace) i.next()).getPrefix();
+                if (prefix == null) { // true for default namespace
+                    prefix = "";
+                }
+                this.filter.startPrefixMapping(prefix, event.getNamespaceURI(prefix));
+            }
+
+            // fire startElement
+            QName qName = event.getName();
+            String prefix = qName.getPrefix();
+            String rawname;
+            if (prefix == null || prefix.length() == 0) {
+                rawname = qName.getLocalPart();
+            } else {
+                rawname = prefix + ':' + qName.getLocalPart();
+            }
+            Attributes saxAttrs = this.getAttributes(event);
+            this.filter.startElement(qName.getNamespaceURI(), qName.getLocalPart(), rawname,
saxAttrs);
+        } catch (SAXException e) {
+            throw new XMLStreamException(e);
+        }
+    }
+
+    /**
+     * Get the attributes associated with the given START_ELEMENT StAXevent.
+     * 
+     * @return the StAX attributes converted to an org.xml.sax.Attributes
+     */
+    @SuppressWarnings("unchecked")
+    private Attributes getAttributes(StartElement event) {
+        AttributesImpl attrs = new AttributesImpl();
+
+        if (!event.isStartElement()) {
+            throw new InternalError("getAttributes() attempting to process: " + event);
+        }
+
+        // Add namspace declarations if required
+        if (this.filter.getNamespacePrefixes()) {
+            for (Iterator i = event.getNamespaces(); i.hasNext();) {
+                Namespace staxNamespace = (javax.xml.stream.events.Namespace) i.next();
+                String uri = staxNamespace.getNamespaceURI();
+                if (uri == null) {
+                    uri = "";
+                }
+
+                String prefix = staxNamespace.getPrefix();
+                if (prefix == null) {
+                    prefix = "";
+                }
+
+                String qName = "xmlns";
+                if (prefix.length() == 0) {
+                    prefix = qName;
+                } else {
+                    qName = qName + ':' + prefix;
+                }
+                attrs.addAttribute("http://www.w3.org/2000/xmlns/", prefix, qName, "CDATA",
uri);
+            }
+        }
+
+        // gather non-namespace attrs
+        for (Iterator i = event.getAttributes(); i.hasNext();) {
+            Attribute staxAttr = (javax.xml.stream.events.Attribute) i.next();
+
+            String uri = staxAttr.getName().getNamespaceURI();
+            if (uri == null) {
+                uri = "";
+            }
+            String localName = staxAttr.getName().getLocalPart();
+            String prefix = staxAttr.getName().getPrefix();
+            String qName;
+            if (prefix == null || prefix.length() == 0) {
+                qName = localName;
+            } else {
+                qName = prefix + ':' + localName;
+            }
+            String type = staxAttr.getDTDType();
+            String value = staxAttr.getValue();
+
+            attrs.addAttribute(uri, localName, qName, type, value);
+        }
+
+        return attrs;
+    }
+
+    private void handleNamespace() {
+        // no-op ???
+        // namespace events don't normally occur outside of a startElement
+        // or endElement
+    }
+
+    private void handleAttribute() {
+        // no-op ???
+        // attribute events don't normally occur outside of a startElement
+        // or endElement
+    }
+
+    private void handleDTD() {
+        // no-op ???
+        // it seems like we need to pass this info along, but how?
+    }
+
+    private void handleComment(Comment comment) throws XMLStreamException {
+        try {
+            String text = comment.getText();
+            this.filter.comment(text.toCharArray(), 0, text.length());
+        } catch (SAXException e) {
+            throw new XMLStreamException(e);
+        }
+    }
+
+    private void handleEntityReference() {
+        // no-op ???
+    }
+
+    private void handleSpace() {
+        // no-op ???
+        // this event is listed in the javadoc, but not in the spec.
+    }
+
+    private void handleNotationDecl() {
+        // no-op ???
+        // this event is listed in the javadoc, but not in the spec.
+    }
+
+    private void handleEntityDecl() {
+        // no-op ???
+        // this event is listed in the javadoc, but not in the spec.
+    }
+
+    private void handleCDATA() {
+        // no-op ???
+        // this event is listed in the javadoc, but not in the spec.
+    }
+}

Propchange: cocoon/cocoon3/trunk/cocoon-stax/src/main/java/org/apache/cocoon/stax/converter/util/XMLEventToContentHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/cocoon3/trunk/cocoon-stax/src/main/java/org/apache/cocoon/stax/converter/util/XMLEventToContentHandler.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cocoon/cocoon3/trunk/cocoon-stax/src/main/java/org/apache/cocoon/stax/converter/util/XMLEventToContentHandler.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: cocoon/cocoon3/trunk/cocoon-stax/src/main/java/org/apache/cocoon/stax/converter/util/XMLFilterImplEx.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-stax/src/main/java/org/apache/cocoon/stax/converter/util/XMLFilterImplEx.java?rev=740557&view=auto
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-stax/src/main/java/org/apache/cocoon/stax/converter/util/XMLFilterImplEx.java
(added)
+++ cocoon/cocoon3/trunk/cocoon-stax/src/main/java/org/apache/cocoon/stax/converter/util/XMLFilterImplEx.java
Wed Feb  4 01:13:31 2009
@@ -0,0 +1,123 @@
+/* Copyright (c) 2004, Sun Microsystems, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *
+ *     * Redistributions in binary form must reproduce the above
+ *       copyright notice, this list of conditions and the following
+ *       disclaimer in the documentation and/or other materials provided
+ *       with the distribution.
+ *
+ *     * Neither the name of Sun Microsystems, Inc. nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.apache.cocoon.stax.converter.util;
+
+import org.xml.sax.SAXException;
+import org.xml.sax.ext.LexicalHandler;
+import org.xml.sax.helpers.XMLFilterImpl;
+
+/**
+ * Extension to XMLFilterImpl that implements LexicalHandler.
+ * 
+ * @author Paul.Sandoz@Sun.Com
+ */
+public class XMLFilterImplEx extends XMLFilterImpl implements LexicalHandler {
+
+    protected LexicalHandler lexicalHandler;
+
+    protected boolean namespacePrefixes;
+
+    public void setNamespacePrefixes(boolean v) {
+        this.namespacePrefixes = v;
+    }
+
+    public boolean getNamespacePrefixes() {
+        return this.namespacePrefixes;
+    }
+
+    /**
+     * Set the lexical event handler.
+     * 
+     * @param handler the new lexical handler
+     */
+    public void setLexicalHandler(LexicalHandler handler) {
+        this.lexicalHandler = handler;
+    }
+
+    /**
+     * Get the lexical event handler.
+     * 
+     * @return The current lexical handler, or null if none was set.
+     */
+    public LexicalHandler getLexicalHandler() {
+        return this.lexicalHandler;
+    }
+
+    @Override
+    public void startDTD(String name, String publicId, String systemId) throws SAXException
{
+        if (this.lexicalHandler != null) {
+            this.lexicalHandler.startDTD(name, publicId, systemId);
+        }
+    }
+
+    @Override
+    public void endDTD() throws SAXException {
+        if (this.lexicalHandler != null) {
+            this.lexicalHandler.endDTD();
+        }
+    }
+
+    @Override
+    public void startEntity(String name) throws SAXException {
+        if (this.lexicalHandler != null) {
+            this.lexicalHandler.startEntity(name);
+        }
+    }
+
+    @Override
+    public void endEntity(String name) throws SAXException {
+        if (this.lexicalHandler != null) {
+            this.lexicalHandler.endEntity(name);
+        }
+    }
+
+    @Override
+    public void startCDATA() throws SAXException {
+        if (this.lexicalHandler != null) {
+            this.lexicalHandler.startCDATA();
+        }
+    }
+
+    @Override
+    public void endCDATA() throws SAXException {
+        if (this.lexicalHandler != null) {
+            this.lexicalHandler.endCDATA();
+        }
+    }
+
+    @Override
+    public void comment(char ch[], int start, int length) throws SAXException {
+        if (this.lexicalHandler != null) {
+            this.lexicalHandler.comment(ch, start, length);
+        }
+    }
+}

Propchange: cocoon/cocoon3/trunk/cocoon-stax/src/main/java/org/apache/cocoon/stax/converter/util/XMLFilterImplEx.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/cocoon3/trunk/cocoon-stax/src/main/java/org/apache/cocoon/stax/converter/util/XMLFilterImplEx.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cocoon/cocoon3/trunk/cocoon-stax/src/main/java/org/apache/cocoon/stax/converter/util/XMLFilterImplEx.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: cocoon/cocoon3/trunk/cocoon-stax/src/test/java/org/apache/cocoon/stax/CleaningTransformerTest.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-stax/src/test/java/org/apache/cocoon/stax/CleaningTransformerTest.java?rev=740557&r1=740556&r2=740557&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-stax/src/test/java/org/apache/cocoon/stax/CleaningTransformerTest.java
(original)
+++ cocoon/cocoon3/trunk/cocoon-stax/src/test/java/org/apache/cocoon/stax/CleaningTransformerTest.java
Wed Feb  4 01:13:31 2009
@@ -23,9 +23,9 @@
 
 import org.apache.cocoon.pipeline.NonCachingPipeline;
 import org.apache.cocoon.pipeline.component.PipelineComponent;
-import org.apache.cocoon.pipeline.component.sax.CleaningTransformer;
-import org.apache.cocoon.pipeline.component.sax.StringGenerator;
-import org.apache.cocoon.pipeline.component.sax.XMLSerializer;
+import org.apache.cocoon.sax.component.CleaningTransformer;
+import org.apache.cocoon.sax.component.StringGenerator;
+import org.apache.cocoon.sax.component.XMLSerializer;
 import org.apache.commons.io.IOUtils;
 import org.custommonkey.xmlunit.Diff;
 import org.custommonkey.xmlunit.XMLUnit;

Modified: cocoon/cocoon3/trunk/cocoon-stax/src/test/java/org/apache/cocoon/stax/StAXPipelineTest.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-stax/src/test/java/org/apache/cocoon/stax/StAXPipelineTest.java?rev=740557&r1=740556&r2=740557&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-stax/src/test/java/org/apache/cocoon/stax/StAXPipelineTest.java
(original)
+++ cocoon/cocoon3/trunk/cocoon-stax/src/test/java/org/apache/cocoon/stax/StAXPipelineTest.java
Wed Feb  4 01:13:31 2009
@@ -25,7 +25,7 @@
 import org.apache.cocoon.pipeline.Pipeline;
 import org.apache.cocoon.pipeline.SetupException;
 import org.apache.cocoon.pipeline.component.PipelineComponent;
-import org.apache.cocoon.pipeline.component.sax.StringGenerator;
+import org.apache.cocoon.sax.component.StringGenerator;
 import org.apache.commons.io.IOUtils;
 import org.custommonkey.xmlunit.Diff;
 import org.custommonkey.xmlunit.XMLUnit;

Added: cocoon/cocoon3/trunk/cocoon-stax/src/test/java/org/apache/cocoon/stax/converter/SAXForStAXPipelineWrapperTest.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-stax/src/test/java/org/apache/cocoon/stax/converter/SAXForStAXPipelineWrapperTest.java?rev=740557&view=auto
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-stax/src/test/java/org/apache/cocoon/stax/converter/SAXForStAXPipelineWrapperTest.java
(added)
+++ cocoon/cocoon3/trunk/cocoon-stax/src/test/java/org/apache/cocoon/stax/converter/SAXForStAXPipelineWrapperTest.java
Wed Feb  4 01:13:31 2009
@@ -0,0 +1,90 @@
+/*
+ * 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.stax.converter;
+
+import static org.junit.Assert.*;
+
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+
+import org.apache.cocoon.pipeline.NonCachingPipeline;
+import org.apache.cocoon.sax.SAXPipelineComponent;
+import org.apache.cocoon.sax.component.CleaningTransformer;
+import org.apache.cocoon.sax.component.StringGenerator;
+import org.apache.cocoon.sax.component.XMLSerializer;
+import org.apache.cocoon.stax.CleaningTransformerTest;
+import org.apache.cocoon.stax.StAXGenerator;
+import org.apache.cocoon.stax.StAXPipelineComponent;
+import org.apache.cocoon.stax.StAXSerializer;
+import org.apache.commons.io.IOUtils;
+import org.custommonkey.xmlunit.Diff;
+import org.custommonkey.xmlunit.XMLUnit;
+import org.junit.Test;
+
+/**
+ * Contains unit tests for the {@link SAXForStAXPipelineWrapper} that allows to use SAX pipeline
+ * components StAX pipelines.<br>
+ * 
+ * <br>
+ * Runs the SAX {@link CleaningTransformer} with a SAX generator and serializer as well as
wrapped
+ * in a {@link SAXForStAXPipelineWrapper} with a StAX generator and serializer and shows
that the
+ * wrapped component produces the same output.
+ */
+public class SAXForStAXPipelineWrapperTest {
+
+    /**
+     * Runs the SAX {@link CleaningTransformer} with a SAX generator and serializer as well
as
+     * wrapped in a {@link SAXForStAXPipelineWrapper} with a StAX generator and serializer
and shows
+     * that the wrapped component produces the same output.
+     * 
+     * @throws Exception Is thrown if an error occurs loading the files or in the pipeline
itself.
+     */
+    @Test
+    public void testSAXComponentInStAXPipeline() throws Exception {
+        NonCachingPipeline<SAXPipelineComponent> pipeSAX = new NonCachingPipeline<SAXPipelineComponent>();
+        ByteArrayOutputStream outputSAX = new ByteArrayOutputStream();
+        pipeSAX.addComponent(new StringGenerator(IOUtils.toString(CleaningTransformerTest.class.getResource(
+                "/org/apache/cocoon/stax/converter/complex-stax-test-document.xml").openStream())));
+        pipeSAX.addComponent(new CleaningTransformer());
+        pipeSAX.addComponent(new XMLSerializer());
+        pipeSAX.setup(outputSAX);
+        pipeSAX.execute();
+
+        String outputSAXString = outputSAX.toString();
+        outputSAX.close();
+
+        // StAX pipeline with SAXCleaningTransformer
+        InputStream input = CleaningTransformerTest.class.getResource(
+                "/org/apache/cocoon/stax/converter/complex-stax-test-document.xml").openStream();
+        ByteArrayOutputStream outputStAX = new ByteArrayOutputStream();
+        NonCachingPipeline<StAXPipelineComponent> pipeStAX = new NonCachingPipeline<StAXPipelineComponent>();
+        pipeStAX.addComponent(new StAXGenerator(input));
+        pipeStAX.addComponent(new SAXForStAXPipelineWrapper(new CleaningTransformer()));
+        pipeStAX.addComponent(new StAXSerializer());
+        pipeStAX.setup(outputStAX);
+        pipeStAX.execute();
+        input.close();
+
+        String outputStAXString = outputStAX.toString();
+        outputStAX.close();
+
+        // Comparing StAX and SAX pipeline output
+        XMLUnit.setIgnoreWhitespace(false);
+        Diff myDiff = new Diff(outputSAXString, outputStAXString);
+        assertTrue("pieces of XML are similar " + myDiff, myDiff.identical());
+    }
+}

Propchange: cocoon/cocoon3/trunk/cocoon-stax/src/test/java/org/apache/cocoon/stax/converter/SAXForStAXPipelineWrapperTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/cocoon3/trunk/cocoon-stax/src/test/java/org/apache/cocoon/stax/converter/SAXForStAXPipelineWrapperTest.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cocoon/cocoon3/trunk/cocoon-stax/src/test/java/org/apache/cocoon/stax/converter/SAXForStAXPipelineWrapperTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: cocoon/cocoon3/trunk/cocoon-stax/src/test/java/org/apache/cocoon/stax/converter/StAXToSAXPipelineAdapterTest.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-stax/src/test/java/org/apache/cocoon/stax/converter/StAXToSAXPipelineAdapterTest.java?rev=740557&view=auto
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-stax/src/test/java/org/apache/cocoon/stax/converter/StAXToSAXPipelineAdapterTest.java
(added)
+++ cocoon/cocoon3/trunk/cocoon-stax/src/test/java/org/apache/cocoon/stax/converter/StAXToSAXPipelineAdapterTest.java
Wed Feb  4 01:13:31 2009
@@ -0,0 +1,88 @@
+/*
+ * 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.stax.converter;
+
+import static org.junit.Assert.*;
+
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+
+import org.apache.cocoon.pipeline.NonCachingPipeline;
+import org.apache.cocoon.pipeline.component.PipelineComponent;
+import org.apache.cocoon.sax.SAXPipelineComponent;
+import org.apache.cocoon.sax.component.CleaningTransformer;
+import org.apache.cocoon.sax.component.StringGenerator;
+import org.apache.cocoon.sax.component.XMLSerializer;
+import org.apache.cocoon.stax.CleaningTransformerTest;
+import org.apache.cocoon.stax.StAXGenerator;
+import org.apache.cocoon.stax.StAXProducer;
+import org.apache.commons.io.IOUtils;
+import org.custommonkey.xmlunit.Diff;
+import org.custommonkey.xmlunit.XMLUnit;
+import org.junit.Test;
+
+/**
+ * Class containing the unit tests for the {@link StAXToSAXPipelineAdapter} which allow to
switch
+ * from StAX-only to SAX-only pipelines.
+ */
+public class StAXToSAXPipelineAdapterTest {
+
+    /**
+     * Very simple test which runs the SAX {@link CleaningTransformer} with a
+     * {@link StringGenerator} and {@link XMLSerializer}. The output of this pipeline is
compare
+     * with a pipeline started with a {@link StAXProducer} which swaps to an SAX pipeline
with a
+     * {@link StAXToSAXPipelineAdapter}. From then also the {@link CleaningTransformer} and
an
+     * {@link XMLSerializer} are taken should be same as with the SAX-only pipeline.
+     * 
+     * @throws Exception Is thrown if an error occurs loading the files or in the pipeline
itself.
+     */
+    @Test
+    public void testSAXComponentInStAXPipeline() throws Exception {
+        NonCachingPipeline<SAXPipelineComponent> pipeSAX = new NonCachingPipeline<SAXPipelineComponent>();
+        ByteArrayOutputStream outputSAX = new ByteArrayOutputStream();
+        pipeSAX.addComponent(new StringGenerator(IOUtils.toString(CleaningTransformerTest.class.getResource(
+                "/org/apache/cocoon/stax/converter/complex-stax-test-document.xml").openStream())));
+        pipeSAX.addComponent(new CleaningTransformer());
+        pipeSAX.addComponent(new XMLSerializer());
+        pipeSAX.setup(outputSAX);
+        pipeSAX.execute();
+
+        String outputSAXString = outputSAX.toString();
+        outputSAX.close();
+
+        // StAX pipeline with SAXCleaningTransformer
+        InputStream input = CleaningTransformerTest.class.getResource(
+                "/org/apache/cocoon/stax/converter/complex-stax-test-document.xml").openStream();
+        ByteArrayOutputStream outputStAX = new ByteArrayOutputStream();
+        NonCachingPipeline<PipelineComponent> pipeStAX = new NonCachingPipeline<PipelineComponent>();
+        pipeStAX.addComponent(new StAXGenerator(input));
+        pipeStAX.addComponent(new StAXToSAXPipelineAdapter());
+        pipeStAX.addComponent(new CleaningTransformer());
+        pipeStAX.addComponent(new XMLSerializer());
+        pipeStAX.setup(outputStAX);
+        pipeStAX.execute();
+        input.close();
+
+        String outputStAXString = outputStAX.toString();
+        outputStAX.close();
+
+        // Comparing StAX and SAX pipeline output
+        XMLUnit.setIgnoreWhitespace(false);
+        Diff myDiff = new Diff(outputSAXString, outputStAXString);
+        assertTrue("pieces of XML are similar " + myDiff, myDiff.identical());
+    }
+}

Propchange: cocoon/cocoon3/trunk/cocoon-stax/src/test/java/org/apache/cocoon/stax/converter/StAXToSAXPipelineAdapterTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/cocoon3/trunk/cocoon-stax/src/test/java/org/apache/cocoon/stax/converter/StAXToSAXPipelineAdapterTest.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cocoon/cocoon3/trunk/cocoon-stax/src/test/java/org/apache/cocoon/stax/converter/StAXToSAXPipelineAdapterTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: cocoon/cocoon3/trunk/cocoon-stax/src/test/resources/org/apache/cocoon/stax/converter/complex-stax-test-document.xml
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-stax/src/test/resources/org/apache/cocoon/stax/converter/complex-stax-test-document.xml?rev=740557&view=auto
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-stax/src/test/resources/org/apache/cocoon/stax/converter/complex-stax-test-document.xml
(added)
+++ cocoon/cocoon3/trunk/cocoon-stax/src/test/resources/org/apache/cocoon/stax/converter/complex-stax-test-document.xml
Wed Feb  4 01:13:31 2009
@@ -0,0 +1,162 @@
+<?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.
+	-->
+
+<wsdl:definitions name="CustomersWrapperServiceService"
+	targetNamespace="http://infosys.tuwien.ac.at/ait08/ass1/dto/customers"
+	xmlns:ns1="http://schemas.xmlsoap.org/soap/http" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
+	xmlns:tns="http://infosys.tuwien.ac.at/ait08/ass1/dto/customers"
+	xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
+	<wsdl:types>
+		<xs:schema attributeFormDefault="unqualified"
+			elementFormDefault="unqualified"
+			targetNamespace="http://infosys.tuwien.ac.at/ait08/ass1/dto/customers"
+			xmlns:tns="http://infosys.tuwien.ac.at/ait08/ass1/dto/customers"
+			xmlns:xs="http://www.w3.org/2001/XMLSchema">
+			<xs:element name="Telephone_Number" type="tns:telephoneNumber" />
+			<xs:element name="adresse" type="tns:address" />
+			<xs:element name="customer" type="tns:customer" />
+			<xs:element name="get_customer" type="tns:get_customer" />
+			<xs:element name="get_customerResponse" type="tns:get_customerResponse" />
+			<xs:element name="update_customer" type="tns:update_customer" />
+			<xs:element name="update_customerResponse" type="tns:update_customerResponse" />
+			<xs:complexType name="update_customer">
+				<xs:sequence>
+					<xs:element minOccurs="0" name="toUpdate" type="tns:customer" />
+				</xs:sequence>
+			</xs:complexType>
+			<xs:complexType name="customer">
+				<xs:sequence>
+					<xs:element minOccurs="0" name="address" type="tns:address" />
+					<xs:element minOccurs="0" name="id" type="xs:string" />
+					<xs:element minOccurs="0" name="name" type="xs:string" />
+					<xs:element name="provider" type="xs:long" />
+					<xs:element maxOccurs="unbounded" minOccurs="0"
+						name="telephoneNumbers" nillable="true" type="tns:telephoneNumber" />
+				</xs:sequence>
+			</xs:complexType>
+			<xs:complexType name="address">
+				<xs:sequence>
+					<xs:element minOccurs="0" name="area_code" type="xs:string" />
+					<xs:element minOccurs="0" name="city" type="xs:string" />
+					<xs:element name="door" type="xs:int" />
+					<xs:element name="house" type="xs:int" />
+					<xs:element minOccurs="0" name="id" type="xs:string" />
+					<xs:element minOccurs="0" name="street" type="xs:string" />
+				</xs:sequence>
+			</xs:complexType>
+			<xs:complexType name="telephoneNumber">
+				<xs:sequence>
+					<xs:element minOccurs="0" name="area_code" type="xs:string" />
+					<xs:element minOccurs="0" name="country_code" type="xs:string" />
+					<xs:element name="dbId" type="xs:long" />
+					<xs:element minOccurs="0" name="id" type="xs:string" />
+					<xs:element minOccurs="0" name="number" type="xs:string" />
+				</xs:sequence>
+			</xs:complexType>
+			<xs:complexType name="update_customerResponse">
+				<xs:sequence />
+			</xs:complexType>
+			<xs:complexType name="get_customer">
+				<xs:sequence>
+					<xs:element minOccurs="0" name="id" type="xs:string" />
+				</xs:sequence>
+			</xs:complexType>
+			<xs:complexType name="get_customerResponse">
+				<xs:sequence>
+					<xs:element minOccurs="0" name="existing_customer" type="tns:customer" />
+				</xs:sequence>
+			</xs:complexType>
+			<xs:element name="InvalidCustomerFault" type="tns:InvalidCustomerFault" />
+			<xs:complexType name="InvalidCustomerFault">
+				<xs:sequence />
+			</xs:complexType>
+		</xs:schema>
+	</wsdl:types>
+	<wsdl:message name="get_customerResponse">
+		<wsdl:part element="tns:get_customerResponse" name="parameters">
+		</wsdl:part>
+	</wsdl:message>
+	<wsdl:message name="InvalidCustomerException">
+		<wsdl:part element="tns:InvalidCustomerFault" name="InvalidCustomerException">
+		</wsdl:part>
+	</wsdl:message>
+	<wsdl:message name="get_customer">
+		<wsdl:part element="tns:get_customer" name="parameters">
+		</wsdl:part>
+	</wsdl:message>
+	<wsdl:message name="update_customer">
+		<wsdl:part element="tns:update_customer" name="parameters">
+		</wsdl:part>
+	</wsdl:message>
+	<wsdl:message name="update_customerResponse">
+		<wsdl:part element="tns:update_customerResponse" name="parameters">
+		</wsdl:part>
+	</wsdl:message>
+	<wsdl:portType name="CustomersWrapperService">
+		<wsdl:operation name="update_customer">
+			<wsdl:input message="tns:update_customer" name="update_customer">
+			</wsdl:input>
+			<wsdl:output message="tns:update_customerResponse" name="update_customerResponse">
+			</wsdl:output>
+			<wsdl:fault message="tns:InvalidCustomerException" name="InvalidCustomerException">
+			</wsdl:fault>
+		</wsdl:operation>
+		<wsdl:operation name="get_customer">
+			<wsdl:input message="tns:get_customer" name="get_customer">
+			</wsdl:input>
+			<wsdl:output message="tns:get_customerResponse" name="get_customerResponse">
+			</wsdl:output>
+			<wsdl:fault message="tns:InvalidCustomerException" name="InvalidCustomerException">
+			</wsdl:fault>
+		</wsdl:operation>
+	</wsdl:portType>
+	<wsdl:binding name="CustomersWrapperServiceServiceSoapBinding"
+		type="tns:CustomersWrapperService">
+		<soap:binding style="document"
+			transport="http://schemas.xmlsoap.org/soap/http" />
+		<wsdl:operation name="update_customer">
+			<soap:operation soapAction="" style="document" />
+			<wsdl:input name="update_customer">
+				<soap:body use="literal" />
+			</wsdl:input>
+			<wsdl:output name="update_customerResponse">
+				<soap:body use="literal" />
+			</wsdl:output>
+			<wsdl:fault name="InvalidCustomerException">
+				<soap:fault name="InvalidCustomerException" use="literal" />
+			</wsdl:fault>
+		</wsdl:operation>
+		<wsdl:operation name="get_customer">
+			<soap:operation soapAction="" style="document" />
+			<wsdl:input name="get_customer">
+				<soap:body use="literal" />
+			</wsdl:input>
+			<wsdl:output name="get_customerResponse">
+				<soap:body use="literal" />
+			</wsdl:output>
+			<wsdl:fault name="InvalidCustomerException">
+				<soap:fault name="InvalidCustomerException" use="literal" />
+			</wsdl:fault>
+		</wsdl:operation>
+	</wsdl:binding>
+	<wsdl:service name="CustomersWrapperServiceService">
+		<wsdl:port binding="tns:CustomersWrapperServiceServiceSoapBinding"
+			name="CustomersPT">
+			<soap:address location="http://localhost:9085/customersService" />
+		</wsdl:port>
+	</wsdl:service>
+</wsdl:definitions>

Propchange: cocoon/cocoon3/trunk/cocoon-stax/src/test/resources/org/apache/cocoon/stax/converter/complex-stax-test-document.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/cocoon3/trunk/cocoon-stax/src/test/resources/org/apache/cocoon/stax/converter/complex-stax-test-document.xml
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cocoon/cocoon3/trunk/cocoon-stax/src/test/resources/org/apache/cocoon/stax/converter/complex-stax-test-document.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Modified: cocoon/cocoon3/trunk/cocoon-stringtemplate/src/main/java/org/apache/cocoon/stringtemplate/StringTemplateGenerator.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-stringtemplate/src/main/java/org/apache/cocoon/stringtemplate/StringTemplateGenerator.java?rev=740557&r1=740556&r2=740557&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-stringtemplate/src/main/java/org/apache/cocoon/stringtemplate/StringTemplateGenerator.java
(original)
+++ cocoon/cocoon3/trunk/cocoon-stringtemplate/src/main/java/org/apache/cocoon/stringtemplate/StringTemplateGenerator.java
Wed Feb  4 01:13:31 2009
@@ -32,7 +32,7 @@
 import org.apache.cocoon.pipeline.caching.TimestampCacheKey;
 import org.apache.cocoon.pipeline.component.CachingPipelineComponent;
 import org.apache.cocoon.pipeline.component.Starter;
-import org.apache.cocoon.pipeline.component.sax.AbstractXMLProducer;
+import org.apache.cocoon.sax.AbstractSAXProducer;
 import org.apache.cocoon.servlet.controller.ControllerContextHelper;
 import org.apache.cocoon.sitemap.util.ExceptionHandler;
 import org.apache.commons.io.IOUtils;
@@ -41,7 +41,7 @@
 import org.xml.sax.XMLReader;
 import org.xml.sax.helpers.XMLReaderFactory;
 
-public class StringTemplateGenerator extends AbstractXMLProducer implements Starter, CachingPipelineComponent
{
+public class StringTemplateGenerator extends AbstractSAXProducer implements Starter, CachingPipelineComponent
{
 
     private URL source;
     private Map<String, Object> parameters = new HashMap<String, Object>();
@@ -115,7 +115,7 @@
     /**
      * {@inheritDoc}
      * 
-     * @see org.apache.cocoon.pipeline.component.AbstractXMLProducer#setConfiguration(java.util.Map)
+     * @see org.apache.cocoon.pipeline.component.AbstractSAXProducer#setConfiguration(java.util.Map)
      */
     @Override
     public void setConfiguration(Map<String, ? extends Object> parameters) {



Mime
View raw message