Novell exteNd
Director 5.2 API

com.sssw.fw.api
Interface EbiContext

All Known Subinterfaces:
EbiActionContext, EbiContext, EbiPortalContext, EbiRenderContext, EbiRequestContext

public interface EbiContext

EbiContext stores information about the user's environment. It has the user's ID, the user's session, response and request objects appropriate to the current user agent or browser

The context object exists for the duration of a request. In a component, the request ends when getComponentData() returns. With each new request, the portal instantiates a new context object.

Information that persists between requests is stored in the EbiSession object, which is available from the context. The session includes a "whiteboard" that holds values that a component needs to keep available. You give each whiteboard value a key, which you use to retrieve the value. If there is no session, the portal creates a session-independent whiteboard for storing your persistent data.

The session and whiteboard persist between requests. When another request occurs, these objects become part of the new context object and passed back to the component.

In a portal component, a context object is passed to the getComponentData() method. In other situations, you can get a portal context object from EboPortalFactory. You can get a generic context object from com.sssw.fw.factory.EboFactory.


Method Summary
 EbiContext cloneCopy(EbiContext context)
          Copy's the common data from one context to another.
 Enumeration getAttributeNames()
          Gets an Enumeration of the whiteboard keys that are defined in the session.
 Map getBrowserInfo()
          Returns information about the current user agent.
 String getContextName()
          Returns the context name associated with the web applications context
 EbiRequest getEbiRequest()
          Gets the request object associated with the context.
 EbiResponse getEbiResponse()
          Gets the response object associated with the context.
 EbiSession getEbiSession()
          Gets a portal session object.
 EbiSession getEbiSession(com.sssw.fw.api.EJBContext ctx)
          Gets a portal session object using the information passed in from an EJB context.
 EbiWhiteboard getEbiWhiteboard()
          The whiteboard is a wrapper of the underlying session
 EJBContext getEJBContext()
          Gets EJB context stored in this EbiContext.
 String getException()
          Deprecated.  
 Locale getLocale()
          Gets information about the user's language and geographical location.
 Principal getPrincipal()
          Deprecated. EboDirectoryHelper.getEbiRealmUser(EbiContext)
 Map getTemporaryData()
          This method returns the temporary key: value pair, stored in the context, as a map.
 Object getTemporaryValue(Object key)
          Gets a value that has been stored in context object for the current request.
 Object getValue(String key)
          Returns the value associated with the specified whiteboard key.
 Object getValue(String key, Object dft)
          Returns the value associated with the specified whiteboard key or a default value.
 String[] getValueNames()
          Deprecated.  
 boolean hasSession()
          Deprecated.  
 boolean hasValue(String key)
          Checks whether the specified key has a value on the whiteboard.
 boolean isNewSession()
          Checks if this is the first request of the session.
 void removeAllValues()
          Removes all values and their keys from the whiteboard.
 void removeValue(String key)
          Removes a value associated with the specified key from the whiteboard.
 void setEbiRequest(EbiRequest request)
          Deprecated. (since v5.0)
 void setEbiResponse(EbiResponse response)
          Deprecated. (since v5.0)
 void setEbiSession(EbiSession ebiSession)
          Associates a session with the context object.
 void setEJBContext(com.sssw.fw.api.EJBContext context)
          Deprecated. (since v5.0)
 void setException(String exception)
          Deprecated.  
 void setTemporaryValue(Object key, Object value)
          Sets a value in the context object for the current request.
 void setValue(String key, Object value)
          Sets a value on the whiteboard.
 

Method Detail

getContextName

public String getContextName()
Returns the context name associated with the web applications context

The context name is the unique name given to the web application. The context name will be null if the EbiContext object is not create with the context name reference. For example the context will be proper set when using:

com.sssw.fw.factory.EboFactory.createEbiContext(HttpServletRequest,HttpServletResponse,ServletContext)

or

com.sssw.fw.factory.EboFactory.createEbiContext(RenderRequest,RenderResponse,PortletContext)

or

com.sssw.fw.factory.EboFactory.createEbiContext(ActionRequest,ActionResponse,PortletContext)

The context name is determined by checking the display name of the web application. If this is null then the web application's init-param "context-name" is used.

Returns:
the context name associated with the web application where the context object was constructed
Since:
v5.0

getEbiRequest

public EbiRequest getEbiRequest()
Gets the request object associated with the context. EbiRequest wraps an HTTP, Render or Action request object. See EbiRequest for further details

In the processRequest() method of a component, you can get parameters that the component set by calling these methods:

For example, FORM_LIST_NAME is a constant whose value is the name of an HTML SELECT control on a form:

  String selected = context.getEbiRequest().getParameter(FORM_LIST_NAME);
  
Returns:
an EbiRequest object
See Also:
EbiRequest

getEbiResponse

public EbiResponse getEbiResponse()
Gets the response object associated with the context. EbiRequest wraps an HTTP, Render or Action request object. See EbiRequest for further details

You don't usually need to get the response object. You can use methods of EbiContext to get and set its property values, such as:

Returns:
an EbiResponse object
See Also:
EbiResponse

setEbiResponse

public void setEbiResponse(EbiResponse response)
Deprecated. (since v5.0)

Do not usethis method. Use the proper factories to construct the EbiContext objects

For example:

com.sssw.fw.factory.EboFactory#createEbiContext(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
Parameters:
response -  

setEbiRequest

public void setEbiRequest(EbiRequest request)
Deprecated. (since v5.0)

Do not use, use the proper factories to construct the EbiContext objects

For example:

com.sssw.fw.factory.EboFactory#createEbiContext(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
Parameters:
request -  

getBrowserInfo

public Map getBrowserInfo()
Returns information about the current user agent. The Map object consists of name/value pairs identifying the browser version, the user's platform, and the browser or other client. In HTTP environments, the information comes from the HTTP request header. EboRequestHelper defines constants for the key names. You will also find constants for typical browser values there.

Applying the toString() method to the Map object generates text like this:

{BrowserMinorVer=01, BrowserMajorVer=5, Platform=Windows NT, BrowserName=MSIE}

This code uses constants of EboRequestHelper for the browser information keys and gets the values for each key. The getMapValue() method appends each key and value to a string:

  java.util.Map browserinfo = context.getBrowserInfo();
  *	s = reportMap(browserinfo);

  private String report(java.util.Map map)
  {
                   	String s = "";
                   	String val = "";
                   	String key = "";

                   	key = EboRequestHelper.BROWSER_MAJOR_VER;
                   	getMapValue(map, key, s);
                   	key = EboRequestHelper.BROWSER_MINOR_VER;
                   	s = getMapValue(map, key, s);
                   	key = EboRequestHelper.BROWSER_NAME;
                   	s = getMapValue(map, key, s);
                   	key = EboRequestHelper.PLATFORM;
                   	s = getMapValue(map, key, s);
                   	return s;
  }

  private String getMapValue(Map map, String key, String s)
  {
                   	String val;
                   	if (map.containsKey(key))
                   	{
                                  		val = (String) map.get(key);
                                  		s = s + key + " " + val + "\n";
                   	}
                   	return s;
  }
  

This code gets the browser name and compares it to the value for Microsoft Internet Explorer:

  if (map.get(EboRequestHelper.BROWSER_NAME).equals(
                   	 EboRequestHelper.BROWSER_MSIE))
  { ... }
  
Returns:
a Map whose keys identify information about the user agent. If there is no session, returns null.

getTemporaryValue

public Object getTemporaryValue(Object key)
Gets a value that has been stored in context object for the current request. The value is identified by a key. Call setTemporaryValue() to store a temporary value.

In contrast to whiteboard values which are stored in the session, temporary values are available until the request ends and getComponentData() returns the generated content to the portal's Presentation Manager. You get and set whiteboard values with the getValue() and setValue() methods.

Parameters:
key - an object that identifies the temporary value
Returns:
an Object that is the temporarily stored value. If no value exists for the specified key, returns null.
See Also:
EbiContext.setTemporaryValue( Object key, Object value ), EbiContext.getValue( String key, Object dft ), EbiContext.setValue( String key, Object value )

getTemporaryData

public Map getTemporaryData()
This method returns the temporary key: value pair, stored in the context, as a map.
Returns:
map containing temporary key: value pairs stored in the context.

setTemporaryValue

public void setTemporaryValue(Object key,
                              Object value)
Sets a value in the context object for the current request. The value is associated with a key, which can be of any object type. Temporary values are available only until the request ends and getComponentData() returns its generated content to the portal's Presentation Manager.

To store values that persist during the session, call setValue().

Parameters:
key - an Object that identifies the temporary value. Temporary keys are not limited to Strings.
value - an Object that is the stored value
See Also:
EbiContext.getTemporaryValue( Object key ), EbiContext.setValue(String, Object)

setEJBContext

public void setEJBContext(com.sssw.fw.api.EJBContext context)
Deprecated. (since v5.0)

Sets EJB context in this EbiContext.

This method should not be exposed to the API, do not use.

Parameters:
context - an EJB context.

getEJBContext

public EJBContext getEJBContext()
Gets EJB context stored in this EbiContext.

getValue

public Object getValue(String key)
Returns the value associated with the specified whiteboard key.

To return a default value instead of null when the whiteboard key does not exist, use getValue(String, Object).

Parameters:
key - the name of the whiteboard key
Returns:
the value of the specified key. Returns null if the key is null or does not exist.
See Also:
EbiContext.getValue( String key, Object dft )

getValue

public Object getValue(String key,
                       Object dft)
Returns the value associated with the specified whiteboard key or a default value.

If the key does not exist, this version of getValue() returns the specified default value.

Parameters:
key - the name of the whiteboard key
dft - an object to be returned when the key value is null or does not exist
Returns:
either the value of the specified key or, when the key is null or does not exist, the parameter dft
See Also:
EbiContext.getValue( String key )

getValueNames

public String[] getValueNames()
Deprecated.  

Gets an array of the whiteboard keys that are defined in the session.
Returns:
an array of Strings that are the keys for whiteboard values
See Also:
EbiContext.getValue( String key ), EbiContext.getValue( String key, Object dft ), EbiContext.getAttributeNames()

getAttributeNames

public Enumeration getAttributeNames()
Gets an Enumeration of the whiteboard keys that are defined in the session.
Returns:
an Enumeration of Strings that are the keys for whiteboard values
See Also:
EbiContext.getValue( String key ), EbiContext.getValue( String key, Object dft )

setValue

public void setValue(String key,
                     Object value)
Sets a value on the whiteboard. For a definition of the whiteboard, see EbiContext.
Parameters:
key - a String that identifies the stored value
value - an Object that is the value being stored
See Also:
EbiContext.getValue( String key), EbiContext.getValue( String key, Object dft )

hasValue

public boolean hasValue(String key)
Checks whether the specified key has a value on the whiteboard.
Returns:
Boolean true is key has a value, false otherwise.

removeAllValues

public void removeAllValues()
Removes all values and their keys from the whiteboard.

removeValue

public void removeValue(String key)
Removes a value associated with the specified key from the whiteboard.
Parameters:
key - a String that identifies a value on the whiteboard

getEbiWhiteboard

public EbiWhiteboard getEbiWhiteboard()
The whiteboard is a wrapper of the underlying session

Gets the whiteboard for the session. The whiteboard contains information stored by various applications. Each value is accessed by its key. For a definition of the whiteboard, see EbiWhiteboard.

Returns:
EbiWhiteboard

getException

public String getException()
Deprecated.  

Used by the rules engine to propagate exceptions This has been deprecated. Use getTemporaryValue to propagate objects within a request or the session to store objects in a more statefull manner.

setException

public void setException(String exception)
Deprecated.  

Used by the rules engine to propagate exceptions This has been deprecated. Use setTemporaryValue to propagate objects within a request or the session to store objects accross multiple requests.

getLocale

public Locale getLocale()
Gets information about the user's language and geographical location. The locale has a 2-character ISO Language Code and a 2-character ISO Country Code.

If the underlying request object does not carry a locale then the systems default locale is used. See java.util.Locale for more information.

Returns:
a Locale object which provides the language and country code for the current user. If no session exists, returns a Locale object with default settings of English and United States.

getEbiSession

public EbiSession getEbiSession()
Gets a portal session object. The session object contains information that persists between requests, including security context and information about the current user.

Returns:
an EbiSession for the current session.
See Also:
EbiSessionManager#getEbiSession()

getEbiSession

public EbiSession getEbiSession(com.sssw.fw.api.EJBContext ctx)
Gets a portal session object using the information passed in from an EJB context.

Returns:
an EbiSession for the current session.
See Also:
EbiSessionManager#getEbiEJBSession(javax.ejb.EJBContext)

hasSession

public boolean hasSession()
Deprecated.  

Checks if the context reference to an http session.
Returns:
true if there is a http session, false otherwise.
See Also:
EbiRequest.getSession()

isNewSession

public boolean isNewSession()
Checks if this is the first request of the session. For a new session, you might want to validate the user, require login, or put values on the whiteboard.
Returns:
true if new session, false otherwise
See Also:
EbiRequest.isNewSession()

setEbiSession

public void setEbiSession(EbiSession ebiSession)
Associates a session with the context object. Whenever you have a session object but need a context object, you can instantiate a context object and call setEbiSession().

This example assigns a session to a new context object. An EbiSession object is passed to the initialize() method of a component. This code in initialize() gets a context object from EboFactory and associates the session with it. A context object with user information is required for many content manager methods.

  EbiContext context =
     com.sssw.fw.factory.EboFactory.createEbiContext(null);
  context.setEbiSession(session);
  EbiContentManager contentMgr = (EbiContentManager)
     portal.getPortalManagerInterface(EbiPortalConstants.PORTAL_CONTENT_MGR);
  
Parameters:
ebiSession - a portal session

getPrincipal

public Principal getPrincipal()
                       throws com.sssw.fw.api.EboException
Deprecated. EboDirectoryHelper.getEbiRealmUser(EbiContext)

Gets the security object for the current user. This security object represents a user or group in the server's security system. You can use the Principal in methods that build ACLs.
Returns:
a Principal object that is the server's security object for the current user
Throws:
EboException - if user information is unavailable or an error occurs

cloneCopy

public EbiContext cloneCopy(EbiContext context)
Copy's the common data from one context to another.

Common Data includes

Parameters:
context - The context that will have its data updated
Returns:
the updated context object

Novell exteNd
Director 5.2 API