Author: danielf Date: Thu Apr 7 15:18:29 2005 New Revision: 160478 URL: http://svn.apache.org/viewcvs?view=rev&rev=160478 Log: Started adding VirtualPipelineReader, doesn't work yet. Corrected bug in ComponentsNodeBuilder, no VPCs in a section must be allowed.
Added: cocoon/trunk/src/java/org/apache/cocoon/reading/VirtualPipelineReader.java Modified: cocoon/trunk/src/java/org/apache/cocoon/components/pipeline/VirtualProcessingPipeline.java cocoon/trunk/src/java/org/apache/cocoon/components/treeprocessor/sitemap-language.xml cocoon/trunk/src/java/org/apache/cocoon/components/treeprocessor/sitemap/ComponentsNodeBuilder.java cocoon/trunk/src/java/org/apache/cocoon/components/treeprocessor/sitemap/VPCsNodeBuilder.java Modified: cocoon/trunk/src/java/org/apache/cocoon/components/pipeline/VirtualProcessingPipeline.java URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/components/pipeline/VirtualProcessingPipeline.java?view=diff&r1=160477&r2=160478 ============================================================================== --- cocoon/trunk/src/java/org/apache/cocoon/components/pipeline/VirtualProcessingPipeline.java (original) +++ cocoon/trunk/src/java/org/apache/cocoon/components/pipeline/VirtualProcessingPipeline.java Thu Apr 7 15:18:29 2005 @@ -380,7 +380,17 @@ } public boolean process(Environment environment) throws ProcessingException { - throw new UnsupportedOperationException(); + if (!this.prepared) { + preparePipeline(environment); + } + + // If this is an internal request, lastConsumer was reset! + if (this.lastConsumer == null) { + this.lastConsumer = this.serializer; + } + + connectPipeline(environment); + return processXMLPipeline(environment); } /** Modified: cocoon/trunk/src/java/org/apache/cocoon/components/treeprocessor/sitemap-language.xml URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/components/treeprocessor/sitemap-language.xml?view=diff&r1=160477&r2=160478 ============================================================================== --- cocoon/trunk/src/java/org/apache/cocoon/components/treeprocessor/sitemap-language.xml (original) +++ cocoon/trunk/src/java/org/apache/cocoon/components/treeprocessor/sitemap-language.xml Thu Apr 7 15:18:29 2005 @@ -57,6 +57,24 @@ <ignored-children>source</ignored-children> </node> + <node name="transformers" builder="org.apache.cocoon.components.treeprocessor.sitemap.VPCsNodeBuilder"/> + + <node name="transformer" builder="org.apache.cocoon.components.treeprocessor.sitemap.VPCNodeBuilder"> + <ignored-children>source</ignored-children> + </node> + + <node name="serializers" builder="org.apache.cocoon.components.treeprocessor.sitemap.VPCsNodeBuilder"/> + + <node name="serializer" builder="org.apache.cocoon.components.treeprocessor.sitemap.VPCNodeBuilder"> + <ignored-children>source</ignored-children> + </node> + + <node name="readers" builder="org.apache.cocoon.components.treeprocessor.sitemap.VPCsNodeBuilder"/> + + <node name="reader" builder="org.apache.cocoon.components.treeprocessor.sitemap.VPCNodeBuilder"> + <ignored-children>source</ignored-children> + </node> + <node name="views" builder="org.apache.cocoon.components.treeprocessor.CategoryNodeBuilder"> <allowed-children>view</allowed-children> </node> Modified: cocoon/trunk/src/java/org/apache/cocoon/components/treeprocessor/sitemap/ComponentsNodeBuilder.java URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/components/treeprocessor/sitemap/ComponentsNodeBuilder.java?view=diff&r1=160477&r2=160478 ============================================================================== --- cocoon/trunk/src/java/org/apache/cocoon/components/treeprocessor/sitemap/ComponentsNodeBuilder.java (original) +++ cocoon/trunk/src/java/org/apache/cocoon/components/treeprocessor/sitemap/ComponentsNodeBuilder.java Thu Apr 7 15:18:29 2005 @@ -28,6 +28,9 @@ */ public class ComponentsNodeBuilder extends AbstractProcessingNodeBuilder { + private static String[] VPCTypes = + {"generators", "transformers", "serializers", "readers"}; + /** This builder has no parameters -- return <code>false</code> */ protected boolean hasParameters() { return false; @@ -35,12 +38,14 @@ public ProcessingNode buildNode(Configuration config) throws Exception { // Handle the VPCs - Configuration child = config.getChild("generators", false); - if (child != null) { - ProcessingNodeBuilder childBuilder = this.treeBuilder.createNodeBuilder(child); - childBuilder.buildNode(child); + for (int i = 0; i < VPCTypes.length; i++) { + Configuration child = config.getChild(VPCTypes[i], false); + if (child != null) { + ProcessingNodeBuilder childBuilder = + this.treeBuilder.createNodeBuilder(child); + childBuilder.buildNode(child); + } } return null; } } - Modified: cocoon/trunk/src/java/org/apache/cocoon/components/treeprocessor/sitemap/VPCsNodeBuilder.java URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/components/treeprocessor/sitemap/VPCsNodeBuilder.java?view=diff&r1=160477&r2=160478 ============================================================================== --- cocoon/trunk/src/java/org/apache/cocoon/components/treeprocessor/sitemap/VPCsNodeBuilder.java (original) +++ cocoon/trunk/src/java/org/apache/cocoon/components/treeprocessor/sitemap/VPCsNodeBuilder.java Thu Apr 7 15:18:29 2005 @@ -18,8 +18,11 @@ import org.apache.avalon.framework.configuration.Configuration; import org.apache.avalon.framework.configuration.ConfigurationException; +import org.apache.cocoon.components.treeprocessor.ContainerNode; import org.apache.cocoon.components.treeprocessor.ContainerNodeBuilder; +import org.apache.cocoon.components.treeprocessor.ProcessingNode; import org.apache.cocoon.generation.VirtualPipelineGenerator; +import org.apache.cocoon.reading.VirtualPipelineReader; /** * Handles a set of virtual sitemap components. @@ -41,6 +44,16 @@ checkNamespace(child); String clazz = child.getAttribute("src"); - return VirtualPipelineGenerator.class.getName().equals(clazz); + return VirtualPipelineGenerator.class.getName().equals(clazz) + || VirtualPipelineReader.class.getName().equals(clazz); + } + + protected void setupNode(ContainerNode node, Configuration config)throws Exception { + + this.treeBuilder.setupNode(node, config); + + ProcessingNode[] children = buildChildNodes(config); + + node.setChildren(children); } } Added: cocoon/trunk/src/java/org/apache/cocoon/reading/VirtualPipelineReader.java URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/reading/VirtualPipelineReader.java?view=auto&rev=160478 ============================================================================== --- cocoon/trunk/src/java/org/apache/cocoon/reading/VirtualPipelineReader.java (added) +++ cocoon/trunk/src/java/org/apache/cocoon/reading/VirtualPipelineReader.java Thu Apr 7 15:18:29 2005 @@ -0,0 +1,120 @@ +/* + * Copyright 1999-2004 The Apache Software Foundation. + * + * Licensed 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.reading; + +import org.apache.cocoon.Constants; +import org.apache.cocoon.ProcessingException; +import org.apache.cocoon.environment.Environment; +import org.apache.cocoon.environment.internal.EnvironmentHelper; +import org.apache.cocoon.sitemap.impl.AbstractVirtualSitemapComponent; + +import org.xml.sax.SAXException; + +import java.io.IOException; +import java.io.OutputStream; +import java.util.Map; + + +public class VirtualPipelineReader extends AbstractVirtualSitemapComponent + implements Reader { + + /** The <code>OutputStream</code> to write on. */ + protected OutputStream out; + + protected String getTypeName() { + return "reader"; + } + + /** + * Set the <code>OutputStream</code> + */ + // The output stream from + // EnvironmentHelper.getCurrentEnvironment() is used instead. Is + // it always the same? + public void setOutputStream(OutputStream out) { + this.out = out; + } + + /** + * Get the mime-type of the output of this <code>Reader</code> + * This default implementation returns null to indicate that the + * mime-type specified in the sitemap is to be used + */ + public String getMimeType() { + return null; + } + + /** + * @return the time the read source was last modified or 0 if it is not + * possible to detect + */ + public long getLastModified() { + return 0; + } + + /** + * Recycle the component + */ + public void recycle() { + this.out = null; + } + + /** + * Test if the component wants to set the content length + */ + public boolean shouldSetContentLength() { + return false; + } + + public void generate() + throws IOException, SAXException, ProcessingException { + + // Should use SourceResolver of the this components' sitemap, not caller sitemap + // Have to switch to another environment... + Environment env = EnvironmentHelper.getCurrentEnvironment(); + String oldPrefix = env.getURIPrefix(); + String oldURI = env.getURI(); + + // save callers resolved sources if there are any + Map oldSourceMap = (Map)env.getAttribute(this.sourceMapName); + // place for resolved sources + env.setAttribute(this.sourceMapName, this.sourceMap); + + try { + try { + String uri = (String) this.context.get(Constants.CONTEXT_ENV_URI); + String prefix = (String) this.context.get(Constants.CONTEXT_ENV_PREFIX); + env.setURI(prefix, uri); + + this.pipeline.prepareInternal(env); + } catch (Exception e) { + throw new ProcessingException("Oops", e); + } finally { + // Restore context + env.setURI(oldPrefix, oldURI); + } + + this.pipeline.process(env); + + } finally { + // restore sourceMap + if (oldSourceMap != null) + env.setAttribute(this.sourceMapName, oldSourceMap); + else + env.removeAttribute(this.sourceMapName); + } + } + }