You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by si...@apache.org on 2010/12/10 12:34:38 UTC
svn commit: r1044301 - in
/cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/builder:
LinkedSAXPipelineComponentBuilderImpl.java
LinkedSAXPipelineStarterBuilderImpl.java SAXPipelineBuilder.java
Author: simonetripodi
Date: Fri Dec 10 11:34:38 2010
New Revision: 1044301
URL: http://svn.apache.org/viewvc?rev=1044301&view=rev
Log:
first checkin of SAX Pipeline DSL
Added:
cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/builder/LinkedSAXPipelineComponentBuilderImpl.java (with props)
cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/builder/LinkedSAXPipelineStarterBuilderImpl.java (with props)
cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/builder/SAXPipelineBuilder.java (with props)
Added: cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/builder/LinkedSAXPipelineComponentBuilderImpl.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/builder/LinkedSAXPipelineComponentBuilderImpl.java?rev=1044301&view=auto
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/builder/LinkedSAXPipelineComponentBuilderImpl.java (added)
+++ cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/builder/LinkedSAXPipelineComponentBuilderImpl.java Fri Dec 10 11:34:38 2010
@@ -0,0 +1,209 @@
+/*
+ * 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.builder;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.net.URL;
+import java.text.SimpleDateFormat;
+import java.util.Collections;
+import java.util.Map;
+
+import org.apache.cocoon.pipeline.Pipeline;
+import org.apache.cocoon.pipeline.builder.LinkedPipelineConfigurationBuilder;
+import org.apache.cocoon.pipeline.builder.LinkedPipelineSetupBuilder;
+import org.apache.cocoon.sax.SAXPipelineComponent;
+import org.apache.cocoon.sax.component.CleaningTransformer;
+import org.apache.cocoon.sax.component.IncludeTransformer;
+import org.apache.cocoon.sax.component.LogAsXMLTransformer;
+import org.apache.cocoon.sax.component.LogTransformer;
+import org.apache.cocoon.sax.component.SchemaProcessorTransformer;
+import org.apache.cocoon.sax.component.XIncludeTransformer;
+import org.apache.cocoon.sax.component.XMLSerializer;
+import org.apache.cocoon.sax.component.XSLTTransformer;
+
+/**
+ *
+ *
+ * @version $Id$
+ */
+public final class LinkedSAXPipelineComponentBuilderImpl implements LinkedSAXPipelineComponentBuilder {
+
+ private final Pipeline<SAXPipelineComponent> pipeline;
+
+ public LinkedSAXPipelineComponentBuilderImpl(final Pipeline<SAXPipelineComponent> pipeline) {
+ this.pipeline = pipeline;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public LinkedSAXPipelineComponentBuilder addCleaningTransformer() {
+ return this.addComponent(new CleaningTransformer());
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public LinkedSAXPipelineComponentBuilder addIncludeTransformer() {
+ return this.addComponent(new IncludeTransformer());
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public LinkedSAXPipelineComponentBuilder addLogAsXMLTransformer() {
+ return this.addComponent(new LogAsXMLTransformer());
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public LinkedSAXPipelineComponentBuilder addLogAsXMLTransformer(File logFile) {
+ if (logFile == null) {
+ throw new IllegalArgumentException("Parameter 'logFile' must be not null");
+ }
+ return this.addComponent(new LogAsXMLTransformer(logFile));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public LinkedSAXPipelineComponentBuilder addLogTransformer(File logFile) throws IOException {
+ return this.addLogTransformer(logFile, false);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public LinkedSAXPipelineComponentBuilder addLogTransformer(File logFile, boolean append) throws IOException {
+ return this.addLogTransformer(logFile, append, "yyyy-MM-dd'T'hh:mm:ss");
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public LinkedSAXPipelineComponentBuilder addLogTransformer(File logFile, boolean append, String datePattern) throws IOException {
+ if (datePattern == null) {
+ throw new IllegalArgumentException("Parameter 'datePattern' must be not null");
+ }
+ return this.addLogTransformer(logFile, append, new SimpleDateFormat(datePattern));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public LinkedSAXPipelineComponentBuilder addLogTransformer(File logFile, boolean append, SimpleDateFormat dateFormat) throws IOException {
+ if (logFile == null) {
+ throw new IllegalArgumentException("Parameter 'logFile' must be not null");
+ }
+ if (dateFormat == null) {
+ throw new IllegalArgumentException("Parameter 'dateFormat' must be not null");
+ }
+ return this.addComponent(new LogTransformer(logFile, append, dateFormat));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public LinkedSAXPipelineComponentBuilder addSchemaProcessorTransformer(URL source) {
+ if (source == null) {
+ throw new IllegalArgumentException("Parameter 'source' must be not null");
+ }
+ return this.addComponent(new SchemaProcessorTransformer(source));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public LinkedSAXPipelineComponentBuilder addXIncludeTransformer() {
+ return this.addXIncludeTransformer(null);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public LinkedSAXPipelineComponentBuilder addXIncludeTransformer(URL baseUrl) {
+ // baseUrl can be null, but only if documents don't have relative paths inside
+ return this.addComponent(new XIncludeTransformer(baseUrl));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public LinkedSAXPipelineComponentBuilder addXSLTTransformer(URL source) {
+ return this.addXSLTTransformer(source, null);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public LinkedSAXPipelineComponentBuilder addXSLTTransformer(URL source, Map<String, Object> attributes) {
+ if (source == null) {
+ throw new IllegalArgumentException("Parameter 'source' must be not null");
+ }
+ return this.addComponent(new XSLTTransformer(source, attributes));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public <SPC extends SAXPipelineComponent> LinkedSAXPipelineComponentBuilder addComponent(SPC pipelineComponent) {
+ if (pipelineComponent == null) {
+ throw new IllegalArgumentException("Parameter 'pipelineComponent' must not be null");
+ }
+ this.pipeline.addComponent(pipelineComponent);
+ return this;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public LinkedPipelineConfigurationBuilder<SAXPipelineComponent> addSerializer() {
+ this.pipeline.addComponent(new XMLSerializer());
+
+ return new LinkedPipelineConfigurationBuilder<SAXPipelineComponent>() {
+
+ @SuppressWarnings("unchecked")
+ public LinkedPipelineSetupBuilder<SAXPipelineComponent> withEmptyConfiguration() {
+ return this.setConfiguration(Collections.EMPTY_MAP);
+ }
+
+ public LinkedPipelineSetupBuilder<SAXPipelineComponent> setConfiguration(final Map<String, ? extends Object> parameters) {
+ if (parameters == null) {
+ throw new IllegalArgumentException("Parameter 'parameters' must be not null");
+ }
+ pipeline.setConfiguration(parameters);
+
+ return new LinkedPipelineSetupBuilder<SAXPipelineComponent>() {
+
+ public Pipeline<SAXPipelineComponent> setup(final OutputStream outputStream) {
+ if (outputStream == null) {
+ throw new IllegalArgumentException("Parameter 'outputStream' must be not null");
+ }
+ pipeline.setup(outputStream);
+ return pipeline;
+ }
+
+ };
+ }
+
+ };
+ }
+
+}
Propchange: cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/builder/LinkedSAXPipelineComponentBuilderImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/builder/LinkedSAXPipelineComponentBuilderImpl.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/builder/LinkedSAXPipelineComponentBuilderImpl.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/builder/LinkedSAXPipelineStarterBuilderImpl.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/builder/LinkedSAXPipelineStarterBuilderImpl.java?rev=1044301&view=auto
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/builder/LinkedSAXPipelineStarterBuilderImpl.java (added)
+++ cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/builder/LinkedSAXPipelineStarterBuilderImpl.java Fri Dec 10 11:34:38 2010
@@ -0,0 +1,144 @@
+/*
+ * 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.builder;
+
+import java.io.File;
+import java.io.InputStream;
+import java.net.URL;
+
+import org.apache.cocoon.pipeline.Pipeline;
+import org.apache.cocoon.pipeline.component.Starter;
+import org.apache.cocoon.sax.SAXPipelineComponent;
+import org.apache.cocoon.sax.component.XMLGenerator;
+import org.apache.cocoon.xml.sax.SAXBuffer;
+import org.w3c.dom.Node;
+
+/**
+ *
+ *
+ * @version $Id$
+ */
+final class LinkedSAXPipelineStarterBuilderImpl implements LinkedSAXPipelineStarterBuilder {
+
+ private final Pipeline<SAXPipelineComponent> pipeline;
+
+ /**
+ *
+ * @param pipeline
+ */
+ public LinkedSAXPipelineStarterBuilderImpl(Pipeline<SAXPipelineComponent> pipeline) {
+ this.pipeline = pipeline;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public LinkedSAXPipelineComponentBuilder setByteArrayGenerator(byte[] bytes) {
+ if (bytes == null) {
+ throw new IllegalArgumentException("Parameter 'bytes' must be not null");
+ }
+ return this.setStarter(new XMLGenerator(bytes));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public LinkedSAXPipelineComponentBuilder setByteArrayGenerator(byte[] bytes, String encoding) {
+ if (bytes == null) {
+ throw new IllegalArgumentException("Parameter 'bytes' must be not null");
+ }
+ if (encoding == null) {
+ throw new IllegalArgumentException("Parameter 'encoding' must be not null");
+ }
+ return this.setStarter(new XMLGenerator(bytes, encoding));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public LinkedSAXPipelineComponentBuilder setFileGenerator(File file) {
+ if (file == null) {
+ throw new IllegalArgumentException("Parameter 'file' must be not null");
+ }
+ return this.setStarter(new XMLGenerator(file));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public LinkedSAXPipelineComponentBuilder setInputStreamGenerator(InputStream inputStream) {
+ if (inputStream == null) {
+ throw new IllegalArgumentException("Parameter 'inputStream' must be not null");
+ }
+ return this.setStarter(new XMLGenerator(inputStream));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public LinkedSAXPipelineComponentBuilder setNodeGenerator(Node node) {
+ if (node == null) {
+ throw new IllegalArgumentException("Parameter 'node' must be not null");
+ }
+ return this.setStarter(new XMLGenerator(node));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public LinkedSAXPipelineComponentBuilder setSAXBufferGenerator(SAXBuffer saxBuffer) {
+ if (saxBuffer == null) {
+ throw new IllegalArgumentException("Parameter 'saxBuffer' must be not null");
+ }
+ return this.setStarter(new XMLGenerator(saxBuffer));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public LinkedSAXPipelineComponentBuilder setStringGenerator(String xmlString) {
+ if (xmlString == null) {
+ throw new IllegalArgumentException("Parameter 'xmlString' must be not null");
+ }
+ return this.setStarter(new XMLGenerator(xmlString));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public LinkedSAXPipelineComponentBuilder setURLGenerator(URL url) {
+ if (url == null) {
+ throw new IllegalArgumentException("Parameter 'url' must be not null");
+ }
+ return this.setStarter(new XMLGenerator(url));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public <SPC extends SAXPipelineComponent> LinkedSAXPipelineComponentBuilder setStarter(SPC starter) {
+ if (starter == null) {
+ throw new IllegalArgumentException("Parameter 'starter' must be not null");
+ }
+ if (!(starter instanceof Starter)) {
+ throw new IllegalArgumentException("Parameter 'starter' must be org.apache.cocoon.pipeline.component.Starter instance");
+ }
+ this.pipeline.addComponent(starter);
+ return null;
+ }
+
+}
Propchange: cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/builder/LinkedSAXPipelineStarterBuilderImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/builder/LinkedSAXPipelineStarterBuilderImpl.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/builder/LinkedSAXPipelineStarterBuilderImpl.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/builder/SAXPipelineBuilder.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/builder/SAXPipelineBuilder.java?rev=1044301&view=auto
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/builder/SAXPipelineBuilder.java (added)
+++ cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/builder/SAXPipelineBuilder.java Fri Dec 10 11:34:38 2010
@@ -0,0 +1,60 @@
+/*
+ * 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.builder;
+
+import org.apache.cocoon.pipeline.AsyncCachePipeline;
+import org.apache.cocoon.pipeline.CachingPipeline;
+import org.apache.cocoon.pipeline.NonCachingPipeline;
+import org.apache.cocoon.pipeline.Pipeline;
+import org.apache.cocoon.sax.SAXPipelineComponent;
+
+/**
+ *
+ *
+ * @version $Id$
+ */
+public final class SAXPipelineBuilder {
+
+ /**
+ * {@inheritDoc}
+ */
+ public LinkedSAXPipelineStarterBuilder newAsyncCachePipeline() {
+ return this.newPipeline(new AsyncCachePipeline<SAXPipelineComponent>());
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public LinkedSAXPipelineStarterBuilder newCachingPipeline() {
+ return this.newPipeline(new CachingPipeline<SAXPipelineComponent>());
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public LinkedSAXPipelineStarterBuilder newNonCachingPipeline() {
+ return this.newPipeline(new NonCachingPipeline<SAXPipelineComponent>());
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ private LinkedSAXPipelineStarterBuilder newPipeline(final Pipeline<SAXPipelineComponent> pipeline) {
+ return new LinkedSAXPipelineStarterBuilderImpl(pipeline);
+ }
+
+}
Propchange: cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/builder/SAXPipelineBuilder.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/builder/SAXPipelineBuilder.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/builder/SAXPipelineBuilder.java
------------------------------------------------------------------------------
svn:mime-type = text/plain