01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.cocoon.components.treeprocessor.sitemap;
18:
19: import java.util.Map;
20:
21: import org.apache.avalon.framework.parameters.Parameters;
22: import org.apache.cocoon.components.treeprocessor.InvokeContext;
23: import org.apache.cocoon.components.treeprocessor.ParameterizableProcessingNode;
24: import org.apache.cocoon.components.treeprocessor.PipelineEventComponentProcessingNode;
25: import org.apache.cocoon.components.treeprocessor.ProcessingNode;
26: import org.apache.cocoon.components.treeprocessor.variables.VariableResolver;
27: import org.apache.cocoon.environment.Environment;
28: import org.apache.cocoon.sitemap.PatternException;
29:
30: /**
31: *
32: * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
33: * @version CVS $Id: GenerateNode.java 433543 2006-08-22 06:22:54Z crossley $
34: */
35: public class GenerateNode extends PipelineEventComponentProcessingNode
36: implements ParameterizableProcessingNode {
37:
38: private String generatorName;
39:
40: private VariableResolver source;
41:
42: private Map parameters;
43:
44: public GenerateNode(String name, VariableResolver source)
45: throws PatternException {
46: this .generatorName = name;
47: this .source = source;
48: }
49:
50: public void setParameters(Map parameterMap) {
51: this .parameters = parameterMap;
52: }
53:
54: public final boolean invoke(Environment env, InvokeContext context)
55: throws Exception {
56:
57: Map objectModel = env.getObjectModel();
58:
59: context
60: .getProcessingPipeline()
61: .setGenerator(
62: this .generatorName,
63: source.resolve(context, objectModel),
64: VariableResolver.buildParameters(
65: this .parameters, context, objectModel),
66: this .pipelineHints == null ? Parameters.EMPTY_PARAMETERS
67: : VariableResolver.buildParameters(
68: this .pipelineHints, context,
69: objectModel));
70:
71: // Check view
72: if (this .views != null) {
73:
74: //inform the pipeline that we have a branch point
75: context.getProcessingPipeline().informBranchPoint();
76:
77: String cocoonView = env.getView();
78: if (cocoonView != null) {
79:
80: // Get view node
81: ProcessingNode viewNode = (ProcessingNode) this .views
82: .get(cocoonView);
83:
84: if (viewNode != null) {
85: if (getLogger().isInfoEnabled()) {
86: getLogger().info(
87: "Jumping to view " + cocoonView
88: + " from generator at "
89: + this .getLocation());
90: }
91: return viewNode.invoke(env, context);
92: }
93: }
94: }
95:
96: // Return false to continue sitemap invocation
97: return false;
98: }
99: }
|