001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.cocoon.environment.wrapper;
018:
019: import java.io.IOException;
020: import java.io.OutputStream;
021: import java.net.MalformedURLException;
022: import java.util.Enumeration;
023: import java.util.Map;
024:
025: import org.apache.cocoon.ProcessingException;
026: import org.apache.cocoon.components.treeprocessor.sitemap.MountNode;
027: import org.apache.cocoon.environment.Environment;
028: import org.apache.cocoon.environment.Source;
029: import org.apache.cocoon.util.Deprecation;
030: import org.xml.sax.SAXException;
031:
032: /**
033: * Enviroment facade, whose delegate object can be changed. This class is
034: * required to handle internal redirects in sitemap sources ("cocoon:").
035: * This is because {@link org.apache.cocoon.components.source.impl.SitemapSource}
036: * keeps the environment in which the internal request should be processed.
037: * But internal redirects create a new processing environment and there's
038: * no way to change the one held by the <code>SitemapSource</code>. So the
039: * processing of internal redirects actually changes the delegate of this
040: * class, transparently for the <code>SitemapSource</code>.
041: *
042: * @see org.apache.cocoon.components.source.impl.SitemapSource
043: * @author <a href="http://www.apache.org/~sylvain/">Sylvain Wallez</a>
044: * @version $Id: MutableEnvironmentFacade.java 433543 2006-08-22 06:22:54Z crossley $
045: */
046: public class MutableEnvironmentFacade implements Environment {
047:
048: private EnvironmentWrapper env;
049:
050: public MutableEnvironmentFacade(EnvironmentWrapper env) {
051: this .env = env;
052: // Ensure we start with a false passthrough flag.
053: // FIXME: this should really be part of the Processor contract rather
054: // than an environment attribute
055: env.setAttribute(MountNode.COCOON_PASS_THROUGH, Boolean.FALSE);
056: }
057:
058: public EnvironmentWrapper getDelegate() {
059: return this .env;
060: }
061:
062: public void setDelegate(EnvironmentWrapper env) {
063: this .env = env;
064: }
065:
066: //----------------------------------
067: // EnvironmentWrapper-specific method (SW:still have to understand why SitemapSource needs them)
068: public void setURI(String prefix, String uri) {
069: this .env.setURI(prefix, uri);
070: }
071:
072: public void setOutputStream(OutputStream os) {
073: this .env.setOutputStream(os);
074: }
075:
076: // Move this to the Environment interface ?
077: public String getRedirectURL() {
078: return this .env.getRedirectURL();
079: }
080:
081: public void reset() {
082: this .env.reset();
083: }
084:
085: //----------------------------------
086:
087: /* (non-Javadoc)
088: * @see org.apache.cocoon.environment.Environment#getURI()
089: */
090: public String getURI() {
091: return env.getURI();
092: }
093:
094: /* (non-Javadoc)
095: * @see org.apache.cocoon.environment.Environment#getURIPrefix()
096: */
097: public String getURIPrefix() {
098: return env.getURIPrefix();
099: }
100:
101: /* (non-Javadoc)
102: * @see org.apache.cocoon.environment.Environment#getRootContext()
103: */
104: public String getRootContext() {
105: return env.getRootContext();
106: }
107:
108: /* (non-Javadoc)
109: * @see org.apache.cocoon.environment.Environment#getContext()
110: */
111: public String getContext() {
112: return env.getContext();
113: }
114:
115: /* (non-Javadoc)
116: * @see org.apache.cocoon.environment.Environment#getView()
117: */
118: public String getView() {
119: return env.getView();
120: }
121:
122: /* (non-Javadoc)
123: * @see org.apache.cocoon.environment.Environment#getAction()
124: */
125: public String getAction() {
126: return env.getAction();
127: }
128:
129: /* (non-Javadoc)
130: * @see org.apache.cocoon.environment.Environment#setContext(java.lang.String, java.lang.String, java.lang.String)
131: */
132: public void setContext(String prefix, String uri, String context) {
133: env.setContext(prefix, uri, context);
134: }
135:
136: /* (non-Javadoc)
137: * @see org.apache.cocoon.environment.Environment#changeContext(java.lang.String, java.lang.String)
138: */
139: public void changeContext(String uriprefix, String context)
140: throws Exception {
141: env.changeContext(uriprefix, context);
142: }
143:
144: /* (non-Javadoc)
145: * @see org.apache.cocoon.environment.Environment#redirect(boolean, java.lang.String)
146: */
147: public void redirect(boolean sessionmode, String url)
148: throws IOException {
149: env.redirect(sessionmode, url);
150: }
151:
152: /* (non-Javadoc)
153: * @see org.apache.cocoon.environment.Environment#setContentType(java.lang.String)
154: */
155: public void setContentType(String mimeType) {
156: env.setContentType(mimeType);
157: }
158:
159: /* (non-Javadoc)
160: * @see org.apache.cocoon.environment.Environment#getContentType()
161: */
162: public String getContentType() {
163: return env.getContentType();
164: }
165:
166: /* (non-Javadoc)
167: * @see org.apache.cocoon.environment.Environment#setContentLength(int)
168: */
169: public void setContentLength(int length) {
170: env.setContentLength(length);
171: }
172:
173: /* (non-Javadoc)
174: * @see org.apache.cocoon.environment.Environment#setStatus(int)
175: */
176: public void setStatus(int statusCode) {
177: env.setStatus(statusCode);
178: }
179:
180: /**
181: * @see org.apache.cocoon.environment.Environment#getOutputStream()
182: * @deprecated Use {@link #getOutputStream(int)} instead.
183: */
184: public OutputStream getOutputStream() throws IOException {
185: Deprecation.logger
186: .warn("The method Environment.getOutputStream() "
187: + "is deprecated. Use getOutputStream(-1) instead.");
188: // by default we use the complete buffering output stream
189: return getOutputStream(-1);
190: }
191:
192: /* (non-Javadoc)
193: * @see org.apache.cocoon.environment.Environment#getOutputStream(int)
194: */
195: public OutputStream getOutputStream(int bufferSize)
196: throws IOException {
197: return env.getOutputStream(bufferSize);
198: }
199:
200: /* (non-Javadoc)
201: * @see org.apache.cocoon.environment.Environment#getObjectModel()
202: */
203: public Map getObjectModel() {
204: return env.getObjectModel();
205: }
206:
207: /* (non-Javadoc)
208: * @see org.apache.cocoon.environment.Environment#isResponseModified(long)
209: */
210: public boolean isResponseModified(long lastModified) {
211: return env.isResponseModified(lastModified);
212: }
213:
214: /* (non-Javadoc)
215: * @see org.apache.cocoon.environment.Environment#setResponseIsNotModified()
216: */
217: public void setResponseIsNotModified() {
218: env.setResponseIsNotModified();
219: }
220:
221: /* (non-Javadoc)
222: * @see org.apache.cocoon.environment.Environment#setAttribute(java.lang.String, java.lang.Object)
223: */
224: public void setAttribute(String name, Object value) {
225: env.setAttribute(name, value);
226: }
227:
228: /* (non-Javadoc)
229: * @see org.apache.cocoon.environment.Environment#getAttribute(java.lang.String)
230: */
231: public Object getAttribute(String name) {
232: return env.getAttribute(name);
233: }
234:
235: /* (non-Javadoc)
236: * @see org.apache.cocoon.environment.Environment#removeAttribute(java.lang.String)
237: */
238: public void removeAttribute(String name) {
239: env.removeAttribute(name);
240: }
241:
242: /* (non-Javadoc)
243: * @see org.apache.cocoon.environment.Environment#getAttributeNames()
244: */
245: public Enumeration getAttributeNames() {
246: return env.getAttributeNames();
247: }
248:
249: /* (non-Javadoc)
250: * @see org.apache.cocoon.environment.Environment#tryResetResponse()
251: */
252: public boolean tryResetResponse() throws IOException {
253: return env.tryResetResponse();
254: }
255:
256: /* (non-Javadoc)
257: * @see org.apache.cocoon.environment.Environment#commitResponse()
258: */
259: public void commitResponse() throws IOException {
260: env.commitResponse();
261: }
262:
263: /* (non-Javadoc)
264: * @see org.apache.cocoon.environment.Environment#startingProcessing()
265: */
266: public void startingProcessing() {
267: env.startingProcessing();
268: }
269:
270: /* (non-Javadoc)
271: * @see org.apache.cocoon.environment.Environment#finishingProcessing()
272: */
273: public void finishingProcessing() {
274: env.finishingProcessing();
275: }
276:
277: /* (non-Javadoc)
278: * @see org.apache.cocoon.environment.Environment#isExternal()
279: */
280: public boolean isExternal() {
281: return env.isExternal();
282: }
283:
284: /* (non-Javadoc)
285: * @see org.apache.cocoon.environment.Environment#isInternRedirect()
286: */
287: public boolean isInternalRedirect() {
288: return env.isInternalRedirect();
289: }
290:
291: /* (non-Javadoc)
292: * @see org.apache.cocoon.environment.SourceResolver#resolve(java.lang.String)
293: */
294: public Source resolve(String systemID) throws ProcessingException,
295: SAXException, IOException {
296: return env.resolve(systemID);
297: }
298:
299: /* (non-Javadoc)
300: * @see org.apache.excalibur.source.SourceResolver#resolveURI(java.lang.String)
301: */
302: public org.apache.excalibur.source.Source resolveURI(String arg0)
303: throws MalformedURLException, IOException {
304: return env.resolveURI(arg0);
305: }
306:
307: /* (non-Javadoc)
308: * @see org.apache.excalibur.source.SourceResolver#resolveURI(java.lang.String, java.lang.String, java.util.Map)
309: */
310: public org.apache.excalibur.source.Source resolveURI(String arg0,
311: String arg1, Map arg2) throws MalformedURLException,
312: IOException {
313: return env.resolveURI(arg0, arg1, arg2);
314: }
315:
316: /* (non-Javadoc)
317: * @see org.apache.excalibur.source.SourceResolver#release(org.apache.excalibur.source.Source)
318: */
319: public void release(org.apache.excalibur.source.Source arg0) {
320: env.release(arg0);
321: }
322: }
|