001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.cocoon.components.treeprocessor.sitemap;
018:
019: import org.apache.avalon.framework.parameters.Parameters;
020: import org.apache.cocoon.components.treeprocessor.InvokeContext;
021: import org.apache.cocoon.components.treeprocessor.ParameterizableProcessingNode;
022: import org.apache.cocoon.components.treeprocessor.PipelineEventComponentProcessingNode;
023: import org.apache.cocoon.components.treeprocessor.ProcessingNode;
024: import org.apache.cocoon.components.treeprocessor.variables.VariableResolver;
025: import org.apache.cocoon.environment.Environment;
026: import org.apache.cocoon.sitemap.PatternException;
027:
028: import java.util.Map;
029:
030: /**
031: *
032: * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
033: * @version CVS $Id: TransformNode.java 433543 2006-08-22 06:22:54Z crossley $
034: */
035:
036: public class TransformNode extends PipelineEventComponentProcessingNode
037: implements ParameterizableProcessingNode {
038:
039: private String transformerName;
040:
041: private VariableResolver source;
042:
043: private Map parameters;
044:
045: public TransformNode(String name, VariableResolver source)
046: throws PatternException {
047: this .transformerName = name;
048: this .source = source;
049: }
050:
051: public void setParameters(Map parameterMap) {
052: this .parameters = parameterMap;
053: }
054:
055: public final boolean invoke(Environment env, InvokeContext context)
056: throws Exception {
057:
058: Map objectModel = env.getObjectModel();
059:
060: context
061: .getProcessingPipeline()
062: .addTransformer(
063: this .transformerName,
064: source.resolve(context, objectModel),
065: VariableResolver.buildParameters(
066: this .parameters, context, objectModel),
067: this .pipelineHints == null ? Parameters.EMPTY_PARAMETERS
068: : VariableResolver.buildParameters(
069: this .pipelineHints, context,
070: objectModel));
071:
072: // Check view
073: if (this .views != null) {
074:
075: //inform the pipeline that we have a branch point
076: context.getProcessingPipeline().informBranchPoint();
077:
078: String cocoonView = env.getView();
079: if (cocoonView != null) {
080:
081: // Get view node
082: ProcessingNode viewNode = (ProcessingNode) this .views
083: .get(cocoonView);
084:
085: if (viewNode != null) {
086: if (getLogger().isInfoEnabled()) {
087: getLogger().info(
088: "Jumping to view " + cocoonView
089: + " from transformer at "
090: + this .getLocation());
091: }
092: return viewNode.invoke(env, context);
093: }
094: }
095: }
096:
097: // Return false to contine sitemap invocation
098: return false;
099: }
100: }
|