1
19
20 package com.liferay.portlet;
21
22 import com.liferay.portal.kernel.log.Log;
23 import com.liferay.portal.kernel.log.LogFactoryUtil;
24
25 import java.util.Locale;
26
27 import javax.portlet.PortletRequest;
28 import javax.portlet.PortletURL;
29 import javax.portlet.ResourceRequest;
30 import javax.portlet.ResourceResponse;
31 import javax.portlet.ResourceURL;
32
33 import javax.servlet.http.Cookie;
34 import javax.servlet.http.HttpServletResponse;
35
36
42 public class ResourceResponseImpl
43 extends MimeResponseImpl implements ResourceResponse {
44
45 public void addDateHeader(String name, long date) {
46 super.addDateHeader(name, date);
47
48 _response.addDateHeader(name, date);
49 }
50
51 public void addHeader(String name, String value) {
52 super.addHeader(name, value);
53
54 _response.addHeader(name, value);
55 }
56
57 public void addIntHeader(String name, int value) {
58 super.addIntHeader(name, value);
59
60 _response.addIntHeader(name, value);
61 }
62
63 public void addProperty(Cookie cookie) {
64 super.addProperty(cookie);
65
66 _response.addCookie(cookie);
67 }
68
69 public PortletURL createActionURL() {
70 return super.createActionURL();
71 }
72
73 public PortletURLImpl createPortletURLImpl(
74 String portletName, String lifecycle) {
75
76 ResourceRequest resourceRequest = (ResourceRequest)getPortletRequest();
77
78 String cacheability = resourceRequest.getCacheability();
79
80 if (cacheability.equals(ResourceURL.PAGE)) {
81 }
82 else if (lifecycle.equals(PortletRequest.ACTION_PHASE)) {
83 throw new IllegalStateException(
84 "Unable to create an action URL from a resource response " +
85 "when the cacheability is not set to PAGE");
86 }
87 else if (lifecycle.equals(PortletRequest.RENDER_PHASE)) {
88 throw new IllegalStateException(
89 "Unable to create a render URL from a resource response when " +
90 "the cacheability is not set to PAGE");
91 }
92
93 return super.createPortletURLImpl(portletName, lifecycle);
94 }
95
96 public PortletURL createRenderURL() {
97 return super.createRenderURL();
98 }
99
100 public ResourceURL createResourceURL() {
101 return super.createResourceURL();
102 }
103
104 public String getLifecycle() {
105 return PortletRequest.RESOURCE_PHASE;
106 }
107
108 public void setCharacterEncoding(String charset) {
109 _response.setCharacterEncoding(charset);
110 }
111
112 public void setLocale(Locale locale) {
113 _response.setLocale(locale);
114 }
115
116 public void setContentLength(int length) {
117 _response.setContentLength(length);
118 }
119
120 public void setDateHeader(String name, long date) {
121 super.setDateHeader(name, date);
122
123 _response.setDateHeader(name, date);
124 }
125
126 public void setHeader(String name, String value) {
127 super.setHeader(name, value);
128
129 _response.setHeader(name, value);
130 }
131
132 public void setIntHeader(String name, int value) {
133 super.setIntHeader(name, value);
134
135 _response.setIntHeader(name, value);
136 }
137
138 protected ResourceResponseImpl() {
139 if (_log.isDebugEnabled()) {
140 _log.debug("Creating new instance " + hashCode());
141 }
142 }
143
144 protected void init(
145 PortletRequestImpl portletRequestImpl, HttpServletResponse response,
146 String portletName, long companyId, long plid) {
147
148 super.init(portletRequestImpl, response, portletName, companyId, plid);
149
150 _response = response;
151 }
152
153 protected void recycle() {
154 if (_log.isDebugEnabled()) {
155 _log.debug("Recycling instance " + hashCode());
156 }
157
158 super.recycle();
159
160 _response = null;
161 }
162
163 private static Log _log = LogFactoryUtil.getLog(ResourceResponseImpl.class);
164
165 private HttpServletResponse _response;
166
167 }