org.apache.jetspeed.portlet
Interface PortletContext


public interface PortletContext

The PortletContext interface defines a portlet's view of the portlet container within which each portlet is running. The PortletContext also allows a portlet to access resources available to it. Using the context, a portlet can access the portlet log, and obtain URL references to resources.

Author:
Thomas F. Boehme

Method Summary
 java.lang.Object getAttribute(java.lang.String name)
          Returns the attribute value with the given name, or null if no such attribute exists.
 java.util.Enumeration getAttributeNames()
          Returns an enumeration of the attribute names that this portlet context is aware of.
 java.lang.String getContainerInfo()
          Returns the name and version of the portlet container which the portlet is running in.
 java.lang.String getInitParameter(java.lang.String name)
          Returns the value of the context-wide initialization parameter with the given name, or null if the parameter does not exist.
 java.util.Enumeration getInitParameterNames()
          Returns the names of this context’s initialization parameters as an enumeration, or an empty enumeration if this context has no initialization parameters.
 PortletLog getLog()
          Returns the portlet log which allows the portlet to write informational, warning, or error messages to a log.
 int getMajorVersion()
          Returns the major version of the Portlet API that this portlet container supports.
 int getMinorVersion()
          Returns the minor version of the Portlet API that this portlet container supports.
 java.io.InputStream getResourceAsStream(java.lang.String path)
          Returns the resource located at the given path as an InputStream object.
 java.lang.String getText(java.lang.String key, java.lang.String bundleName, java.util.Locale locale)
          Returns the localized text resource with the given key and using the given locale.
 void include(java.lang.String path, PortletRequest request, PortletResponse response)
           Allows the portlet to delegate the rendering to another resource as specified by the given path.
 void removeAttribute(java.lang.String name)
          Removes the attribute with the given name.
 void send(java.lang.String aPortletName, PortletMessage aMessage)
          Sends the given message to all portlets on the same page that have the given name.
 void setAttribute(java.lang.String name, java.lang.Object value)
          Associates an attribute with the given name and value with this context.
 

Method Detail

getInitParameter

public java.lang.String getInitParameter(java.lang.String name)
Returns the value of the context-wide initialization parameter with the given name, or null if the parameter does not exist.

This method can make available configuration information useful to all portlets.

Parameters:
name - the parameter name
Returns:
the parameter value,
or null if it does not exist

getInitParameterNames

public java.util.Enumeration getInitParameterNames()
Returns the names of this context’s initialization parameters as an enumeration, or an empty enumeration if this context has no initialization parameters.

Returns:
an enumeration of parameter names

setAttribute

public void setAttribute(java.lang.String name,
                         java.lang.Object value)
Associates an attribute with the given name and value with this context. If a portlet needs to communicate information to embedded servlets or JSP, this methods can used carry the information along.

Parameters:
name - the attribute name
value - the attribute value

getAttribute

public java.lang.Object getAttribute(java.lang.String name)
Returns the attribute value with the given name, or null if no such attribute exists.

The context attributes can be used to share information between the portlets of one portlet application.

Parameters:
name - the attribute name
Returns:
the attribute value

getAttributeNames

public java.util.Enumeration getAttributeNames()
Returns an enumeration of the attribute names that this portlet context is aware of.

Returns:
an enumeration of attribute names

removeAttribute

public void removeAttribute(java.lang.String name)
Removes the attribute with the given name.

Parameters:
name - the name of attribute to be removed

include

public void include(java.lang.String path,
                    PortletRequest request,
                    PortletResponse response)
             throws PortletException,
                    java.io.IOException

Allows the portlet to delegate the rendering to another resource as specified by the given path. The path has to be relative and will be resolved by this method, so that the portlet's resources are accessed.

To access protected resources the path has to be prefixed with /portlet-inf/ (e.g. /portlet-inf/myportlet/myportlet.jsp). Otherwise, the direct path is used. (e.g. /myportlet/myportlet.jsp).

This method is enabled for multi-language and multi-device support. For example, a jsp file "/myportlet/mytemplate.jsp" will be searched for in the following order, when accessing via HTML-Browser: 1. /html/en/US/IE/mytemplate.jsp 2. /html/en/US/mytemplate.jsp 3. /html/en/mytemplate.jsp 4. /html/mytemplate.jsp 5. /en/US/IE/mytemplate.jsp 6. /en/US/mytemplate.jsp 7. /en/mytemplate.jsp 8. /mytemplate.jsp

Parameters:
path - the path of the delegate resource
request - the portlet request
response - the portlet response
Throws:
PortletException - if the delegated resource has trouble fulfilling the rendering request
java.io.IOException - if the streaming causes an I/O problem

getResourceAsStream

public java.io.InputStream getResourceAsStream(java.lang.String path)
Returns the resource located at the given path as an InputStream object.

The data in the InputStream can be of any type or length. The method returns null if no resource exists at the given path.

To access protected resources the path has to be prefixed with /portlet-inf/ (e.g. /portlet-inf/myportlet/myportlet.jsp). Otherwise, the direct path is used. (e.g. /myportlet/myportlet.jsp).

Parameters:
path - the path to the resource
Returns:
the input stream

getText

public java.lang.String getText(java.lang.String key,
                                java.lang.String bundleName,
                                java.util.Locale locale)
Returns the localized text resource with the given key and using the given locale.

To use this feature, the CLASSPATH has to contain a resource bundle with the same name (including the package) as the portlet.

Parameters:
key - the text key
bundleName - the name of the resource bundle
locale - the locale to observe
Returns:
the localized text resource

send

public void send(java.lang.String aPortletName,
                 PortletMessage aMessage)
Sends the given message to all portlets on the same page that have the given name. If the portlet name is null the message is broadcast to all portlets. If more than one instance of the portlet with the given name exists on the current page, the message is sent to every single instance of that portlet. If the source portlet has the same name as the target portlet(s), the message will not be sent to avoid possible cyclic calls.

The portlet(s) with the given name will only receive the message event if it has/they have registered the appropriate listener. This is done by registering the listener in the portlet descriptor.

Parameters:
aPortletName - the name of the portlet(s) that this
aMessage - the message to be sent

getMajorVersion

public int getMajorVersion()
Returns the major version of the Portlet API that this portlet container supports.

Returns:
the major version
See Also:
getMinorVersion()

getMinorVersion

public int getMinorVersion()
Returns the minor version of the Portlet API that this portlet container supports.

Returns:
the minor version
See Also:
getMajorVersion()

getContainerInfo

public java.lang.String getContainerInfo()
Returns the name and version of the portlet container which the portlet is running in.

The form of the returned string is servername/versionnumber. For the Jetspeed Framework this method may return the string Apache Jetspeed/1.3a1.

Returns:
the string containing at least name and version number

getLog

public PortletLog getLog()
Returns the portlet log which allows the portlet to write informational, warning, or error messages to a log.

Returns:
the portlet log


Copyright © 2002 Apache Software Foundation. All Rights Reserved.