com.caucho.portal.generic
Class GenericWindow

java.lang.Object
  extended by com.caucho.portal.generic.GenericWindow
All Implemented Interfaces:
Window
Direct Known Subclasses:
GenericLayoutWindow, GenericPortletWindow

public abstract class GenericWindow
extends java.lang.Object
implements Window


Field Summary
protected static java.util.logging.Logger log
           
 
Constructor Summary
GenericWindow()
           
 
Method Summary
 void addInitParam(NameValuePair nameValuePair)
           
 void addInitParam(java.lang.String name, java.lang.String value)
          Add an init-param for the portlet.
 void destroy()
           
 int getBufferSize()
          Return a preferred buffer size, may be overridden by the portlet if it calls setBufferSize().
 java.util.ArrayList<Constraint> getConstraints()
          Return a list of Constraint that are applied before the processAction() and render() of the portlet are called, null if there are no Constraints.
 PortletPreferences getDefaultPreferences()
          Return the default preferences for the portlet, null if there are no default preferences.
 int getExpirationCache()
          Time in seconds, 0 disables caching and -1 means never expire.
 java.lang.String getInitParameter(java.lang.String name)
           
 java.util.Enumeration getInitParameterNames()
           
protected  java.lang.String getNamespace()
           
 PortletConfig getPortletConfig()
          
 PortletContext getPortletContext()
          
 java.lang.String getPortletName()
          
 java.util.ArrayList<PreferencesValidator> getPreferencesValidators()
          Return the preferences validators for the portlet, null if there are no preference validators.
 Renderer getRenderer()
          
 java.util.ResourceBundle getResourceBundle(java.util.Locale locale)
          
 java.util.Map<java.lang.String,java.lang.String> getRoleRefMap()
          Return a map that map's role names used by the portlet to the role names recognized by the portal, null if the role names used by the portlet are to be used unchanged.
 java.util.Set<java.lang.String> getSupportedContentTypes(PortletMode portletMode)
          Return the content types supported for the mode, null if all content types are permitted.
 java.util.Set<java.util.Locale> getSupportedLocales()
          Return the Locales supported, null if all Locales are permitted.
 void handleConstraintFailure(RenderRequest request, RenderResponse response, ConstraintFailureEvent event)
          Optionally handle a constraint failure by sending some output to the client using the response or by hiding the window.
 void handleException(RenderRequest request, RenderResponse response, ExceptionEvent event)
          Optionally handle an exception by sending some output to the client using the response or by hiding the window.
 PortletMode handlePortletModeFailure(PortletRequest request, PortletMode notAllowed)
          This is called when a request arrives requesting a PortletMode that does not pass the isPortletModeAllowed() tests.
 WindowState handleWindowStateFailure(PortletRequest request, WindowState notAllowed)
          This is called when a request arrives requesting a WindowState that does not pass the isWindowStateAllowed() tests.
 void init(PortletContext portletContext)
           
 boolean isPortletModeAllowed(PortletRequest request, PortletMode portletMode)
          Return true if the PortletMode is allowed.
 boolean isPrivate()
          Return true if the contents of the portlet are private.
 boolean isWindowStateAllowed(PortletRequest request, WindowState windowState)
          Return true if the WindowState is allowed.
protected  java.lang.Object newInstance(java.lang.Class targetClass, java.lang.String className)
          Instantiate a new instance of an object, performing checks for validity.
abstract  void processAction(PortletConnection connection)
           
abstract  void render(PortletConnection connection)
           
 void setBufferSize(int bufferSize)
          0 disables buffering, -1 allows the portal to choose a buffer size, a positive number indicaets a minimum buffer size.
 void setErrorPage(java.lang.String errorPage)
          Specify a location to forward to if an exception or constraint failure occurs while rendering the portlet.
 void setExpirationCache(int expirationCache)
          Enable caching of the response and set the expiration time in seconds.
 void setNamespace(java.lang.String namespace)
          The namespace is used to uniquely identify this usage of the portlet, the default is "" (the empty string).
 void setPortletName(java.lang.String portletName)
          The default is the namespace.
 void setPortletPreferences(GenericPortletPreferences defaultPreferences)
          Set the default preferences.
 void setPrivate(boolean isPrivate)
          If true then the response is private, indicating that it contains information that should only be provided to the current client, default is false.
 void setRenderer(Renderer renderer)
          A Renderer wraps decorations around the portlet, see AbstractRenderer.
 void setRendererClass(java.lang.String className)
          An alternative to setRenderer(Renderer), specify the class name of an object to instantiate
 void setResourceBundle(java.lang.String name)
          Set a resource bundle name, used to instantiate an instance of ResourceBundleFactory.
 void setResourceBundleFactory(ResourceBundleFactory factory)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

protected static final java.util.logging.Logger log
Constructor Detail

GenericWindow

public GenericWindow()
Method Detail

setNamespace

public void setNamespace(java.lang.String namespace)
The namespace is used to uniquely identify this usage of the portlet, the default is "" (the empty string). The namespace is important when using a portlet preferences store, and also has an effect on the encoding of parameters.


setPortletName

public void setPortletName(java.lang.String portletName)
The default is the namespace.


addInitParam

public void addInitParam(java.lang.String name,
                         java.lang.String value)
Add an init-param for the portlet.


addInitParam

public void addInitParam(NameValuePair nameValuePair)

setPortletPreferences

public void setPortletPreferences(GenericPortletPreferences defaultPreferences)
Set the default preferences.


setExpirationCache

public void setExpirationCache(int expirationCache)
Enable caching of the response and set the expiration time in seconds. 0 (the default) means do not cache, -1 means unlimited cach time, any other number is the number of seconds for which the response can be cached.


setPrivate

public void setPrivate(boolean isPrivate)
If true then the response is private, indicating that it contains information that should only be provided to the current client, default is false. Setting this to true has an effect on caching, if true then a cached value cannot be shared amongst different users and the effectiveness of caching is greatly reduced.


setResourceBundle

public void setResourceBundle(java.lang.String name)
Set a resource bundle name, used to instantiate an instance of ResourceBundleFactory.


setResourceBundleFactory

public void setResourceBundleFactory(ResourceBundleFactory factory)

setRenderer

public void setRenderer(Renderer renderer)
A Renderer wraps decorations around the portlet, see AbstractRenderer.


setRendererClass

public void setRendererClass(java.lang.String className)
An alternative to setRenderer(Renderer), specify the class name of an object to instantiate


setBufferSize

public void setBufferSize(int bufferSize)
0 disables buffering, -1 allows the portal to choose a buffer size, a positive number indicaets a minimum buffer size. Default is 0 unless `error-page' (setErrorPage(String) has been used, then the default is -1.


setErrorPage

public void setErrorPage(java.lang.String errorPage)
Specify a location to forward to if an exception or constraint failure occurs while rendering the portlet. The default behaviour is for an exception or constraint failure to propogate to the parent window, or if there is no parent then to the servlet container. If an exception occurs the following request attributes are set:
com.caucho.portal.error.exception
java.lang.Throwable
com.caucho.portal.error.exception_type
java.lang.Class
com.caucho.portal.error.message
java.lang.String
javax.portlet.renderRequest
javax.portlet.RenderRequest
javax.portlet.renderResponse
javax.portlet.RenderResponse
javax.portlet.portletConfig
javax.portlet.PortletConfig
If a constraint failure occurs the following request attributes are set:
com.caucho.portal.error.constraint
com.caucho.portal.generic.Constraint
com.caucho.portal.error.constraint_type
java.lang.Class
com.caucho.portal.error.status_code
java.lang.Integer
javax.portlet.renderRequest
javax.portlet.RenderRequest
javax.portlet.renderResponse
javax.portlet.RenderResponse
javax.portlet.portletConfig
javax.portlet.PortletConfig


init

public void init(PortletContext portletContext)
          throws PortletException
Throws:
PortletException

newInstance

protected java.lang.Object newInstance(java.lang.Class targetClass,
                                       java.lang.String className)
                                throws java.lang.IllegalArgumentException
Instantiate a new instance of an object, performing checks for validity. The object that results from instantiating an instance of className must be an instance of targetClass.

Parameters:
targetClass - the class that the instantiated Object should be compatible with.
className - the String name of a class to use when instantiating the object.
Returns:
a new Object
Throws:
java.lang.IllegalArgumentException

getNamespace

protected java.lang.String getNamespace()

getPortletContext

public PortletContext getPortletContext()


getPortletConfig

public PortletConfig getPortletConfig()

Specified by:
getPortletConfig in interface Window

getPortletName

public java.lang.String getPortletName()


getInitParameter

public java.lang.String getInitParameter(java.lang.String name)

getInitParameterNames

public java.util.Enumeration getInitParameterNames()

getExpirationCache

public int getExpirationCache()
Time in seconds, 0 disables caching and -1 means never expire.

Specified by:
getExpirationCache in interface Window

isPrivate

public boolean isPrivate()
Return true if the contents of the portlet are private. The portlet specification states that "cached content must not be shared across different user clients displaying the same portlet". If a portal implementation supports caching, then a return value of false will allow the portal to share the cached content across different user clients.

Specified by:
isPrivate in interface Window

isWindowStateAllowed

public boolean isWindowStateAllowed(PortletRequest request,
                                    WindowState windowState)
Return true if the WindowState is allowed. portletRequest.getResponseContentType() can be used if the allowed portlet modes depends on the mime type of the response. This implementation returns true.

Specified by:
isWindowStateAllowed in interface Window

isPortletModeAllowed

public boolean isPortletModeAllowed(PortletRequest request,
                                    PortletMode portletMode)
Return true if the PortletMode is allowed. portletRequest.getResponseContentType() can be used if the allowed portlet modes depends on the mime type of the response. This implementation returns true.

Specified by:
isPortletModeAllowed in interface Window

getSupportedContentTypes

public java.util.Set<java.lang.String> getSupportedContentTypes(PortletMode portletMode)
Return the content types supported for the mode, null if all content types are permitted. This implementation returns null, which means that all content types are supported.

Specified by:
getSupportedContentTypes in interface Window

getSupportedLocales

public java.util.Set<java.util.Locale> getSupportedLocales()
Return the Locales supported, null if all Locales are permitted. This implementation returns null, which means that all locales are supported.

Specified by:
getSupportedLocales in interface Window

getDefaultPreferences

public PortletPreferences getDefaultPreferences()
Return the default preferences for the portlet, null if there are no default preferences. This implementation returns null.

Specified by:
getDefaultPreferences in interface Window

getPreferencesValidators

public java.util.ArrayList<PreferencesValidator> getPreferencesValidators()
Return the preferences validators for the portlet, null if there are no preference validators.

Specified by:
getPreferencesValidators in interface Window

getRoleRefMap

public java.util.Map<java.lang.String,java.lang.String> getRoleRefMap()
Return a map that map's role names used by the portlet to the role names recognized by the portal, null if the role names used by the portlet are to be used unchanged. This implementation returns null.

Specified by:
getRoleRefMap in interface Window

getConstraints

public java.util.ArrayList<Constraint> getConstraints()
Return a list of Constraint that are applied before the processAction() and render() of the portlet are called, null if there are no Constraints. This implementation returns null.

Specified by:
getConstraints in interface Window

getRenderer

public Renderer getRenderer()

Specified by:
getRenderer in interface Window

handlePortletModeFailure

public PortletMode handlePortletModeFailure(PortletRequest request,
                                            PortletMode notAllowed)
This is called when a request arrives requesting a PortletMode that does not pass the isPortletModeAllowed() tests. It gives the Window an opportunity to return a PortletMode that can be used. If the returned mode is also not allowed, a PortletModeException occurs. Implementations can use handleException to handle PortletModeException. This implementation returns PortletMode.VIEW.

Specified by:
handlePortletModeFailure in interface Window
Returns:
a new PortletMode to try, or null to cause an exception.

handleWindowStateFailure

public WindowState handleWindowStateFailure(PortletRequest request,
                                            WindowState notAllowed)
This is called when a request arrives requesting a WindowState that does not pass the isWindowStateAllowed() tests. It gives the Window an opportunity to return a WindowState that can be used. If the returned window state is also not allowed, a WindowStateException occurs. Implementations can use handleException to handle WindowStateException. This implementation returns WindowState.NORMAL.

Specified by:
handleWindowStateFailure in interface Window
Returns:
a new WindowState to try, or null to cause an exception,

handleConstraintFailure

public void handleConstraintFailure(RenderRequest request,
                                    RenderResponse response,
                                    ConstraintFailureEvent event)
Optionally handle a constraint failure by sending some output to the client using the response or by hiding the window. When a Portlet fails a Constriant during processAction(), it is stored until the render stage, and handleConstriantFailure() is called instead of render(). When a Portlet fails a Constraint during render(), handleConstriantFailure() is immediately called. If the implementation of this method does nothing, then the response of this window is reset() and the failure propagates to the parent window. If there is no parent window, PortletConnection#handleConstraintFailure() is called. Implementations of this method can change that behaviour by using the event.setHandled(boolean hideWindow) callback method. See Window.handleException(RenderRequest, RenderResponse, com.caucho.portal.generic.ExceptionEvent) for more information.

Specified by:
handleConstraintFailure in interface Window
See Also:
setErrorPage(String)

handleException

public void handleException(RenderRequest request,
                            RenderResponse response,
                            ExceptionEvent event)
Optionally handle an exception by sending some output to the client using the response or by hiding the window. When a Portlet throws an Exception during processAction(), it is stored until the render stage, and handleException() is called instead of render(). When a Portlet throws an exception during render(), the handleException() is immediately called. If the implementation of this method does nothing, then the repsonse of this window is reset() and the exception propagates to the parent window. If there is no parent window, PortletConnection#handleException() is called. Implementations of this method can change that behaviour by using the event.setHandled(boolean hideWindow) callback method.

exceptionEvent.setHandled(false)

If handleException calls exceptionEvent.setHandled(false) then the content that the portlet has written is kept, and the request continues. Implementations use this when they have written some contents to the portlet that should be visible to the user.
 public void handleException(RenderRequest request, RenderResponse response, ExceptionEvent event)
   throws PortletException, IOException 
 {
   if (event.getException() instanceof UnavailableException) {
     PrintWriter out = response.getWriter();
     response.setContentType("text/html"); 
     out.println("This service is currently unavailable."); 
     event.setHandled(false);
   } 
 } 
 
If an implementation is handling an exception that can occur after the Portlet has written some content already, it should call response.reset() before it writes anything to the response.
 public void handleException(RenderRequest request, RenderResponse response, ExceptionEvent event)
   throws PortletException, IOException 
 {
   response.reset(); 
   response.setContentType("text/html"); 
   PrintWriter out = response.getWriter();
   printFancyExceptionMessage(event.getException());
   event.setHandled(false);
 } 
 

exceptionEvent.setHandled(true)

If handleException calls exceptionEvent.setHandled(true) then the output is reset(), including any output from a Renderer, and the request continues. The effect of this call is to make the window invisible, no content for this window is shown but other windows on the page will be shown. Implementations use this when they have dealt with the exception in some way and wish to hide the exception from the user.
 public void handleException(ExceptionEvent event)
   throws PortletException, IOException 
 {
   log.log(Level.WARNING, ex.toString(), ex);
   event.setHandled(true); 
 } 
 

Specified by:
handleException in interface Window
See Also:
setErrorPage(String)

getResourceBundle

public java.util.ResourceBundle getResourceBundle(java.util.Locale locale)


getBufferSize

public int getBufferSize()
Return a preferred buffer size, may be overridden by the portlet if it calls setBufferSize(). A value of 0 disables buffering for the portlet. A value of -1 allows the portal to use a default buffer size.

Specified by:
getBufferSize in interface Window

processAction

public abstract void processAction(PortletConnection connection)
                            throws PortletException,
                                   java.io.IOException
Throws:
PortletException
java.io.IOException

render

public abstract void render(PortletConnection connection)
                     throws PortletException,
                            java.io.IOException
Throws:
PortletException
java.io.IOException

destroy

public void destroy()