com.bowstreet.profiles
Class SelectionHandlerBase

java.lang.Object
  extended by com.bowstreet.profiles.SelectionHandlerBase
All Implemented Interfaces:
ProfileSelection

public abstract class SelectionHandlerBase
extends java.lang.Object
implements ProfileSelection

Base class for creating a ProfileSelection implementation. This class provides the base functionality for matching segments to a profile and handling the processing of explicit profile validation and selection.


Field Summary
static java.lang.String BOWSTREET_ADMINISTRATORS_NAME_PROPERTY
          Name of the property for getting the name of the Factory Administrator Role
static java.util.Iterator emptyIterator
           
static java.lang.String FROM_DESIGNER_SESSION_KEY
          Name of the session attribute for specifying we are in development mode, where explicit profile selection rules are relaxed for testing purposes
 
Constructor Summary
SelectionHandlerBase()
           
 
Method Summary
 java.lang.String getProfileBySegment(java.lang.String profileSetName, java.util.Iterator segments)
          Gets the name of the Profile that matches one of the specified segments.
 java.lang.String getUserID(javax.servlet.http.HttpServletRequest request)
          Gets the id of the user by calling the getUserID() method on the UserInfo class.
 void init(java.util.Map properties)
          Initialization method that is used to pass handler properties to implementers of the ProfileSelection interface.
 boolean isSegmentInProfile(javax.servlet.http.HttpServletRequest request, Profile profile, java.util.Iterator segments)
          Tests to see if there is a matching segment for the specified profile.
 boolean validateExplicitProfile(javax.servlet.http.HttpServletRequest request, java.lang.String explicitProfile, ProfileSet profileSet, java.util.Iterator segments)
          Validates the explicit profile to see if it should be used as the selection.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.bowstreet.profiles.ProfileSelection
selectProfile
 

Field Detail

BOWSTREET_ADMINISTRATORS_NAME_PROPERTY

public static final java.lang.String BOWSTREET_ADMINISTRATORS_NAME_PROPERTY
Name of the property for getting the name of the Factory Administrator Role

See Also:
Constant Field Values

emptyIterator

public static final java.util.Iterator emptyIterator

FROM_DESIGNER_SESSION_KEY

public static final java.lang.String FROM_DESIGNER_SESSION_KEY
Name of the session attribute for specifying we are in development mode, where explicit profile selection rules are relaxed for testing purposes

See Also:
Constant Field Values
Constructor Detail

SelectionHandlerBase

public SelectionHandlerBase()
Method Detail

getProfileBySegment

public java.lang.String getProfileBySegment(java.lang.String profileSetName,
                                            java.util.Iterator segments)
Gets the name of the Profile that matches one of the specified segments. If a segment match is not found then the "Default" profile name is returned.

Parameters:
profileSetName - The name of the ProfileSet to find the matching profile in.
segments - An Iterator of segment names that the user is in.
Returns:
The name of the matching Profile, or "Default" if there was no match.

getUserID

public java.lang.String getUserID(javax.servlet.http.HttpServletRequest request)
Gets the id of the user by calling the getUserID() method on the UserInfo class.

Parameters:
request - The HttpServletRequest for the current request.
Returns:
The user ID of the current user (e.g. msmith), or null if the user is not authenticated.

init

public void init(java.util.Map properties)
Initialization method that is used to pass handler properties to implementers of the ProfileSelection interface. Implementers of this interface should use this method to do any required Initialization before the selectProfile(..) method is called.

Specified by:
init in interface ProfileSelection
Parameters:
properties - A Map of name value pairs specified in the handler definition file. The Map key and values are both of type java.lang.String.

isSegmentInProfile

public boolean isSegmentInProfile(javax.servlet.http.HttpServletRequest request,
                                  Profile profile,
                                  java.util.Iterator segments)
Tests to see if there is a matching segment for the specified profile. If the user is the Factory Administrators role then this will return true. This allows developers to test their app with different explicit profiles.

Parameters:
request - The HttpServletRequest for the current request. This can be used to get additional information about the requestor. Implementers of this method should test this for null.
profile - The profile that the match will be performed on.
segments - an Iterator on segment names that the used is a member of.
Returns:
true if one of the segments matches one on the profile, or true if the profile has no segments defined, else false if no match.

validateExplicitProfile

public boolean validateExplicitProfile(javax.servlet.http.HttpServletRequest request,
                                       java.lang.String explicitProfile,
                                       ProfileSet profileSet,
                                       java.util.Iterator segments)
Validates the explicit profile to see if it should be used as the selection. This will check to make sure the profile exists in the profile set, and that the user's segment matches one of the profiles segments. If the profile does not exits or the segments don't match a WebAppRuntimeException will be thrown. This is an unchecked exception. If the server is in the development mode(inDevelopmentMode = true) or the user is the Factory Administrators role then this will return true. This allows developers to test their app with different explicit profiles.

Parameters:
request - The HttpServletRequest for the current request. This can be used to get additional information about the requestor. Implementers of this method should test this for null.
explicitProfile - The name of the explicit profile to validate.
profileSet - The profile set name to validate against. This method will make sure that the explicit profile exists in this profile set.
segments - The segments for the current user. This method will check if the user's segment matches one of the profiles segments
Returns:
true if an explicit profile was passed in, else false. If this method return true your selectProfile(..) method should return the value of its explicitProfile argument.


Copyright © 2009 IBM. All Rights Reserved.