com.goodeast.webobjects.switchablestring
Class SSHelper

java.lang.Object
  |
  +--com.goodeast.webobjects.switchablestring.SSHelper

public class SSHelper
extends java.lang.Object

A helper class that is used to add behavior to the dynamic elements. This class allows us to add multiple inheritance-like extensions to a class's behavior within the constraints of Java. It has alternative implementations of appendToResponse and takeValuesFromRequest that can provide static content as well as form elements. To use this class, you need to declare that your class implements the SSHelper.Callbacks interface and implement four methods in your class as follows (assuming that you have an NSDictionary of WOAssociations called "associations" as an instance variable):

public void appendToResponse( WOResponse r, WOContext c ) {
SSHelper.performAppendToResponse( r, c, associations, this );
}

public void takeValuesFromRequest( WORequest r, WOContext c ) {
SSHelper.performTakeValuesFromRequest( r, c, associations, this );
}

public void callSuperAppendToResponse( WOResponse r, WOContext c ) {
super.appendToResponse( r, c );
}

public void callSuperTakeValuesFromRequest( WORequest r, WOContext c ) {
super.takeValuesFromRequest( r, c );
}


Nested Class Summary
static interface SSHelper.Callbacks
          Used to provide callbacks into the dynamic elements so that the helper can call superclass methods.
 
Field Summary
protected static java.lang.String DEFAULT_SEPARATOR
          For lists of items, such as from WOCheckboxMatrix or WOBrowser, the default item separator is ", ".
 
Method Summary
protected static boolean booleanValueForAssociation(java.lang.String assocName, com.webobjects.foundation.NSDictionary assocDict, com.webobjects.appserver.WOContext c)
          Boolean version of valueForAssociation().
static com.webobjects.foundation.NSDictionary cleanUpAssociations(com.webobjects.foundation.NSDictionary incomingAssociations, com.webobjects.foundation.NSArray myAssociations)
          Cleans up the dictionary of associations to remove any that are specific to the SwitchableString framework.
protected static java.lang.String filterContent(java.lang.String truncatedString, com.webobjects.foundation.NSDictionary associations, com.webobjects.appserver.WOContext c)
          Filters the HTML content based on the escapeHTML, allowedTags, and disallowedTags bindings.
static void performAppendToResponse(com.webobjects.appserver.WOResponse r, com.webobjects.appserver.WOContext c, com.webobjects.foundation.NSDictionary associations, SSHelper.Callbacks dynelt)
          Performs the appendToResponse phase for a SwitchableString element.
static void performTakeValuesFromRequest(com.webobjects.appserver.WORequest r, com.webobjects.appserver.WOContext c, com.webobjects.foundation.NSDictionary associations, SSHelper.Callbacks dynelt)
          Performs the takeValuesFromRequest phase for a SwitchableString element.
protected static java.lang.String readRawValue(com.webobjects.foundation.NSDictionary associations, com.webobjects.appserver.WOContext c)
          Returns the contents of the form element, based on which bindings exist.
protected static java.lang.String stringForSelection(java.lang.Object rawValue, com.webobjects.foundation.NSDictionary associations, com.webobjects.appserver.WOContext c)
          Returns a raw value string based on the selection binding.
protected static java.lang.String stringForSelections(com.webobjects.foundation.NSArray selections, com.webobjects.foundation.NSDictionary associations, com.webobjects.appserver.WOContext c)
          Returns a raw value string based on the selections binding.
protected static java.lang.String stringForValue(java.lang.Object rawValue, com.webobjects.foundation.NSDictionary associations, com.webobjects.appserver.WOContext c)
          Returns a raw value string based on the raw value passed through any formatter or formatter subclass that might be bound to the dynamic element.
protected static java.lang.String truncateRawValueString(java.lang.String rawValueString, com.webobjects.foundation.NSDictionary associations, com.webobjects.appserver.WOContext c)
          Truncates the raw value string at the right length.
protected static java.lang.Object valueForAssociation(java.lang.String assocName, com.webobjects.foundation.NSDictionary assocDict, com.webobjects.appserver.WOContext c)
          Utility method that makes it neater to pull out an association's value and handles the absence of a binding gracefully.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_SEPARATOR

protected static final java.lang.String DEFAULT_SEPARATOR
For lists of items, such as from WOCheckboxMatrix or WOBrowser, the default item separator is ", ".

See Also:
Constant Field Values
Method Detail

cleanUpAssociations

public static com.webobjects.foundation.NSDictionary cleanUpAssociations(com.webobjects.foundation.NSDictionary incomingAssociations,
                                                                         com.webobjects.foundation.NSArray myAssociations)
Cleans up the dictionary of associations to remove any that are specific to the SwitchableString framework. A WODynamicElement will take any binding that it doesn't recognize and add it to the dynamic element's tag in the HTML. This method strips out the extra bindings that are used only by the SwitchableString framework elements before the dictionary of WOAssociations is passed on to the superclass constructor.

Parameters:
incomingAssociations - Dictionary of all incoming WOAssociations
myAssociations - Array of associations that should be removed
Returns:
Dictionary of associations with myAssociations removed

valueForAssociation

protected static java.lang.Object valueForAssociation(java.lang.String assocName,
                                                      com.webobjects.foundation.NSDictionary assocDict,
                                                      com.webobjects.appserver.WOContext c)
Utility method that makes it neater to pull out an association's value and handles the absence of a binding gracefully.

Parameters:
assocName - Name of the association
assocDict - Dictionary of WOAssociations
c - WOContext in which to evaluate the association
Returns:
Value of the association in the specified WOContext

booleanValueForAssociation

protected static boolean booleanValueForAssociation(java.lang.String assocName,
                                                    com.webobjects.foundation.NSDictionary assocDict,
                                                    com.webobjects.appserver.WOContext c)
Boolean version of valueForAssociation().

Parameters:
assocName - Name of the association
assocDict - Dictionary of WOAssociations
c - WOContext in which to evaluate the association
Returns:
Boolean value of the association in the specified context

performAppendToResponse

public static void performAppendToResponse(com.webobjects.appserver.WOResponse r,
                                           com.webobjects.appserver.WOContext c,
                                           com.webobjects.foundation.NSDictionary associations,
                                           SSHelper.Callbacks dynelt)
Performs the appendToResponse phase for a SwitchableString element. If the editable binding is absent, or is present and has a value of true, then the element is a form element and control flow is passed on to the superclass's method to generate the appropriate HTML.

Otherwise, the content of the element is read, the content is truncated if necessary, the truncated content is filtered for allowed and disallowed HTML, and the filtered result is appended to the WOResponse.

Parameters:
r - Current WOResponse
c - Current WOContext
associations - Dictionary of WOAssociations
dynelt - Original WODynamicElement, so that superclass functionality can be invoked

readRawValue

protected static java.lang.String readRawValue(com.webobjects.foundation.NSDictionary associations,
                                               com.webobjects.appserver.WOContext c)
Returns the contents of the form element, based on which bindings exist. The value binding has first priority, then the selection binding, then the selections binding, then the noSelectionString binding. If none of these returns any content, the raw value is returned as the empty string.

Parameters:
associations - Dictionary of WOAssociations
c - The current WOContext
Returns:
Raw value of the dynamic element

stringForValue

protected static java.lang.String stringForValue(java.lang.Object rawValue,
                                                 com.webobjects.foundation.NSDictionary associations,
                                                 com.webobjects.appserver.WOContext c)
Returns a raw value string based on the raw value passed through any formatter or formatter subclass that might be bound to the dynamic element. This includes formatter produced by NumberFormat and DateFormat strings.

Parameters:
rawValue - Object returned from the value binding
associations - Dictionary of WOAssociations
c - The current WOContext
Returns:
String from the value binding

stringForSelection

protected static java.lang.String stringForSelection(java.lang.Object rawValue,
                                                     com.webobjects.foundation.NSDictionary associations,
                                                     com.webobjects.appserver.WOContext c)
Returns a raw value string based on the selection binding. We need to push the selection up into the item association, then pull down the displayString association, both because we need to object correctly formatted for display and also because the developer might be playing tricks with the accessors.

Parameters:
rawValue - Object returned from the selection binding
associations - Dictionary of WOAssociations
c - The current WOContext
Returns:
String from the selection binding

stringForSelections

protected static java.lang.String stringForSelections(com.webobjects.foundation.NSArray selections,
                                                      com.webobjects.foundation.NSDictionary associations,
                                                      com.webobjects.appserver.WOContext c)
Returns a raw value string based on the selections binding. By calling stringForSelection as a part of the process, we get the same benefits of getting a properly formatted object and proper usage of accessors.

Parameters:
selections - Object returned from the selections binding
associations - Dictionary of WOAssociations
c - The current WOContext
Returns:
String from the selections binding

truncateRawValueString

protected static java.lang.String truncateRawValueString(java.lang.String rawValueString,
                                                         com.webobjects.foundation.NSDictionary associations,
                                                         com.webobjects.appserver.WOContext c)
Truncates the raw value string at the right length. If there is no truncateLength binding, then no truncation happens.

Parameters:
rawValueString - String value from the appropriate binding for the current element
associations - Dictionary of WOAssociations
c - The current WOContext
Returns:
Truncated string

filterContent

protected static java.lang.String filterContent(java.lang.String truncatedString,
                                                com.webobjects.foundation.NSDictionary associations,
                                                com.webobjects.appserver.WOContext c)
Filters the HTML content based on the escapeHTML, allowedTags, and disallowedTags bindings.
  1. If escapeHTML is true, all HTML tags are escaped.
  2. If escapeHTML is false, no HTML tags are escaped.
  3. If the escapeHTML, allowedTags and disallowedTags bindings are all null then all tags are escaped.
  4. If escapeHTML is not bound, use the allowedTags and disallowedTags bindings.

Parameters:
truncatedString - String to be filtered
associations - Dictionary of WOAssociations
c - The current WOContext
Returns:
The value string filtered of unwanted HTML tags

performTakeValuesFromRequest

public static void performTakeValuesFromRequest(com.webobjects.appserver.WORequest r,
                                                com.webobjects.appserver.WOContext c,
                                                com.webobjects.foundation.NSDictionary associations,
                                                SSHelper.Callbacks dynelt)
Performs the takeValuesFromRequest phase for a SwitchableString element. If the editable binding is absent, or is present and has a value of true, then the element is a form element and control flow is passed on to the superclass's method to extract the form values from the WORequest.

Otherwise, the takeValue phase is skipped since we don't want to read in a bogus null value.

Parameters:
r - The current WORequest
c - The current WOContext
associations - Dictionary of WOAssociations
dynelt - Original WODynamicElement, so that superclass functionality can be invoked