You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by jh...@apache.org on 2005/11/03 15:00:48 UTC
svn commit: r330548 [32/132] - in
/cocoon/whiteboard/maven2/cocoon-flat-layout: ./ cocoon-ajax-block/
cocoon-ajax-block/api/ cocoon-ajax-block/api/src/
cocoon-ajax-block/api/src/main/ cocoon-ajax-block/api/src/main/java/
cocoon-ajax-block/api/src/main/...
Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/PipelineNode.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/PipelineNode.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/PipelineNode.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/PipelineNode.java Thu Nov 3 05:41:06 2005
@@ -0,0 +1,172 @@
+/*
+ * Copyright 1999-2005 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.components.treeprocessor.sitemap;
+
+import org.apache.avalon.framework.logger.Logger;
+import org.apache.avalon.framework.parameters.Parameters;
+import org.apache.avalon.framework.service.ServiceManager;
+import org.apache.avalon.framework.service.Serviceable;
+
+import org.apache.cocoon.ConnectionResetException;
+import org.apache.cocoon.ResourceNotFoundException;
+import org.apache.cocoon.components.treeprocessor.AbstractParentProcessingNode;
+import org.apache.cocoon.components.treeprocessor.InvokeContext;
+import org.apache.cocoon.components.treeprocessor.ParameterizableProcessingNode;
+import org.apache.cocoon.components.treeprocessor.ProcessingNode;
+import org.apache.cocoon.components.treeprocessor.variables.VariableResolver;
+import org.apache.cocoon.environment.Environment;
+import org.apache.cocoon.sitemap.SitemapErrorHandler;
+import org.apache.cocoon.sitemap.SitemapExecutor;
+
+import java.util.Map;
+
+/**
+ * Handles <map:pipeline>
+ *
+ * @author <a href="mailto:juergen.seitz@basf-it-services.com">Jürgen Seitz</a>
+ * @author <a href="mailto:bluetkemeier@s-und-n.de">Björn Lütkemeier</a>
+ * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
+ * @author <a href="mailto:gianugo@apache.org">Gianugo Rabellino</a>
+ * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
+ * @version $Id: PipelineNode.java 280821 2005-09-14 11:03:46Z cziegeler $
+ */
+public class PipelineNode extends AbstractParentProcessingNode
+ implements Serviceable, ParameterizableProcessingNode {
+
+ // TODO: handle a 'fail-hard' environment attribute
+ // can be useful to stop off-line generation when there's an error
+
+ private ProcessingNode[] children;
+
+ private ErrorHandlerHelper errorHandlerHelper;
+
+ private boolean internalOnly;
+
+ /** Is it the last <pipeline> in the enclosing <pipelines> ? */
+ private boolean isLast;
+
+ /** The component name of the processing pipeline */
+ protected String processingPipeline;
+
+ /** Optional sitemap parameters */
+ protected Map parameters;
+
+ /**
+ * A constructor to receive the optional expires parameter
+ * and optional parameters for the processing pipeline
+ */
+ public PipelineNode(String name) {
+ this.processingPipeline = name;
+ this.errorHandlerHelper = new ErrorHandlerHelper();
+ }
+
+ /**
+ * The component manager is used to create error pipelines
+ */
+ public void service(ServiceManager manager) {
+ this.errorHandlerHelper.service(manager);
+ }
+
+ public void enableLogging(Logger logger) {
+ super.enableLogging(logger);
+ this.errorHandlerHelper.enableLogging(logger);
+ }
+
+ public void setChildren(ProcessingNode[] nodes) {
+ this.children = nodes;
+ }
+
+ public void setParameters(Map parameterMap) {
+ this.parameters = parameterMap;
+ }
+
+ public void setLast(boolean isLast) {
+ this.isLast = isLast;
+ }
+
+ public void set404Handler(ProcessingNode node) {
+ this.errorHandlerHelper.set404Handler(node);
+ }
+
+ public void set500Handler(ProcessingNode node) {
+ this.errorHandlerHelper.set500Handler(node);
+ }
+
+ public void setInternalOnly(boolean internalOnly) {
+ this.internalOnly = internalOnly;
+ }
+
+ public final boolean invoke(Environment env, InvokeContext context)
+ throws Exception {
+ boolean passThrough;
+ Object passThroughRaw = env.getAttribute(MountNode.COCOON_PASS_THROUGH);
+ if (passThroughRaw == null) {
+ // Use default value
+ passThrough = false;
+ } else {
+ passThrough = ((Boolean) passThroughRaw).booleanValue();
+ }
+
+ // Always fail on external request if pipeline is internal only.
+ if (this.internalOnly && env.isExternal()) {
+ if (!this.isLast || passThrough) {
+ return false;
+ }
+
+ // Do not use internal-only pipeline error handler for external requests.
+ throw new ResourceNotFoundException("No pipeline matched request: " +
+ env.getURIPrefix() + env.getURI());
+ }
+
+ Parameters params = VariableResolver.buildParameters(this.parameters,
+ context,
+ env.getObjectModel());
+
+ SitemapExecutor.PipelineComponentDescription desc = new SitemapExecutor.PipelineComponentDescription();
+ desc.type = this.processingPipeline;
+ desc.parameters = params;
+
+ desc = this.executor.enteringPipeline(this, env.getObjectModel(), desc);
+ context.inform(desc.type, desc.parameters, env.getObjectModel());
+
+ try {
+ if (this.errorHandlerHelper.isInternal()) {
+ // Set internal error handler in the pipeline
+ context.setErrorHandler(
+ new SitemapErrorHandler(this.errorHandlerHelper, env, context));
+ } else {
+ // Reset internal error handler (previous pipeline might had set it)
+ context.setErrorHandler(null);
+ }
+
+ if (invokeNodes(children, env, context)) {
+ return true;
+ } else if (!this.isLast || passThrough) {
+ return false;
+ }
+
+ throw new ResourceNotFoundException("No pipeline matched request: " +
+ env.getURIPrefix() + env.getURI());
+
+ } catch (ConnectionResetException e) {
+ // Will be reported by CocoonServlet, rethrowing
+ throw e;
+ } catch (Exception e) {
+ // Invoke error handler
+ return this.errorHandlerHelper.invokeErrorHandler(e, env, context);
+ }
+ }
+}
Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/PipelineNode.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/PipelineNodeBuilder.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/PipelineNodeBuilder.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/PipelineNodeBuilder.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/PipelineNodeBuilder.java Thu Nov 3 05:41:06 2005
@@ -0,0 +1,122 @@
+/*
+ * Copyright 1999-2005 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.components.treeprocessor.sitemap;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.avalon.framework.thread.ThreadSafe;
+import org.apache.cocoon.components.pipeline.ProcessingPipeline;
+import org.apache.cocoon.components.treeprocessor.AbstractParentProcessingNodeBuilder;
+import org.apache.cocoon.components.treeprocessor.ProcessingNode;
+import org.apache.cocoon.components.treeprocessor.ProcessingNodeBuilder;
+
+/**
+ * Builds a <map:pipeline>
+ *
+ * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
+ * @author <a href="mailto:gianugo@apache.org">Gianugo Rabellino</a>
+ * @version $Id: PipelineNodeBuilder.java 157555 2005-03-15 15:49:32Z vgritsenko $
+ */
+public class PipelineNodeBuilder extends AbstractParentProcessingNodeBuilder
+ implements ThreadSafe {
+
+ /** This builder can have parameters -- return <code>true</code> */
+ protected boolean hasParameters() {
+ return true;
+ }
+
+ public ProcessingNode buildNode(Configuration config)
+ throws Exception {
+ String type = this.treeBuilder.getTypeForStatement(config, ProcessingPipeline.ROLE);
+ PipelineNode node = new PipelineNode(type);
+
+ this.treeBuilder.setupNode(node, config);
+ node.setInternalOnly(config.getAttributeAsBoolean("internal-only", false));
+
+ // Main (with no "type" attribute) error handler: new in Cocoon 2.1, must have a generator
+ ProcessingNode mainHandler = null;
+
+ // 404 & 500 error handlers as in Cocoon 2.0.x, have an implicit generator
+ ProcessingNode error404Handler = null;
+ ProcessingNode error500Handler = null;
+
+ Configuration[] childConfigs = config.getChildren();
+ List children = new ArrayList();
+ for (int i = 0; i < childConfigs.length; i++) {
+ Configuration childConfig = childConfigs[i];
+ if (isChild(childConfig)) {
+
+ ProcessingNodeBuilder builder = this.treeBuilder.createNodeBuilder(childConfig);
+ if (builder instanceof HandleErrorsNodeBuilder) {
+ // Error handler : check type
+ HandleErrorsNode handler = (HandleErrorsNode)builder.buildNode(childConfig);
+ int status = handler.getStatusCode();
+
+ switch(status) {
+ case -1: // main handler (needs generator)
+ if (mainHandler != null) {
+ throw new ConfigurationException("Duplicate <handle-errors> at " + handler.getLocation());
+ } else if (error500Handler != null || error404Handler != null) {
+ throw new ConfigurationException("Cannot mix <handle-errors> with and without 'type' attribute at " +
+ handler.getLocation());
+ } else {
+ mainHandler = handler;
+ }
+ break;
+
+ case 404:
+ if (error404Handler != null) {
+ throw new ConfigurationException("Duplicate <handle-errors type='404' at " + handler.getLocation());
+ } else if(mainHandler != null) {
+ throw new ConfigurationException("Cannot mix <handle-errors> with and without 'type' attribute at " +
+ handler.getLocation());
+ } else {
+ error404Handler = handler;
+ }
+ break;
+
+ case 500:
+ if (error500Handler != null) {
+ throw new ConfigurationException("Duplicate <handle-errors type='500' at " + handler.getLocation());
+ } else if (mainHandler != null) {
+ throw new ConfigurationException("Cannot mix <handle-errors> with and without 'type' attribute at " +
+ handler.getLocation());
+ } else {
+ error500Handler = handler;
+ }
+ break;
+
+ default:
+ throw new ConfigurationException("Unknown handle-errors type (" + type + ") at " + handler.getLocation());
+ }
+ } else {
+ // Regular builder
+ children.add(builder.buildNode(childConfig));
+ }
+ }
+ }
+
+ node.setChildren(toNodeArray(children));
+ node.set404Handler(error404Handler);
+ // Set either main or error500 handler as only one can exist
+ node.set500Handler(error500Handler == null ? mainHandler : error500Handler);
+
+ return node;
+ }
+}
Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/PipelineNodeBuilder.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/PipelinesNode.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/PipelinesNode.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/PipelinesNode.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/PipelinesNode.java Thu Nov 3 05:41:06 2005
@@ -0,0 +1,115 @@
+/*
+ * 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.components.treeprocessor.sitemap;
+
+import org.apache.avalon.framework.activity.Disposable;
+import org.apache.avalon.framework.logger.Logger;
+import org.apache.avalon.framework.service.ServiceManager;
+import org.apache.avalon.framework.service.Serviceable;
+
+import org.apache.cocoon.ConnectionResetException;
+import org.apache.cocoon.components.treeprocessor.InvokeContext;
+import org.apache.cocoon.components.treeprocessor.ProcessingNode;
+import org.apache.cocoon.components.treeprocessor.SimpleParentProcessingNode;
+import org.apache.cocoon.environment.Environment;
+
+/**
+ * Handles <map:pipelines>
+ *
+ * @author <a href="mailto:juergen.seitz@basf-it-services.com">Jürgen Seitz</a>
+ * @author <a href="mailto:bluetkemeier@s-und-n.de">Björn Lütkemeier</a>
+ * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
+ * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
+ * @version $Id: PipelinesNode.java 157155 2005-03-11 20:59:21Z vgritsenko $
+ */
+public final class PipelinesNode extends SimpleParentProcessingNode
+ implements Serviceable, Disposable {
+
+ private ServiceManager manager;
+
+ private ErrorHandlerHelper errorHandlerHelper;
+
+ /**
+ * Constructor
+ */
+ public PipelinesNode() {
+ super(null);
+ this.errorHandlerHelper = new ErrorHandlerHelper();
+ }
+
+ /**
+ * Keep the component manager used everywhere in the tree so that we can
+ * cleanly dispose it.
+ */
+ public void service(ServiceManager manager) {
+ this.manager = manager;
+ this.errorHandlerHelper.service(manager);
+ }
+
+ public void enableLogging(Logger logger) {
+ super.enableLogging(logger);
+ this.errorHandlerHelper.enableLogging(logger);
+ }
+
+ public void setErrorHandler(ProcessingNode node) {
+ this.errorHandlerHelper.set500Handler(node);
+ }
+
+ public void setChildren(ProcessingNode[] nodes) {
+ // Mark the last pipeline so that it can throw a ResourceNotFoundException
+ ((PipelineNode) nodes[nodes.length - 1]).setLast(true);
+ super.setChildren(nodes);
+ }
+
+ /**
+ * Process the environment. Also adds a <code>SourceResolver</code>
+ * and a <code>Redirector</code> in the object model. The previous resolver and
+ * redirector, if any, are restored before return.
+ */
+ public final boolean invoke(Environment env, InvokeContext context)
+ throws Exception {
+
+ // Perform any common invoke functionality
+ super.invoke(env, context);
+
+ // Recompose context (and pipelines) to the local component manager
+ context.service(this.manager);
+
+ try {
+ // FIXME: Is there any useful information that can be passed as top-level parameters,
+ // such as the URI of the mount point ?
+
+ return invokeNodes(this.children, env, context);
+
+ } catch (ConnectionResetException e) {
+ // Will be reported by CocoonServlet, rethrowing
+ throw e;
+ } catch (Exception ex) {
+ // Invoke pipelines handler
+ return this.errorHandlerHelper.invokeErrorHandler(ex, env, context);
+ }
+ }
+
+ /**
+ * Dispose the component manager.
+ */
+ public void dispose() {
+ if (this.manager instanceof Disposable) {
+ ((Disposable) this.manager).dispose();
+ }
+ this.manager = null;
+ }
+}
Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/PipelinesNode.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/PipelinesNodeBuilder.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/PipelinesNodeBuilder.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/PipelinesNodeBuilder.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/PipelinesNodeBuilder.java Thu Nov 3 05:41:06 2005
@@ -0,0 +1,80 @@
+/*
+ * Copyright 1999-2005 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.components.treeprocessor.sitemap;
+
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.avalon.framework.thread.ThreadSafe;
+
+import org.apache.cocoon.components.treeprocessor.ContainerNodeBuilder;
+import org.apache.cocoon.components.treeprocessor.ProcessingNode;
+import org.apache.cocoon.components.treeprocessor.ProcessingNodeBuilder;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Builds a <map:pipelines>
+ *
+ * @author <a href="mailto:juergen.seitz@basf-it-services.com">Jürgen Seitz</a>
+ * @author <a href="mailto:bluetkemeier@s-und-n.de">Björn Lütkemeier</a>
+ * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
+ * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
+ * @version $Id: PipelinesNodeBuilder.java 157155 2005-03-11 20:59:21Z vgritsenko $
+ */
+public class PipelinesNodeBuilder extends ContainerNodeBuilder implements ThreadSafe {
+
+ public ProcessingNode buildNode(Configuration config)
+ throws Exception {
+ // Check for component configurations
+ Configuration child = config.getChild("component-configurations", false);
+ if (child != null) {
+ checkNamespace(child);
+ this.treeBuilder.getProcessor().setComponentConfigurations(child);
+ }
+
+ PipelinesNode node = new PipelinesNode();
+ this.treeBuilder.setupNode(node, config);
+
+ Configuration[] childConfigs = config.getChildren();
+ List children = new ArrayList();
+ HandleErrorsNode handler = null;
+
+ for (int i = 0; i < childConfigs.length; i++) {
+ Configuration childConfig = childConfigs[i];
+ if (isChild(childConfig)) {
+
+ ProcessingNodeBuilder builder = this.treeBuilder.createNodeBuilder(childConfig);
+ if (builder instanceof HandleErrorsNodeBuilder) {
+ handler = (HandleErrorsNode)builder.buildNode(childConfig);
+ } else {
+ // Regular builder
+ children.add(builder.buildNode(childConfig));
+ }
+ }
+ }
+
+ if (children.size() == 0) {
+ String msg = "There must be at least one pipeline at " + config.getLocation();
+ throw new ConfigurationException(msg);
+ }
+
+ node.setChildren(toNodeArray(children));
+ node.setErrorHandler(handler);
+
+ return node;
+ }
+}
Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/PipelinesNodeBuilder.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/PreparableMatchNode.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/PreparableMatchNode.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/PreparableMatchNode.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/PreparableMatchNode.java Thu Nov 3 05:41:06 2005
@@ -0,0 +1,122 @@
+/*
+ * 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.components.treeprocessor.sitemap;
+
+import java.util.Map;
+
+import org.apache.avalon.framework.activity.Initializable;
+import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.avalon.framework.parameters.Parameters;
+import org.apache.cocoon.components.treeprocessor.InvokeContext;
+import org.apache.cocoon.components.treeprocessor.ParameterizableProcessingNode;
+import org.apache.cocoon.components.treeprocessor.SimpleSelectorProcessingNode;
+import org.apache.cocoon.components.treeprocessor.variables.VariableResolver;
+import org.apache.cocoon.environment.Environment;
+import org.apache.cocoon.matching.Matcher;
+import org.apache.cocoon.matching.PreparableMatcher;
+import org.apache.cocoon.sitemap.PatternException;
+
+/**
+ *
+ * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
+ * @version CVS $Id: PreparableMatchNode.java 240034 2005-08-25 10:04:05Z cziegeler $
+ */
+public class PreparableMatchNode extends SimpleSelectorProcessingNode
+ implements ParameterizableProcessingNode, Initializable {
+
+ /** The 'pattern' attribute */
+ private String pattern;
+
+ /** The 'name' for the variable anchor */
+ private String name;
+
+ private Object preparedPattern;
+
+ private Map parameters;
+
+ public PreparableMatchNode(String type, String pattern, String name) {
+ super(Matcher.ROLE + "Selector", type);
+ this.pattern = pattern;
+ this.name = name;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.cocoon.components.treeprocessor.ParameterizableProcessingNode#setParameters(java.util.Map)
+ */
+ public void setParameters(Map parameterMap) {
+ this.parameters = parameterMap;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.avalon.framework.activity.Initializable#initialize()
+ */
+ public void initialize() throws Exception {
+
+ // Prepare the pattern
+ PreparableMatcher matcher = (PreparableMatcher)getComponent();
+
+ try {
+ this.preparedPattern = matcher.preparePattern(this.pattern);
+ } catch(PatternException pe) {
+ String msg = "Invalid pattern '" + this.pattern + "' for matcher at " + this.getLocation();
+ throw new ConfigurationException(msg, pe);
+ } finally {
+ releaseComponent(matcher);
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.cocoon.components.treeprocessor.ProcessingNode#invoke(org.apache.cocoon.environment.Environment, org.apache.cocoon.components.treeprocessor.InvokeContext)
+ */
+ public final boolean invoke(Environment env, InvokeContext context)
+ throws Exception {
+
+ // Perform any common invoke functionality
+ super.invoke(env, context);
+
+ Map objectModel = env.getObjectModel();
+ Parameters resolvedParams = VariableResolver.buildParameters(
+ this.parameters, context, objectModel
+ );
+
+ Map result = null;
+
+ PreparableMatcher matcher = (PreparableMatcher)getComponent();
+ try {
+ result = this.executor.invokePreparableMatcher(this,
+ objectModel,
+ matcher,
+ this.pattern,
+ preparedPattern,
+ resolvedParams);
+ } finally {
+ releaseComponent(matcher);
+ }
+
+ if (result != null) {
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug("Matcher '" + this.componentName + "' matched prepared pattern '" +
+ this.pattern + "' at " + this.getLocation());
+ }
+
+ // Invoke children with the matcher results
+ return this.invokeNodes(children, env, context, name, result);
+
+ }
+ // Matcher failed
+ return false;
+ }
+}
Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/PreparableMatchNode.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/ReadNode.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/ReadNode.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/ReadNode.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/ReadNode.java Thu Nov 3 05:41:06 2005
@@ -0,0 +1,102 @@
+/*
+ * 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.components.treeprocessor.sitemap;
+
+import org.apache.cocoon.components.pipeline.ProcessingPipeline;
+import org.apache.cocoon.components.treeprocessor.AbstractProcessingNode;
+import org.apache.cocoon.components.treeprocessor.InvokeContext;
+import org.apache.cocoon.components.treeprocessor.ParameterizableProcessingNode;
+import org.apache.cocoon.components.treeprocessor.variables.VariableResolver;
+import org.apache.cocoon.environment.Environment;
+import org.apache.cocoon.sitemap.SitemapExecutor;
+
+import java.util.Map;
+
+/**
+ *
+ * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
+ * @version CVS $Id: ReadNode.java 165284 2005-04-29 09:24:28Z cziegeler $
+ */
+
+public class ReadNode extends AbstractProcessingNode implements ParameterizableProcessingNode {
+
+ private String readerName;
+
+ private VariableResolver source;
+
+ private VariableResolver mimeType;
+
+ private int statusCode;
+
+ private Map parameters;
+
+ /**
+ * Build a <code>SerializerNode</code> having a name, a mime-type and a status code (HTTP codes).
+ *
+ * @param name the name of the serializer to use.
+ * @param mimeType the mime-type, or <code>null</code> not specified.
+ * @param statusCode the HTTP response status code, or <code>-1</code> if not specified.
+ */
+ public ReadNode(String name, VariableResolver source, VariableResolver mimeType, int statusCode) {
+ this.readerName = name;
+ this.source = source;
+ this.mimeType = mimeType;
+ this.statusCode = statusCode;
+ }
+
+ public void setParameters(Map parameterMap) {
+ this.parameters = parameterMap;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.cocoon.components.treeprocessor.ProcessingNode#invoke(org.apache.cocoon.environment.Environment, org.apache.cocoon.components.treeprocessor.InvokeContext)
+ */
+ public final boolean invoke(Environment env, InvokeContext context)
+ throws Exception {
+
+ final Map objectModel = env.getObjectModel();
+
+ final ProcessingPipeline pipeline = context.getProcessingPipeline();
+
+ SitemapExecutor.PipelineComponentDescription desc = new SitemapExecutor.PipelineComponentDescription();
+ desc.type = this.readerName;
+ desc.source = source.resolve(context, objectModel);
+ desc.parameters = VariableResolver.buildParameters(this.parameters, context, objectModel);
+ desc.mimeType = this.mimeType.resolve(context, objectModel);
+
+ desc = this.executor.addReader(this, objectModel, desc);
+
+ pipeline.setReader(
+ desc.type,
+ desc.source,
+ desc.parameters,
+ desc.mimeType
+ );
+
+ // Set status code if there is one
+ if (this.statusCode >= 0) {
+ env.setStatus(this.statusCode);
+ }
+
+ if (! context.isBuildingPipelineOnly()) {
+ // Process pipeline
+ return pipeline.process(env);
+
+ }
+ // Return true : pipeline is finished.
+ return true;
+ }
+}
Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/ReadNode.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/ReadNodeBuilder.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/ReadNodeBuilder.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/ReadNodeBuilder.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/ReadNodeBuilder.java Thu Nov 3 05:41:06 2005
@@ -0,0 +1,51 @@
+/*
+ * 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.components.treeprocessor.sitemap;
+
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.thread.ThreadSafe;
+import org.apache.cocoon.components.treeprocessor.AbstractProcessingNodeBuilder;
+import org.apache.cocoon.components.treeprocessor.ProcessingNode;
+import org.apache.cocoon.components.treeprocessor.variables.VariableResolverFactory;
+import org.apache.cocoon.reading.Reader;
+
+/**
+ *
+ * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
+ * @version CVS $Id: ReadNodeBuilder.java 123887 2005-01-02 15:12:01Z sylvain $
+ */
+
+public class ReadNodeBuilder extends AbstractProcessingNodeBuilder implements ThreadSafe {
+
+ public ProcessingNode buildNode(Configuration config) throws Exception {
+
+ String type = this.treeBuilder.getTypeForStatement(config, Reader.ROLE);
+
+ String mimeType = config.getAttribute("mime-type", null);
+ if (mimeType == null) {
+ mimeType = ((SitemapLanguage)this.treeBuilder).getMimeType(Reader.ROLE, type);
+ }
+
+ ReadNode node = new ReadNode(
+ type,
+ VariableResolverFactory.getResolver(config.getAttribute("src", null), this.manager),
+ VariableResolverFactory.getResolver(mimeType, this.manager),
+ config.getAttributeAsInteger("status-code", -1)
+ );
+
+ return this.treeBuilder.setupNode(node, config);
+ }
+}
Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/ReadNodeBuilder.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/RedirectToNodeBuilder.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/RedirectToNodeBuilder.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/RedirectToNodeBuilder.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/RedirectToNodeBuilder.java Thu Nov 3 05:41:06 2005
@@ -0,0 +1,99 @@
+/*
+ * 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.components.treeprocessor.sitemap;
+
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.cocoon.components.treeprocessor.AbstractProcessingNodeBuilder;
+import org.apache.cocoon.components.treeprocessor.CategoryNode;
+import org.apache.cocoon.components.treeprocessor.CategoryNodeBuilder;
+import org.apache.cocoon.components.treeprocessor.LinkedProcessingNodeBuilder;
+import org.apache.cocoon.components.treeprocessor.ProcessingNode;
+import org.apache.cocoon.components.treeprocessor.variables.VariableResolverFactory;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ *
+ * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
+ * @version CVS $Id: RedirectToNodeBuilder.java 165284 2005-04-29 09:24:28Z cziegeler $
+ */
+
+public class RedirectToNodeBuilder extends AbstractProcessingNodeBuilder
+ implements LinkedProcessingNodeBuilder {
+
+ private CallNode callNode;
+ private String resourceName;
+
+ /** This builder has no parameters -- return <code>false</code> */
+ protected boolean hasParameters() {
+ return false;
+ }
+
+ public ProcessingNode buildNode(Configuration config) throws Exception {
+
+ if (((SitemapLanguage)this.treeBuilder).isBuildingErrorHandler()) {
+ throw new ConfigurationException("'map:redirect' is forbidden inside a 'map:handle-errors', at "
+ + config.getLocation());
+ }
+
+ // Is it a redirect to resource ?
+ this.resourceName = config.getAttribute("resource", null);
+ if (this.resourceName != null) {
+
+ getLogger().warn("Redirect to resource is deprecated. Use map:call instead at " +
+ config.getLocation());
+
+ this.callNode = new CallNode();
+ this.treeBuilder.setupNode(this.callNode, config);
+
+ String target = config.getAttribute("target", null);
+ if (target != null) {
+ Map params = new HashMap(1);
+ params.put("target", VariableResolverFactory.getResolver(target, this.manager));
+ this.callNode.setParameters(params);
+ }
+ return this.callNode;
+
+ }
+ ProcessingNode URINode = new RedirectToURINode(
+ VariableResolverFactory.getResolver(config.getAttribute("uri"), this.manager),
+ config.getAttributeAsBoolean("session", false),
+ config.getAttributeAsBoolean("global", false),
+ config.getAttributeAsBoolean("permanent", false)
+ );
+ return this.treeBuilder.setupNode(URINode, config);
+ }
+
+ public void linkNode() throws Exception {
+
+ if (this.callNode != null) {
+ CategoryNode resources = CategoryNodeBuilder.getCategoryNode(this.treeBuilder, "resources");
+
+ if (resources == null) {
+ String msg = "This sitemap contains no resources. Cannot redirect at " +
+ this.callNode.getLocation();
+ throw new ConfigurationException(msg);
+ }
+
+ this.callNode.setResource(
+ resources,
+ VariableResolverFactory.getResolver(this.resourceName, this.manager)
+ );
+ }
+ }
+}
Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/RedirectToNodeBuilder.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/RedirectToURINode.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/RedirectToURINode.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/RedirectToURINode.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/RedirectToURINode.java Thu Nov 3 05:41:06 2005
@@ -0,0 +1,81 @@
+/*
+ * 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.components.treeprocessor.sitemap;
+
+import org.apache.cocoon.components.treeprocessor.AbstractProcessingNode;
+import org.apache.cocoon.components.treeprocessor.InvokeContext;
+import org.apache.cocoon.components.treeprocessor.variables.VariableResolver;
+import org.apache.cocoon.environment.Environment;
+import org.apache.cocoon.environment.Redirector;
+import org.apache.cocoon.environment.PermanentRedirector;
+
+/**
+ *
+ * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
+ * @version CVS $Id: RedirectToURINode.java 232509 2005-08-13 17:26:07Z cziegeler $
+ */
+
+public class RedirectToURINode extends AbstractProcessingNode {
+
+ // TODO: It can implement ParameterizableProcessingNode to pass redirect parameters
+ // Those parameters will be URL-encoded and appended to the redirect URI
+
+ /** The 'uri' attribute */
+ private VariableResolver uri;
+
+ private boolean createSession;
+
+ private boolean global;
+
+ private boolean permanent;
+
+ public RedirectToURINode(VariableResolver uri,
+ boolean createSession,
+ boolean global,
+ boolean permanent ) {
+ this.global = global;
+ this.uri = uri;
+ this.createSession = createSession;
+ this.permanent = permanent;
+ }
+
+ public final boolean invoke(Environment env, InvokeContext context)
+ throws Exception {
+ String resolvedURI = uri.resolve(context, env.getObjectModel());
+
+ if (getLogger().isInfoEnabled()) {
+ getLogger().info("Redirecting to '" + resolvedURI + "' at " + this.getLocation());
+ }
+
+ resolvedURI = this.executor.redirectTo(this,
+ env.getObjectModel(),
+ resolvedURI,
+ this.createSession,
+ this.global,
+ this.permanent);
+ final Redirector redirector = context.getRedirector();
+
+ if( this.global ) {
+ redirector.globalRedirect(this.createSession, resolvedURI);
+ } else if (this.permanent && redirector instanceof PermanentRedirector) {
+ ((PermanentRedirector)redirector).permanentRedirect(this.createSession, resolvedURI);
+ } else {
+ redirector.redirect(this.createSession, resolvedURI);
+ }
+
+ return true;
+ }
+}
Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/RedirectToURINode.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/ScriptNode.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/ScriptNode.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/ScriptNode.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/ScriptNode.java Thu Nov 3 05:41:06 2005
@@ -0,0 +1,61 @@
+/*
+ * 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.components.treeprocessor.sitemap;
+
+import org.apache.cocoon.components.flow.AbstractInterpreter;
+import org.apache.cocoon.components.flow.Interpreter;
+import org.apache.cocoon.components.treeprocessor.AbstractProcessingNode;
+import org.apache.cocoon.components.treeprocessor.InvokeContext;
+import org.apache.cocoon.environment.Environment;
+
+/**
+ * Handler for <map:script> elements in the sitemap. It registers the
+ *
+ * @author <a href="mailto:ovidiu@apache.org">Ovidiu Predescu</a>
+ * @since March 13, 2002
+ * @version CVS $Id: ScriptNode.java 30941 2004-07-29 19:56:58Z vgritsenko $
+ */
+public class ScriptNode extends AbstractProcessingNode
+{
+ String source;
+
+ public ScriptNode(String source)
+ {
+ this.source = source;
+ }
+
+ /**
+ * This method should never be called by the TreeProcessor, since a
+ * <map:script> element should not be in an "executable" sitemap
+ * node.
+ *
+ * @param env an <code>Environment</code> value
+ * @param context an <code>InvokeContext</code> value
+ * @return a <code>boolean</code> value
+ * @exception Exception if an error occurs
+ */
+ public boolean invoke(Environment env, InvokeContext context)
+ throws Exception
+ {
+ return true;
+ }
+
+ public void registerScriptWithInterpreter(Interpreter interpreter)
+ {
+ if (interpreter instanceof AbstractInterpreter)
+ ((AbstractInterpreter)interpreter).register(source);
+ }
+}
Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/ScriptNode.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/ScriptNodeBuilder.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/ScriptNodeBuilder.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/ScriptNodeBuilder.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/ScriptNodeBuilder.java Thu Nov 3 05:41:06 2005
@@ -0,0 +1,61 @@
+/*
+ * 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.components.treeprocessor.sitemap;
+
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.cocoon.components.treeprocessor.AbstractProcessingNodeBuilder;
+import org.apache.cocoon.components.treeprocessor.LinkedProcessingNodeBuilder;
+import org.apache.cocoon.components.treeprocessor.ProcessingNode;
+import org.apache.cocoon.components.flow.Interpreter;
+
+/**
+ * Builder class for creating a {@link ScriptNode} instance
+ * corresponding to a <map:script> element in the sitemap.
+ *
+ * @author <a href="mailto:ovidiu@apache.org">Ovidiu Predescu</a>
+ * @since March 13, 2002
+ * @version CVS $Id: ScriptNodeBuilder.java 30941 2004-07-29 19:56:58Z vgritsenko $
+ */
+public class ScriptNodeBuilder
+ extends AbstractProcessingNodeBuilder
+ implements LinkedProcessingNodeBuilder
+{
+ protected ScriptNode node;
+
+ public ProcessingNode buildNode(Configuration config)
+ throws Exception
+ {
+ String source = config.getAttribute("src");
+
+ this.node = new ScriptNode(source);
+ this.treeBuilder.setupNode(this.node, config);
+
+ return this.node;
+ }
+
+ /**
+ * Call the built node to register the script it contains with the
+ * flow interpreter.
+ */
+ public void linkNode()
+ throws Exception
+ {
+ FlowNode flowNode = (FlowNode)this.treeBuilder.getRegisteredNode("flow");
+ Interpreter interpreter = flowNode.getInterpreter();
+
+ this.node.registerScriptWithInterpreter(interpreter);
+ }
+}
Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/ScriptNodeBuilder.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/SelectNode.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/SelectNode.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/SelectNode.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/SelectNode.java Thu Nov 3 05:41:06 2005
@@ -0,0 +1,94 @@
+/*
+ * 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.components.treeprocessor.sitemap;
+
+import java.util.Map;
+
+import org.apache.avalon.framework.parameters.Parameters;
+import org.apache.cocoon.components.treeprocessor.InvokeContext;
+import org.apache.cocoon.components.treeprocessor.ParameterizableProcessingNode;
+import org.apache.cocoon.components.treeprocessor.ProcessingNode;
+import org.apache.cocoon.components.treeprocessor.SimpleSelectorProcessingNode;
+import org.apache.cocoon.components.treeprocessor.variables.VariableResolver;
+import org.apache.cocoon.environment.Environment;
+import org.apache.cocoon.selection.Selector;
+
+/**
+ *
+ * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
+ * @version CVS $Id: SelectNode.java 179045 2005-05-30 11:08:13Z cziegeler $
+ */
+public class SelectNode extends SimpleSelectorProcessingNode
+ implements ParameterizableProcessingNode {
+
+ /** The parameters of this node */
+ private Map parameters;
+
+ private ProcessingNode[][] whenNodes;
+
+ private VariableResolver[] whenTests;
+
+ private ProcessingNode[] otherwhiseNodes;
+
+ public SelectNode(String name) {
+ super(Selector.ROLE + "Selector", name);
+ }
+
+ public void setParameters(Map parameterMap) {
+ this.parameters = parameterMap;
+ }
+
+ public void setCases(ProcessingNode[][] whenNodes, VariableResolver[] whenTests, ProcessingNode[] otherwhiseNodes) {
+ this.whenNodes = whenNodes;
+ this.whenTests = whenTests;
+ this.otherwhiseNodes = otherwhiseNodes;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.cocoon.components.treeprocessor.ProcessingNode#invoke(org.apache.cocoon.environment.Environment, org.apache.cocoon.components.treeprocessor.InvokeContext)
+ */
+ public final boolean invoke(Environment env, InvokeContext context)
+ throws Exception {
+
+ // Perform any common invoke functionality
+ super.invoke(env, context);
+
+ // Prepare data needed by the action
+ final Map objectModel = env.getObjectModel();
+ final Parameters resolvedParams = VariableResolver.buildParameters(this.parameters, context, objectModel);
+
+ final Selector selector = (Selector)getComponent();
+ try {
+
+ for (int i = 0; i < this.whenTests.length; i++) {
+ if ( this.executor.invokeSelector(this, objectModel,
+ selector,
+ whenTests[i].resolve(context, objectModel),
+ resolvedParams)) {
+ return invokeNodes(this.whenNodes[i], env, context);
+ }
+ }
+
+ if (this.otherwhiseNodes != null) {
+ return invokeNodes(this.otherwhiseNodes, env, context);
+ }
+
+ return false;
+ } finally {
+ releaseComponent(selector);
+ }
+ }
+}
Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/SelectNode.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/SelectNodeBuilder.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/SelectNodeBuilder.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/SelectNodeBuilder.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/SelectNodeBuilder.java Thu Nov 3 05:41:06 2005
@@ -0,0 +1,115 @@
+/*
+ * 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.components.treeprocessor.sitemap;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.avalon.framework.service.ServiceSelector;
+import org.apache.cocoon.components.treeprocessor.AbstractParentProcessingNodeBuilder;
+import org.apache.cocoon.components.treeprocessor.ProcessingNode;
+import org.apache.cocoon.components.treeprocessor.variables.VariableResolver;
+import org.apache.cocoon.components.treeprocessor.variables.VariableResolverFactory;
+import org.apache.cocoon.selection.Selector;
+import org.apache.cocoon.selection.SwitchSelector;
+
+/**
+ *
+ * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
+ * @version CVS $Id: SelectNodeBuilder.java 165284 2005-04-29 09:24:28Z cziegeler $
+ */
+
+public class SelectNodeBuilder extends AbstractParentProcessingNodeBuilder {
+
+ public ProcessingNode buildNode(Configuration config) throws Exception {
+
+ String type = this.treeBuilder.getTypeForStatement(config, Selector.ROLE);
+
+ // Lists of ProcessingNode[] and test resolvers for each "when"
+ List whenChildren = new ArrayList();
+ List whenTests = new ArrayList();
+
+ // Nodes for otherwise (if any)
+ ProcessingNode[] otherwiseNodes = null;
+
+ Configuration[] childrenConfig = config.getChildren();
+ for (int i = 0; i < childrenConfig.length; i++) {
+
+ Configuration childConfig = childrenConfig[i];
+ String name = childConfig.getName();
+
+ if ("when".equals(name)) {
+
+ checkNamespace(childConfig);
+ whenTests.add(
+ VariableResolverFactory.getResolver(childConfig.getAttribute("test"), this.manager)
+ );
+ whenChildren.add(buildChildNodes(childConfig));
+
+ } else if ("otherwise".equals(name)) {
+
+ checkNamespace(childConfig);
+ if (otherwiseNodes != null) {
+ String msg = "Duplicate " + name + " (only one is allowed) at " + childConfig.getLocation();
+ getLogger().error(msg);
+ throw new ConfigurationException(msg);
+ }
+
+ otherwiseNodes = buildChildNodes(childConfig);
+
+ } else if (isParameter(childConfig)) {
+ // ignore it. It is handled automatically in setupNode()
+
+ } else {
+ // Unknown element
+ String msg = "Unknown element '" + name + "' in select at " + childConfig.getLocation();
+ throw new ConfigurationException(msg);
+ }
+ }
+
+ ProcessingNode[][] whenChildrenNodes = (ProcessingNode[][])whenChildren.toArray(new ProcessingNode[0][0]);
+ VariableResolver[] whenResolvers = (VariableResolver[])whenTests.toArray(new VariableResolver[whenTests.size()]);
+
+ // Get the type and class for this selector
+ ServiceSelector compSelector = (ServiceSelector)this.manager.lookup(Selector.ROLE + "Selector");
+
+ Class clazz = null;
+ try {
+ // Find selector class
+ Selector selector = (Selector)compSelector.select(type);
+ try {
+ clazz = selector.getClass();
+ } finally {
+ compSelector.release(selector);
+ }
+ } finally {
+ this.manager.release(compSelector);
+ }
+
+ if (SwitchSelector.class.isAssignableFrom(clazz)) {
+ SwitchSelectNode node = new SwitchSelectNode(type);
+ this.treeBuilder.setupNode(node, config);
+ node.setCases(whenChildrenNodes, whenResolvers, otherwiseNodes);
+ return node;
+ }
+ SelectNode node = new SelectNode(type);
+ this.treeBuilder.setupNode(node, config);
+ node.setCases(whenChildrenNodes, whenResolvers, otherwiseNodes);
+ return node;
+ }
+}
Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/SelectNodeBuilder.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/SerializeNode.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/SerializeNode.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/SerializeNode.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/SerializeNode.java Thu Nov 3 05:41:06 2005
@@ -0,0 +1,142 @@
+/*
+ * Copyright 1999-2005 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.components.treeprocessor.sitemap;
+
+import java.util.Map;
+
+import org.apache.avalon.framework.parameters.Parameters;
+import org.apache.cocoon.Constants;
+import org.apache.cocoon.components.pipeline.ProcessingPipeline;
+import org.apache.cocoon.components.treeprocessor.InvokeContext;
+import org.apache.cocoon.components.treeprocessor.ParameterizableProcessingNode;
+import org.apache.cocoon.components.treeprocessor.PipelineEventComponentProcessingNode;
+import org.apache.cocoon.components.treeprocessor.ProcessingNode;
+import org.apache.cocoon.components.treeprocessor.variables.VariableResolver;
+import org.apache.cocoon.environment.Environment;
+import org.apache.cocoon.sitemap.SitemapExecutor;
+
+/**
+ *
+ * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
+ * @author <a href="mailto:uv@upaya.co.uk">Upayavira</a>
+ * @version CVS $Id: SerializeNode.java 280345 2005-09-12 14:25:56Z cziegeler $
+ */
+public class SerializeNode extends PipelineEventComponentProcessingNode implements ParameterizableProcessingNode {
+
+ private String serializerName;
+
+ private VariableResolver source;
+
+ private VariableResolver mimeType;
+
+ private int statusCode;
+
+ private Map parameters;
+
+
+ /**
+ * Build a <code>SerializerNode</code> having a name, a mime-type and a status code (HTTP codes).
+ *
+ * @param name the name of the serializer to use.
+ * @param mimeType the mime-type, or <code>null</code> not specified.
+ * @param statusCode the HTTP response status code, or <code>-1</code> if not specified.
+ */
+ public SerializeNode(String name,
+ VariableResolver source,
+ VariableResolver mimeType,
+ int statusCode) {
+ this.serializerName = name;
+ this.source = source;
+ this.mimeType = mimeType;
+ this.statusCode = statusCode;
+ }
+
+ public void setParameters(Map parameterMap) {
+ this.parameters = parameterMap;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.cocoon.components.treeprocessor.ProcessingNode#invoke(org.apache.cocoon.environment.Environment, org.apache.cocoon.components.treeprocessor.InvokeContext)
+ */
+ public final boolean invoke(Environment env, InvokeContext context)
+ throws Exception {
+
+ // Check view
+ if (this.views != null) {
+
+ //inform the pipeline that we have a branch point
+ context.getProcessingPipeline().informBranchPoint();
+
+ String cocoonView = env.getView();
+ if (cocoonView != null) {
+
+ // Get view node
+ ProcessingNode viewNode = (ProcessingNode)this.views.get(cocoonView);
+
+ if (viewNode != null) {
+ if (getLogger().isInfoEnabled()) {
+ getLogger().info("Jumping to view " + cocoonView + " from serializer at " + this.getLocation());
+ }
+ return viewNode.invoke(env, context);
+ }
+ }
+ }
+
+ final Map objectModel = env.getObjectModel();
+ final ProcessingPipeline pipeline = context.getProcessingPipeline();
+
+ // Perform link translation if requested
+ if (objectModel.containsKey(Constants.LINK_OBJECT)) {
+ pipeline.addTransformer("<translator>", null, Parameters.EMPTY_PARAMETERS, Parameters.EMPTY_PARAMETERS);
+ }
+
+ if (objectModel.containsKey(Constants.LINK_COLLECTION_OBJECT) && env.isExternal()) {
+ pipeline.addTransformer("<gatherer>", null, Parameters.EMPTY_PARAMETERS, Parameters.EMPTY_PARAMETERS);
+ }
+
+ SitemapExecutor.PipelineComponentDescription desc = new SitemapExecutor.PipelineComponentDescription();
+ desc.type = this.serializerName;
+ desc.source = source.resolve(context, objectModel);
+ desc.parameters = VariableResolver.buildParameters(this.parameters, context, objectModel);
+ desc.hintParameters = this.pipelineHints == null
+ ? Parameters.EMPTY_PARAMETERS
+ : VariableResolver.buildParameters(this.pipelineHints, context, objectModel);
+ desc.mimeType = this.mimeType.resolve(context, objectModel);
+
+ // inform executor
+ desc = this.executor.addSerializer(this, objectModel, desc);
+
+ pipeline.setSerializer(
+ desc.type,
+ desc.source,
+ desc.parameters,
+ desc.hintParameters,
+ desc.mimeType
+ );
+
+ // Set status code if there is one
+ if (this.statusCode >= 0) {
+ env.setStatus(this.statusCode);
+ }
+
+ if (! context.isBuildingPipelineOnly()) {
+ // Process pipeline
+ return pipeline.process(env);
+ }
+ // Return true : pipeline is finished.
+ return true;
+ }
+}
Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/SerializeNode.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/SerializeNodeBuilder.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/SerializeNodeBuilder.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/SerializeNodeBuilder.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/SerializeNodeBuilder.java Thu Nov 3 05:41:06 2005
@@ -0,0 +1,76 @@
+/*
+ * 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.components.treeprocessor.sitemap;
+
+import java.util.Collection;
+import java.util.Map;
+
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.cocoon.components.treeprocessor.AbstractProcessingNodeBuilder;
+import org.apache.cocoon.components.treeprocessor.LinkedProcessingNodeBuilder;
+import org.apache.cocoon.components.treeprocessor.ProcessingNode;
+import org.apache.cocoon.components.treeprocessor.variables.VariableResolverFactory;
+import org.apache.cocoon.serialization.Serializer;
+
+/**
+ *
+ * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
+ * @version CVS $Id: SerializeNodeBuilder.java 123887 2005-01-02 15:12:01Z sylvain $
+ */
+
+public class SerializeNodeBuilder extends AbstractProcessingNodeBuilder
+ implements LinkedProcessingNodeBuilder {
+
+ private SerializeNode node;
+
+ private Collection views;
+ private Map pipelineHints;
+
+ /** Serializers can have parameters -- return <code>true</code> */
+ protected boolean hasParameters() {
+ return true;
+ }
+
+ public ProcessingNode buildNode(Configuration config) throws Exception {
+
+ String type = this.treeBuilder.getTypeForStatement(config, Serializer.ROLE);
+
+ SitemapLanguage sitemapBuilder = (SitemapLanguage)this.treeBuilder;
+
+ String mimeType = config.getAttribute("mime-type", null);
+ if (mimeType == null) {
+ mimeType = sitemapBuilder.getMimeType(Serializer.ROLE, type);
+ }
+
+ this.views = sitemapBuilder.getViewsForStatement(Serializer.ROLE, type, config);
+ this.pipelineHints = sitemapBuilder.getHintsForStatement(Serializer.ROLE, type, config);
+
+ this.node = new SerializeNode(
+ type,
+ VariableResolverFactory.getResolver(config.getAttribute("src", null), this.manager),
+ VariableResolverFactory.getResolver(mimeType, this.manager),
+ config.getAttributeAsInteger("status-code", -1)
+ );
+ this.node.setPipelineHints(this.pipelineHints);
+ return this.treeBuilder.setupNode(node, config);
+ }
+
+ public void linkNode() throws Exception {
+ this.node.setViews(
+ ((SitemapLanguage)this.treeBuilder).getViewNodes(this.views)
+ );
+ }
+}
Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/SerializeNodeBuilder.java
------------------------------------------------------------------------------
svn:eol-style = native