001// Copyright 2005 The Apache Software Foundation
002//
003// Licensed under the Apache License, Version 2.0 (the "License");
004// you may not use this file except in compliance with the License.
005// You may obtain a copy of the License at
006//
007//     http://www.apache.org/licenses/LICENSE-2.0
008//
009// Unless required by applicable law or agreed to in writing, software
010// distributed under the License is distributed on an "AS IS" BASIS,
011// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012// See the License for the specific language governing permissions and
013// limitations under the License.
014
015package org.apache.tapestry.portlet;
016
017import java.io.IOException;
018import java.io.OutputStream;
019import java.io.PrintWriter;
020
021import javax.portlet.PortletResponse;
022
023import org.apache.hivemind.util.Defense;
024import org.apache.tapestry.util.ContentType;
025import org.apache.tapestry.web.WebResponse;
026
027/**
028 * Adapts {@link javax.portlet.PortletResponse} as {@link org.apache.tapestry.web.WebResponse}.
029 * 
030 * @author Howard M. Lewis Ship
031 * @since 4.0
032 */
033public class PortletWebResponse implements WebResponse
034{
035    private final PortletResponse _portletResponse;
036
037    public PortletWebResponse(PortletResponse portletResponse)
038    {
039        Defense.notNull(portletResponse, "portletResponse");
040
041        _portletResponse = portletResponse;
042    }
043
044    public OutputStream getOutputStream(ContentType contentType) throws IOException
045    {
046        unsupported("getOutputStream");
047
048        return null;
049    }
050
051    public PrintWriter getPrintWriter(ContentType contentType) throws IOException
052    {
053        unsupported("getPrintWriter");
054
055        return null;
056    }
057
058    public String encodeURL(String url)
059    {
060        return _portletResponse.encodeURL(url);
061    }
062
063    /** Unsupported. */
064    public void reset()
065    {
066        unsupported("reset");
067    }
068
069    /** Unsupported. */
070    public void setContentLength(int contentLength)
071    {
072        unsupported("setContentLength");
073    }
074
075    /**
076     * Returns the empty string. The {@link RenderWebResponse} subclass actually provides a
077     * real value here.
078     */
079    public String getNamespace()
080    {
081        return "";
082    }
083
084    protected final void unsupported(String methodName)
085    {
086        throw new UnsupportedOperationException(PortletMessages.unsupportedMethod(methodName));
087    }
088
089    /** Unsupported. */
090    public void setDateHeader(String string, long date)
091    {
092        unsupported("setDateHeader");
093    }
094
095    /** Unsupported. */
096    public void setStatus(int status)
097    {
098        unsupported("setStatus");
099    }
100
101    /** Unsupported. */
102    public void setHeader(String name, String value)
103    {
104        unsupported("setHeader");
105    }
106
107    /** Unsupported. */
108    public void setIntHeader(String name, int value)
109    {
110        unsupported("setIntHeader");
111    }
112
113    /** Unsupported. */
114    public void sendError(int statusCode, String message) throws IOException
115    {
116        unsupported("sendError");
117    }
118
119}