Class PortletResponseWrapper
- java.lang.Object
-
- jakarta.portlet.filter.PortletResponseWrapper
-
- All Implemented Interfaces:
PortletResponse
- Direct Known Subclasses:
MimeResponseWrapper,StateAwareResponseWrapper
public class PortletResponseWrapper extends Object implements PortletResponse
ThePortletResponseWrapperprovides a convenient implementation of thePortletResponseinterface and is extended by other response wrappers. This class implements the Wrapper or Decorator pattern. Methods default to calling through to the wrapped response object.- Since:
- 2.0
- See Also:
PortletResponse
-
-
Constructor Summary
Constructors Constructor Description PortletResponseWrapper(PortletResponse response)Creates anActionResponseadaptor wrapping the given response object.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddProperty(jakarta.servlet.http.Cookie cookie)Adds a HTTP Cookie property to the response.
The portlet should note that the cookie may not make it to the client, but may be stored at the portal.voidaddProperty(String key, String value)Adds a String property to an existing key to be returned to the portal.voidaddProperty(String key, Element element)Adds an XML DOM element property to the response.ElementcreateElement(String tagName)Creates an element of the type specified to be used in thePortletResponse.addProperty(String,Element)method.StringencodeURL(String path)Returns the encoded URL of the resource, like servlets, JSPs, images and other static files, at the given path.StringgetNamespace()The value returned by this method should be prefixed or appended to elements, such as JavaScript variables or function names, to ensure they are unique in the context of the portal page.StringgetProperty(String key)Gets the value of the response property with the given name.Collection<String>getPropertyNames()Gets the names of all response properties set on the response.Collection<String>getPropertyValues(String name)Gets the values of the response property with the given name.PortletResponsegetResponse()Return the wrapped response object.voidsetProperty(String key, String value)Sets a String property to be returned to the portal.voidsetResponse(PortletResponse response)Sets the response object being wrapped.
-
-
-
Constructor Detail
-
PortletResponseWrapper
public PortletResponseWrapper(PortletResponse response)
Creates anActionResponseadaptor wrapping the given response object.- Parameters:
response- the action response to wrap- Throws:
IllegalArgumentException- if the response isnull
-
-
Method Detail
-
addProperty
public void addProperty(String key, String value)
Description copied from interface:PortletResponseAdds a String property to an existing key to be returned to the portal. If there are no property values already associated with the key, a new key is created.This method allows response properties to have multiple values.
Response properties can be viewed as header values set for the portal application. If these header values are intended to be transmitted to the client they should be set before the response is committed.
- Specified by:
addPropertyin interfacePortletResponse- Parameters:
key- the key of the property to be returned to the portalvalue- the value of the property to be returned to the portal. The value should be encoded according to RFC 2047 (http://www.ietf.org/rfc/rfc2047.txt).
-
encodeURL
public String encodeURL(String path)
Description copied from interface:PortletResponseReturns the encoded URL of the resource, like servlets, JSPs, images and other static files, at the given path.Portlets should encode all resource URLs pointing to resources in the portlet application via this method in order to ensure that they get served via the portal application.
Some portal/portlet-container implementation may require those URLs to contain implementation specific data encoded in it. Because of that, portlets should use this method to create such URLs.
The
encodeURLmethod may include the session ID and other portal/portlet-container specific information into the URL. If encoding is not needed, it returns the URL unchanged.Portlet developer should be aware that the returned URL might not be a well formed URL but a special token at the time the portlet is generating its content. Thus portlets should not add additional parameters on the resulting URL or expect to be able to parse the URL. As a result, the outcome of the encodeURL call may be different than calling encodeURL in the servlet world.
- Specified by:
encodeURLin interfacePortletResponse- Parameters:
path- the URI path to the resource. This must be either an absolute URL (e.g.http://my.co/myportal/mywebap/myfolder/myresource.gif) or a full path URI (e.g./myportal/mywebap/myfolder/myresource.gif).- Returns:
- the encoded resource URL as string, may not be a valid URL
-
getNamespace
public String getNamespace()
Description copied from interface:PortletResponseThe value returned by this method should be prefixed or appended to elements, such as JavaScript variables or function names, to ensure they are unique in the context of the portal page.The namespace value must be constant for the lifetime of the portlet window.
- Specified by:
getNamespacein interfacePortletResponse- Returns:
- the namespace
-
setProperty
public void setProperty(String key, String value)
Description copied from interface:PortletResponseSets a String property to be returned to the portal.Response properties can be viewed as header values set for the portal application. If these header values are intended to be transmitted to the client they should be set before the response is committed.
This method resets all properties previously added with the same key.
- Specified by:
setPropertyin interfacePortletResponse- Parameters:
key- the key of the property to be returned to the portalvalue- the value of the property to be returned to the portal. The value should be encoded according to RFC 2047 (http://www.ietf.org/rfc/rfc2047.txt).
-
getResponse
public PortletResponse getResponse()
Return the wrapped response object.- Returns:
- the wrapped response
-
setResponse
public void setResponse(PortletResponse response)
Sets the response object being wrapped.- Parameters:
response- the response to set- Throws:
IllegalArgumentException- if the response is null.
-
addProperty
public void addProperty(String key, Element element)
Description copied from interface:PortletResponseAdds an XML DOM element property to the response.If a DOM element with the provided key already exists the provided element will be stored in addition to the existing element under the same key.
If the element is
nullthe key is removed from the response.Response XML DOM element properties can be viewed as additional response document sections set for the portal application. If these header values are intended to be transmitted to the client they should be set before the response is committed.
- Specified by:
addPropertyin interfacePortletResponse- Parameters:
key- the key of the property to be returned to the portalelement- the XML DOM element to be added to the response
-
createElement
public Element createElement(String tagName)
Description copied from interface:PortletResponseCreates an element of the type specified to be used in thePortletResponse.addProperty(String,Element)method.- Specified by:
createElementin interfacePortletResponse- Parameters:
tagName- name of the element type to instantiate- Returns:
- A new Element object with the nodeName attribute set to tagName, and localName, prefix, and namespaceURI set to null.
-
addProperty
public void addProperty(jakarta.servlet.http.Cookie cookie)
Description copied from interface:PortletResponseAdds a HTTP Cookie property to the response.
The portlet should note that the cookie may not make it to the client, but may be stored at the portal.This method allows response properties to have multiple cookies.
- Specified by:
addPropertyin interfacePortletResponse- Parameters:
cookie- the cookie to be added to the response
-
getProperty
public String getProperty(String key)
Description copied from interface:PortletResponseGets the value of the response property with the given name.If a response property with the given name exists and contains multiple values, the value that was added first will be returned.
This method considers only response properties set or added via
setProperty(java.lang.String, java.lang.String)oraddProperty(java.lang.String, java.lang.String).- Specified by:
getPropertyin interfacePortletResponse- Parameters:
key- the name of the response property whose value is to be returned- Returns:
- the value of the response property with the given name, or null if no property with the given name has been set on this response
-
getPropertyValues
public Collection<String> getPropertyValues(String name)
Description copied from interface:PortletResponseGets the values of the response property with the given name.This method considers only response properties set or added via
setProperty(java.lang.String, java.lang.String)oraddProperty(java.lang.String, java.lang.String).Altering the returned collection will not affect the properties set on the response.
- Specified by:
getPropertyValuesin interfacePortletResponse- Parameters:
name- the name of the response property whose values are to be returned- Returns:
- the values of the response property with the given name, or an empty collection if no property with the given name has been set on this response
-
getPropertyNames
public Collection<String> getPropertyNames()
Description copied from interface:PortletResponseGets the names of all response properties set on the response.This method considers only response properties set or added via
setProperty(java.lang.String, java.lang.String)oraddProperty(java.lang.String, java.lang.String).Altering the returned collection will not affect the properties set on the response.
- Specified by:
getPropertyNamesin interfacePortletResponse- Returns:
- the names of the response properties with the given name, or an empty collection if no properties have been set on this response
-
-