cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From reinh...@apache.org
Subject svn commit: r671045 - in /cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline: component/ util/
Date Tue, 24 Jun 2008 07:13:13 GMT
Author: reinhard
Date: Tue Jun 24 00:13:11 2008
New Revision: 671045

URL: http://svn.apache.org/viewvc?rev=671045&view=rev
Log:
. follow Cocoon trunk by introducing AbstractSerializer -> AbstractXMLPipe -> XMLConsumerAdapter
. provide an EmbeddedXMLPipe and a SaxBuffer
. enhance the AbstractTransformer by recording capabilities
. toSax() for URLConnections (URLConnectionUtils)

Added:
    cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/AbstractSerializer.java   (with props)
    cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/util/AbstractXMLPipe.java   (with props)
    cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/util/EmbeddedXMLPipe.java   (with props)
    cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/util/SaxBuffer.java   (with props)
    cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/util/URLConnectionUtils.java   (with props)
    cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/util/XMLUtils.java   (with props)
Modified:
    cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/AbstractTransformer.java
    cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/FileGenerator.java
    cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/XMLConsumerAdapter.java
    cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/XMLSerializer.java
    cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/XSLTTransformer.java

Added: cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/AbstractSerializer.java
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/AbstractSerializer.java?rev=671045&view=auto
==============================================================================
--- cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/AbstractSerializer.java (added)
+++ cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/AbstractSerializer.java Tue Jun 24 00:13:11 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.corona.pipeline.component;
+
+import java.io.OutputStream;
+import java.util.Map;
+
+import org.apache.cocoon.corona.pipeline.util.AbstractXMLPipe;
+import org.apache.cocoon.corona.pipeline.util.StringRepresentation;
+
+public abstract class AbstractSerializer extends AbstractXMLPipe implements PipelineComponent, Finisher {
+
+    @SuppressWarnings("unused")
+    protected OutputStream outputStream;
+
+    protected String contentType;
+
+    @SuppressWarnings("unused")
+    protected Map<String, ? extends Object> configuration;
+
+    @SuppressWarnings("unused")
+    protected Map<String, Object> inputParameters;
+
+    public void setContentType(String contentType) {
+        this.contentType = contentType;
+    }
+
+    /**
+     * 
+     * {@inheritDoc}
+     * 
+     * @see org.apache.cocoon.corona.pipeline.component.PipelineComponent#setConfiguration(java.util.Map)
+     */
+    public void setConfiguration(Map<String, ? extends Object> parameters) {
+        if (parameters.containsKey("mime-type")) {
+            this.contentType = (String) parameters.get("mime-type");
+        }
+    }
+
+    /**
+     * 
+     * {@inheritDoc}
+     * 
+     * @see org.apache.cocoon.corona.pipeline.component.PipelineComponent#setInputParameters(java.util.Map)
+     */
+    public void setInputParameters(Map<String, Object> parameters) {
+        this.inputParameters = parameters;
+    }
+
+    /**
+     * 
+     * {@inheritDoc}
+     * 
+     * @see org.apache.cocoon.corona.pipeline.component.Finisher#getContentType()
+     */
+    public String getContentType() {
+        return this.contentType;
+    }
+
+    /**
+     * 
+     * {@inheritDoc}
+     * 
+     * @see org.apache.cocoon.corona.pipeline.component.Finisher#setOutputStream(java.io.OutputStream)
+     */
+    public void setOutputStream(OutputStream outputStream) {
+        this.outputStream = outputStream;
+    }
+
+    /**
+     * 
+     * {@inheritDoc}
+     * 
+     * @see java.lang.Object#toString()
+     */
+    @Override
+    public String toString() {
+        return StringRepresentation.buildString(this);
+    }
+}

Propchange: cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/AbstractSerializer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/AbstractSerializer.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/AbstractSerializer.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/AbstractTransformer.java
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/AbstractTransformer.java?rev=671045&r1=671044&r2=671045&view=diff
==============================================================================
--- cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/AbstractTransformer.java (original)
+++ cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/AbstractTransformer.java Tue Jun 24 00:13:11 2008
@@ -16,12 +16,19 @@
  */
 package org.apache.cocoon.corona.pipeline.component;
 
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.cocoon.corona.pipeline.ProcessingException;
+import org.apache.cocoon.corona.pipeline.util.SaxBuffer;
 import org.xml.sax.Attributes;
 import org.xml.sax.Locator;
 import org.xml.sax.SAXException;
 
 public abstract class AbstractTransformer extends AbstractXMLProducer implements XMLConsumer {
 
+    private List<String[]> namespaces = new ArrayList<String[]>();
+
     public void characters(char[] ch, int start, int length) throws SAXException {
         this.getXMLConsumer().characters(ch, start, length);
     }
@@ -51,6 +58,22 @@
     }
 
     public void endPrefixMapping(String prefix) throws SAXException {
+        if (prefix != null) {
+            // Find and remove the namespace prefix
+            boolean found = false;
+            for (int i = this.namespaces.size() - 1; i >= 0; i--) {
+                final String[] prefixAndUri = this.namespaces.get(i);
+                if (prefixAndUri[0].equals(prefix)) {
+                    this.namespaces.remove(i);
+                    found = true;
+                    break;
+                }
+            }
+            if (!found) {
+                throw new SAXException("Namespace for prefix '" + prefix + "' not found.");
+            }
+        }
+
         this.getXMLConsumer().endPrefixMapping(prefix);
     }
 
@@ -91,6 +114,78 @@
     }
 
     public void startPrefixMapping(String prefix, String uri) throws SAXException {
+        if (prefix != null) {
+            this.namespaces.add(new String[] { prefix, uri });
+        }
+
         this.getXMLConsumer().startPrefixMapping(prefix, uri);
     }
+
+    private XMLConsumer originalXMLConsumer;
+
+    private boolean isRecording;
+
+    /**
+     * Set a recorder. Do not invoke this method directly.
+     * 
+     * @param recorder
+     */
+    protected void setRecorder(XMLConsumer recorder) {
+        if (this.isRecording) {
+            throw new ProcessingException("Only one recorder can be set.");
+        }
+
+        this.isRecording = true;
+        this.originalXMLConsumer = this.getXMLConsumer();
+        this.setXMLConsumer(recorder);
+    }
+
+    /**
+     * Remove a recorder. Do not invoke this method directly.
+     */
+    protected XMLConsumer removeRecorder() {
+        XMLConsumer saxBuffer = this.getXMLConsumer();
+        this.setXMLConsumer(this.originalXMLConsumer);
+        this.isRecording = false;
+        return saxBuffer;
+    }
+
+    /**
+     * Start recording of SAX events. All incoming events are recorded and not forwarded. The resulting XMLizable can be
+     * obtained by the matching {@link #endSAXRecording} call.
+     */
+    public void startSAXRecording() throws SAXException {
+        this.setRecorder(new SaxBuffer());
+        this.sendStartPrefixMapping();
+    }
+
+    /**
+     * Stop recording of SAX events. This method returns the resulting XMLizable.
+     */
+    public SaxBuffer endSAXRecording() throws SAXException {
+        this.sendEndPrefixMapping();
+        return (SaxBuffer) this.removeRecorder();
+    }
+
+    /**
+     * Send all start prefix mapping events to the current content handler
+     */
+    protected void sendStartPrefixMapping() throws SAXException {
+        final int l = this.namespaces.size();
+        for (int i = 0; i < l; i++) {
+            String[] prefixAndUri = this.namespaces.get(i);
+            super.getXMLConsumer().startPrefixMapping(prefixAndUri[0], prefixAndUri[1]);
+        }
+    }
+
+    /**
+     * Send all end prefix mapping events to the current content handler
+     */
+    protected void sendEndPrefixMapping() throws SAXException {
+        final int l = this.namespaces.size();
+        for (int i = 0; i < l; i++) {
+            String[] prefixAndUri = this.namespaces.get(i);
+            this.getXMLConsumer().endPrefixMapping(prefixAndUri[0]);
+        }
+    }
 }

Modified: cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/FileGenerator.java
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/FileGenerator.java?rev=671045&r1=671044&r2=671045&view=diff
==============================================================================
--- cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/FileGenerator.java (original)
+++ cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/FileGenerator.java Tue Jun 24 00:13:11 2008
@@ -18,20 +18,16 @@
  */
 package org.apache.cocoon.corona.pipeline.component;
 
-import java.io.BufferedInputStream;
 import java.io.IOException;
-import java.io.InputStream;
 import java.net.URL;
 import java.util.Map;
 
 import org.apache.cocoon.corona.pipeline.caching.CacheKey;
 import org.apache.cocoon.corona.pipeline.caching.TimestampCacheKey;
 import org.apache.cocoon.corona.pipeline.util.StringRepresentation;
+import org.apache.cocoon.corona.pipeline.util.URLConnectionUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.xml.sax.InputSource;
-import org.xml.sax.XMLReader;
-import org.xml.sax.helpers.XMLReaderFactory;
 
 public class FileGenerator extends AbstractXMLProducer implements Starter, CachingPipelineComponent {
 
@@ -73,27 +69,10 @@
             throw new IllegalArgumentException("FileGenerator has no source.");
         }
 
-        InputStream inputStream = null;
         try {
-            XMLReader xmlReader = XMLReaderFactory.createXMLReader();
-
-            xmlReader.setContentHandler(this.getXMLConsumer());
-            xmlReader.setProperty("http://xml.org/sax/properties/lexical-handler", this.getXMLConsumer());
-
-            inputStream = new BufferedInputStream(this.source.openStream());
-
-            xmlReader.parse(new InputSource(inputStream));
-        } catch (Exception e) {
-            this.logger.error("Can't parse " + this.source, e);
-            throw new RuntimeException(e);
-        } finally {
-            if (inputStream != null) {
-                try {
-                    inputStream.close();
-                } catch (IOException e) {
-                    this.logger.error("Error while closing input stream on " + this.source, e);
-                }
-            }
+            URLConnectionUtils.toSax(this.source.openConnection(), this.getXMLConsumer());
+        } catch (IOException e) {
+            throw new RuntimeException("Can't open connection to " + this.source, e);
         }
     }
 

Modified: cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/XMLConsumerAdapter.java
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/XMLConsumerAdapter.java?rev=671045&r1=671044&r2=671045&view=diff
==============================================================================
--- cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/XMLConsumerAdapter.java (original)
+++ cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/XMLConsumerAdapter.java Tue Jun 24 00:13:11 2008
@@ -24,8 +24,12 @@
 
 public class XMLConsumerAdapter implements XMLConsumer {
 
-    private ContentHandler contentHandler;
-    private LexicalHandler lexicalHandler;
+    protected ContentHandler contentHandler;
+    protected LexicalHandler lexicalHandler;
+    protected XMLConsumer consumer;
+
+    public XMLConsumerAdapter() {
+    }
 
     public XMLConsumerAdapter(ContentHandler contentHandler, LexicalHandler lexicalHandler) {
         super();
@@ -33,6 +37,20 @@
         this.lexicalHandler = lexicalHandler;
     }
 
+    public void setConsumer(XMLConsumer consumer) {
+        this.consumer = consumer;
+        this.setContentHandler(consumer);
+        this.setLexicalHandler(consumer);
+    }
+
+    public void setContentHandler(ContentHandler contentHandler) {
+        this.contentHandler = contentHandler;
+    }
+
+    public void setLexicalHandler(LexicalHandler lexicalHandler) {
+        this.lexicalHandler = lexicalHandler;
+    }
+
     public void characters(char[] ch, int start, int length) throws SAXException {
         this.contentHandler.characters(ch, start, length);
     }

Modified: cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/XMLSerializer.java
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/XMLSerializer.java?rev=671045&r1=671044&r2=671045&view=diff
==============================================================================
--- cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/XMLSerializer.java (original)
+++ cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/XMLSerializer.java Tue Jun 24 00:13:11 2008
@@ -19,7 +19,6 @@
 package org.apache.cocoon.corona.pipeline.component;
 
 import java.io.OutputStream;
-import java.util.Map;
 import java.util.Properties;
 
 import javax.xml.transform.TransformerConfigurationException;
@@ -28,135 +27,40 @@
 import javax.xml.transform.sax.TransformerHandler;
 import javax.xml.transform.stream.StreamResult;
 
+import org.apache.cocoon.corona.pipeline.ProcessingException;
 import org.apache.cocoon.corona.pipeline.caching.CacheKey;
 import org.apache.cocoon.corona.pipeline.caching.SimpleCacheKey;
-import org.apache.cocoon.corona.pipeline.util.StringRepresentation;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.xml.sax.Attributes;
-import org.xml.sax.Locator;
-import org.xml.sax.SAXException;
 
-public class XMLSerializer implements XMLConsumer, Finisher, CachingPipelineComponent {
+public class XMLSerializer extends AbstractSerializer implements CachingPipelineComponent {
 
-    private final Log logger = LogFactory.getLog(this.getClass());
     private static final SAXTransformerFactory SAX_TRANSFORMER_FACTORY = (SAXTransformerFactory) TransformerFactory
             .newInstance();
 
-    private String contentType;
     private Properties format = new Properties();
 
     private TransformerHandler transformerHandler;
 
-    public void characters(char[] ch, int start, int length) throws SAXException {
-        this.transformerHandler.characters(ch, start, length);
-    }
-
-    public void comment(char[] ch, int start, int length) throws SAXException {
-        this.transformerHandler.comment(ch, start, length);
-    }
-
-    public CacheKey constructCacheKey() {
-        return new SimpleCacheKey();
-    }
-
-    public void endCDATA() throws SAXException {
-        this.transformerHandler.endCDATA();
-    }
-
-    public void endDocument() throws SAXException {
-        this.transformerHandler.endDocument();
-    }
-
-    public void endDTD() throws SAXException {
-        this.transformerHandler.endDTD();
-    }
-
-    public void endElement(String uri, String localName, String name) throws SAXException {
-        this.transformerHandler.endElement(uri, localName, name);
-    }
-
-    public void endEntity(String name) throws SAXException {
-        this.transformerHandler.endEntity(name);
-    }
-
-    public void endPrefixMapping(String prefix) throws SAXException {
-        this.transformerHandler.endPrefixMapping(prefix);
-    }
-
-    public String getContentType() {
-        return this.contentType;
-    }
-
-    public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException {
-        this.transformerHandler.ignorableWhitespace(ch, start, length);
-    }
-
-    public void processingInstruction(String target, String data) throws SAXException {
-        this.transformerHandler.processingInstruction(target, data);
-    }
-
-    public void setConfiguration(Map<String, ? extends Object> parameters) {
-        if (parameters.containsKey("mime-type")) {
-            this.contentType = (String) parameters.get("mime-type");
-        }
-    }
-
-    public void setContentType(String contentType) {
-        this.contentType = contentType;
-    }
-
-    public void setDocumentLocator(Locator locator) {
-        this.transformerHandler.setDocumentLocator(locator);
-    }
-
-    public void setFormat(Properties format) {
-        this.format = format;
-    }
-
-    public void setInputParameters(Map<String, Object> parameters) {
-    }
-
-    public void setOutputStream(OutputStream outputStream) {
+    public void init() {
         try {
             this.transformerHandler = SAX_TRANSFORMER_FACTORY.newTransformerHandler();
-            this.transformerHandler.getTransformer().setOutputProperties(this.format);
-            this.transformerHandler.setResult(new StreamResult(outputStream));
         } catch (TransformerConfigurationException e) {
-            this.logger.error("Can't configure trax transformer ", e);
+            throw new ProcessingException("Can't setup transformer handler for the serializer.", e);
         }
+        this.transformerHandler.getTransformer().setOutputProperties(this.format);
+        this.setContentHandler(this.transformerHandler);
+        this.setLexicalHandler(this.transformerHandler);
     }
 
-    public void skippedEntity(String name) throws SAXException {
-        this.transformerHandler.skippedEntity(name);
-    }
-
-    public void startCDATA() throws SAXException {
-        this.transformerHandler.startCDATA();
-    }
-
-    public void startDocument() throws SAXException {
-        this.transformerHandler.startDocument();
-    }
-
-    public void startDTD(String name, String publicId, String systemId) throws SAXException {
-        this.transformerHandler.startDTD(name, publicId, systemId);
-    }
-
-    public void startElement(String uri, String localName, String name, Attributes atts) throws SAXException {
-        this.transformerHandler.startElement(uri, localName, name, atts);
-    }
-
-    public void startEntity(String name) throws SAXException {
-        this.transformerHandler.startEntity(name);
+    public CacheKey constructCacheKey() {
+        return new SimpleCacheKey();
     }
 
-    public void startPrefixMapping(String prefix, String uri) throws SAXException {
-        this.transformerHandler.startPrefixMapping(prefix, uri);
+    public void setFormat(Properties format) {
+        this.format = format;
     }
 
     @Override
-    public String toString() {
-        return StringRepresentation.buildString(this);
+    public void setOutputStream(OutputStream outputStream) {
+        this.transformerHandler.setResult(new StreamResult(outputStream));
     }
 }

Modified: cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/XSLTTransformer.java
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/XSLTTransformer.java?rev=671045&r1=671044&r2=671045&view=diff
==============================================================================
--- cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/XSLTTransformer.java (original)
+++ cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/XSLTTransformer.java Tue Jun 24 00:13:11 2008
@@ -91,7 +91,9 @@
 
         XMLReader xmlReader = XMLReaderFactory.createXMLReader();
         xmlReader.setContentHandler(templatesHandler);
-        xmlReader.parse(new InputSource(this.source.toURI().toString()));
+        String systemId = this.source.toURI().toString();
+        InputSource inputSource = new InputSource(systemId);
+        xmlReader.parse(inputSource);
 
         // Create transformer handler
         final TransformerHandler handler = transformerFactory.newTransformerHandler(templatesHandler.getTemplates());

Added: cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/util/AbstractXMLPipe.java
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/util/AbstractXMLPipe.java?rev=671045&view=auto
==============================================================================
--- cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/util/AbstractXMLPipe.java (added)
+++ cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/util/AbstractXMLPipe.java Tue Jun 24 00:13:11 2008
@@ -0,0 +1,225 @@
+/*
+ * 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.corona.pipeline.util;
+
+import org.apache.cocoon.corona.pipeline.component.XMLConsumerAdapter;
+import org.xml.sax.Attributes;
+import org.xml.sax.ContentHandler;
+import org.xml.sax.Locator;
+import org.xml.sax.SAXException;
+import org.xml.sax.ext.LexicalHandler;
+
+/**
+ * This class provides a bridge class to connect to existing content handlers and lexical handlers.
+ */
+public abstract class AbstractXMLPipe extends XMLConsumerAdapter {
+
+    public AbstractXMLPipe() {
+    }
+
+    public AbstractXMLPipe(ContentHandler contentHandler, LexicalHandler lexicalHandler) {
+        super(contentHandler, lexicalHandler);
+    }
+
+    /**
+     * Receive an object for locating the origin of SAX document events.
+     * 
+     * @param locator An object that can return the location of any SAX document event.
+     */
+    @Override
+    public void setDocumentLocator(Locator locator) {
+        this.contentHandler.setDocumentLocator(locator);
+    }
+
+    /**
+     * Receive notification of the beginning of a document.
+     */
+    @Override
+    public void startDocument() throws SAXException {
+        this.contentHandler.startDocument();
+    }
+
+    /**
+     * Receive notification of the end of a document.
+     */
+    @Override
+    public void endDocument() throws SAXException {
+        this.contentHandler.endDocument();
+    }
+
+    /**
+     * Begin the scope of a prefix-URI Namespace mapping.
+     * 
+     * @param prefix The Namespace prefix being declared.
+     * @param uri The Namespace URI the prefix is mapped to.
+     */
+    @Override
+    public void startPrefixMapping(String prefix, String uri) throws SAXException {
+        this.contentHandler.startPrefixMapping(prefix, uri);
+    }
+
+    /**
+     * End the scope of a prefix-URI mapping.
+     * 
+     * @param prefix The prefix that was being mapping.
+     */
+    @Override
+    public void endPrefixMapping(String prefix) throws SAXException {
+        this.contentHandler.endPrefixMapping(prefix);
+    }
+
+    /**
+     * Receive notification of the beginning of an element.
+     * 
+     * @param uri The Namespace URI, or the empty string if the element has no Namespace URI or if Namespace processing
+     *            is not being performed.
+     * @param loc The local name (without prefix), or the empty string if Namespace processing is not being performed.
+     * @param raw The raw XML 1.0 name (with prefix), or the empty string if raw names are not available.
+     * @param a The attributes attached to the element. If there are no attributes, it shall be an empty Attributes
+     *            object.
+     */
+    @Override
+    public void startElement(String uri, String loc, String raw, Attributes a) throws SAXException {
+        this.contentHandler.startElement(uri, loc, raw, a);
+    }
+
+    /**
+     * Receive notification of the end of an element.
+     * 
+     * @param uri The Namespace URI, or the empty string if the element has no Namespace URI or if Namespace processing
+     *            is not being performed.
+     * @param loc The local name (without prefix), or the empty string if Namespace processing is not being performed.
+     * @param raw The raw XML 1.0 name (with prefix), or the empty string if raw names are not available.
+     */
+    @Override
+    public void endElement(String uri, String loc, String raw) throws SAXException {
+        this.contentHandler.endElement(uri, loc, raw);
+    }
+
+    /**
+     * Receive notification of character data.
+     * 
+     * @param c The characters from the XML document.
+     * @param start The start position in the array.
+     * @param len The number of characters to read from the array.
+     */
+    @Override
+    public void characters(char c[], int start, int len) throws SAXException {
+        this.contentHandler.characters(c, start, len);
+    }
+
+    /**
+     * Receive notification of ignorable whitespace in element content.
+     * 
+     * @param c The characters from the XML document.
+     * @param start The start position in the array.
+     * @param len The number of characters to read from the array.
+     */
+    @Override
+    public void ignorableWhitespace(char c[], int start, int len) throws SAXException {
+        this.contentHandler.ignorableWhitespace(c, start, len);
+    }
+
+    /**
+     * Receive notification of a processing instruction.
+     * 
+     * @param target The processing instruction target.
+     * @param data The processing instruction data, or null if none was supplied.
+     */
+    @Override
+    public void processingInstruction(String target, String data) throws SAXException {
+        this.contentHandler.processingInstruction(target, data);
+    }
+
+    /**
+     * Receive notification of a skipped entity.
+     * 
+     * @param name The name of the skipped entity. If it is a parameter entity, the name will begin with '%'.
+     */
+    @Override
+    public void skippedEntity(String name) throws SAXException {
+        this.contentHandler.skippedEntity(name);
+    }
+
+    /**
+     * Report the start of DTD declarations, if any.
+     * 
+     * @param name The document type name.
+     * @param publicId The declared public identifier for the external DTD subset, or null if none was declared.
+     * @param systemId The declared system identifier for the external DTD subset, or null if none was declared.
+     */
+    @Override
+    public void startDTD(String name, String publicId, String systemId) throws SAXException {
+        this.lexicalHandler.startDTD(name, publicId, systemId);
+    }
+
+    /**
+     * Report the end of DTD declarations.
+     */
+    @Override
+    public void endDTD() throws SAXException {
+        this.lexicalHandler.endDTD();
+    }
+
+    /**
+     * Report the beginning of an entity.
+     * 
+     * @param name The name of the entity. If it is a parameter entity, the name will begin with '%'.
+     */
+    @Override
+    public void startEntity(String name) throws SAXException {
+        this.lexicalHandler.startEntity(name);
+    }
+
+    /**
+     * Report the end of an entity.
+     * 
+     * @param name The name of the entity that is ending.
+     */
+    @Override
+    public void endEntity(String name) throws SAXException {
+        this.lexicalHandler.endEntity(name);
+    }
+
+    /**
+     * Report the start of a CDATA section.
+     */
+    @Override
+    public void startCDATA() throws SAXException {
+        this.lexicalHandler.startCDATA();
+    }
+
+    /**
+     * Report the end of a CDATA section.
+     */
+    @Override
+    public void endCDATA() throws SAXException {
+        this.lexicalHandler.endCDATA();
+    }
+
+    /**
+     * Report an XML comment anywhere in the document.
+     * 
+     * @param ch An array holding the characters in the comment.
+     * @param start The starting position in the array.
+     * @param len The number of characters to use from the array.
+     */
+    @Override
+    public void comment(char ch[], int start, int len) throws SAXException {
+        this.lexicalHandler.comment(ch, start, len);
+    }
+}

Propchange: cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/util/AbstractXMLPipe.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/util/AbstractXMLPipe.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/util/AbstractXMLPipe.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/util/EmbeddedXMLPipe.java
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/util/EmbeddedXMLPipe.java?rev=671045&view=auto
==============================================================================
--- cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/util/EmbeddedXMLPipe.java (added)
+++ cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/util/EmbeddedXMLPipe.java Tue Jun 24 00:13:11 2008
@@ -0,0 +1,109 @@
+/*
+ * 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.corona.pipeline.util;
+
+import org.apache.cocoon.corona.pipeline.component.XMLConsumer;
+import org.xml.sax.ContentHandler;
+import org.xml.sax.SAXException;
+import org.xml.sax.ext.LexicalHandler;
+
+/**
+ * This class implements a ContentHandler for embedding a full SAX event stream into an existing stream of SAX events.
+ * An instance of this class will pass unmodified all the SAX events to the linked ContentHandler, but it will ignore
+ * the startDocument/endDocument and startDTD/endDTD events, as well as all comment events within the DTD.
+ * 
+ * @version $Id$
+ */
+public class EmbeddedXMLPipe extends AbstractXMLPipe {
+
+    private boolean inDTD;
+
+    public EmbeddedXMLPipe() {
+    }
+
+    public EmbeddedXMLPipe(ContentHandler handler) {
+        this.setContentHandler(handler);
+        if (handler instanceof LexicalHandler) {
+            this.setLexicalHandler((LexicalHandler) handler);
+        }
+    }
+
+    public EmbeddedXMLPipe(ContentHandler contentHandler, LexicalHandler lexicalHandler) {
+        super();
+        this.contentHandler = contentHandler;
+        this.lexicalHandler = lexicalHandler;
+    }
+
+    /**
+     * Creates an EmbeddedXMLPipe that writes into the given XMLConsumer.
+     */
+    public EmbeddedXMLPipe(XMLConsumer consumer) {
+        this.setConsumer(consumer);
+    }
+
+    /**
+     * Ignore the <code>startDocument</code> event: this method does nothing.
+     * 
+     * @exception SAXException if an error occurs
+     */
+    @Override
+    public void startDocument() throws SAXException {
+    }
+
+    /**
+     * Ignore the <code>endDocument</code> event: this method does nothing.
+     * 
+     * @exception SAXException if an error occurs
+     */
+    @Override
+    public void endDocument() throws SAXException {
+    }
+
+    /**
+     * Ignore the <code>startDTD</code> event: this method does nothing.
+     * 
+     * @exception SAXException if an error occurs
+     */
+    @Override
+    public void startDTD(String name, String publicId, String systemId) throws SAXException {
+        // Ignored
+        this.inDTD = true;
+    }
+
+    /**
+     * Ignore the <code>endDTD</code> event: this method does nothing.
+     * 
+     * @exception SAXException if an error occurs
+     */
+    @Override
+    public void endDTD() throws SAXException {
+        // Ignored
+        this.inDTD = false;
+    }
+
+    /**
+     * Ignore all <code>comment</code> events if between startDTD/endDTD events.
+     * 
+     * @exception SAXException if an error occurs
+     */
+    @Override
+    public void comment(char ch[], int start, int len) throws SAXException {
+        if (!this.inDTD) {
+            super.comment(ch, start, len);
+        }
+    }
+}

Propchange: cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/util/EmbeddedXMLPipe.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/util/EmbeddedXMLPipe.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/util/EmbeddedXMLPipe.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/util/SaxBuffer.java
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/util/SaxBuffer.java?rev=671045&view=auto
==============================================================================
--- cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/util/SaxBuffer.java (added)
+++ cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/util/SaxBuffer.java Tue Jun 24 00:13:11 2008
@@ -0,0 +1,543 @@
+/*
+ * 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.corona.pipeline.util;
+
+import java.io.IOException;
+import java.io.Serializable;
+import java.io.Writer;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.cocoon.corona.pipeline.component.XMLConsumer;
+import org.xml.sax.Attributes;
+import org.xml.sax.ContentHandler;
+import org.xml.sax.Locator;
+import org.xml.sax.SAXException;
+import org.xml.sax.ext.LexicalHandler;
+
+/**
+ * A class that can record SAX events and replay them later.
+ * 
+ * <p>
+ * Use this class if you need to frequently generate smaller amounts of SAX events, or replay a set of recorded start
+ * events immediately.
+ * </p>
+ * 
+ * <p>
+ * Both {@link ContentHandler} and {@link LexicalHandler} are supported, the only exception is that the
+ * setDocumentLocator event is not recorded.
+ * </p>
+ * 
+ * @version $Id$
+ */
+public class SaxBuffer implements XMLConsumer, Serializable {
+
+    /**
+     * Stores list of {@link SaxBit} objects.
+     */
+    protected List saxbits;
+
+    /**
+     * Creates empty SaxBuffer
+     */
+    public SaxBuffer() {
+        this.saxbits = new ArrayList();
+    }
+
+    /**
+     * Creates SaxBuffer based on the provided bits list.
+     */
+    public SaxBuffer(List bits) {
+        this.saxbits = bits;
+    }
+
+    /**
+     * Creates copy of another SaxBuffer
+     */
+    public SaxBuffer(SaxBuffer saxBuffer) {
+        this.saxbits = new ArrayList(saxBuffer.saxbits);
+    }
+
+    //
+    // ContentHandler Interface
+    //
+
+    public void skippedEntity(String name) throws SAXException {
+        this.saxbits.add(new SkippedEntity(name));
+    }
+
+    public void setDocumentLocator(Locator locator) {
+        // Don't record this event
+    }
+
+    public void ignorableWhitespace(char ch[], int start, int length) throws SAXException {
+        this.saxbits.add(new IgnorableWhitespace(ch, start, length));
+    }
+
+    public void processingInstruction(String target, String data) throws SAXException {
+        this.saxbits.add(new PI(target, data));
+    }
+
+    public void startDocument() throws SAXException {
+        this.saxbits.add(StartDocument.SINGLETON);
+    }
+
+    public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException {
+        this.saxbits.add(new StartElement(namespaceURI, localName, qName, atts));
+    }
+
+    public void endPrefixMapping(String prefix) throws SAXException {
+        this.saxbits.add(new EndPrefixMapping(prefix));
+    }
+
+    public void characters(char ch[], int start, int length) throws SAXException {
+        this.saxbits.add(new Characters(ch, start, length));
+    }
+
+    public void endElement(String namespaceURI, String localName, String qName) throws SAXException {
+        this.saxbits.add(new EndElement(namespaceURI, localName, qName));
+    }
+
+    public void endDocument() throws SAXException {
+        this.saxbits.add(EndDocument.SINGLETON);
+    }
+
+    public void startPrefixMapping(String prefix, String uri) throws SAXException {
+        this.saxbits.add(new StartPrefixMapping(prefix, uri));
+    }
+
+    //
+    // LexicalHandler Interface
+    //
+
+    public void endCDATA() throws SAXException {
+        this.saxbits.add(EndCDATA.SINGLETON);
+    }
+
+    public void comment(char ch[], int start, int length) throws SAXException {
+        this.saxbits.add(new Comment(ch, start, length));
+    }
+
+    public void startEntity(String name) throws SAXException {
+        this.saxbits.add(new StartEntity(name));
+    }
+
+    public void endDTD() throws SAXException {
+        this.saxbits.add(EndDTD.SINGLETON);
+    }
+
+    public void startDTD(String name, String publicId, String systemId) throws SAXException {
+        this.saxbits.add(new StartDTD(name, publicId, systemId));
+    }
+
+    public void startCDATA() throws SAXException {
+        this.saxbits.add(StartCDATA.SINGLETON);
+    }
+
+    public void endEntity(String name) throws SAXException {
+        this.saxbits.add(new EndEntity(name));
+    }
+
+    //
+    // Public Methods
+    //
+
+    /**
+     * @return true if buffer is empty
+     */
+    public boolean isEmpty() {
+        return this.saxbits.isEmpty();
+    }
+
+    /**
+     * @return unmodifiable list of SAX bits
+     */
+    public List getBits() {
+        return Collections.unmodifiableList(this.saxbits);
+    }
+
+    /**
+     * Stream this buffer into the provided content handler. If contentHandler object implements LexicalHandler, it will
+     * get lexical events as well.
+     */
+    public void toSAX(ContentHandler contentHandler) throws SAXException {
+        for (Iterator i = this.saxbits.iterator(); i.hasNext();) {
+            SaxBit saxbit = (SaxBit) i.next();
+            saxbit.send(contentHandler);
+        }
+    }
+
+    /**
+     * @return String value of the buffer
+     */
+    @Override
+    public String toString() {
+        // NOTE: This method is used in i18n XML bundle implementation
+        final StringBuffer value = new StringBuffer();
+        for (Iterator i = this.saxbits.iterator(); i.hasNext();) {
+            final SaxBit saxbit = (SaxBit) i.next();
+            if (saxbit instanceof Characters) {
+                ((Characters) saxbit).toString(value);
+            }
+        }
+
+        return value.toString();
+    }
+
+    /**
+     * Dump buffer contents into the provided writer.
+     */
+    public void dump(Writer writer) throws IOException {
+        Iterator i = this.saxbits.iterator();
+        while (i.hasNext()) {
+            final SaxBit saxbit = (SaxBit) i.next();
+            saxbit.dump(writer);
+        }
+        writer.flush();
+    }
+
+    //
+    // Implementation Methods
+    //
+
+    /**
+     * Adds a SaxBit to the bits list
+     */
+    protected final void addBit(SaxBit bit) {
+        this.saxbits.add(bit);
+    }
+
+    /**
+     * Iterates through the bits list
+     */
+    protected final Iterator bits() {
+        return this.saxbits.iterator();
+    }
+
+    /**
+     * SaxBit is a representation of the SAX event. Every SaxBit is immutable object.
+     */
+    interface SaxBit {
+        public void send(ContentHandler contentHandler) throws SAXException;
+
+        public void dump(Writer writer) throws IOException;
+    }
+
+    public final static class StartDocument implements SaxBit, Serializable {
+        public static final StartDocument SINGLETON = new StartDocument();
+
+        public void send(ContentHandler contentHandler) throws SAXException {
+            contentHandler.startDocument();
+        }
+
+        public void dump(Writer writer) throws IOException {
+            writer.write("[StartDocument]\n");
+        }
+    }
+
+    public final static class EndDocument implements SaxBit, Serializable {
+        public static final EndDocument SINGLETON = new EndDocument();
+
+        public void send(ContentHandler contentHandler) throws SAXException {
+            contentHandler.endDocument();
+        }
+
+        public void dump(Writer writer) throws IOException {
+            writer.write("[EndDocument]\n");
+        }
+    }
+
+    public final static class PI implements SaxBit, Serializable {
+        public final String target;
+        public final String data;
+
+        public PI(String target, String data) {
+            this.target = target;
+            this.data = data;
+        }
+
+        public void send(ContentHandler contentHandler) throws SAXException {
+            contentHandler.processingInstruction(this.target, this.data);
+        }
+
+        public void dump(Writer writer) throws IOException {
+            writer.write("[ProcessingInstruction] target=" + this.target + ",data=" + this.data + "\n");
+        }
+    }
+
+    public final static class StartDTD implements SaxBit, Serializable {
+        public final String name;
+        public final String publicId;
+        public final String systemId;
+
+        public StartDTD(String name, String publicId, String systemId) {
+            this.name = name;
+            this.publicId = publicId;
+            this.systemId = systemId;
+        }
+
+        public void send(ContentHandler contentHandler) throws SAXException {
+            if (contentHandler instanceof LexicalHandler) {
+                ((LexicalHandler) contentHandler).startDTD(this.name, this.publicId, this.systemId);
+            }
+        }
+
+        public void dump(Writer writer) throws IOException {
+            writer.write("[StartDTD] name=" + this.name + ",publicId=" + this.publicId + ",systemId=" + this.systemId
+                    + "\n");
+        }
+    }
+
+    public final static class EndDTD implements SaxBit, Serializable {
+        public static final EndDTD SINGLETON = new EndDTD();
+
+        public void send(ContentHandler contentHandler) throws SAXException {
+            if (contentHandler instanceof LexicalHandler) {
+                ((LexicalHandler) contentHandler).endDTD();
+            }
+        }
+
+        public void dump(Writer writer) throws IOException {
+            writer.write("[EndDTD]\n");
+        }
+    }
+
+    public final static class StartEntity implements SaxBit, Serializable {
+        public final String name;
+
+        public StartEntity(String name) {
+            this.name = name;
+        }
+
+        public void send(ContentHandler contentHandler) throws SAXException {
+            if (contentHandler instanceof LexicalHandler) {
+                ((LexicalHandler) contentHandler).startEntity(this.name);
+            }
+        }
+
+        public void dump(Writer writer) throws IOException {
+            writer.write("[StartEntity] name=" + this.name + "\n");
+        }
+    }
+
+    public final static class EndEntity implements SaxBit, Serializable {
+        public final String name;
+
+        public EndEntity(String name) {
+            this.name = name;
+        }
+
+        public void send(ContentHandler contentHandler) throws SAXException {
+            if (contentHandler instanceof LexicalHandler) {
+                ((LexicalHandler) contentHandler).endEntity(this.name);
+            }
+        }
+
+        public void dump(Writer writer) throws IOException {
+            writer.write("[EndEntity] name=" + this.name + "\n");
+        }
+    }
+
+    public final static class SkippedEntity implements SaxBit, Serializable {
+        public final String name;
+
+        public SkippedEntity(String name) {
+            this.name = name;
+        }
+
+        public void send(ContentHandler contentHandler) throws SAXException {
+            contentHandler.skippedEntity(this.name);
+        }
+
+        public void dump(Writer writer) throws IOException {
+            writer.write("[SkippedEntity] name=" + this.name + "\n");
+        }
+    }
+
+    public final static class StartPrefixMapping implements SaxBit, Serializable {
+        public final String prefix;
+        public final String uri;
+
+        public StartPrefixMapping(String prefix, String uri) {
+            this.prefix = prefix;
+            this.uri = uri;
+        }
+
+        public void send(ContentHandler contentHandler) throws SAXException {
+            contentHandler.startPrefixMapping(this.prefix, this.uri);
+        }
+
+        public void dump(Writer writer) throws IOException {
+            writer.write("[StartPrefixMapping] prefix=" + this.prefix + ",uri=" + this.uri + "\n");
+        }
+    }
+
+    public final static class EndPrefixMapping implements SaxBit, Serializable {
+        public final String prefix;
+
+        public EndPrefixMapping(String prefix) {
+            this.prefix = prefix;
+        }
+
+        public void send(ContentHandler contentHandler) throws SAXException {
+            contentHandler.endPrefixMapping(this.prefix);
+        }
+
+        public void dump(Writer writer) throws IOException {
+            writer.write("[EndPrefixMapping] prefix=" + this.prefix + "\n");
+        }
+    }
+
+    public final static class StartElement implements SaxBit, Serializable {
+        public final String namespaceURI;
+        public final String localName;
+        public final String qName;
+        public final Attributes attrs;
+
+        public StartElement(String namespaceURI, String localName, String qName, Attributes attrs) {
+            this.namespaceURI = namespaceURI;
+            this.localName = localName;
+            this.qName = qName;
+            this.attrs = new org.xml.sax.helpers.AttributesImpl(attrs);
+        }
+
+        public void send(ContentHandler contentHandler) throws SAXException {
+            contentHandler.startElement(this.namespaceURI, this.localName, this.qName, this.attrs);
+        }
+
+        public void dump(Writer writer) throws IOException {
+            writer.write("[StartElement] namespaceURI=" + this.namespaceURI + ",localName=" + this.localName
+                    + ",qName=" + this.qName + "\n");
+            for (int i = 0; i < this.attrs.getLength(); i++) {
+                writer.write("      [Attribute] namespaceURI=" + this.attrs.getURI(i) + ",localName="
+                        + this.attrs.getLocalName(i) + ",qName=" + this.attrs.getQName(i) + ",type="
+                        + this.attrs.getType(i) + ",value=" + this.attrs.getValue(i) + "\n");
+            }
+        }
+    }
+
+    public final static class EndElement implements SaxBit, Serializable {
+        public final String namespaceURI;
+        public final String localName;
+        public final String qName;
+
+        public EndElement(String namespaceURI, String localName, String qName) {
+            this.namespaceURI = namespaceURI;
+            this.localName = localName;
+            this.qName = qName;
+        }
+
+        public void send(ContentHandler contentHandler) throws SAXException {
+            contentHandler.endElement(this.namespaceURI, this.localName, this.qName);
+        }
+
+        public void dump(Writer writer) throws IOException {
+            writer.write("[EndElement] namespaceURI=" + this.namespaceURI + ",localName=" + this.localName + ",qName="
+                    + this.qName + "\n");
+        }
+    }
+
+    public final static class Characters implements SaxBit, Serializable {
+        public final char[] ch;
+
+        public Characters(char[] ch, int start, int length) {
+            // make a copy so that we don't hold references to a potentially large array we don't control
+            this.ch = new char[length];
+            System.arraycopy(ch, start, this.ch, 0, length);
+        }
+
+        public void send(ContentHandler contentHandler) throws SAXException {
+            contentHandler.characters(this.ch, 0, this.ch.length);
+        }
+
+        public void toString(StringBuffer value) {
+            value.append(this.ch);
+        }
+
+        public void dump(Writer writer) throws IOException {
+            writer.write("[Characters] ch=" + new String(this.ch) + "\n");
+        }
+    }
+
+    public final static class Comment implements SaxBit, Serializable {
+        public final char[] ch;
+
+        public Comment(char[] ch, int start, int length) {
+            // make a copy so that we don't hold references to a potentially large array we don't control
+            this.ch = new char[length];
+            System.arraycopy(ch, start, this.ch, 0, length);
+        }
+
+        public void send(ContentHandler contentHandler) throws SAXException {
+            if (contentHandler instanceof LexicalHandler) {
+                ((LexicalHandler) contentHandler).comment(this.ch, 0, this.ch.length);
+            }
+        }
+
+        public void dump(Writer writer) throws IOException {
+            writer.write("[Comment] ch=" + new String(this.ch) + "\n");
+        }
+    }
+
+    public final static class StartCDATA implements SaxBit, Serializable {
+        public static final StartCDATA SINGLETON = new StartCDATA();
+
+        public void send(ContentHandler contentHandler) throws SAXException {
+            if (contentHandler instanceof LexicalHandler) {
+                ((LexicalHandler) contentHandler).startCDATA();
+            }
+        }
+
+        public void dump(Writer writer) throws IOException {
+            writer.write("[StartCDATA]\n");
+        }
+    }
+
+    public final static class EndCDATA implements SaxBit, Serializable {
+        public static final EndCDATA SINGLETON = new EndCDATA();
+
+        public void send(ContentHandler contentHandler) throws SAXException {
+            if (contentHandler instanceof LexicalHandler) {
+                ((LexicalHandler) contentHandler).endCDATA();
+            }
+        }
+
+        public void dump(Writer writer) throws IOException {
+            writer.write("[EndCDATA]\n");
+        }
+    }
+
+    public final static class IgnorableWhitespace implements SaxBit, Serializable {
+        public final char[] ch;
+
+        public IgnorableWhitespace(char[] ch, int start, int length) {
+            // make a copy so that we don't hold references to a potentially large array we don't control
+            this.ch = new char[length];
+            System.arraycopy(ch, start, this.ch, 0, length);
+        }
+
+        public void send(ContentHandler contentHandler) throws SAXException {
+            contentHandler.ignorableWhitespace(this.ch, 0, this.ch.length);
+        }
+
+        public void dump(Writer writer) throws IOException {
+            writer.write("[IgnorableWhitespace] ch=" + new String(this.ch) + "\n");
+        }
+    }
+}

Propchange: cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/util/SaxBuffer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/util/SaxBuffer.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/util/SaxBuffer.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/util/URLConnectionUtils.java
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/util/URLConnectionUtils.java?rev=671045&view=auto
==============================================================================
--- cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/util/URLConnectionUtils.java (added)
+++ cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/util/URLConnectionUtils.java Tue Jun 24 00:13:11 2008
@@ -0,0 +1,47 @@
+/*
+ * 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.corona.pipeline.util;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URLConnection;
+
+import org.apache.cocoon.corona.pipeline.component.XMLConsumer;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+public abstract class URLConnectionUtils {
+
+    private static final Log LOGGER = LogFactory.getLog(URLConnectionUtils.class);
+
+    public static void toSax(URLConnection urlConnection, XMLConsumer xmlConsumer) {
+        InputStream inputStream = null;
+        try {
+            XMLUtils.toSax(urlConnection.getInputStream(), xmlConsumer);
+        } catch (Exception e) {
+            throw new RuntimeException("Can't parse url connection " + urlConnection.getURL(), e);
+        } finally {
+            if (inputStream != null) {
+                try {
+                    inputStream.close();
+                } catch (IOException e) {
+                    LOGGER.error("Error while closing input stream on " + urlConnection.getURL(), e);
+                }
+            }
+        }
+    }
+}
\ No newline at end of file

Propchange: cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/util/URLConnectionUtils.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/util/URLConnectionUtils.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/util/URLConnectionUtils.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/util/XMLUtils.java
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/util/XMLUtils.java?rev=671045&view=auto
==============================================================================
--- cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/util/XMLUtils.java (added)
+++ cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/util/XMLUtils.java Tue Jun 24 00:13:11 2008
@@ -0,0 +1,65 @@
+/*
+ * 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.corona.pipeline.util;
+
+import java.io.BufferedInputStream;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.sax.SAXTransformerFactory;
+import javax.xml.transform.sax.TransformerHandler;
+import javax.xml.transform.stream.StreamResult;
+
+import org.apache.cocoon.corona.pipeline.component.XMLConsumer;
+import org.xml.sax.InputSource;
+import org.xml.sax.XMLReader;
+import org.xml.sax.helpers.XMLReaderFactory;
+
+public abstract class XMLUtils {
+
+    private static final SAXTransformerFactory SAX_TRANSFORMER_FACTORY = (SAXTransformerFactory) TransformerFactory
+            .newInstance();
+
+    public static void toSax(InputStream inputStream, XMLConsumer xmlConsumer) {
+        try {
+            XMLReader xmlReader = XMLReaderFactory.createXMLReader();
+            xmlReader.setContentHandler(xmlConsumer);
+            xmlReader.setProperty("http://xml.org/sax/properties/lexical-handler", xmlConsumer);
+
+            inputStream = new BufferedInputStream(inputStream);
+            xmlReader.parse(new InputSource(inputStream));
+        } catch (Exception e) {
+            throw new RuntimeException("Can't parse inputStream.", e);
+        }
+    }
+
+    public static void toOutputStream(OutputStream outputStream, SaxBuffer saxBuffer) {
+        try {
+            TransformerHandler transformerHandler = SAX_TRANSFORMER_FACTORY.newTransformerHandler();
+            transformerHandler.getTransformer().setOutputProperties(null);
+            transformerHandler.setResult(new StreamResult(outputStream));
+
+            transformerHandler.startDocument();
+            saxBuffer.toSAX(new EmbeddedXMLPipe(transformerHandler));
+            transformerHandler.endDocument();
+        } catch (Exception e) {
+            throw new RuntimeException("Can't stream the provided SaxBuffer.", e);
+        }
+    }
+
+}
\ No newline at end of file

Propchange: cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/util/XMLUtils.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/util/XMLUtils.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/util/XMLUtils.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message