org.apache.jetspeed.velocity
Class JetspeedPowerToolImpl

java.lang.Object
  extended by org.apache.jetspeed.velocity.JetspeedPowerToolImpl
All Implemented Interfaces:
JetspeedPowerTool, JetspeedVelocityPowerTool

public class JetspeedPowerToolImpl
extends java.lang.Object
implements JetspeedVelocityPowerTool

JetspeedPowerTool

The JetspeedPowerTool is meant to be used by template designers to build templates for internal Jetspeed portlet applications. It hides the implementation details of the more common template actions so that future changes to said implementation have minimal effect on template.

Where applicable, methods have been marked with a BEST PRATICES meaning that this method should be used instead the synonymous code listed within the method docuementation.

Version:
$Id: JetspeedPowerToolImpl.java 589933 2007-10-30 01:51:50Z woonsan $
Author:
Scott T. Weaver

Field Summary
protected  CapabilityMap capabilityMap
           
protected static java.lang.String COLUMN_SIZES
           
protected static java.lang.String COLUMNS_ATTR
           
protected  TemplateLocator decorationLocator
           
protected  LocatorDescriptor decorationLocatorDescriptor
           
protected  PortletEntityAccessComponent entityAccess
           
protected  java.util.Locale locale
           
protected static org.apache.commons.logging.Log log
           
protected static java.lang.String PORTLET_CONFIG_ATTR
           
protected  javax.portlet.PortletConfig portletConfig
           
protected static java.lang.String RENDER_REQUEST_ATTR
           
protected static java.lang.String RENDER_RESPONSE_ATTR
           
protected  javax.portlet.RenderRequest renderRequest
           
protected  javax.portlet.RenderResponse renderResponse
           
protected  RequestContext requestContext
           
protected  TemplateLocator templateLocator
           
protected  LocatorDescriptor templateLocatorDescriptor
           
protected  java.io.Writer templateWriter
           
protected  org.apache.velocity.context.Context velocityContext
           
protected  PortletWindowAccessor windowAccess
           
 
Fields inherited from interface org.apache.jetspeed.layout.JetspeedPowerTool
DECORATOR_TYPE, FRAGMENT_ATTR, FRAGMENT_PROCESSING_ERROR_PREFIX, GENERIC_TEMPLATE_TYPE, HIDDEN, LAYOUT_ATTR, LAYOUT_TEMPLATE_TYPE
 
Constructor Summary
JetspeedPowerToolImpl(RequestContext requestContext, DynamicTitleService titleService, PortletRenderer renderer)
           
 
Method Summary
protected  void checkState()
           
 java.lang.String decorateAndInclude(ContentFragment f)
           Decorate and include fragment content.
protected  java.lang.String decorateAndIncludePortlet(ContentFragment f)
           The decorator template itself is responsible for including the content of the target Fragment which is easily acheived like so:
in Velocity:
 java.lang.String getAbsoluteUrl(java.lang.String relativePath)
           
 java.lang.String getBasePath()
           
 java.util.List[] getColumns()
           
 java.util.List getColumnSizes()
           
 java.lang.Object getComponent(java.lang.String name)
           
 ContentFragment getCurrentFragment()
           
 ContentFragment getCurrentLayout()
           
 org.apache.pluto.om.entity.PortletEntity getCurrentPortletEntity()
           
 TemplateDescriptor getDecoration(java.lang.String path, java.lang.String templateType)
           
 java.util.List getDecoratorActions()
          Deprecated.  
 boolean getLoggedOn()
           
 javax.portlet.PortletMode getMappedPortletMode()
          Gets the internal (portal) portlet mode for a current portlet window (fragment)
 javax.portlet.WindowState getMappedWindowState()
          Gets the internal (portal) window state for the current portlet window (fragment)
 Page getPage()
           
 java.lang.String getPageBasePath()
           
 java.util.List getPageDecoratorActions()
          Deprecated.  
 org.apache.pluto.om.entity.PortletEntity getPortletEntity(ContentFragment f)
           
 javax.portlet.PortletMode getPortletMode()
          Gets the portlet mode for a current portlet window (fragment)
protected  RequestContext getRequestContext()
           getRequestContext
 javax.security.auth.Subject getSubject()
           
 TemplateDescriptor getTemplate(java.lang.String path, java.lang.String templateType)
          Retreives a template using Jetspeed's
protected  TemplateDescriptor getTemplate(java.lang.String path, java.lang.String templateType, TemplateLocator locator, LocatorDescriptor descriptor)
           
 java.lang.String getTitle(org.apache.pluto.om.entity.PortletEntity entity)
           getTitle
 java.lang.String getTitle(org.apache.pluto.om.entity.PortletEntity entity, ContentFragment f)
           getTitle
 org.apache.commons.configuration.Configuration getTypeConfiguration(java.lang.String type, java.lang.String name, java.lang.String location)
           
 javax.portlet.WindowState getWindowState()
          Gets the window state for the current portlet window (fragment)
protected  void handleError(java.lang.Exception e, java.lang.String msg, ContentFragment fragment)
           handleError
 java.lang.String includeDecoration(java.lang.String template, java.lang.String templateType)
           
 java.lang.String includeTemplate(java.lang.String template, java.lang.String templateType)
           
 boolean isHidden(ContentFragment f)
          Checks the the visibilty of this fragment with respect to the current RenderReqeust.
 java.lang.String renderPortletEntity(java.lang.String entityId, java.lang.String portletId)
           
protected  void setAttribute(java.lang.String name, java.lang.Object object)
          Sets an attribute for use within your layout and decoration templates.
 void setCurrentFragment(ContentFragment f)
           
 void setCurrentLayout()
           
 void setVelocityContext(org.apache.velocity.context.Context velocityContext)
          Sets the Velocity Context object for this powertool instance.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PORTLET_CONFIG_ATTR

protected static final java.lang.String PORTLET_CONFIG_ATTR
See Also:
Constant Field Values

RENDER_RESPONSE_ATTR

protected static final java.lang.String RENDER_RESPONSE_ATTR
See Also:
Constant Field Values

RENDER_REQUEST_ATTR

protected static final java.lang.String RENDER_REQUEST_ATTR
See Also:
Constant Field Values

COLUMNS_ATTR

protected static final java.lang.String COLUMNS_ATTR
See Also:
Constant Field Values

COLUMN_SIZES

protected static final java.lang.String COLUMN_SIZES
See Also:
Constant Field Values

renderRequest

protected javax.portlet.RenderRequest renderRequest

renderResponse

protected javax.portlet.RenderResponse renderResponse

portletConfig

protected javax.portlet.PortletConfig portletConfig

templateWriter

protected java.io.Writer templateWriter

log

protected static final org.apache.commons.logging.Log log

capabilityMap

protected CapabilityMap capabilityMap

locale

protected java.util.Locale locale

templateLocatorDescriptor

protected LocatorDescriptor templateLocatorDescriptor

templateLocator

protected TemplateLocator templateLocator

entityAccess

protected PortletEntityAccessComponent entityAccess

decorationLocator

protected TemplateLocator decorationLocator

decorationLocatorDescriptor

protected LocatorDescriptor decorationLocatorDescriptor

windowAccess

protected PortletWindowAccessor windowAccess

requestContext

protected RequestContext requestContext

velocityContext

protected org.apache.velocity.context.Context velocityContext
Constructor Detail

JetspeedPowerToolImpl

public JetspeedPowerToolImpl(RequestContext requestContext,
                             DynamicTitleService titleService,
                             PortletRenderer renderer)
                      throws java.lang.Exception
Throws:
java.lang.Exception
Method Detail

getRequestContext

protected final RequestContext getRequestContext()

getRequestContext

Returns:

getWindowState

public javax.portlet.WindowState getWindowState()
                                         throws java.lang.Exception
Gets the window state for the current portlet window (fragment)

Specified by:
getWindowState in interface JetspeedPowerTool
Returns:
The window state for the current window
Throws:
java.lang.Exception

getMappedWindowState

public javax.portlet.WindowState getMappedWindowState()
                                               throws java.lang.Exception
Gets the internal (portal) window state for the current portlet window (fragment)

Specified by:
getMappedWindowState in interface JetspeedPowerTool
Returns:
The window state for the current window
Throws:
java.lang.Exception

getPortletMode

public javax.portlet.PortletMode getPortletMode()
                                         throws java.lang.Exception
Gets the portlet mode for a current portlet window (fragment)

Specified by:
getPortletMode in interface JetspeedPowerTool
Returns:
The portlet mode of the current window
Throws:
java.lang.Exception

getMappedPortletMode

public javax.portlet.PortletMode getMappedPortletMode()
                                               throws java.lang.Exception
Gets the internal (portal) portlet mode for a current portlet window (fragment)

Specified by:
getMappedPortletMode in interface JetspeedPowerTool
Returns:
The portlet mode of the current window
Throws:
java.lang.Exception

getCurrentFragment

public ContentFragment getCurrentFragment()
Specified by:
getCurrentFragment in interface JetspeedPowerTool
Returns:

setCurrentFragment

public void setCurrentFragment(ContentFragment f)
Specified by:
setCurrentFragment in interface JetspeedPowerTool
Parameters:
f -

setCurrentLayout

public void setCurrentLayout()
Specified by:
setCurrentLayout in interface JetspeedPowerTool

getCurrentLayout

public ContentFragment getCurrentLayout()
Specified by:
getCurrentLayout in interface JetspeedPowerTool
Returns:

getPage

public Page getPage()
Specified by:
getPage in interface JetspeedPowerTool
Returns:

getColumns

public java.util.List[] getColumns()
Specified by:
getColumns in interface JetspeedPowerTool
Returns:

getColumnSizes

public java.util.List getColumnSizes()
Specified by:
getColumnSizes in interface JetspeedPowerTool

getCurrentPortletEntity

public org.apache.pluto.om.entity.PortletEntity getCurrentPortletEntity()
                                                                 throws java.lang.Exception
Specified by:
getCurrentPortletEntity in interface JetspeedPowerTool
Returns:
Throws:
java.lang.Exception

getPortletEntity

public org.apache.pluto.om.entity.PortletEntity getPortletEntity(ContentFragment f)
                                                          throws java.lang.Exception
Specified by:
getPortletEntity in interface JetspeedPowerTool
Parameters:
f - Fragment whose PortletEntity we want to retreive.
Returns:
The PortletEntity represented by the current fragment.
Throws:
java.lang.Exception

isHidden

public boolean isHidden(ContentFragment f)
Checks the the visibilty of this fragment with respect to the current RenderReqeust.

Specified by:
isHidden in interface JetspeedPowerTool
Parameters:
f - Fragment
Returns:
whether or not the Fragment in question should be considered visible during rendering.

getTemplate

public TemplateDescriptor getTemplate(java.lang.String path,
                                      java.lang.String templateType)
                               throws TemplateLocatorException
Retreives a template using Jetspeed's

Specified by:
getTemplate in interface JetspeedPowerTool
Parameters:
path - Expected to the template. This may actually be changed by the TL service based the capability and localization information provided by the client.
templateType - Type off template we are interested in.
Returns:
Template object containng the pertinent information required to inlcude the request template path in the current response
Throws:
TemplateLocatorException - if the path does not exist.
See Also:
TemplateLocator

getTypeConfiguration

public org.apache.commons.configuration.Configuration getTypeConfiguration(java.lang.String type,
                                                                           java.lang.String name,
                                                                           java.lang.String location)
                                                                    throws java.lang.Exception
Throws:
java.lang.Exception

getDecoration

public TemplateDescriptor getDecoration(java.lang.String path,
                                        java.lang.String templateType)
                                 throws TemplateLocatorException
Specified by:
getDecoration in interface JetspeedPowerTool
Throws:
TemplateLocatorException

includeTemplate

public java.lang.String includeTemplate(java.lang.String template,
                                        java.lang.String templateType)
                                 throws java.io.IOException
Specified by:
includeTemplate in interface JetspeedPowerTool
Throws:
java.io.IOException

includeDecoration

public java.lang.String includeDecoration(java.lang.String template,
                                          java.lang.String templateType)
                                   throws java.io.IOException
Specified by:
includeDecoration in interface JetspeedPowerTool
Throws:
java.io.IOException

decorateAndInclude

public java.lang.String decorateAndInclude(ContentFragment f)
                                    throws java.lang.Exception

Decorate and include fragment content.

Specified by:
decorateAndInclude in interface JetspeedPowerTool
Parameters:
f - Fragment to include and decorate
Returns:
String path to the decorator.
Throws:
java.lang.Exception

decorateAndIncludePortlet

protected java.lang.String decorateAndIncludePortlet(ContentFragment f)
                                              throws java.lang.Exception

The decorator template itself is responsible for including the content of the target Fragment which is easily acheived like so:
in Velocity:

   
 $jetspeed.include($jetspeed.currentFragment)
 
 
In JSP:
   
  
              <% 
               JetspeedPowerTool jetspeed = new JetspeedPowerTool(renderRequest, renderResponse, portletConfig);
               jetspeed.include(jetspeed.getCurrentFragment());
              %>
   
 
 

Parameters:
f - Portlet fragment to "decorate"
Throws:
java.lang.Exception

checkState

protected void checkState()
Throws:
java.lang.IllegalStateException - if the PortletConfig, RenderRequest or RenderReponse is null.

getTemplate

protected TemplateDescriptor getTemplate(java.lang.String path,
                                         java.lang.String templateType,
                                         TemplateLocator locator,
                                         LocatorDescriptor descriptor)
                                  throws TemplateLocatorException
Throws:
TemplateLocatorException

handleError

protected void handleError(java.lang.Exception e,
                           java.lang.String msg,
                           ContentFragment fragment)

handleError

Parameters:
e -
msg -

getDecoratorActions

public java.util.List getDecoratorActions()
Deprecated. 

Gets the list of decorator actions for a window. Each window (on each page) has its own collection of actionAccess flags associated with it.

Specified by:
getDecoratorActions in interface JetspeedPowerTool
Returns:
A list of actions available to the current window, filtered by securty access and current state.
Throws:
java.lang.Exception

getPageDecoratorActions

public java.util.List getPageDecoratorActions()
                                       throws java.lang.Exception
Deprecated. 

Gets the list of decorator actions for a page. Each layout fragment on a page has its own collection of actionAccess flags associated with it.

Specified by:
getPageDecoratorActions in interface JetspeedPowerTool
Returns:
A list of actions available to the current window, filtered by securty access and current state.
Throws:
java.lang.Exception

getTitle

public java.lang.String getTitle(org.apache.pluto.om.entity.PortletEntity entity,
                                 ContentFragment f)

getTitle

Returns the appropriate for the title based on locale prferences

Specified by:
getTitle in interface JetspeedPowerTool
Parameters:
entity -
Returns:

getTitle

public java.lang.String getTitle(org.apache.pluto.om.entity.PortletEntity entity)

getTitle

Returns the appropriate for the title based on locale prferences

Specified by:
getTitle in interface JetspeedPowerTool
Parameters:
entity -
Returns:

getComponent

public java.lang.Object getComponent(java.lang.String name)
Specified by:
getComponent in interface JetspeedPowerTool

getAbsoluteUrl

public java.lang.String getAbsoluteUrl(java.lang.String relativePath)
Specified by:
getAbsoluteUrl in interface JetspeedPowerTool

getSubject

public javax.security.auth.Subject getSubject()
Specified by:
getSubject in interface JetspeedPowerTool

getLoggedOn

public boolean getLoggedOn()
Specified by:
getLoggedOn in interface JetspeedPowerTool

getBasePath

public java.lang.String getBasePath()
Specified by:
getBasePath in interface JetspeedPowerTool

getPageBasePath

public java.lang.String getPageBasePath()
Specified by:
getPageBasePath in interface JetspeedPowerTool

setVelocityContext

public void setVelocityContext(org.apache.velocity.context.Context velocityContext)
Description copied from interface: JetspeedVelocityPowerTool
Sets the Velocity Context object for this powertool instance. This is only required if using Velocity based decortaions and layouts.

Specified by:
setVelocityContext in interface JetspeedVelocityPowerTool

setAttribute

protected void setAttribute(java.lang.String name,
                            java.lang.Object object)
Sets an attribute for use within your layout and decoration templates. The value is always stored within the current javax.portlet.Renderrequest and is also stored within the current org.apache.velocity.Context if it is available.

Parameters:
name - to store the attribute under.
obj - object to set.

renderPortletEntity

public java.lang.String renderPortletEntity(java.lang.String entityId,
                                            java.lang.String portletId)
Specified by:
renderPortletEntity in interface JetspeedPowerTool


Copyright © 1999-2010 Apache Software Foundation. All Rights Reserved.