com.gentics.api.portalnode.portlet
Class AbstractGenticsPortlet

java.lang.Object
  extended by javax.portlet.GenericPortlet
      extended by com.gentics.api.portalnode.portlet.AbstractGenticsPortlet
All Implemented Interfaces:
Changeable, PropertyModificationListener, Resolvable, EventHandler, GenticsPluginServer, GenticsPortlet, javax.portlet.EventPortlet, javax.portlet.Portlet, javax.portlet.PortletConfig, javax.portlet.ResourceServingPortlet

public abstract class AbstractGenticsPortlet
extends javax.portlet.GenericPortlet
implements GenticsPortlet, PropertyModificationListener

AbstractGenticsPortlet is the base class for all gentics portlets. It implements basic functionality and should be extended to create new gentics portlets.


Nested Class Summary
protected  class AbstractGenticsPortlet.SubPluginEventBrokerProvider
          Internal helper class to provide the event broker for nested plugins
 
Field Summary
static String EVENT_ONCHANGE
          constant for the name of the onChange event.
protected  org.apache.log4j.Logger logger
          module logger object for generating log messages in different log-levels
 
Constructor Summary
AbstractGenticsPortlet(String moduleId)
          basic constructor that initializes the gentics portlet.
 
Method Summary
protected  void addListener(String eventPath)
          Deprecated. use addListener(String, String)instead
protected  void addListener(String eventPath, String actionCommand)
          adds this module as listener to the portal
protected  void addPluginListener(String pluginId, EventHandler handler, String actionCommand)
          adds an event handler to the plugin with the given id
 void afterProcessAction(javax.portlet.ActionRequest request, javax.portlet.ActionResponse response)
          perform required actions after GenericPortlet.processAction(javax.portlet.ActionRequest, javax.portlet.ActionResponse) (cleaning up, etc.)
 void afterProcessPluginAction(String pluginId, javax.portlet.ActionRequest actionRequest, javax.portlet.ActionResponse actionResponse)
          This method is called by the portal after processPluginAction(String, javax.portlet.ActionRequest, javax.portlet.ActionResponse).
 boolean canResolve()
          returns whether the module can resolve properties via calls to getProperty(String).
 void destroy()
           
protected  void doDispatch(javax.portlet.RenderRequest renderRequest, javax.portlet.RenderResponse renderResponse)
           
protected  void doEditPNode(javax.portlet.RenderRequest renderRequest, javax.portlet.RenderResponse renderResponse)
          This method is called when the gentics portlet is rendered in PortletMode GenticsPortletMode.EDITPNODE.
protected  void doFull(javax.portlet.RenderRequest request, javax.portlet.RenderResponse response)
          This method is called when the gentics portlet shall be rendered in portlet mode GenticsPortletMode.FULL.
 Object get(String key)
          alias for getProperty(String)
 Map getContainerRuntimeOptions()
           
 Datasource getDatasource(String id)
          Get a datasource by id.
 FileUploadProvider getFileUploadProvider()
          Get a file upload provider for the module.
 String getFullModuleType()
          Get the full module type (including the application prefix)
 GenticsPortletContext getGenticsPortletContext()
          returns the specific GenticsPortletContext of this Module
 GenticsImpInterface getImp(String impId)
          Get an instance of the imp with the given id.
 String getModuleId()
          return the unique if of this module
 String getModuleType()
          get the module type
 GenticsPlugin getPlugin(String id)
          returns the plugin that was registered via registerPlugin(String, GenticsPlugin)with the given id
protected  Object getPortalProperty(String propertyPath)
          returns the portal property (not implemented in abstractmodule)
 PropertyResolver getPortalPropertyResolver()
          Get a property resolver for resolving portal properties
 javax.portlet.PortletRequest getPortletRequest()
          get the current PortletRequest
 Object getProperty(String key)
          resolve the given property key to a property.
protected  String getSessionPropertyName(String propertyName)
          Get the session property name for the given property name (prefix it with the form name)
 TemplateProcessor getTemplateProcessor(javax.portlet.RenderRequest renderRequest, javax.portlet.RenderResponse renderResponse)
          Deprecated. use GenticsPortletContext.getTemplateProcessor(GenticsPortlet, PortletConfig) instead.
 String getTitle(javax.portlet.RenderRequest renderRequest)
          get the module title as defined in the pnode of the module
 void handleEvent(ActionEvent e)
          handle an event this module listenes at
protected  void handlePortalEvent(EventRequest request, EventResponse response)
          event handler method that can be overwritten by classes extending AbstractGenticsPortlet.
 I18nString i18n(String key)
          Get a localized string for the given key.
 void init(javax.portlet.PortletConfig config)
           
protected  void initSessionPropertyNames()
          Initialize the session property names
protected  void onChanged()
          this is the primitive brother of onParameterChanged() it is called by the default implementation of onParameterChanged and should update what the module is about to render, because one of its parameters has changed.
protected  void onLoad()
          onload is called when the module is loaded for the first time.
protected  void onParameterChanged(String parameterName, ActionEvent e)
          onParameterChanged() is called, whenever one of the paramters defined in the module-description's parameter section changes.
 void onPluginEvent(EventRequest eventRequest, EventResponse eventResponse)
          is called whenever a plugin is performing an event
protected  void onPrepareRender()
          onPrepareRender() is called every time the portal is displayed - after action handling but before render stage (doView, doHelp, doFull, ....) this is the last chance for a portlet to change what the render method will display, and the last chance to trigger events.
protected  void onSessionCreate()
          onSessionCreate() is called when the user enters the portal.
 void processPluginAction(String pluginId, javax.portlet.ActionRequest actionRequest, javax.portlet.ActionResponse actionResponse)
          Processes a plugins action.
 void propertyModified(String path, String property, Object value)
          This method is called by the PropertySetter when one of the (sub-)properties of this object is modified
 void registerPlugin(String id, GenticsPlugin plugin)
          registers a plugin to this module.
 void reloadModule()
          This method is called if a module has to be reloaded.
protected  void removeListener(String eventPath)
          removes this module from the listeners collection
 String renderPlugin(String id, javax.portlet.RenderRequest request, javax.portlet.RenderResponse response)
          renders a specific plugin that was registered via registerPlugin(String, GenticsPlugin)before
 void returnFileUploadProvider()
          return a previously via getFileUploadProvider()fetched file upload provider to the portal.
 void returnTemplateProcessor(TemplateProcessor proc)
          return an exclusive templateprocessor that was previously fetched via getTemplateProcessor(RenderRequest, RenderResponse).
 void setModuleType(String applicationPrefix, String moduleType)
          Set the application prefix and portlet name
 boolean setProperty(String propertyName, Object prop)
          sets a specified property of the module.
 void setRequest(javax.portlet.PortletRequest request)
          set the current PortletRequest.
 String toString()
           
protected  void triggerEvent(javax.portlet.PortletRequest request, ActionEvent e)
          convenience method to trigger a module event.
 void unregisterPlugin(String id)
          Unregister the plugin with the given id.
 
Methods inherited from class javax.portlet.GenericPortlet
doEdit, doHeaders, doHelp, doView, getDefaultNamespace, getInitParameter, getInitParameterNames, getNextPossiblePortletModes, getPortletConfig, getPortletContext, getPortletName, getProcessingEventQNames, getPublicRenderParameterNames, getPublishingEventQNames, getResourceBundle, getSupportedLocales, init, processAction, processEvent, render, serveResource
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.gentics.api.portalnode.portlet.GenticsPortlet
getPortletConfig, getPortletContext
 
Methods inherited from interface javax.portlet.Portlet
processAction, render
 
Methods inherited from interface javax.portlet.ResourceServingPortlet
serveResource
 

Field Detail

EVENT_ONCHANGE

public static final String EVENT_ONCHANGE
constant for the name of the onChange event. this event is triggered when a parameter of portlet changes

See Also:
Constant Field Values

logger

protected org.apache.log4j.Logger logger
module logger object for generating log messages in different log-levels

Constructor Detail

AbstractGenticsPortlet

public AbstractGenticsPortlet(String moduleId)
                       throws javax.portlet.PortletException
basic constructor that initializes the gentics portlet. constructors of classes extending AbstractGenticsPortlet should always call this constructor to correctly initialize the portlet.

Parameters:
moduleId - the module id of this module
Throws:
javax.portlet.PortletException - a portlet exception if anything problem during execution occurs
Method Detail

initSessionPropertyNames

protected void initSessionPropertyNames()
Initialize the session property names


getSessionPropertyName

protected String getSessionPropertyName(String propertyName)
Get the session property name for the given property name (prefix it with the form name)

Parameters:
propertyName - property name
Returns:
prefixed property name

init

public void init(javax.portlet.PortletConfig config)
          throws javax.portlet.PortletException
Specified by:
init in interface javax.portlet.Portlet
Overrides:
init in class javax.portlet.GenericPortlet
Throws:
javax.portlet.PortletException

setRequest

public void setRequest(javax.portlet.PortletRequest request)
set the current PortletRequest. this is done by the portal and should not be called from somewhere else

Specified by:
setRequest in interface GenticsPortlet
Parameters:
request - PortletRequest

getPortletRequest

public javax.portlet.PortletRequest getPortletRequest()
get the current PortletRequest

Specified by:
getPortletRequest in interface GenticsPortlet
Returns:
portletrequest

getModuleId

public String getModuleId()
return the unique if of this module

Specified by:
getModuleId in interface GenticsPortlet
Returns:
the module id

getTitle

public String getTitle(javax.portlet.RenderRequest renderRequest)
get the module title as defined in the pnode of the module

Overrides:
getTitle in class javax.portlet.GenericPortlet
Parameters:
renderRequest - a request for rendering this module
Returns:
title of the module

getProperty

public Object getProperty(String key)
resolve the given property key to a property.
this implementation can resolve: modules overriding this method must call super.getProperty() first, and if this method returns != null, they have to return immediatly, without checking own properties!

Specified by:
getProperty in interface Resolvable
Parameters:
key - the object key
Returns:
the resolved value or null if the key cannot be resolved

get

public Object get(String key)
alias for getProperty(String)

Specified by:
get in interface Resolvable
Parameters:
key - the object key
Returns:
the resolved value

canResolve

public boolean canResolve()
returns whether the module can resolve properties via calls to getProperty(String). this implementation always returns true

Specified by:
canResolve in interface Resolvable
Returns:
true

setProperty

public boolean setProperty(String propertyName,
                           Object prop)
sets a specified property of the module. this is an empty implementation and can be overwritten to set implementation specific properties

Specified by:
setProperty in interface Changeable
Parameters:
propertyName - property name
prop - property value
Returns:
true if property was set successful, false otherwise.

doDispatch

protected void doDispatch(javax.portlet.RenderRequest renderRequest,
                          javax.portlet.RenderResponse renderResponse)
                   throws javax.portlet.PortletException,
                          IOException
Overrides:
doDispatch in class javax.portlet.GenericPortlet
Throws:
javax.portlet.PortletException
IOException

doFull

protected void doFull(javax.portlet.RenderRequest request,
                      javax.portlet.RenderResponse response)
               throws javax.portlet.PortletException,
                      IOException
This method is called when the gentics portlet shall be rendered in portlet mode GenticsPortletMode.FULL.

Parameters:
request - render request
response - render response
Throws:
javax.portlet.PortletException
IOException

getGenticsPortletContext

public GenticsPortletContext getGenticsPortletContext()
returns the specific GenticsPortletContext of this Module

Specified by:
getGenticsPortletContext in interface GenticsPortlet
Returns:
GenticsPortletContext

getPortalProperty

protected Object getPortalProperty(String propertyPath)
                            throws UnknownPropertyException
returns the portal property (not implemented in abstractmodule)

Parameters:
propertyPath - the path for the property
Returns:
the property object
Throws:
UnknownPropertyException - is thrown if there is no such property

removeListener

protected void removeListener(String eventPath)
removes this module from the listeners collection

Parameters:
eventPath - for this event path

addListener

protected void addListener(String eventPath)
Deprecated. use addListener(String, String)instead

adds this module as listener to the portal

Parameters:
eventPath - event path

addListener

protected void addListener(String eventPath,
                           String actionCommand)
adds this module as listener to the portal

Parameters:
eventPath - event path
actionCommand - action command like "onSave" "onChange"

addPluginListener

protected void addPluginListener(String pluginId,
                                 EventHandler handler,
                                 String actionCommand)
adds an event handler to the plugin with the given id

Parameters:
pluginId - id of the plugin
handler - event handler
actionCommand - action command of the handled events

triggerEvent

protected void triggerEvent(javax.portlet.PortletRequest request,
                            ActionEvent e)
convenience method to trigger a module event. uses the event broker to call the handle method of all listening event handlers

Parameters:
request - portlet request
e - event to be triggered

handleEvent

public final void handleEvent(ActionEvent e)
handle an event this module listenes at

Specified by:
handleEvent in interface EventHandler
Parameters:
e - event to be handled

handlePortalEvent

protected void handlePortalEvent(EventRequest request,
                                 EventResponse response)
                          throws NoEventsAllowedException
event handler method that can be overwritten by classes extending AbstractGenticsPortlet. The default implementation is empty. This method is called by handleEvent(ActionEvent).

Parameters:
request - event request
response - event response
Throws:
NoEventsAllowedException - is thrown if there are no events currently allowed

onPrepareRender

protected void onPrepareRender()
onPrepareRender() is called every time the portal is displayed - after action handling but before render stage (doView, doHelp, doFull, ....) this is the last chance for a portlet to change what the render method will display, and the last chance to trigger events.


onLoad

protected void onLoad()
onload is called when the module is loaded for the first time. it should read it's init-parameters via getModuleParameter() and set an initial state.


onParameterChanged

protected void onParameterChanged(String parameterName,
                                  ActionEvent e)
onParameterChanged() is called, whenever one of the paramters defined in the module-description's parameter section changes. this can be due to datasources changing, or other's modules properties changing (see reaction-section of pnode-tag) the default implementation calles onChanged() and triggers the correct events to let listerens know, that the "properties" (i.e. the state of the module) has likely changed. it assumes that every change of whatever parameter of this module will lead to different output from this module. overwrite this method, if you have parameters that do - under certain circumstances - not change anything in you module, to avoid unneccesary triggering of events.

Parameters:
parameterName - the parameter that has changed
e - the event

onChanged

protected void onChanged()
this is the primitive brother of onParameterChanged() it is called by the default implementation of onParameterChanged and should update what the module is about to render, because one of its parameters has changed. when using this method instead of onParameterChanged() the module does not have to worry about correcty triggering onChange() events.


getPlugin

public GenticsPlugin getPlugin(String id)
returns the plugin that was registered via registerPlugin(String, GenticsPlugin)with the given id

Specified by:
getPlugin in interface GenticsPluginServer
Parameters:
id - plugin id
Returns:
plugin registered with the given id or null

registerPlugin

public void registerPlugin(String id,
                           GenticsPlugin plugin)
registers a plugin to this module. a plugin must be registered before it can be used (rendered) in the module

Specified by:
registerPlugin in interface GenticsPluginServer
Parameters:
id - id of the plugin
plugin - the new plugin

unregisterPlugin

public void unregisterPlugin(String id)
Description copied from interface: GenticsPluginServer
Unregister the plugin with the given id.

Specified by:
unregisterPlugin in interface GenticsPluginServer
Parameters:
id - id of the plugin to unregister

renderPlugin

public String renderPlugin(String id,
                           javax.portlet.RenderRequest request,
                           javax.portlet.RenderResponse response)
                    throws javax.portlet.PortletException,
                           IOException
renders a specific plugin that was registered via registerPlugin(String, GenticsPlugin)before

Specified by:
renderPlugin in interface GenticsPluginServer
Parameters:
id - plugin id
request - portlet request
response - portlet response
Returns:
rendered snippet of this plugin
Throws:
javax.portlet.PortletException - is thrown if there is an error during execution of processing
IOException - is thrown if there is any i/o error

onSessionCreate

protected void onSessionCreate()
onSessionCreate() is called when the user enters the portal. i.e. only once per session


onPluginEvent

public void onPluginEvent(EventRequest eventRequest,
                          EventResponse eventResponse)
is called whenever a plugin is performing an event

Specified by:
onPluginEvent in interface GenticsPluginServer
Parameters:
eventRequest - event request
eventResponse - event response

processPluginAction

public final void processPluginAction(String pluginId,
                                      javax.portlet.ActionRequest actionRequest,
                                      javax.portlet.ActionResponse actionResponse)
                               throws javax.portlet.PortletException,
                                      IOException
Processes a plugins action. This method is called for action requests that are directed to a specific plugin inside a module

Specified by:
processPluginAction in interface GenticsPluginServer
Parameters:
pluginId - plugin id
actionRequest - action request
actionResponse - action response
Throws:
javax.portlet.PortletException - is thrown if there is any error during processing
IOException - is thrown if there is any i/o error

afterProcessPluginAction

public void afterProcessPluginAction(String pluginId,
                                     javax.portlet.ActionRequest actionRequest,
                                     javax.portlet.ActionResponse actionResponse)
This method is called by the portal after processPluginAction(String, javax.portlet.ActionRequest, javax.portlet.ActionResponse). The call is forwarded to GenticsPlugin.afterProcessAction(ActionRequest, ActionResponse) of the addressed plugin

Specified by:
afterProcessPluginAction in interface GenticsPluginServer
Parameters:
pluginId - id of the plugin
actionRequest - action request
actionResponse - action response

afterProcessAction

public void afterProcessAction(javax.portlet.ActionRequest request,
                               javax.portlet.ActionResponse response)
perform required actions after GenericPortlet.processAction(javax.portlet.ActionRequest, javax.portlet.ActionResponse) (cleaning up, etc.)

Specified by:
afterProcessAction in interface GenticsPortlet
Parameters:
request - action request
response - action response

getFileUploadProvider

public FileUploadProvider getFileUploadProvider()
Get a file upload provider for the module. The file upload provider instance is internally cached such that multiple calls to this method in the same request will return the same instance

Specified by:
getFileUploadProvider in interface GenticsPortlet
Returns:
a FileUploadProvider

returnFileUploadProvider

public void returnFileUploadProvider()
return a previously via getFileUploadProvider()fetched file upload provider to the portal. This method is called in afterProcessAction(ActionRequest, ActionResponse), so there is no need to call it from within the module.

Specified by:
returnFileUploadProvider in interface GenticsPortlet

i18n

public I18nString i18n(String key)
Get a localized string for the given key.

Specified by:
i18n in interface GenticsPortlet
Parameters:
key - the key of the i18n item. the syntax is [a-z0-9.]+, and will generate a warning if violated.
Returns:
the localized string object.

getPortalPropertyResolver

public PropertyResolver getPortalPropertyResolver()
Get a property resolver for resolving portal properties

Returns:
a portal property resolver

toString

public String toString()
Overrides:
toString in class Object

getImp

public GenticsImpInterface getImp(String impId)
Get an instance of the imp with the given id.

Parameters:
impId - id of the imp to get
Returns:
the imp or null if no such imp exists

doEditPNode

protected void doEditPNode(javax.portlet.RenderRequest renderRequest,
                           javax.portlet.RenderResponse renderResponse)
                    throws javax.portlet.PortletException,
                           IOException
This method is called when the gentics portlet is rendered in PortletMode GenticsPortletMode.EDITPNODE. This implementation shows a form with a big textfield to modify the pnode

Parameters:
renderRequest - render request
renderResponse - render response
Throws:
javax.portlet.PortletException
IOException

getTemplateProcessor

public TemplateProcessor getTemplateProcessor(javax.portlet.RenderRequest renderRequest,
                                              javax.portlet.RenderResponse renderResponse)
Deprecated. use GenticsPortletContext.getTemplateProcessor(GenticsPortlet, PortletConfig) instead.

Get an instance of a template processor, that can be used to render output based on templates. The instance must be returned via returnTemplateProcessor(TemplateProcessor) after usage

Specified by:
getTemplateProcessor in interface GenticsPortlet
Parameters:
renderRequest - render request
renderResponse - render response
Returns:
an instance of a template processor

returnTemplateProcessor

public void returnTemplateProcessor(TemplateProcessor proc)
return an exclusive templateprocessor that was previously fetched via getTemplateProcessor(RenderRequest, RenderResponse).

Parameters:
proc - an recently fetched templateprocessor, which is not needed any more.

getDatasource

public Datasource getDatasource(String id)
Get a datasource by id.

Specified by:
getDatasource in interface GenticsPortlet
Parameters:
id - id of Datasource as defined in portalconfiguration.
Returns:
Datasource corresponding the id or null if no such datasource exists

reloadModule

public void reloadModule()
Description copied from interface: GenticsPortlet
This method is called if a module has to be reloaded.

Specified by:
reloadModule in interface GenticsPortlet

getModuleType

public String getModuleType()
Description copied from interface: GenticsPortlet
get the module type

Specified by:
getModuleType in interface GenticsPortlet
Returns:
module type

getFullModuleType

public String getFullModuleType()
Description copied from interface: GenticsPortlet
Get the full module type (including the application prefix)

Specified by:
getFullModuleType in interface GenticsPortlet
Returns:
full module type

setModuleType

public void setModuleType(String applicationPrefix,
                          String moduleType)
Description copied from interface: GenticsPortlet
Set the application prefix and portlet name

Specified by:
setModuleType in interface GenticsPortlet
Parameters:
applicationPrefix - application prefix
moduleType - module type (portlet name)

destroy

public void destroy()
Specified by:
destroy in interface javax.portlet.Portlet
Overrides:
destroy in class javax.portlet.GenericPortlet

getContainerRuntimeOptions

public Map getContainerRuntimeOptions()
Specified by:
getContainerRuntimeOptions in interface javax.portlet.PortletConfig
Overrides:
getContainerRuntimeOptions in class javax.portlet.GenericPortlet

propertyModified

public void propertyModified(String path,
                             String property,
                             Object value)
Description copied from interface: PropertyModificationListener
This method is called by the PropertySetter when one of the (sub-)properties of this object is modified

Specified by:
propertyModified in interface PropertyModificationListener
Parameters:
path - path of the changed property (not containing the actual name of the property)
property - name of the changed property
value - new value of the property


Copyright © 2013 Gentics Software GmbH. All Rights Reserved.