You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by re...@apache.org on 2009/12/11 14:57:25 UTC
svn commit: r889623 - in /cocoon/cocoon3/trunk:
cocoon-optional/src/test/java/org/apache/cocoon/optional/pipeline/components/sax/fop/
cocoon-optional/src/test/java/org/apache/cocoon/optional/pipeline/components/sax/solr/
cocoon-sax/src/main/java/org/ap...
Author: reinhard
Date: Fri Dec 11 13:57:24 2009
New Revision: 889623
URL: http://svn.apache.org/viewvc?rev=889623&view=rev
Log:
add SAXGenerator (constructors for File, InputStream, String, Node) which is useful if the pipeline API is used directly
Added:
cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/component/SAXGenerator.java (with props)
cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/component/URLGenerator.java
- copied, changed from r824908, cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/component/FileGenerator.java
cocoon/cocoon3/trunk/cocoon-sax/src/test/java/org/apache/cocoon/sax/component/
cocoon/cocoon3/trunk/cocoon-sax/src/test/java/org/apache/cocoon/sax/component/SAXGeneratorTest.java (with props)
Removed:
cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/component/FileGenerator.java
cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/component/StringGenerator.java
Modified:
cocoon/cocoon3/trunk/cocoon-optional/src/test/java/org/apache/cocoon/optional/pipeline/components/sax/fop/FopSerializerTestCase.java
cocoon/cocoon3/trunk/cocoon-optional/src/test/java/org/apache/cocoon/optional/pipeline/components/sax/solr/SolrConsumerTestCase.java
cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/util/TransformationUtils.java
cocoon/cocoon3/trunk/cocoon-sax/src/test/java/org/apache/cocoon/sax/PipelineTest.java
cocoon/cocoon3/trunk/cocoon-sax/src/test/java/org/apache/cocoon/sax/SchemaProcessorTransformerTest.java
cocoon/cocoon3/trunk/cocoon-sitemap/src/main/resources/META-INF/cocoon/spring/cocoon-pipeline-component.xml
cocoon/cocoon3/trunk/cocoon-stax/src/test/java/org/apache/cocoon/stax/CleaningTransformerTest.java
cocoon/cocoon3/trunk/cocoon-stax/src/test/java/org/apache/cocoon/stax/StAXPipelineTest.java
cocoon/cocoon3/trunk/cocoon-stax/src/test/java/org/apache/cocoon/stax/converter/SAXForStAXPipelineWrapperTest.java
cocoon/cocoon3/trunk/cocoon-stax/src/test/java/org/apache/cocoon/stax/converter/StAXToSAXPipelineAdapterTest.java
Modified: cocoon/cocoon3/trunk/cocoon-optional/src/test/java/org/apache/cocoon/optional/pipeline/components/sax/fop/FopSerializerTestCase.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-optional/src/test/java/org/apache/cocoon/optional/pipeline/components/sax/fop/FopSerializerTestCase.java?rev=889623&r1=889622&r2=889623&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-optional/src/test/java/org/apache/cocoon/optional/pipeline/components/sax/fop/FopSerializerTestCase.java (original)
+++ cocoon/cocoon3/trunk/cocoon-optional/src/test/java/org/apache/cocoon/optional/pipeline/components/sax/fop/FopSerializerTestCase.java Fri Dec 11 13:57:24 2009
@@ -25,7 +25,7 @@
import org.apache.cocoon.pipeline.NonCachingPipeline;
import org.apache.cocoon.pipeline.Pipeline;
import org.apache.cocoon.sax.SAXPipelineComponent;
-import org.apache.cocoon.sax.component.FileGenerator;
+import org.apache.cocoon.sax.component.URLGenerator;
import org.apache.cocoon.sax.component.XSLTTransformer;
import org.apache.commons.io.IOUtils;
import org.junit.Test;
@@ -35,7 +35,7 @@
@Test
public void testPipelineWithFOPSerializer() throws Exception {
Pipeline<SAXPipelineComponent> pipeline = new NonCachingPipeline<SAXPipelineComponent>();
- pipeline.addComponent(new FileGenerator(this.getClass().getResource("page.xml")));
+ pipeline.addComponent(new URLGenerator(this.getClass().getResource("page.xml")));
pipeline.addComponent(new XSLTTransformer(this.getClass().getResource("page2fo.xsl")));
pipeline.addComponent(new FopSerializer());
Modified: cocoon/cocoon3/trunk/cocoon-optional/src/test/java/org/apache/cocoon/optional/pipeline/components/sax/solr/SolrConsumerTestCase.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-optional/src/test/java/org/apache/cocoon/optional/pipeline/components/sax/solr/SolrConsumerTestCase.java?rev=889623&r1=889622&r2=889623&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-optional/src/test/java/org/apache/cocoon/optional/pipeline/components/sax/solr/SolrConsumerTestCase.java (original)
+++ cocoon/cocoon3/trunk/cocoon-optional/src/test/java/org/apache/cocoon/optional/pipeline/components/sax/solr/SolrConsumerTestCase.java Fri Dec 11 13:57:24 2009
@@ -27,7 +27,7 @@
import org.apache.cocoon.pipeline.NonCachingPipeline;
import org.apache.cocoon.pipeline.Pipeline;
import org.apache.cocoon.sax.SAXPipelineComponent;
-import org.apache.cocoon.sax.component.FileGenerator;
+import org.apache.cocoon.sax.component.URLGenerator;
import org.apache.cocoon.sax.component.XMLSerializer;
import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.SolrServer;
@@ -58,7 +58,7 @@
public void testPipelineWithSolrConsumer() throws Exception {
Pipeline<SAXPipelineComponent> pipeline = new NonCachingPipeline<SAXPipelineComponent>();
- pipeline.addComponent(new FileGenerator(this.getClass().getResource("sample.xml")));
+ pipeline.addComponent(new URLGenerator(this.getClass().getResource("sample.xml")));
pipeline.addComponent(new SolrConsumer(this.solr));
pipeline.addComponent(new XMLSerializer());
Added: cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/component/SAXGenerator.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/component/SAXGenerator.java?rev=889623&view=auto
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/component/SAXGenerator.java (added)
+++ cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/component/SAXGenerator.java Fri Dec 11 13:57:24 2009
@@ -0,0 +1,260 @@
+/*
+ * 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.sax.component;
+
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.io.UnsupportedEncodingException;
+
+import org.apache.cocoon.pipeline.PipelineException;
+import org.apache.cocoon.pipeline.ProcessingException;
+import org.apache.cocoon.pipeline.SetupException;
+import org.apache.cocoon.pipeline.component.Starter;
+import org.apache.cocoon.pipeline.util.StringRepresentation;
+import org.apache.cocoon.sax.AbstractSAXGenerator;
+import org.apache.cocoon.sax.AbstractSAXProducer;
+import org.apache.cocoon.sax.util.XMLUtils;
+import org.apache.cocoon.xml.dom.DOMStreamer;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.w3c.dom.Node;
+import org.xml.sax.SAXException;
+
+/**
+ * General purpose SAX generator that produces SAX events from different sources.
+ */
+public class SAXGenerator extends AbstractSAXGenerator {
+
+ private Starter generator;
+
+ private final Log logger = LogFactory.getLog(this.getClass());
+
+ public SAXGenerator(byte[] bytes) {
+ this.generator = new ByteArrayGenerator(bytes);
+ }
+
+ public SAXGenerator(byte[] bytes, String encoding) {
+ this.generator = new ByteArrayGenerator(bytes, encoding);
+ }
+
+ public SAXGenerator(File file) {
+ this.generator = new FileGenerator(file);
+ }
+
+ public SAXGenerator(InputStream inputStream) {
+ this.generator = new InputStreamGenerator(inputStream);
+ }
+
+ public SAXGenerator(Node node) {
+ this.generator = new NodeGenerator(node);
+ }
+
+ public SAXGenerator(String xmlString) {
+ this.generator = new StringGenerator(xmlString);
+ }
+
+ public void execute() {
+ this.generator.execute();
+ }
+
+ @Override
+ public String toString() {
+ return StringRepresentation.buildString(this, "internalGenerator=" + this.generator);
+ }
+
+ private class ByteArrayGenerator extends AbstractSAXGenerator {
+
+ private final byte[] bytes;
+ private final String encoding;
+
+ public ByteArrayGenerator(byte[] bytes) {
+ this(bytes, null);
+ }
+
+ public ByteArrayGenerator(byte[] bytes, String encoding) {
+ if (bytes == null) {
+ throw new SetupException("A byte array has to be passed.");
+ }
+
+ this.bytes = bytes;
+ this.encoding = encoding;
+ }
+
+ public void execute() {
+ try {
+ if (SAXGenerator.this.logger.isDebugEnabled()) {
+ SAXGenerator.this.logger.debug("Using a byte array as source to produce SAX events.");
+ }
+
+ if (this.encoding == null) {
+ XMLUtils.toSax(new ByteArrayInputStream(this.bytes), SAXGenerator.this.getSAXConsumer());
+ } else {
+ XMLUtils.toSax(new String(this.bytes, this.encoding), SAXGenerator.this.getSAXConsumer());
+ }
+ } catch (PipelineException e) {
+ throw e;
+ } catch (UnsupportedEncodingException e) {
+ throw new ProcessingException("The encoding " + this.encoding + " is not supported.", e);
+ } catch (Exception e) {
+ throw new ProcessingException("Can't parse byte array " + this.bytes, e);
+ }
+ }
+
+ @Override
+ public String toString() {
+ return StringRepresentation.buildString(this, "bytes=" + this.bytes, "encoding=" + this.encoding);
+ }
+ }
+
+ private class FileGenerator extends AbstractSAXGenerator {
+
+ private final File file;
+
+ public FileGenerator(File file) {
+ if (file == null) {
+ throw new SetupException("A file has to be passed.");
+ }
+
+ this.file = file;
+ }
+
+ public void execute() {
+ try {
+ if (SAXGenerator.this.logger.isDebugEnabled()) {
+ SAXGenerator.this.logger.debug("Using file " + this.file.getAbsolutePath()
+ + " as source to produce SAX events.");
+ }
+
+ XMLUtils.toSax(new FileInputStream(this.file), SAXGenerator.this.getSAXConsumer());
+ } catch (PipelineException e) {
+ throw e;
+ } catch (Exception e) {
+ throw new ProcessingException("Can't read or parse file " + this.file.getAbsolutePath(), e);
+ }
+ }
+
+ @Override
+ public String toString() {
+ return StringRepresentation.buildString(this, "file=" + this.file);
+ }
+ }
+
+ private class InputStreamGenerator extends AbstractSAXGenerator {
+
+ private final InputStream inputStream;
+
+ public InputStreamGenerator(InputStream inputStream) {
+ super();
+
+ if (inputStream == null) {
+ throw new SetupException("An input stream has to be passed.");
+ }
+
+ this.inputStream = inputStream;
+ }
+
+ public void execute() {
+ try {
+ if (SAXGenerator.this.logger.isDebugEnabled()) {
+ SAXGenerator.this.logger.debug("Using input stream " + this.inputStream
+ + " as source to produce SAX events.");
+ }
+
+ XMLUtils.toSax(this.inputStream, SAXGenerator.this.getSAXConsumer());
+ } catch (PipelineException e) {
+ throw e;
+
+ } catch (Exception e) {
+ throw new ProcessingException("Can't read or parse file " + this.inputStream, e);
+ }
+ }
+
+ @Override
+ public String toString() {
+ return StringRepresentation.buildString(this, "inputStream=" + this.inputStream);
+ }
+ }
+
+ private class NodeGenerator extends AbstractSAXGenerator {
+
+ private final Node node;
+
+ public NodeGenerator(Node document) {
+ if (document == null) {
+ throw new SetupException("A DOM document has to be passed.");
+ }
+
+ this.node = document;
+ }
+
+ public void execute() {
+ DOMStreamer streamer = new DOMStreamer(SAXGenerator.this.getSAXConsumer());
+ try {
+ streamer.stream(this.node);
+ } catch (SAXException e) {
+ throw new SetupException("Can't stream DOM node + " + this.node);
+ }
+ }
+
+ @Override
+ public String toString() {
+ return StringRepresentation.buildString(this, "node=" + this.node);
+ }
+ }
+
+ private class StringGenerator extends AbstractSAXProducer implements Starter {
+
+ private String xmlString;
+
+ public StringGenerator(String xmlString) {
+ super();
+ if (xmlString == null) {
+ throw new SetupException("An XML string has to be passed.");
+ }
+
+ this.xmlString = xmlString;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.apache.cocoon.pipeline.component.Starter#execute()
+ */
+ public void execute() {
+ try {
+ if (SAXGenerator.this.logger.isDebugEnabled()) {
+ SAXGenerator.this.logger.debug("Using a string to produce SAX events.");
+ }
+
+ XMLUtils.toSax(new ByteArrayInputStream(this.xmlString.getBytes()), SAXGenerator.this.getSAXConsumer());
+ } catch (PipelineException e) {
+ throw e;
+ } catch (Exception e) {
+ throw new ProcessingException("Can't parse the XML string.", e);
+ }
+ }
+
+ @Override
+ public String toString() {
+ return StringRepresentation.buildString(this, "xmlString=" + this.xmlString);
+ }
+ }
+}
Propchange: cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/component/SAXGenerator.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/component/SAXGenerator.java
------------------------------------------------------------------------------
svn:keywords = Id
Propchange: cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/component/SAXGenerator.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Copied: cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/component/URLGenerator.java (from r824908, cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/component/FileGenerator.java)
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/component/URLGenerator.java?p2=cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/component/URLGenerator.java&p1=cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/component/FileGenerator.java&r1=824908&r2=889623&rev=889623&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/component/FileGenerator.java (original)
+++ cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/component/URLGenerator.java Fri Dec 11 13:57:24 2009
@@ -34,17 +34,17 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-public class FileGenerator extends AbstractSAXGenerator implements CachingPipelineComponent {
+public class URLGenerator extends AbstractSAXGenerator implements CachingPipelineComponent {
private final Log logger = LogFactory.getLog(this.getClass());
private URL source;
- public FileGenerator() {
+ public URLGenerator() {
super();
}
- public FileGenerator(URL source) {
+ public URLGenerator(URL source) {
super();
this.source = source;
}
Modified: cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/util/TransformationUtils.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/util/TransformationUtils.java?rev=889623&r1=889622&r2=889623&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/util/TransformationUtils.java (original)
+++ cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/util/TransformationUtils.java Fri Dec 11 13:57:24 2009
@@ -25,7 +25,7 @@
import org.apache.cocoon.pipeline.NonCachingPipeline;
import org.apache.cocoon.pipeline.Pipeline;
import org.apache.cocoon.sax.SAXPipelineComponent;
-import org.apache.cocoon.sax.component.StringGenerator;
+import org.apache.cocoon.sax.component.SAXGenerator;
import org.apache.cocoon.sax.component.XMLSerializer;
import org.apache.cocoon.sax.component.XSLTTransformer;
@@ -162,7 +162,7 @@
OutputStream outputStream, URL... xsltUrls) throws Exception {
Pipeline<SAXPipelineComponent> pipeline = new NonCachingPipeline<SAXPipelineComponent>();
- pipeline.addComponent(new StringGenerator(xmlString));
+ pipeline.addComponent(new SAXGenerator(xmlString));
for (URL xsltUrl : xsltUrls) {
XSLTTransformer xsltTransformer = new XSLTTransformer(xsltUrl);
xsltTransformer.setParameters(xsltParameters);
Modified: cocoon/cocoon3/trunk/cocoon-sax/src/test/java/org/apache/cocoon/sax/PipelineTest.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-sax/src/test/java/org/apache/cocoon/sax/PipelineTest.java?rev=889623&r1=889622&r2=889623&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-sax/src/test/java/org/apache/cocoon/sax/PipelineTest.java (original)
+++ cocoon/cocoon3/trunk/cocoon-sax/src/test/java/org/apache/cocoon/sax/PipelineTest.java Fri Dec 11 13:57:24 2009
@@ -26,7 +26,7 @@
import org.apache.cocoon.pipeline.NonCachingPipeline;
import org.apache.cocoon.pipeline.Pipeline;
-import org.apache.cocoon.sax.component.StringGenerator;
+import org.apache.cocoon.sax.component.SAXGenerator;
import org.apache.cocoon.sax.component.XMLSerializer;
import org.apache.cocoon.sax.component.XSLTTransformer;
import org.custommonkey.xmlunit.Diff;
@@ -39,7 +39,7 @@
*/
public void testPipelineWithTransformer() throws Exception {
Pipeline<SAXPipelineComponent> pipeline = new NonCachingPipeline<SAXPipelineComponent>();
- pipeline.addComponent(new StringGenerator("<x></x>"));
+ pipeline.addComponent(new SAXGenerator("<x></x>"));
pipeline.addComponent(new XSLTTransformer(this.getClass().getResource("/test.xslt")));
pipeline.addComponent(new XMLSerializer());
@@ -54,7 +54,7 @@
/**
* A pipeline that performs a simple transformation: generator -> transformer ->
* serializer; the transformer uses a compiled XSLT using Xalan xsltc.
- *
+ *
* @throws Exception if any error occurs.
*/
public void testPipelineWithCompiledXSLT() throws Exception {
@@ -63,7 +63,7 @@
attributes.put("package-name", "org.apache.cocoon.sax");
Pipeline<SAXPipelineComponent> pipeline = new NonCachingPipeline<SAXPipelineComponent>();
- pipeline.addComponent(new StringGenerator("<x></x>"));
+ pipeline.addComponent(new SAXGenerator("<x></x>"));
pipeline.addComponent(new XSLTTransformer(this.getClass().getResource("/test.xslt"), attributes));
pipeline.addComponent(new XMLSerializer());
Modified: cocoon/cocoon3/trunk/cocoon-sax/src/test/java/org/apache/cocoon/sax/SchemaProcessorTransformerTest.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-sax/src/test/java/org/apache/cocoon/sax/SchemaProcessorTransformerTest.java?rev=889623&r1=889622&r2=889623&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-sax/src/test/java/org/apache/cocoon/sax/SchemaProcessorTransformerTest.java (original)
+++ cocoon/cocoon3/trunk/cocoon-sax/src/test/java/org/apache/cocoon/sax/SchemaProcessorTransformerTest.java Fri Dec 11 13:57:24 2009
@@ -24,10 +24,9 @@
import org.apache.cocoon.pipeline.NonCachingPipeline;
import org.apache.cocoon.pipeline.Pipeline;
-import org.apache.cocoon.sax.SAXPipelineComponent;
+import org.apache.cocoon.sax.component.SAXGenerator;
import org.apache.cocoon.sax.component.SchemaProcessorTransformer;
import org.apache.cocoon.sax.component.SchemaValidationException;
-import org.apache.cocoon.sax.component.StringGenerator;
import org.apache.cocoon.sax.component.XMLSerializer;
import org.custommonkey.xmlunit.Diff;
import org.junit.Test;
@@ -58,23 +57,17 @@
* validator -> serializer. An error is expected performing <code>execute</code> method due
* to not valid xml input.
*/
- @Test
+ @Test(expected = SchemaValidationException.class)
public void testPipelineWithWrongValidation() throws Exception {
Pipeline<SAXPipelineComponent> pipeline = this.createValidatingPipeline("<y><z/></y>");
-
ByteArrayOutputStream baos = new ByteArrayOutputStream();
pipeline.setup(baos);
- try {
- pipeline.execute();
- fail("A specific SchemaValidationException is expected.");
- } catch (SchemaValidationException e) {
- // success
- }
+ pipeline.execute();
}
private Pipeline<SAXPipelineComponent> createValidatingPipeline(String xmlInput) {
Pipeline<SAXPipelineComponent> pipeline = new NonCachingPipeline<SAXPipelineComponent>();
- pipeline.addComponent(new StringGenerator(xmlInput));
+ pipeline.addComponent(new SAXGenerator(xmlInput));
pipeline.addComponent(new SchemaProcessorTransformer(this.getClass().getResource("/test.xsd")));
pipeline.addComponent(new XMLSerializer());
Added: cocoon/cocoon3/trunk/cocoon-sax/src/test/java/org/apache/cocoon/sax/component/SAXGeneratorTest.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-sax/src/test/java/org/apache/cocoon/sax/component/SAXGeneratorTest.java?rev=889623&view=auto
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-sax/src/test/java/org/apache/cocoon/sax/component/SAXGeneratorTest.java (added)
+++ cocoon/cocoon3/trunk/cocoon-sax/src/test/java/org/apache/cocoon/sax/component/SAXGeneratorTest.java Fri Dec 11 13:57:24 2009
@@ -0,0 +1,123 @@
+/*
+ * 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.sax.component;
+
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.InputStream;
+
+import junit.framework.Assert;
+
+import org.apache.cocoon.pipeline.NonCachingPipeline;
+import org.apache.cocoon.pipeline.Pipeline;
+import org.apache.cocoon.pipeline.ProcessingException;
+import org.apache.cocoon.pipeline.SetupException;
+import org.apache.cocoon.sax.SAXPipelineComponent;
+import org.apache.cocoon.sax.SAXProducer;
+import org.custommonkey.xmlunit.Diff;
+import org.junit.Test;
+
+public class SAXGeneratorTest {
+
+ private static final String INVALID_XML_STRING = "<?xml version=\"1.0\"?><test>text<test>";
+
+ private static final String VALID_XML_STRING = "<?xml version=\"1.0\"?><test>text</test>";
+
+ @Test
+ public void execByteArrayGenerator() throws Exception {
+ runPipeline(new SAXGenerator(VALID_XML_STRING.getBytes()), VALID_XML_STRING);
+ }
+
+ @Test
+ public void execFileGenerator() throws Exception {
+ runPipeline(new SAXGenerator(this.createXMLFile(VALID_XML_STRING)), VALID_XML_STRING);
+ }
+
+ @Test
+ public void execInputStreamGenerator() throws Exception {
+ runPipeline(new SAXGenerator(new FileInputStream(this.createXMLFile(VALID_XML_STRING))), VALID_XML_STRING);
+ }
+
+ @Test
+ public void execStringGenerator() throws Exception {
+ runPipeline(new SAXGenerator(VALID_XML_STRING), VALID_XML_STRING);
+ }
+
+ @Test(expected = ProcessingException.class)
+ public void invalidExecByteArrayGenerator() throws Exception {
+ runPipeline(new SAXGenerator(INVALID_XML_STRING.getBytes()), INVALID_XML_STRING);
+ }
+
+ @Test(expected = ProcessingException.class)
+ public void invalidExecFileGenerator() throws Exception {
+ runPipeline(new SAXGenerator(this.createXMLFile(INVALID_XML_STRING)), INVALID_XML_STRING);
+ }
+
+ @Test(expected = ProcessingException.class)
+ public void invalidExecInputStreamGenerator() throws Exception {
+ runPipeline(new SAXGenerator(new FileInputStream(this.createXMLFile(INVALID_XML_STRING))), INVALID_XML_STRING);
+ }
+
+ @Test(expected = ProcessingException.class)
+ public void invalidExecStringGenerator() throws Exception {
+ runPipeline(new SAXGenerator(INVALID_XML_STRING), INVALID_XML_STRING);
+ }
+
+ @Test(expected = SetupException.class)
+ public void newStringGenerator() {
+ new SAXGenerator((String) null);
+ }
+
+ @Test(expected = SetupException.class)
+ public void testByteArrayGenerator() {
+ new SAXGenerator((byte[]) null);
+ }
+
+ @Test(expected = SetupException.class)
+ public void testFileGenerator() {
+ new SAXGenerator((File) null);
+ }
+
+ @Test(expected = SetupException.class)
+ public void testInputStreamGenerator() {
+ new SAXGenerator((InputStream) null);
+ }
+
+ private File createXMLFile(String xmlString) throws IOException {
+ File temp = File.createTempFile("cocoon", ".tmp");
+ FileWriter writer = new FileWriter(temp);
+ writer.write(xmlString);
+ writer.flush();
+ writer.close();
+ return temp;
+ }
+
+ private static void runPipeline(SAXProducer generator, String expectedContent) throws Exception {
+ Pipeline<SAXPipelineComponent> pipeline = new NonCachingPipeline<SAXPipelineComponent>();
+ pipeline.addComponent(generator);
+ pipeline.addComponent(new XMLSerializer());
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ pipeline.setup(baos);
+ pipeline.execute();
+
+ Assert.assertTrue(new Diff(expectedContent, baos.toString()).similar());
+ }
+}
Propchange: cocoon/cocoon3/trunk/cocoon-sax/src/test/java/org/apache/cocoon/sax/component/SAXGeneratorTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cocoon/cocoon3/trunk/cocoon-sax/src/test/java/org/apache/cocoon/sax/component/SAXGeneratorTest.java
------------------------------------------------------------------------------
svn:keywords = Id
Propchange: cocoon/cocoon3/trunk/cocoon-sax/src/test/java/org/apache/cocoon/sax/component/SAXGeneratorTest.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: cocoon/cocoon3/trunk/cocoon-sitemap/src/main/resources/META-INF/cocoon/spring/cocoon-pipeline-component.xml
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-sitemap/src/main/resources/META-INF/cocoon/spring/cocoon-pipeline-component.xml?rev=889623&r1=889622&r2=889623&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-sitemap/src/main/resources/META-INF/cocoon/spring/cocoon-pipeline-component.xml (original)
+++ cocoon/cocoon3/trunk/cocoon-sitemap/src/main/resources/META-INF/cocoon/spring/cocoon-pipeline-component.xml Fri Dec 11 13:57:24 2009
@@ -58,7 +58,9 @@
</property>
</bean>
- <bean name="generator:file" class="org.apache.cocoon.sax.component.FileGenerator" scope="prototype" />
+ <bean name="generator:url" class="org.apache.cocoon.sax.component.URLGenerator" scope="prototype" />
+
+ <alias name="generator:url" alias="generator:file"/>
<bean name="generator:exception" class="org.apache.cocoon.sitemap.component.ExceptionGenerator" scope="prototype" />
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=889623&r1=889622&r2=889623&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 Fri Dec 11 13:57:24 2009
@@ -5,9 +5,9 @@
* 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
@@ -24,7 +24,7 @@
import org.apache.cocoon.pipeline.NonCachingPipeline;
import org.apache.cocoon.pipeline.component.PipelineComponent;
import org.apache.cocoon.sax.component.CleaningTransformer;
-import org.apache.cocoon.sax.component.StringGenerator;
+import org.apache.cocoon.sax.component.SAXGenerator;
import org.apache.cocoon.sax.component.XMLSerializer;
import org.apache.cocoon.stax.component.StAXCleaningTransformer;
import org.apache.commons.io.IOUtils;
@@ -41,7 +41,7 @@
/**
* Compares the output of the {@link StAXCleaningTransformer} with the output of the
* {@link CleaningTransformer} to show that they process input data identically.
- *
+ *
* @throws Exception Is thrown if an error occurs loading the files or in the pipeline itself.
*/
@Test
@@ -49,7 +49,7 @@
// TODO andreas.pieber [2009-01-27] use the correct generic parameter
// (SAXPipelineComponent) as soon as the SAX module allows this
NonCachingPipeline<PipelineComponent> pipeSAX = new NonCachingPipeline<PipelineComponent>();
- pipeSAX.addComponent(new StringGenerator(IOUtils.toString(CleaningTransformerTest.class.getResource(
+ pipeSAX.addComponent(new SAXGenerator(IOUtils.toString(CleaningTransformerTest.class.getResource(
"/org/apache/cocoon/stax/" + "complex-stax-test-document.xml").openStream())));
pipeSAX.addComponent(new CleaningTransformer());
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=889623&r1=889622&r2=889623&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 Fri Dec 11 13:57:24 2009
@@ -5,9 +5,9 @@
* 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
@@ -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.sax.component.StringGenerator;
+import org.apache.cocoon.sax.component.SAXGenerator;
import org.apache.commons.io.IOUtils;
import org.custommonkey.xmlunit.Diff;
import org.custommonkey.xmlunit.XMLUnit;
@@ -33,7 +33,7 @@
/**
* Contains unit tests for testing and presenting the most simple cases for a StAX pipeline.<br>
- *
+ *
* Communication between a StAX Generator and a StAX Serializer<br>
* Connection of SAX and StAX Components is detected as error
*/
@@ -43,7 +43,7 @@
* Very simple test case loading a simple xml file as input stream, and starts the most simple
* pipeline (Generator -> Serializer) on it. Finally the output is compared to the file used for
* input. This test should present the most basic ideas about a StAX pipeline.
- *
+ *
* @exception Exception Is thrown if an error occurs loading the files or in the pipeline
* itself.
*/
@@ -75,7 +75,7 @@
@Test(expected = SetupException.class)
public void pipelineWithWrongComponents() {
Pipeline<PipelineComponent> pipeline = new NonCachingPipeline<PipelineComponent>();
- pipeline.addComponent(new StringGenerator("<test/>"));
+ pipeline.addComponent(new SAXGenerator("<test/>"));
pipeline.addComponent(new StAXSerializer());
pipeline.setup(new ByteArrayOutputStream());
Modified: 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=889623&r1=889622&r2=889623&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-stax/src/test/java/org/apache/cocoon/stax/converter/SAXForStAXPipelineWrapperTest.java (original)
+++ cocoon/cocoon3/trunk/cocoon-stax/src/test/java/org/apache/cocoon/stax/converter/SAXForStAXPipelineWrapperTest.java Fri Dec 11 13:57:24 2009
@@ -5,9 +5,9 @@
* 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
@@ -24,7 +24,7 @@
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.SAXGenerator;
import org.apache.cocoon.sax.component.XMLSerializer;
import org.apache.cocoon.stax.CleaningTransformerTest;
import org.apache.cocoon.stax.StAXGenerator;
@@ -38,7 +38,7 @@
/**
* 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
@@ -50,14 +50,14 @@
* 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(
+ pipeSAX.addComponent(new SAXGenerator(IOUtils.toString(CleaningTransformerTest.class.getResource(
"/org/apache/cocoon/stax/converter/complex-stax-test-document.xml").openStream())));
pipeSAX.addComponent(new CleaningTransformer());
pipeSAX.addComponent(new XMLSerializer());
Modified: 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=889623&r1=889622&r2=889623&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-stax/src/test/java/org/apache/cocoon/stax/converter/StAXToSAXPipelineAdapterTest.java (original)
+++ cocoon/cocoon3/trunk/cocoon-stax/src/test/java/org/apache/cocoon/stax/converter/StAXToSAXPipelineAdapterTest.java Fri Dec 11 13:57:24 2009
@@ -5,9 +5,9 @@
* 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
@@ -25,7 +25,7 @@
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.SAXGenerator;
import org.apache.cocoon.sax.component.XMLSerializer;
import org.apache.cocoon.stax.CleaningTransformerTest;
import org.apache.cocoon.stax.StAXGenerator;
@@ -47,14 +47,14 @@
* 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(
+ pipeSAX.addComponent(new SAXGenerator(IOUtils.toString(CleaningTransformerTest.class.getResource(
"/org/apache/cocoon/stax/converter/complex-stax-test-document.xml").openStream())));
pipeSAX.addComponent(new CleaningTransformer());
pipeSAX.addComponent(new XMLSerializer());