KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > components > treeprocessor > sitemap > GenerateNode


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.cocoon.components.treeprocessor.sitemap;
17
18 import java.util.Map JavaDoc;
19
20 import org.apache.avalon.framework.parameters.Parameters;
21 import org.apache.cocoon.components.treeprocessor.InvokeContext;
22 import org.apache.cocoon.components.treeprocessor.ParameterizableProcessingNode;
23 import org.apache.cocoon.components.treeprocessor.PipelineEventComponentProcessingNode;
24 import org.apache.cocoon.components.treeprocessor.ProcessingNode;
25 import org.apache.cocoon.components.treeprocessor.variables.VariableResolver;
26 import org.apache.cocoon.environment.Environment;
27 import org.apache.cocoon.sitemap.PatternException;
28
29 /**
30  *
31  * @author <a HREF="mailto:sylvain@apache.org">Sylvain Wallez</a>
32  * @version CVS $Id: GenerateNode.java 30932 2004-07-29 17:35:38Z vgritsenko $
33  */

34 public class GenerateNode extends PipelineEventComponentProcessingNode implements ParameterizableProcessingNode {
35
36     private String JavaDoc generatorName;
37
38     private VariableResolver source;
39
40     private Map JavaDoc parameters;
41
42
43     public GenerateNode(String JavaDoc name, VariableResolver source) throws PatternException {
44         this.generatorName = name;
45         this.source = source;
46     }
47
48     public void setParameters(Map JavaDoc parameterMap) {
49         this.parameters = parameterMap;
50     }
51
52     public final boolean invoke(Environment env, InvokeContext context)
53     throws Exception JavaDoc {
54
55         Map JavaDoc objectModel = env.getObjectModel();
56
57         context.getProcessingPipeline().setGenerator(
58             this.generatorName,
59             source.resolve(context, objectModel),
60             VariableResolver.buildParameters(this.parameters, context, objectModel),
61             this.pipelineHints == null
62                 ? Parameters.EMPTY_PARAMETERS
63                 : VariableResolver.buildParameters(this.pipelineHints, context, objectModel)
64         );
65
66
67         // Check view
68
if (this.views != null) {
69      
70             //inform the pipeline that we have a branch point
71
context.getProcessingPipeline().informBranchPoint();
72
73             String JavaDoc cocoonView = env.getView();
74             if (cocoonView != null) {
75
76                 // Get view node
77
ProcessingNode viewNode = (ProcessingNode)this.views.get(cocoonView);
78
79                 if (viewNode != null) {
80                     if (getLogger().isInfoEnabled()) {
81                         getLogger().info("Jumping to view " + cocoonView + " from generator at " + this.getLocation());
82                     }
83                     return viewNode.invoke(env, context);
84                 }
85             }
86         }
87
88         // Return false to continue sitemap invocation
89
return false;
90     }
91 }
92
Popular Tags