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 org.apache.cocoon.components.pipeline.ProcessingPipeline;
20: import org.apache.cocoon.components.treeprocessor.AbstractProcessingNode;
21: import org.apache.cocoon.components.treeprocessor.InvokeContext;
22: import org.apache.cocoon.components.treeprocessor.ParameterizableProcessingNode;
23: import org.apache.cocoon.components.treeprocessor.variables.VariableResolver;
24: import org.apache.cocoon.environment.Environment;
25:
26: import java.util.Map;
27:
28: /**
29: *
30: * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
31: * @version CVS $Id: ReadNode.java 433543 2006-08-22 06:22:54Z crossley $
32: */
33:
34: public class ReadNode extends AbstractProcessingNode implements
35: ParameterizableProcessingNode {
36:
37: private String readerName;
38:
39: private VariableResolver source;
40:
41: private VariableResolver mimeType;
42:
43: private int statusCode;
44:
45: private Map parameters;
46:
47: /**
48: * Build a <code>SerializerNode</code> having a name, a mime-type and a status code (HTTP codes).
49: *
50: * @param name the name of the serializer to use.
51: * @param mimeType the mime-type, or <code>null</code> not specified.
52: * @param statusCode the HTTP response status code, or <code>-1</code> if not specified.
53: */
54: public ReadNode(String name, VariableResolver source,
55: VariableResolver mimeType, int statusCode) {
56: this .readerName = name;
57: this .source = source;
58: this .mimeType = mimeType;
59: this .statusCode = statusCode;
60: }
61:
62: public void setParameters(Map parameterMap) {
63: this .parameters = parameterMap;
64: }
65:
66: public final boolean invoke(Environment env, InvokeContext context)
67: throws Exception {
68:
69: Map objectModel = env.getObjectModel();
70:
71: ProcessingPipeline pipeline = context.getProcessingPipeline();
72:
73: pipeline.setReader(this .readerName, source.resolve(context,
74: objectModel), VariableResolver.buildParameters(
75: this .parameters, context, objectModel), this .mimeType
76: .resolve(context, objectModel));
77:
78: // Set status code if there is one
79: if (this .statusCode >= 0) {
80: env.setStatus(this .statusCode);
81: }
82:
83: if (!context.isBuildingPipelineOnly()) {
84: // Process pipeline
85: return pipeline.process(env);
86:
87: } else {
88: // Return true : pipeline is finished.
89: return true;
90: }
91: }
92: }
|