KickJava   Java API By Example, From Geeks To Geeks.

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


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

32
33 public class ReadNode extends AbstractProcessingNode implements ParameterizableProcessingNode {
34
35     private String JavaDoc readerName;
36
37     private VariableResolver source;
38
39     private VariableResolver mimeType;
40
41     private int statusCode;
42
43     private Map JavaDoc parameters;
44
45     /**
46      * Build a <code>SerializerNode</code> having a name, a mime-type and a status code (HTTP codes).
47      *
48      * @param name the name of the serializer to use.
49      * @param mimeType the mime-type, or <code>null</code> not specified.
50      * @param statusCode the HTTP response status code, or <code>-1</code> if not specified.
51      */

52     public ReadNode(String JavaDoc name, VariableResolver source, VariableResolver mimeType, int statusCode) {
53         this.readerName = name;
54         this.source = source;
55         this.mimeType = mimeType;
56         this.statusCode = statusCode;
57     }
58
59     public void setParameters(Map JavaDoc parameterMap) {
60         this.parameters = parameterMap;
61     }
62
63     public final boolean invoke(Environment env, InvokeContext context)
64       throws Exception JavaDoc {
65
66         Map JavaDoc objectModel = env.getObjectModel();
67
68         ProcessingPipeline pipeline = context.getProcessingPipeline();
69
70         pipeline.setReader(
71             this.readerName,
72             source.resolve(context, objectModel),
73             VariableResolver.buildParameters(this.parameters, context, objectModel),
74             this.mimeType.resolve(context, objectModel)
75         );
76
77         // Set status code if there is one
78
if (this.statusCode >= 0) {
79             env.setStatus(this.statusCode);
80         }
81
82         if (! context.isBuildingPipelineOnly()) {
83             // Process pipeline
84
return pipeline.process(env);
85
86         } else {
87             // Return true : pipeline is finished.
88
return true;
89         }
90     }
91 }
92
Popular Tags