net.sf.jportlet.portlet
Interface PortletContext

All Superinterfaces:
javax.servlet.ServletContext
All Known Implementing Classes:
PortletContextImpl

public interface PortletContext
extends javax.servlet.ServletContext

The PortletContext interface defines a portlet's view of the portlet container within which each portlet is running.

Author:
Herve Tchepannou

Method Summary
 java.lang.Object getAttribute(java.lang.String arg0)
           
 java.util.Enumeration getAttributeNames()
           
 java.lang.String getInitParameter(java.lang.String name)
           
 java.util.Enumeration getInitParameterNames()
           
 net.sf.jportlet.portlet.PortletLog getLog()
          Returns the portlet log which allows the portlet to write debug, informational, warning, or error messages to a log
 java.io.InputStream getResourceAsStream(java.lang.String path, net.sf.jportlet.portlet.Client client)
          Returns the resource located at the given path (inside the portlet context) as an InputStream for a given client device , or null if the resource not found.
 java.io.InputStream getResourceAsStream(java.lang.String path, net.sf.jportlet.portlet.Client client, java.util.Locale locale)
          Returns the resource located at the given path (inside the portlet context) as an java.io.InputStream for a given client device and Locale, or null if the resource not found.
 java.lang.String getResourcePath(java.lang.String path, net.sf.jportlet.portlet.Client client)
          Return the path of a resource for a given client device , or null if the resource not found.
 java.lang.String getResourcePath(java.lang.String path, net.sf.jportlet.portlet.Client client, java.util.Locale locale)
          Return the path of a resource for a given client device and Locale, or null if the resource not found.
 net.sf.jportlet.service.PortletService getService(java.lang.String name)
          This function looks up a portlet service with the given classname.
 java.lang.String getText(java.lang.String key, java.util.Locale locale)
          Returns the localized text resource with the given key and using the given locale.
 void include(java.lang.String path, net.sf.jportlet.portlet.PortletRequest request, net.sf.jportlet.portlet.PortletResponse response)
          Allows the portlet to render a resource as specified by the given path (inside the portlet context).
 void removeAttribute(java.lang.String name)
           
 void send(java.lang.String portletName, java.lang.Object message, net.sf.jportlet.portlet.PortletRequest request, net.sf.jportlet.portlet.PortletResponse response)
          Send a message to a portlet.
 void setAttribute(java.lang.String name, java.lang.Object value)
           
 
Methods inherited from interface javax.servlet.ServletContext
getContext, getMajorVersion, getMimeType, getMinorVersion, getNamedDispatcher, getRealPath, getRequestDispatcher, getResource, getResourceAsStream, getResourcePaths, getServerInfo, getServlet, getServletContextName, getServletNames, getServlets, log, log, log
 

Method Detail

getAttribute

public java.lang.Object getAttribute(java.lang.String arg0)
Specified by:
getAttribute in interface javax.servlet.ServletContext
See Also:
ServletContext.getAttribute(java.lang.String)

getAttributeNames

public java.util.Enumeration getAttributeNames()
Specified by:
getAttributeNames in interface javax.servlet.ServletContext
See Also:
ServletContext.getAttributeNames()

getInitParameter

public java.lang.String getInitParameter(java.lang.String name)
Specified by:
getInitParameter in interface javax.servlet.ServletContext
See Also:
ServletContext.getInitParameter(java.lang.String)

getInitParameterNames

public java.util.Enumeration getInitParameterNames()
Specified by:
getInitParameterNames in interface javax.servlet.ServletContext
See Also:
ServletContext.getInitParameterNames()

getLog

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


getResourceAsStream

public java.io.InputStream getResourceAsStream(java.lang.String path,
                                               net.sf.jportlet.portlet.Client client)
Returns the resource located at the given path (inside the portlet context) as an InputStream for a given client device , or null if the resource not found. The resource are always searched first from the portlet classpath, and if not found, it will be searched from the portlet web module.

For example, if a web-browser request to the portlet com.foo.MyPortlet named myportlet the resource /template.vm, This function will search the following files until it found it:

  1. com/foo/html/myportlet/mytemplate.vm [classpath]
  2. com/foo/myportlet/mytemplate.vm [classpath]
  3. /PORTLET-INF/myportlet/html/mytemplate.vm [web-module]
  4. /PORTLET-INF/myportlet/mytemplate.vm [web-module]

Parameters:
path - Path of the requested resource
client - Information about the client device
Returns:
InputStream

getResourceAsStream

public java.io.InputStream getResourceAsStream(java.lang.String path,
                                               net.sf.jportlet.portlet.Client client,
                                               java.util.Locale locale)
Returns the resource located at the given path (inside the portlet context) as an java.io.InputStream for a given client device and Locale, or null if the resource not found. The resource are always searched first from the portlet classpath, and if not found, it will be searched from the portlet web module.

For example, if a web-browser from US request to the portlet com.foo.MyPortlet named myportlet the resource /template.vm, This function will search the following files until it found it:

  1. com/foo/html/mytemplate_en_US.vm [classpath]
  2. com/foo/html/mytemplate_en.vm [classpath]
  3. com/foo/html/mytemplate.vm [classpath]
  4. com/foo/mytemplate.vm [classpath]
  5. /PORTLET-INF/myportlet/html/mytemplate_en_US.vm [web-module]
  6. /PORTLET-INF/myportlet/html/mytemplate_en.vm [web-module]
  7. /PORTLET-INF/myportlet/html/mytemplate.vm [web-module]
  8. /PORTLET-INF/myportlet/mytemplate.vm [web-module]

Parameters:
path - resource path
client - client
locale - locale
Returns:
InputStream

getResourcePath

public java.lang.String getResourcePath(java.lang.String path,
                                        net.sf.jportlet.portlet.Client client)
Return the path of a resource for a given client device , or null if the resource not found. See #getResourcePath() to understand how the container find the requested resource

Parameters:
path - resource path
client - client
Returns:
String

getResourcePath

public java.lang.String getResourcePath(java.lang.String path,
                                        net.sf.jportlet.portlet.Client client,
                                        java.util.Locale locale)
Return the path of a resource for a given client device and Locale, or null if the resource not found. See #getResourcePath() to understand how the container find the requested resource

Parameters:
path - resource path
client - client
locale - locale
Returns:

getService

public net.sf.jportlet.service.PortletService getService(java.lang.String name)
                                                  throws PortletServiceUnavailableException,
                                                         PortletServiceNotFoundException
This function looks up a portlet service with the given classname.

Parameters:
name - name of the service
Returns:
PortletService
Throws:
PortletServiceUnavailableException - if an exception has occurrred that interferes with the portlet service's normal initialization
PortletServiceNotFoundException - if the service not found

getText

public java.lang.String getText(java.lang.String key,
                                java.util.Locale locale)
Returns the localized text resource with the given key and using the given locale. To use this feature, the portlet application's CLASSPATH has to contain a resource bundle with the same name (including the package) as the portlet

Parameters:
key - key of the text
locale - target locale
Returns:
String

include

public void include(java.lang.String path,
                    net.sf.jportlet.portlet.PortletRequest request,
                    net.sf.jportlet.portlet.PortletResponse response)
             throws PortletException,
                    java.io.IOException
Allows the portlet to render a resource as specified by the given path (inside the portlet context). This function is doing a kind of Server Side Include

For example, For the portlet com.foo.MyPortlet named myportlet, a file /template.vm will be searched for in the following order, when accessing via HTML-Browser:

  1. com/foo/html/mytemplate_en_US.vm [classpath]
  2. com/foo/html/mytemplate_en.vm [classpath]
  3. com/foo/html/mytemplate.vm [classpath]
  4. com/foo/mytemplate.vm [classpath]
  5. /PORTLET-INF/myportlet/html/en/US/mytemplate.vm [web-module]
  6. /PORTLET-INF/myportlet/html/en/mytemplate.vm [web-module]
  7. /PORTLET-INF/myportlet/html/mytemplate.vm [web-module]
  8. /PORTLET-INF/myportlet/mytemplate.vm [web-module]

Parameters:
path - path of the file to include
request - request of the portlet
response - response of the portlet
Throws:
java.io.IOException - if any IO error
PortletException - if any other error

removeAttribute

public void removeAttribute(java.lang.String name)
Specified by:
removeAttribute in interface javax.servlet.ServletContext
See Also:
ServletContext.removeAttribute(java.lang.String)

send

public void send(java.lang.String portletName,
                 java.lang.Object message,
                 net.sf.jportlet.portlet.PortletRequest request,
                 net.sf.jportlet.portlet.PortletResponse response)
          throws PortletException
Send a message to a portlet. If the portletName not specified, this method will broadcast the message to all portlets

Parameters:
portletName - name of the portlet
message - message to send
request -
response -
Throws:
PortletException

setAttribute

public void setAttribute(java.lang.String name,
                         java.lang.Object value)
Specified by:
setAttribute in interface javax.servlet.ServletContext
See Also:
ServletContext.setAttribute(java.lang.String, java.lang.Object)


Copyright © 2002 Herve Tchepannou. All Rights Reserved.