1 16 package org.apache.cocoon.environment.portlet; 17 18 import org.apache.cocoon.environment.Cookie; 19 import org.apache.cocoon.environment.Response; 20 21 import org.apache.avalon.framework.CascadingRuntimeException; 22 23 import javax.portlet.PortletPreferences; 24 import javax.portlet.ReadOnlyException; 25 26 import java.io.IOException ; 27 import java.io.OutputStream ; 28 import java.util.HashMap ; 29 import java.util.Locale ; 30 import java.util.Map ; 31 32 39 public abstract class PortletResponse implements Response { 40 41 42 private final javax.portlet.PortletResponse response; 43 44 private final PortletPreferences preferences; 45 46 50 private Map properties = new HashMap (5); 51 52 53 56 protected PortletResponse(javax.portlet.PortletResponse response, 57 PortletPreferences preferences) { 58 this.response = response; 59 this.preferences = preferences; 60 } 61 62 63 public boolean containsHeader(String name) { 64 return properties.containsKey(name); 65 } 66 67 public void setHeader(String name, String value) { 68 properties.put(name, name); 69 response.setProperty(name, value); 70 } 71 72 public void setIntHeader(String name, int value) { 73 setHeader(name, "" + value); 74 } 75 76 public void setDateHeader(String name, long date) { 77 setHeader(name, "" + date); 78 } 79 80 public void addHeader(String name, String value) { 81 properties.put(name, name); 82 response.addProperty(name, value); 83 } 84 85 public void addIntHeader(String name, int value) { 86 addHeader(name, "" + value); 87 } 88 89 public void addDateHeader(String name, long date) { 90 addHeader(name, "" + date); 91 } 92 93 94 public String getCharacterEncoding() { 95 return null; 96 } 97 98 public Cookie createCookie(String name, String value) { 99 return new PortletCookie(name, value); 100 } 101 102 public void addCookie(Cookie cookie) { 103 try { 104 this.preferences.setValue(cookie.getName(), cookie.getValue()); 105 this.preferences.store(); 107 } catch (ReadOnlyException e) { 108 throw new CascadingRuntimeException("Cannot set read-only preference '" + cookie.getName() + "'", e); 109 } catch (Exception e) { 110 throw new CascadingRuntimeException("Cannot set preference '" + cookie.getName() + "'", e); 111 } 112 } 113 114 public void setLocale(Locale locale) { 115 } 116 117 public Locale getLocale() { 118 return null; 119 } 120 121 public String encodeURL(String url) { 122 if (url != null && url.indexOf(";jsessionid=") != -1) { 124 return url; 125 } 126 return this.response.encodeURL(url); 127 } 128 129 130 132 136 public javax.portlet.PortletResponse getPortletResponse() { 137 return response; 138 } 139 140 public void addProperty(String key, String value) { 141 getPortletResponse().addProperty(key, value); 142 } 143 144 public void setProperty(String key, String value) { 145 getPortletResponse().setProperty(key, value); 146 } 147 148 149 151 OutputStream getOutputStream() throws IOException { 152 throw new IllegalStateException ("Operation 'getOutputStream' is not supported by '" + getClass().getName() + "'"); 153 } 154 155 void setContentType(String type) { 156 throw new IllegalStateException ("Operation 'setContentType' is not supported by '" + getClass().getName() + "'"); 157 } 158 159 void sendRedirect(String location) throws IOException { 160 throw new IllegalStateException ("Operation 'sendRedirect' is not supported by '" + getClass().getName() + "'"); 161 } 162 163 boolean isCommitted() { 164 throw new IllegalStateException ("Operation 'isCommitted' is not supported by '" + getClass().getName() + "'"); 165 } 166 167 void reset() { 168 throw new IllegalStateException ("Operation 'reset' is not supported by '" + getClass().getName() + "'"); 169 } 170 } 171 | Popular Tags |