Author: unico Date: Mon Oct 18 06:10:24 2004 New Revision: 55002 Added: cocoon/trunk/src/java/org/apache/cocoon/environment/wrapper/ResponseWrapper.java Modified: cocoon/trunk/src/java/org/apache/cocoon/environment/wrapper/EnvironmentWrapper.java Log: introduce WrappedResponse for preventing internal requests to modify the response headers as discussed here: http://marc.theaimsgroup.com/?t=109783260100005&r=1&w=2
Modified: cocoon/trunk/src/java/org/apache/cocoon/environment/wrapper/EnvironmentWrapper.java ============================================================================== --- cocoon/trunk/src/java/org/apache/cocoon/environment/wrapper/EnvironmentWrapper.java (original) +++ cocoon/trunk/src/java/org/apache/cocoon/environment/wrapper/EnvironmentWrapper.java Mon Oct 18 06:10:24 2004 @@ -27,6 +27,7 @@ import org.apache.cocoon.environment.Environment; import org.apache.cocoon.environment.ObjectModelHelper; import org.apache.cocoon.environment.Request; +import org.apache.cocoon.environment.Response; import org.apache.cocoon.util.BufferedOutputStream; @@ -37,7 +38,7 @@ * * @author <a href="mailto:[EMAIL PROTECTED]">Björn Lütkemeier</a> * @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a> - * @version CVS $Id: EnvironmentWrapper.java,v 1.21 2004/06/25 15:36:38 cziegeler Exp $ + * @version CVS $Id$ */ public class EnvironmentWrapper extends AbstractEnvironment { @@ -90,7 +91,9 @@ info.queryString, this, info.rawMode); + Response response = new ResponseWrapper(ObjectModelHelper.getResponse(oldObjectModel)); this.objectModel.put(ObjectModelHelper.REQUEST_OBJECT, this.request); + this.objectModel.put(ObjectModelHelper.RESPONSE_OBJECT, response); this.setURI(info.prefix, info.uri); } Added: cocoon/trunk/src/java/org/apache/cocoon/environment/wrapper/ResponseWrapper.java ============================================================================== --- (empty file) +++ cocoon/trunk/src/java/org/apache/cocoon/environment/wrapper/ResponseWrapper.java Mon Oct 18 06:10:24 2004 @@ -0,0 +1,82 @@ +/* + * Copyright 1999-2004 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.cocoon.environment.wrapper; + +import java.util.Locale; + +import org.apache.cocoon.environment.Cookie; +import org.apache.cocoon.environment.Response; + +/** + * This is a wrapper class for the Response object. + * It contains the same properties as the wrapped instance + * but swallows calls that would modify response headers. + */ +public class ResponseWrapper implements Response { + + private Response res; + + public ResponseWrapper(Response response) { + this.res = response; + } + + public String getCharacterEncoding() { + return res.getCharacterEncoding(); + } + + public void setLocale(Locale loc) { + res.setLocale(loc); + } + + public Locale getLocale() { + return res.getLocale(); + } + + public Cookie createCookie(String name, String value) { + return res.createCookie(name, value); + } + + public void addCookie(Cookie cookie) { + res.addCookie(cookie); + } + + public String encodeURL(String url) { + return res.encodeURL(url); + } + + public boolean containsHeader(String name) { + return res.containsHeader(name); + } + + public void setDateHeader(String name, long date) { + } + + public void addDateHeader(String name, long date) { + } + + public void setHeader(String name, String value) { + } + + public void addHeader(String name, String value) { + } + + public void setIntHeader(String name, int value) { + } + + public void addIntHeader(String name, int value) { + } + +}
