KickJava   Java API By Example, From Geeks To Geeks.

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


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

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