public abstract class GenericPortlet extends Object implements Portlet, PortletConfig, EventPortlet, ResourceServingPortlet, HeaderPortlet
GenericPortlet
class provides a default implementation for
the Portlet
interface.
It provides an abstract class to be subclassed to create portlets. A subclass
of GenericPortlet
should either use one of the following annotations:
@ProcessAction
@ProcessEvent
@RenderMode
Normally there is no need to override the render or the doDispatch methods. Render handles render requests setting the title of the portlet in the response and invoking doDispatch. doDispatch dispatches the request to one of the doView, doEdit or doHelp method depending on the portlet mode indicated in the request.
Portlets typically run on multithreaded servers, so please note that a portlet must handle concurrent requests and be careful to synchronize access to shared resources. Shared resources include in-memory data such as instance or class variables and external objects such as files, database connections, and network connections.
Modifier and Type | Field and Description |
---|---|
static String |
AUTOMATIC_RESOURCE_DISPATCH
This property is set by the container if the container
has a cached response for the given validation tag.
|
Constructor and Description |
---|
GenericPortlet()
Does nothing.
|
Modifier and Type | Method and Description |
---|---|
void |
destroy()
Called by the portlet container to indicate to a portlet that the portlet
is being taken out of service.
|
protected boolean |
dispatchAnnotatedActionMethod(String name,
ActionRequest request,
ActionResponse response)
Dispatches an action request to an annotated action method.
|
protected boolean |
dispatchAnnotatedEventMethod(String name,
EventRequest request,
EventResponse response)
Dispatches an event request to an annotated event method.
|
protected boolean |
dispatchAnnotatedRenderMethod(String name,
RenderRequest request,
RenderResponse response)
Dispatches an render request to an annotated render method.
|
protected void |
doDispatch(RenderRequest request,
RenderResponse response)
The default implementation of this method routes the render request to:
method annotated with
@RenderMode and the name of the portlet mode
a set of helper methods depending on the current portlet mode the portlet
is currently in. |
protected void |
doEdit(RenderRequest request,
RenderResponse response)
Helper method to serve up the
edit mode. |
protected void |
doHeaders(RenderRequest request,
RenderResponse response)
Used
by the render method to set the response properties and headers.
|
protected void |
doHelp(RenderRequest request,
RenderResponse response)
Helper method to serve up the
help mode. |
protected void |
doView(RenderRequest request,
RenderResponse response)
Helper method to serve up the mandatory
view mode. |
Map<String,String[]> |
getContainerRuntimeOptions()
Returns the container runtime options
and values for this portlet.
|
String |
getDefaultNamespace()
Returns the default namespace for events and public parameters.
|
String |
getInitParameter(String name)
Returns a String containing the value of the named initialization * parameter, or null if the parameter does not exist.
|
Enumeration<String> |
getInitParameterNames()
Returns the names of the portlet initialization parameters as an
Enumeration of String objects, or an empty Enumeration if the portlet has
no initialization parameters.
|
protected Collection<PortletMode> |
getNextPossiblePortletModes(RenderRequest request)
Used by the render method to set the next possible portlet modes.
|
PortletConfig |
getPortletConfig()
Returns the PortletConfig object of this portlet.
|
PortletContext |
getPortletContext()
Returns the
PortletContext of the portlet application the
portlet is in. |
Enumeration<PortletMode> |
getPortletModes(String mimeType)
Returns an
Enumeration of PortletMode objects that are defined
for the portlet for the given MIME type. |
String |
getPortletName()
Returns the name of this portlet.
|
Enumeration<QName> |
getProcessingEventQNames()
Returns the QNames of the processing events supported by the portlet
as an
Enumeration of QName objects,
or an empty Enumeration if the
portlet has not defined any processing events. |
Map<String,QName> |
getPublicRenderParameterDefinitions()
Returns a Map of public render parameter names to their qualified names.
|
Enumeration<String> |
getPublicRenderParameterNames()
Returns the names of the public render parameters supported by the
portlet as an
Enumeration of String objects, or an empty
Enumeration if the portlet has no public render
parameters. |
Enumeration<QName> |
getPublishingEventQNames()
Returns the QNames of the publishing events supported by the portlet
as an
Enumeration of QName objects,
or an empty Enumeration if the
portlet has not defined any publishing events. |
ResourceBundle |
getResourceBundle(Locale locale)
Gets the resource bundle for the given locale based on the resource
bundle defined in the deployment descriptor with
resource-bundle tag or the inlined resources defined in
the deployment descriptor. |
Enumeration<Locale> |
getSupportedLocales()
Returns the locales supported by the portlet
as an
Enumeration of Locale objects,
or an empty Enumeration if the
portlet has not defined any supported locales. |
protected String |
getTitle(RenderRequest request)
Used by the render method to get the title.
|
Enumeration<WindowState> |
getWindowStates(String mimeType)
Returns an
Enumeration of WindowState objects that are defined
for the portlet for the given MIME type. |
void |
init()
A convenience method which can be overridden so that there's no need to
call
super.init(config) . |
void |
init(PortletConfig config)
Called by the portlet container to indicate to a portlet that the portlet
is being placed into service.
|
void |
processAction(ActionRequest request,
ActionResponse response)
Called by the portlet container to allow the portlet to process an action
request.
|
void |
processEvent(EventRequest request,
EventResponse response)
The default implementation tries to dispatch to a method
annotated with
@ProcessEvent that matches the
event name or, if no
such method is found just sets the current render parameters on
the response.Note that the annotated methods needs to be public in order to be allowed to be called by GenericPortlet . |
void |
render(RenderRequest request,
RenderResponse response)
The default implementation of this method sets the headers using the
doHeaders method, sets the title using the
getTitle method and invokes the doDispatch
method. |
void |
renderHeaders(HeaderRequest request,
HeaderResponse response)
V3 method implementing the headers stage within the render phase.
|
void |
serveResource(ResourceRequest request,
ResourceResponse response)
Default resource serving.
|
public static final String AUTOMATIC_RESOURCE_DISPATCH
getProperty
method.
The value is "javax.portlet.automaticResourceDispatching"
.
public void init(PortletConfig config) throws PortletException
The default implementation stores the PortletConfig
object
and checks for annotated methods with the annotations
The portlet container calls the init
method exactly once
after instantiating the portlet. The init
method must
complete successfully before the portlet can receive any requests.
The portlet container cannot place the portlet into service if the
init
method does one of the following:
PortletException
init
in interface Portlet
config
- a PortletConfig
object containing the portlet
configuration and initialization parametersPortletException
- if an exception has occurred that interferes with the
portlet normal operation.UnavailableException
- if the portlet cannot perform the initialization at this
time.public void init() throws PortletException
super.init(config)
.
Instead of overriding init(PortletConfig)
, simply override this
method and it will be called by
GenericPortlet.init(PortletConfig config)
. The
PortletConfig
object can still be retrieved via getPortletConfig()
.
PortletException
- if an exception has occurred that interferes with the
portlet normal operation.UnavailableException
- if the portlet is unavailable to perform initpublic void processAction(ActionRequest request, ActionResponse response) throws PortletException, IOException
RenderResponse.createActionURL()
method.
The default implementation tries to dispatch to a method
annotated with @ProcessAction
that matches the action parameter
value ActionRequest.ACTION_NAME
or, if no
such method is found throws a PortletException
.
Note that the annotated methods needs to be public in order
to be allowed to be called by GenericPortlet
.
processAction
in interface Portlet
request
- the action requestresponse
- the action responsePortletException
- if the portlet cannot fulfill the requestUnavailableException
- if the portlet is unavailable to process the action at
this timePortletSecurityException
- if the portlet cannot fulfill this request due to
security reasonsIOException
- if the streaming causes an I/O problempublic void renderHeaders(HeaderRequest request, HeaderResponse response) throws PortletException, IOException
Version 3 portlets should override this method to set HTTP headers, cookies, and
to provide markup for the overall document HEAD
section.
renderHeaders
in interface HeaderPortlet
request
- the header requestresponse
- the header responsePortletException
- if the portlet has problems fulfilling the requestUnavailableException
- if the portlet is unavailable to process the request at this timePortletSecurityException
- if the portlet cannot fulfill this request due to security reasonsIOException
- if the streaming causes an I/O problempublic void render(RenderRequest request, RenderResponse response) throws PortletException, IOException
doHeaders
method, sets the title using the
getTitle
method and invokes the doDispatch
method.
It also evaluates the RENDER_PART
request attribute and if
set calls the doHeaders, getNextPossiblePortletModes
and
getTitle
methods for the RENDER_HEADERS
part and the doDispatch
method for the
RENDER_MARKUP
part.
If the RENDER_PART
request attribute is not set all of the
above methods will be called.
render
in interface Portlet
request
- the render requestresponse
- the render responsePortletException
- if the portlet cannot fulfill the requestUnavailableException
- if the portlet is unavailable to perform render at this
timePortletSecurityException
- if the portlet cannot fulfill this request due to
security reasonsIOException
- if the streaming causes an I/O problemprotected String getTitle(RenderRequest request)
The default implementation gets the title from the ResourceBundle of the PortletConfig of the portlet. The title is retrieved using the 'javax.portlet.title' resource name.
Portlets can overwrite this method to provide dynamic titles (e.g. based on locale, client, and session information). Examples are:
IllegalStateException
- if no portlet config object is availableprotected void doDispatch(RenderRequest request, RenderResponse response) throws PortletException, IOException
@RenderMode
and the name of the portlet mode
doView
for handling view
requestsdoEdit
for handling edit
requestsdoHelp
for handling help
requests
If the window state of this portlet is minimized
, this
method does not invoke any of the portlet mode rendering methods.
For handling custom portlet modes the portlet should either use the
@RenderMode
annotation or override this
method. Note that the annotated methods needs to be public in order
to be allowed to be called by GenericPortlet
.
request
- the render requestresponse
- the render responsePortletException
- if the portlet cannot fulfill the requestUnavailableException
- if the portlet is unavailable to perform render at this
timePortletSecurityException
- if the portlet cannot fulfill this request due to
security reasonsIOException
- if the streaming causes an I/O problemdoView(RenderRequest, RenderResponse)
,
doEdit(RenderRequest, RenderResponse)
,
doHelp(RenderRequest, RenderResponse)
protected void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException
view
mode.
The default implementation throws an exception.
request
- the portlet requestresponse
- the render responsePortletException
- if the portlet cannot fulfill the requestUnavailableException
- if the portlet is unavailable to perform render at this
timePortletSecurityException
- if the portlet cannot fulfill this request due to
security reasonsIOException
- if the streaming causes an I/O problemprotected void doEdit(RenderRequest request, RenderResponse response) throws PortletException, IOException
edit
mode.
The default implementation throws an exception.
request
- the portlet requestresponse
- the render responsePortletException
- if the portlet cannot fulfill the requestUnavailableException
- if the portlet is unavailable to perform render at this
timePortletSecurityException
- if the portlet cannot fulfill this request due to
security reasonsIOException
- if the streaming causes an I/O problemprotected void doHelp(RenderRequest request, RenderResponse response) throws PortletException, IOException
help
mode.
The default implementation throws an exception.
request
- the portlet requestresponse
- the render responsePortletException
- if the portlet cannot fulfill the requestUnavailableException
- if the portlet is unavailable to perform render at this
timePortletSecurityException
- if the portlet cannot fulfill this request due to
security reasonsIOException
- if the streaming causes an I/O problempublic PortletConfig getPortletConfig()
public void destroy()
The default implementation does nothing.
public String getPortletName()
getPortletName
in interface PortletConfig
PortletConfig.getPortletName()
public PortletContext getPortletContext()
PortletContext
of the portlet application the
portlet is in.getPortletContext
in interface PortletConfig
PortletContext
public ResourceBundle getResourceBundle(Locale locale)
resource-bundle
tag or the inlined resources defined in
the deployment descriptor.getResourceBundle
in interface PortletConfig
locale
- the locale for which to retrieve the resource bundlepublic String getInitParameter(String name)
getInitParameter
in interface PortletConfig
name
- a String
specifying the name of the
initialization parameterString
containing the value of the
initialization parameterIllegalArgumentException
- if name is null
.public Enumeration<String> getInitParameterNames()
getInitParameterNames
in interface PortletConfig
Enumeration
of String
objects
containing the names of the portlet initialization parameters, or
an empty Enumeration if the portlet has no initialization
parameters.public Enumeration<QName> getProcessingEventQNames()
PortletConfig
Enumeration
of QName
objects,
or an empty Enumeration
if the
portlet has not defined any processing events.
Processing events are defined in the portlet deployment descriptor
with the supported-processing-event
element.
If the event was defined using the name
element instead of
the qname
element the defined default namespace
is added as namespace for the returned QName.
getProcessingEventQNames
in interface PortletConfig
Enumeration
of QName
objects containing the names of the processing events,
or an empty Enumeration
if the
portlet has not defined any support for processing events in
the deployment descriptor.public Enumeration<QName> getPublishingEventQNames()
PortletConfig
Enumeration
of QName
objects,
or an empty Enumeration
if the
portlet has not defined any publishing events.
Publishing events are defined in the portlet deployment descriptor
with the supported-publishing-event
element.
Note that this call does not return any events published that have not been declared in the deployment descriptor as supported.
If the event was defined using the name
element instead of
the qname
element the defined default namespace
is added as namespace for the returned QName.
getPublishingEventQNames
in interface PortletConfig
Enumeration
of QName
objects containing the names of the publishing events,
or an empty Enumeration
if the
portlet has not defined any support for publishing events in
the deployment descriptor.public Enumeration<Locale> getSupportedLocales()
PortletConfig
Enumeration
of Locale
objects,
or an empty Enumeration
if the
portlet has not defined any supported locales.
Supported locales are defined in the portlet deployment descriptor
with the supported-locale
element.
getSupportedLocales
in interface PortletConfig
Enumeration
of Locale
objects containing the supported locales,
or an empty Enumeration
if the
portlet has not defined any supported locales in
the deployment descriptor.public Map<String,String[]> getContainerRuntimeOptions()
PortletConfig
The portlet can set container runtime
options in the portlet.xml
via the
container-runtime-option
element with a name and a
value on the application and portlet level.
If a container runtime option is set on the portlet application
level and on the portlet level with the same name the setting
on the portlet level takes precedence and overwrites the one
set on the portal application level.
The map returned from this method will provide the subset the
portlet container supports of the options the portlet has specified
in the portlet.xml
. Options that the portlet container
does not support will not be returned in this map.
The map will contain name of the runtime option as key of type String
and the runtime options as values of type String array (String[]
)
with the values specified in the portlet.xml
deployment descriptor.
getContainerRuntimeOptions
in interface PortletConfig
Map
containing portlet
container runtime options names as keys and the
container runtime values as map values, or an empty Map
if no portlet container runtime options are set
in the portlet.xml
or supported by this portlet container.
The keys in the map are of type String. The values in the map are of type
String array (String[]
).public void serveResource(ResourceRequest request, ResourceResponse response) throws PortletException, IOException
The default implementation of this method does nothing.
However, if the reserved portlet initialization parameter
AUTOMATIC_RESOURCE_DISPATCH
(= "javax.portlet.automaticResourceDispatching")
is set to true
, the default
implementation will perform a
PortletRequestDispatcher.forward
to the location designated by
the ResourceID of the ResourceRequest.
If no ResourceID is set on the resource URL the default implementation
does nothing.
serveResource
in interface ResourceServingPortlet
request
- the resource requestresponse
- the resource responsePortletException
- if the portlet has problems fulfilling the
rendering requestUnavailableException
- if the portlet is unavailable to perform render at this timePortletSecurityException
- if the portlet cannot fulfill this request due to security reasonsIOException
- if the streaming causes an I/O problempublic void processEvent(EventRequest request, EventResponse response) throws PortletException, IOException
@ProcessEvent
that matches the
event name or, if no
such method is found just sets the current render parameters on
the response.GenericPortlet
.processEvent
in interface EventPortlet
request
- the event requestresponse
- the event responsePortletException
- if the portlet has problems fulfilling the
requestUnavailableException
- if the portlet is unavailable to process the event at this timePortletSecurityException
- if the portlet cannot fulfill this request due to security reasonsIOException
- if the streaming causes an I/O problemEventPortlet.processEvent(javax.portlet.EventRequest,
javax.portlet.EventResponse)
protected void doHeaders(RenderRequest request, RenderResponse response) throws PortletException, IOException
The portlet should override this method and set its response header using this method in order to ensure that they are set before anything is written to the output stream.
The default implemention of this method is emtpy.
request
- the render requestresponse
- the render responsePortletException
- if the portlet cannot fulfill the requestUnavailableException
- if the portlet is unavailable to perform render at this
timePortletSecurityException
- if the portlet cannot fulfill this request due to
security reasonsIOException
- if the streaming causes an I/O problemprotected Collection<PortletMode> getNextPossiblePortletModes(RenderRequest request)
The portlet should override this method and set the next possible portlet modes using this method in order to ensure that they are set before anything is written to the output stream.
The default implemention of this method returns null
.
public Enumeration<String> getPublicRenderParameterNames()
Enumeration
of String objects, or an empty
Enumeration
if the portlet has no public render
parameters.getPublicRenderParameterNames
in interface PortletConfig
Enumeration
of String
objects
containing the names of the public render parameters, or an empty
Enumeration
if the portlet does not define any
public render parameters.PortletConfig.getPublicRenderParameterNames()
public String getDefaultNamespace()
default-namespace
element.
If no default namespace is defined in the portlet deployment descriptor
this methods returns the XML default namespace
XMLConstants.NULL_NS_URI
.
getDefaultNamespace
in interface PortletConfig
XMLConstants.NULL_NS_URI
is non is
defined.PortletConfig.getDefaultNamespace()
public Enumeration<PortletMode> getPortletModes(String mimeType)
Enumeration
of PortletMode objects that are defined
for the portlet for the given MIME type.
Note that a supported portlet mode may not be allowed in all situations
due to security or other reasons. To
determine whether a portlet mode is allowed during a request, use the
PortletRequest.isPortletModeAllowed(PortletMode)
method.
To determine which portlet modes are supported by the portal, use
PortalContext.getSupportedPortletModes()
getPortletModes
in interface PortletConfig
mimeType
- MIME typeEnumeration
of PortletMode
objects containing the defined and supported portlet modes.PortletMode
,
PortletRequest.isPortletModeAllowed(PortletMode)
public Enumeration<WindowState> getWindowStates(String mimeType)
Enumeration
of WindowState objects that are defined
for the portlet for the given MIME type.
Note that a supported window state may not be allowed in all situations
due to security or other reasons. To
determine whether a window state is allowed during a request, use the
PortletRequest.isWindowStateAllowed(WindowState)
method.
To determine which window states are supported by the portal, use
PortalContext.getSupportedWindowStates()
.
getWindowStates
in interface PortletConfig
mimeType
- MIME typeEnumeration
of WindowState
objects containing the defined and supported window states.WindowState
,
PortletRequest.isWindowStateAllowed(WindowState)
public Map<String,QName> getPublicRenderParameterDefinitions()
PortletConfig.getPublicRenderParameterNames()
method.
The values are the QName
values associated with the public
render parameter.
If the public render parameter is specified in the portlet descriptor
using the <.name>.
tag rather than the
<.qname>.
tag, the QName is built from the default namespace
from the deployment descriptor
together with the value from the <.name>.
tag.
getPublicRenderParameterDefinitions
in interface PortletConfig
Map
of String
to QName
PortletConfig.getPublicRenderParameterNames()
protected boolean dispatchAnnotatedActionMethod(String name, ActionRequest request, ActionResponse response) throws PortletException, IOException
Retrieves an action method annotated with the provided name and
invokes it. Returns true
if the method could be
successfully located and invoked, and false
if no
annotated action method by that name could be found.
This method allows a portlet to extend annotation processing for the action method.
name
- Annotation namerequest
- Action requestresponse
- Action responsetrue
, if the request was dispatched,
false
, if no annotated method matching the specified action
method name could be found.PortletException
- if the portlet cannot fulfill the requestUnavailableException
- if the portlet is unavailable to process the action at
this timePortletSecurityException
- if the portlet cannot fulfill this request due to
security reasonsIOException
- if the streaming causes an I/O problemprocessAction(ActionRequest, ActionResponse)
protected boolean dispatchAnnotatedEventMethod(String name, EventRequest request, EventResponse response) throws PortletException, IOException
Retrieves an action method annotated with the provided name and
invokes it. Returns true
if the method could be
successfully located and invoked, and false
if no
annotated event method by that name could be found.
This method allows a portlet to extend annotation processing for portlet events.
name
- Annotation namerequest
- Event requestresponse
- Event responsetrue
, if the request was dispatched,
false
, if no annotated method matching the specified event
method name could be found.PortletException
- if the portlet cannot fulfill the requestUnavailableException
- if the portlet is unavailable to process the action at
this timePortletSecurityException
- if the portlet cannot fulfill this request due to
security reasonsIOException
- if the streaming causes an I/O problemprocessEvent(EventRequest, EventResponse)
protected boolean dispatchAnnotatedRenderMethod(String name, RenderRequest request, RenderResponse response) throws PortletException, IOException
Retrieves an render method annotated with the provided name and
invokes it. Returns true
if the method could be
successfully located and invoked, and false
if no
annotated render method by that name could be found.
This method allows a portlet to extend annotation processing for the render methods.
name
- Annotation namerequest
- Render requestresponse
- Render responsetrue
, if the request was dispatched,
false
, if no annotated method matching the specified render
method name could be found.PortletException
- if the portlet cannot fulfill the requestUnavailableException
- if the portlet is unavailable to process the render at
this timePortletSecurityException
- if the portlet cannot fulfill this request due to
security reasonsIOException
- if the streaming causes an I/O problemdoDispatch(RenderRequest, RenderResponse)
Java Portlet 3.0 API Specification. See the Copyright and License provided with this distribution. Use is subject to license terms.