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.portlet;
018:
019: import javax.portlet.PortletPreferences;
020: import javax.portlet.PortletURL;
021:
022: import java.io.IOException;
023: import java.io.OutputStream;
024: import java.io.PrintWriter;
025: import java.util.Locale;
026:
027: /**
028: * Implements the {@link org.apache.cocoon.environment.Response} interface for
029: * the JSR-168 (Portlet) environment.
030: *
031: * @author <a href="mailto:alex.rudnev@dc.gov">Alex Rudnev</a>
032: * @author <a href="mailto:vgritsenko@apache.org">Vadim Gritsenko</a>
033: * @version CVS $Id: RenderResponse.java 433543 2006-08-22 06:22:54Z crossley $
034: */
035: public final class RenderResponse extends PortletResponse {
036:
037: private String contentType = null;
038:
039: /**
040: * Creates a RenderResponse based on a real RenderResponse object
041: */
042: protected RenderResponse(javax.portlet.RenderResponse response,
043: PortletPreferences preferences) {
044: super (response, preferences);
045: }
046:
047: public String getCharacterEncoding() {
048: return getRenderResponse().getCharacterEncoding();
049: }
050:
051: public Locale getLocale() {
052: return getRenderResponse().getLocale();
053: }
054:
055: /**
056: *
057: * @see PortletEnvironment#HEADER_PORTLET_TITLE
058: */
059: public void addHeader(String name, String value) {
060: if (PortletEnvironment.HEADER_PORTLET_TITLE.equals(name)) {
061: getRenderResponse().setTitle(value);
062: } else {
063: super .addHeader(name, value);
064: }
065: }
066:
067: /**
068: *
069: * @see PortletEnvironment#HEADER_PORTLET_TITLE
070: */
071: public void setHeader(String name, String value) {
072: if (PortletEnvironment.HEADER_PORTLET_TITLE.equals(name)) {
073: getRenderResponse().setTitle(value);
074: } else {
075: super .setHeader(name, value);
076: }
077: }
078:
079: // RenderResponse API related methods
080:
081: /**
082: * Type cast portletResponse to RenderResponse
083: *
084: * @return type casted portletResponse
085: */
086: public javax.portlet.RenderResponse getRenderResponse() {
087: return (javax.portlet.RenderResponse) getPortletResponse();
088: }
089:
090: public PortletURL createActionURL() {
091: return getRenderResponse().createActionURL();
092: }
093:
094: public PortletURL createRenderURL() {
095: return getRenderResponse().createRenderURL();
096: }
097:
098: public void flushBuffer() throws IOException {
099: getRenderResponse().flushBuffer();
100: }
101:
102: public int getBufferSize() {
103: return getRenderResponse().getBufferSize();
104: }
105:
106: public String getContentType() {
107: return getRenderResponse().getContentType();
108: }
109:
110: public String getNamespace() {
111: return getRenderResponse().getNamespace();
112: }
113:
114: public OutputStream getPortletOutputStream() throws IOException {
115: return getRenderResponse().getPortletOutputStream();
116: }
117:
118: public PrintWriter getWriter() throws IOException {
119: return getRenderResponse().getWriter();
120: }
121:
122: public boolean isCommitted() {
123: return getRenderResponse().isCommitted();
124: }
125:
126: public void reset() {
127: getRenderResponse().reset();
128: }
129:
130: public void resetBuffer() {
131: getRenderResponse().resetBuffer();
132: }
133:
134: public void setBufferSize(int size) {
135: getRenderResponse().setBufferSize(size);
136: }
137:
138: public void setContentType(String type) {
139: this .contentType = type;
140: getRenderResponse().setContentType(type);
141: }
142:
143: public void setTitle(String title) {
144: getRenderResponse().setTitle(title);
145: }
146:
147: // Portlet Environment related methods
148:
149: OutputStream getOutputStream() throws IOException {
150: // TODO: Why this is needed? What's the purpose?
151: if (this .contentType == null) {
152: setContentType("text/html");
153: }
154:
155: return getRenderResponse().getPortletOutputStream();
156: }
157: }
|