SilverStream eXtend
Director 4.0

com.sssw.fw.api
Interface EbiContext

All Known Subinterfaces:
EbiContext, EbiContext, EbiPortalContext, EbiRequestContext

public interface EbiContext

Interface for storing and retrieving information about the user's environment. The context 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. When another request occurs, the session and whiteboard become part of the new context object and are passed back to the component.

Different parts of Director use different types of context objects. In a portal component (EbiPortalComponent), a portal context object is passed to the getComponentData() method. To work with rules in a portal component, you can get a rule context (EbiContext) from the portal context. See EboFactory.createEbiContext(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse). In other situations, you can get a portal context object from EboFactory. You can get a generic context object from EboFactory. Generic context objects do not persist; they provide access to methods that require a context and security information, but they do not have the full functionality of an HTTP-based portal context.


Method Summary
 EbiContext cloneCopy(EbiContext context)
          Copies the common data from this context object 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.
 EbiRequest getEbiRequest()
          Gets the request object associated with the session.
 EbiResponse getEbiResponse()
          Gets the response object associated with the session.
 EbiSession getEbiSession()
          Gets a portal session object.
 EbiSession getEbiSession(EJBContext ctx)
          Gets a portal session object using information passed in from an EJB context object.
 EbiWhiteboard getEbiWhiteboard()
          Gets the whiteboard for the session.
 EJBContext getEJBContext()
          Gets the EJB context stored in this EbiContext object.
 String getException()
          No information.
 Locale getLocale()
          Gets information about the user's language and geographical location.
 Principal getPrincipal()
          Deprecated.  
 Map getTemporaryData()
          Gets all the temporary key/value pairs stored in the context.
 Object getTemporaryValue(Object key)
          Gets a value that has been stored in the context object for the current request.
 Object getValue(String key)
          Gets the value associated with the specified whiteboard key.
 Object getValue(String key, Object dft)
          Gets either the value associated with the specified whiteboard key or a default value.
 String[] getValueNames()
          Deprecated.  
 boolean hasSession()
          Checks if the context has a reference to an HTTP session.
 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)
          No information available
 void setEbiResponse(EbiResponse response)
          No information available
 void setEbiSession(EbiSession ebiSession)
          Associates a session with the context object.
 void setEJBContext(EJBContext context)
          Sets the EJB context in this EbiContext object.
 void setException(String exception)
          No information.
 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

getEbiRequest

public EbiRequest getEbiRequest()
Gets the request object associated with the session. When the client is a browser, EbiRequest is an HTTP request object.

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.

getEbiResponse

public EbiResponse getEbiResponse()
Gets the response object associated with the session. When the client is a browser, EbiResponse is an HTTP response object.

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.

setEbiResponse

public void setEbiResponse(EbiResponse response)
No information available

setEbiRequest

public void setEbiRequest(EbiRequest request)
No information available

getBrowserInfo

public Map getBrowserInfo()
Returns information about the current user agent. The returned Map object consists of key/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 the 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 only available until the request ends; that is, when 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()
Gets all the temporary key/value pairs stored in the context.
Returns:
A Map object containing the key/value pairs.

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; that is, when getComponentData() returns the generated content to the portal's Presentation Manager.

To store values that persist during the session, call setValue(), which stores them on the whiteboard.

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(EJBContext context)
Sets the EJB context in this EbiContext object.
Parameters:
context - An EJB context.

getEJBContext

public EJBContext getEJBContext()
Gets the EJB context stored in this EbiContext object.
Returns:
An EJB context object.

getValue

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

To return a default value instead of null when the whiteboard key does not exist, use the 2-argument version of getValue().

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)
Gets either 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 if the 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()
Gets the whiteboard for the session. The whiteboard contains information stored by portal components. Each value is accessed by its key. For a definition of the whiteboard, see EbiContext.
Returns:
An EbiWhiteboard object.

getException

public String getException()
No information.

setException

public void setException(String exception)
No information.

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.

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 the whiteboard, the security context, and information about the current user.

Returns:
An EbiSession object for the current session.

getEbiSession

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

Parameters:
ctx - An EJB context object.
Returns:
An EbiSession object for the current session.

hasSession

public boolean hasSession()
Checks if the context has a reference to an HTTP session.
Returns:
Boolean true if there is a HTTP session, false otherwise.

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:
Boolean true if new session, false otherwise.

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 EbiContentManager 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 EboException
Deprecated.  

Gets the security object for the current user. This security object, called a Principal, 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.
Throws:
EboException - if user information is unavailable or an error occurs. occurs
See Also:
EbiSecurityAclDelegate.addPrincipalsToAcl(EbiContext context, java.lang.String elementIID, java.lang.String elementType, java.lang.String right, java.security.Principal[] principals)

cloneCopy

public EbiContext cloneCopy(EbiContext context)
Copies the common data from this context object to another.
Parameters:
context - The context that will have its data updated.
Returns:
The updated context object.

SilverStream eXtend
Director 4.0