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 015 package org.apache.tapestry.portlet; 016 017 import java.io.IOException; 018 import java.io.OutputStream; 019 import java.io.PrintWriter; 020 021 import javax.portlet.PortletResponse; 022 023 import org.apache.hivemind.util.Defense; 024 import org.apache.tapestry.util.ContentType; 025 import org.apache.tapestry.web.WebResponse; 026 027 /** 028 * Adapts {@link javax.portlet.PortletResponse} as 029 * {@link org.apache.tapestry.web.WebResponse}. 030 * 031 * @author Howard M. Lewis Ship 032 * @since 4.0 033 */ 034 public class PortletWebResponse implements WebResponse 035 { 036 037 private final PortletResponse _portletResponse; 038 039 public PortletWebResponse(PortletResponse portletResponse) 040 { 041 Defense.notNull(portletResponse, "portletResponse"); 042 043 _portletResponse = portletResponse; 044 } 045 046 public OutputStream getOutputStream(ContentType contentType) 047 throws IOException 048 { 049 unsupported("getOutputStream"); 050 051 return null; 052 } 053 054 public PrintWriter getPrintWriter(ContentType contentType) 055 throws IOException 056 { 057 unsupported("getPrintWriter"); 058 059 return null; 060 } 061 062 public String encodeURL(String url) 063 { 064 return _portletResponse.encodeURL(url); 065 } 066 067 /** Unsupported. */ 068 public void reset() 069 { 070 unsupported("reset"); 071 } 072 073 /** Unsupported. */ 074 public void setContentLength(int contentLength) 075 { 076 unsupported("setContentLength"); 077 } 078 079 /** 080 * Returns the empty string. The {@link RenderWebResponse} subclass 081 * actually provides a real value here. 082 */ 083 public String getNamespace() 084 { 085 return ""; 086 } 087 088 protected final void unsupported(String methodName) 089 { 090 throw new UnsupportedOperationException(PortletMessages 091 .unsupportedMethod(methodName)); 092 } 093 094 /** Unsupported. */ 095 public void setDateHeader(String string, long date) 096 { 097 unsupported("setDateHeader"); 098 } 099 100 /** Unsupported. */ 101 public void setStatus(int status) 102 { 103 unsupported("setStatus"); 104 } 105 106 /** Unsupported. */ 107 public void setHeader(String name, String value) 108 { 109 unsupported("setHeader"); 110 } 111 112 /** Unsupported. */ 113 public void setIntHeader(String name, int value) 114 { 115 unsupported("setIntHeader"); 116 } 117 118 /** Unsupported. */ 119 public void sendError(int statusCode, String message) 120 throws IOException 121 { 122 unsupported("sendError"); 123 } 124 125 }