KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > environment > wrapper > MutableEnvironmentFacade


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.environment.wrapper;
17
18 import java.io.IOException JavaDoc;
19 import java.io.OutputStream JavaDoc;
20 import java.net.MalformedURLException JavaDoc;
21 import java.util.Enumeration JavaDoc;
22 import java.util.Map JavaDoc;
23
24 import org.apache.cocoon.ProcessingException;
25 import org.apache.cocoon.components.treeprocessor.sitemap.MountNode;
26 import org.apache.cocoon.environment.Environment;
27 import org.apache.cocoon.environment.Source;
28 import org.xml.sax.SAXException JavaDoc;
29
30 /**
31  * Enviroment facade, whose delegate object can be changed. This class is
32  * required to handle internal redirects in sitemap sources ("cocoon:").
33  * This is because {@link org.apache.cocoon.components.source.impl.SitemapSource}
34  * keeps the environment in which the internal request should be processed.
35  * But internal redirects create a new processing environment and there's
36  * no way to change the one held by the <code>SitemapSource</code>. So the
37  * processing of internal redirects actually changes the delegate of this
38  * class, transparently for the <code>SitemapSource</code>.
39  *
40  * @see org.apache.cocoon.components.source.impl.SitemapSource
41  * @author <a HREF="http://www.apache.org/~sylvain/">Sylvain Wallez</a>
42  * @version CVS $Id: MutableEnvironmentFacade.java 165641 2005-05-02 14:28:56Z sylvain $
43  */

44 public class MutableEnvironmentFacade implements Environment {
45
46     private EnvironmentWrapper env;
47
48     public MutableEnvironmentFacade(EnvironmentWrapper env) {
49         this.env = env;
50         // Ensure we start with a false passthrough flag.
51
// FIXME: this should really be part of the Processor contract rather
52
// than an environment attribute
53
env.setAttribute(MountNode.COCOON_PASS_THROUGH, Boolean.FALSE);
54     }
55
56     public EnvironmentWrapper getDelegate() {
57         return this.env;
58     }
59
60     public void setDelegate(EnvironmentWrapper env) {
61         this.env = env;
62     }
63
64     //----------------------------------
65
// EnvironmentWrapper-specific method (SW:still have to understand why SitemapSource needs them)
66
public void setURI(String JavaDoc prefix, String JavaDoc uri) {
67         this.env.setURI(prefix, uri);
68     }
69
70     public void setOutputStream(OutputStream JavaDoc os) {
71         this.env.setOutputStream(os);
72     }
73
74     // Move this to the Environment interface ?
75
public String JavaDoc getRedirectURL() {
76         return this.env.getRedirectURL();
77     }
78
79     public void reset() {
80         this.env.reset();
81     }
82     //----------------------------------
83

84     /* (non-Javadoc)
85      * @see org.apache.cocoon.environment.Environment#getURI()
86      */

87     public String JavaDoc getURI() {
88         return env.getURI();
89     }
90
91     /* (non-Javadoc)
92      * @see org.apache.cocoon.environment.Environment#getURIPrefix()
93      */

94     public String JavaDoc getURIPrefix() {
95         return env.getURIPrefix();
96     }
97
98     /* (non-Javadoc)
99      * @see org.apache.cocoon.environment.Environment#getRootContext()
100      */

101     public String JavaDoc getRootContext() {
102         return env.getRootContext();
103     }
104
105     /* (non-Javadoc)
106      * @see org.apache.cocoon.environment.Environment#getContext()
107      */

108     public String JavaDoc getContext() {
109         return env.getContext();
110     }
111
112     /* (non-Javadoc)
113      * @see org.apache.cocoon.environment.Environment#getView()
114      */

115     public String JavaDoc getView() {
116         return env.getView();
117     }
118
119     /* (non-Javadoc)
120      * @see org.apache.cocoon.environment.Environment#getAction()
121      */

122     public String JavaDoc getAction() {
123         return env.getAction();
124     }
125
126     /* (non-Javadoc)
127      * @see org.apache.cocoon.environment.Environment#setContext(java.lang.String, java.lang.String, java.lang.String)
128      */

129     public void setContext(String JavaDoc prefix, String JavaDoc uri, String JavaDoc context) {
130         env.setContext(prefix, uri, context);
131     }
132
133     /* (non-Javadoc)
134      * @see org.apache.cocoon.environment.Environment#changeContext(java.lang.String, java.lang.String)
135      */

136     public void changeContext(String JavaDoc uriprefix, String JavaDoc context) throws Exception JavaDoc {
137         env.changeContext(uriprefix, context);
138     }
139
140     /* (non-Javadoc)
141      * @see org.apache.cocoon.environment.Environment#redirect(boolean, java.lang.String)
142      */

143     public void redirect(boolean sessionmode, String JavaDoc url) throws IOException JavaDoc {
144         env.redirect(sessionmode, url);
145     }
146
147     /* (non-Javadoc)
148      * @see org.apache.cocoon.environment.Environment#setContentType(java.lang.String)
149      */

150     public void setContentType(String JavaDoc mimeType) {
151         env.setContentType(mimeType);
152     }
153
154     /* (non-Javadoc)
155      * @see org.apache.cocoon.environment.Environment#getContentType()
156      */

157     public String JavaDoc getContentType() {
158         return env.getContentType();
159     }
160
161     /* (non-Javadoc)
162      * @see org.apache.cocoon.environment.Environment#setContentLength(int)
163      */

164     public void setContentLength(int length) {
165         env.setContentLength(length);
166     }
167
168     /* (non-Javadoc)
169      * @see org.apache.cocoon.environment.Environment#setStatus(int)
170      */

171     public void setStatus(int statusCode) {
172         env.setStatus(statusCode);
173     }
174
175     /* (non-Javadoc)
176      * @see org.apache.cocoon.environment.Environment#getOutputStream()
177      */

178     public OutputStream JavaDoc getOutputStream() throws IOException JavaDoc {
179         return env.getOutputStream();
180     }
181
182     /* (non-Javadoc)
183      * @see org.apache.cocoon.environment.Environment#getOutputStream(int)
184      */

185     public OutputStream JavaDoc getOutputStream(int bufferSize) throws IOException JavaDoc {
186         return env.getOutputStream(bufferSize);
187     }
188
189     /* (non-Javadoc)
190      * @see org.apache.cocoon.environment.Environment#getObjectModel()
191      */

192     public Map JavaDoc getObjectModel() {
193         return env.getObjectModel();
194     }
195
196     /* (non-Javadoc)
197      * @see org.apache.cocoon.environment.Environment#isResponseModified(long)
198      */

199     public boolean isResponseModified(long lastModified) {
200         return env.isResponseModified(lastModified);
201     }
202
203     /* (non-Javadoc)
204      * @see org.apache.cocoon.environment.Environment#setResponseIsNotModified()
205      */

206     public void setResponseIsNotModified() {
207         env.setResponseIsNotModified();
208     }
209
210     /* (non-Javadoc)
211      * @see org.apache.cocoon.environment.Environment#setAttribute(java.lang.String, java.lang.Object)
212      */

213     public void setAttribute(String JavaDoc name, Object JavaDoc value) {
214         env.setAttribute(name, value);
215     }
216
217     /* (non-Javadoc)
218      * @see org.apache.cocoon.environment.Environment#getAttribute(java.lang.String)
219      */

220     public Object JavaDoc getAttribute(String JavaDoc name) {
221         return env.getAttribute(name);
222     }
223
224     /* (non-Javadoc)
225      * @see org.apache.cocoon.environment.Environment#removeAttribute(java.lang.String)
226      */

227     public void removeAttribute(String JavaDoc name) {
228         env.removeAttribute(name);
229     }
230
231     /* (non-Javadoc)
232      * @see org.apache.cocoon.environment.Environment#getAttributeNames()
233      */

234     public Enumeration JavaDoc getAttributeNames() {
235         return env.getAttributeNames();
236     }
237
238     /* (non-Javadoc)
239      * @see org.apache.cocoon.environment.Environment#tryResetResponse()
240      */

241     public boolean tryResetResponse() throws IOException JavaDoc {
242         return env.tryResetResponse();
243     }
244
245     /* (non-Javadoc)
246      * @see org.apache.cocoon.environment.Environment#commitResponse()
247      */

248     public void commitResponse() throws IOException JavaDoc {
249         env.commitResponse();
250     }
251
252     /* (non-Javadoc)
253      * @see org.apache.cocoon.environment.Environment#startingProcessing()
254      */

255     public void startingProcessing() {
256         env.startingProcessing();
257     }
258
259     /* (non-Javadoc)
260      * @see org.apache.cocoon.environment.Environment#finishingProcessing()
261      */

262     public void finishingProcessing() {
263         env.finishingProcessing();
264     }
265
266     /* (non-Javadoc)
267      * @see org.apache.cocoon.environment.Environment#isExternal()
268      */

269     public boolean isExternal() {
270         return env.isExternal();
271     }
272
273     /* (non-Javadoc)
274      * @see org.apache.cocoon.environment.Environment#isInternRedirect()
275      */

276     public boolean isInternalRedirect() {
277         return env.isInternalRedirect();
278     }
279
280     /* (non-Javadoc)
281      * @see org.apache.cocoon.environment.SourceResolver#resolve(java.lang.String)
282      */

283     public Source resolve(String JavaDoc systemID)
284     throws ProcessingException, SAXException JavaDoc, IOException JavaDoc {
285         return env.resolve(systemID);
286     }
287
288     /* (non-Javadoc)
289      * @see org.apache.excalibur.source.SourceResolver#resolveURI(java.lang.String)
290      */

291     public org.apache.excalibur.source.Source resolveURI(String JavaDoc arg0)
292     throws MalformedURLException JavaDoc, IOException JavaDoc {
293         return env.resolveURI(arg0);
294     }
295
296     /* (non-Javadoc)
297      * @see org.apache.excalibur.source.SourceResolver#resolveURI(java.lang.String, java.lang.String, java.util.Map)
298      */

299     public org.apache.excalibur.source.Source resolveURI(String JavaDoc arg0, String JavaDoc arg1, Map JavaDoc arg2)
300     throws MalformedURLException JavaDoc, IOException JavaDoc {
301         return env.resolveURI(arg0, arg1, arg2);
302     }
303
304     /* (non-Javadoc)
305      * @see org.apache.excalibur.source.SourceResolver#release(org.apache.excalibur.source.Source)
306      */

307     public void release(org.apache.excalibur.source.Source arg0) {
308         env.release(arg0);
309     }
310 }
311
Popular Tags