com.sas.servlet.util
Class BaseUtil

com.sas.servlet.util.BaseUtil

public class BaseUtil

Utility methods for use within JSP pages and/or servlets.


Field Summary
static java.lang.String AJAX_BASEUTIL_URL_TEMPLATE
           
static java.lang.String AJAX_URL_SUFFIX
           
static java.lang.String APP_SESSION_TIMEOUT_WARNING_INTERVAL
           
static java.lang.String BASE_AJAX_URL
           
static java.lang.String COMPONENTS_INIT
           
static java.lang.String CONTEXTPATH
           
static java.lang.String DIRECTION
           
static java.lang.String DOC_TYPE
           
static java.lang.String IMAGE_LOCATION
           
static java.lang.String JAVASCRIPT_LOCATION
           
static int LABEL_ONLY
           
static int MNEMONIC_AND_LABEL
           
static int MNEMONIC_ONLY
           
static java.lang.String POLICY_DISPLAY_SESSION_TIMEOUT_WARNING
           
static java.lang.String SELECTOR
           
static java.lang.String STYLE_LOCATION
           
static java.lang.String TEMPLATE_LOCATION
           
static java.lang.String TEXT_PLAIN_MIME_TYPE
           
static int TIMEOUT_WARNING_INTERVAL_DEFAULT
           
 
Constructor Summary
BaseUtil()
           
 
Method Summary
static void applyCommandAttributesFromMap(DynamicAttributeCommandInterface command, java.util.Map attributesMap)
           
static void applySingleCommandAttributes(javax.servlet.http.HttpServletRequest request, java.lang.Object target, java.lang.String parameterPrefix)
           Finds all the request parameters that match attributes on the command object and sets each command attribute with the request paramter's value accordingly.
static void applyTbeanStringParameterValues(javax.servlet.http.HttpServletRequest request, TransformationInterface tbean, java.util.Map parameterMap)
          Apply String request attributes to tbean component.
static java.lang.String decodeBase64(java.lang.String s)
          Decode a base64 encoded string.
static java.lang.String escapeSpecialCharacters(java.lang.String text)
          Deprecated. Use Strings.escapeForJavaScript(String) or (for old behavior) #escapeSpecialQuotesAndBackslash(String).
static java.util.Properties getApplicationSettings(javax.servlet.http.HttpServletRequest request)
           
protected static com.sas.datatypes.DataTypeInterface getDataTypeFromString(java.lang.String typeStr)
           
static java.lang.StringBuffer getFormattedMessage(java.lang.Exception ex, java.util.Locale locale)
           
static java.lang.String getInputCharacterEncoding(javax.servlet.http.HttpServletRequest request)
          Method that returns back a character encoding String.
static java.lang.String getMnemonicLabel(java.lang.String label, int showMnemonic)
          Returns a mnemonic label created from the passed in text, the text with the & removed or the character in the text immediately after the &.
static java.lang.Object getObjectAttributeValue(java.lang.String[] stringParameterValues, java.lang.Class attributeTypeClass)
           
static java.lang.String getOutputCharacterEncoding(javax.servlet.http.HttpServletRequest request)
          Method that returns back the output character encoding to set on the HttpServletResponse.
static java.beans.PropertyDescriptor[] getPropertyDescriptors(java.lang.Object source)
           
static java.lang.String getRemoteSessionParameters(javax.servlet.http.HttpServletRequest request, boolean firstParam)
          Gets the RemoteSession additional parameters (session id and session host).
static java.lang.StringBuffer getTimeoutScript(javax.servlet.http.HttpServletRequest request, java.lang.String url, int refreshInterval, java.lang.String function, boolean dialog, boolean disableWarning, boolean frames, boolean centerWarning)
          Returns the timeout script used for checking if the session is timed out and redirect the page to the timeout url.
static int getTimeoutWarningDuration(javax.servlet.http.HttpServletRequest request)
           
static boolean isTimeoutWarningEnabled(javax.servlet.http.HttpServletRequest request)
           
static java.lang.String replaceSpecialCharacters(java.lang.String inputString, int browserType)
          Utility method for replacing special characters (&,$,<,>,',").
static void setAttribute(java.lang.Object target, java.beans.PropertyDescriptor pd, java.lang.String attributeName, java.lang.Object objectAttributeValue)
           
static void setLabelAndAccessKeyOnButton(BaseButton button, java.lang.String text)
          Sets the access key and mnemonic label for the given BaseButton given the text.
static void writeAdditionalParameters(java.util.HashMap additionalParameters, java.io.PrintWriter out)
          Takes a HashMap containing additional parameters that are specified by a name/value pair.
 

Field Detail

BASE_AJAX_URL

public static final java.lang.String BASE_AJAX_URL
See Also:
Constant Field Values

AJAX_URL_SUFFIX

public static final java.lang.String AJAX_URL_SUFFIX
See Also:
Constant Field Values

AJAX_BASEUTIL_URL_TEMPLATE

public static final java.lang.String AJAX_BASEUTIL_URL_TEMPLATE

MNEMONIC_ONLY

public static int MNEMONIC_ONLY

LABEL_ONLY

public static int LABEL_ONLY

MNEMONIC_AND_LABEL

public static int MNEMONIC_AND_LABEL

COMPONENTS_INIT

public static java.lang.String COMPONENTS_INIT

CONTEXTPATH

public static java.lang.String CONTEXTPATH

IMAGE_LOCATION

public static java.lang.String IMAGE_LOCATION

STYLE_LOCATION

public static java.lang.String STYLE_LOCATION

JAVASCRIPT_LOCATION

public static java.lang.String JAVASCRIPT_LOCATION

TEMPLATE_LOCATION

public static java.lang.String TEMPLATE_LOCATION

SELECTOR

public static java.lang.String SELECTOR

DOC_TYPE

public static java.lang.String DOC_TYPE

DIRECTION

public static java.lang.String DIRECTION

TEXT_PLAIN_MIME_TYPE

public static java.lang.String TEXT_PLAIN_MIME_TYPE

POLICY_DISPLAY_SESSION_TIMEOUT_WARNING

public static final java.lang.String POLICY_DISPLAY_SESSION_TIMEOUT_WARNING
See Also:
Constant Field Values

APP_SESSION_TIMEOUT_WARNING_INTERVAL

public static final java.lang.String APP_SESSION_TIMEOUT_WARNING_INTERVAL
See Also:
Constant Field Values

TIMEOUT_WARNING_INTERVAL_DEFAULT

public static final int TIMEOUT_WARNING_INTERVAL_DEFAULT
See Also:
Constant Field Values
Constructor Detail

BaseUtil

public BaseUtil()
Method Detail

decodeBase64

public static java.lang.String decodeBase64(java.lang.String s)
Decode a base64 encoded string.

Parameters:
s - The base64 encoded string
Returns:
The decoded string

replaceSpecialCharacters

public static java.lang.String replaceSpecialCharacters(java.lang.String inputString,
                                                        int browserType)
Utility method for replacing special characters (&,$,<,>,',"). Valid values of browserType are ints defined by com.sas.servlet.util.ClientInfo: ClientInfo.WML_UP_BROWSER ClientInfo.WML_OTHER_BROWSER ClientInfo.HDML_BROWSER ClientInfo.HTML_BROWSER

Parameters:
inputString - The String on which to perform the replacements
browserType - The type of browser replaced with.
Returns:
The String with replaced characters

escapeSpecialCharacters

public static java.lang.String escapeSpecialCharacters(java.lang.String text)
Deprecated. Use Strings.escapeForJavaScript(String) or (for old behavior) #escapeSpecialQuotesAndBackslash(String).

Utility method for escaping special characters (\,",').

Parameters:
text - The String on which to perform the escaping
Returns:
The String with escaped characters, null if the received text is null

writeAdditionalParameters

public static void writeAdditionalParameters(java.util.HashMap additionalParameters,
                                             java.io.PrintWriter out)
Takes a HashMap containing additional parameters that are specified by a name/value pair. The name/value pairs are write to the output stream within a hidden <input> html tag. Each parameter will be written in its own hidden field using the name of the item as the name= parameter and the value of the item as the value= parameter on the input tag.

Parameters:
map - HashMap the map of additional parameters to be written out.
out - the output stream
See Also:
HashMap

getInputCharacterEncoding

public static java.lang.String getInputCharacterEncoding(javax.servlet.http.HttpServletRequest request)
Method that returns back a character encoding String. The search order is request.getCharacterEncoding, and then the System property "file.encoding". This String is used when an encoding is required such as in the java.net.URLEncoder.encode method, which takes a character encoding as a parameter.

Parameters:
request - The HttpServletRequest
Returns:
the input character encoding

getOutputCharacterEncoding

public static java.lang.String getOutputCharacterEncoding(javax.servlet.http.HttpServletRequest request)
Method that returns back the output character encoding to set on the HttpServletResponse. First, this method looks for a parameter on the request object named ComponentKeys.CHARACTER_ENCODING. If not found, then the method looks for this parameter on the HttpSession. Finally, if not found, then it returns the outputCharacterEncoding on the ComponentPropertyManager.

Parameters:
request - The HttpServletRequest
Returns:
the character encoding string to set on the HttpServletResponse

getRemoteSessionParameters

public static java.lang.String getRemoteSessionParameters(javax.servlet.http.HttpServletRequest request,
                                                          boolean firstParam)
Gets the RemoteSession additional parameters (session id and session host). These parameters must be added to requests that go through the portal.

Parameters:
request - The request object
firstParam - True if these parameters are the first parameters (an ampersand will be NOT be prepended).
Returns:
The addtional parameter String

applySingleCommandAttributes

public static void applySingleCommandAttributes(javax.servlet.http.HttpServletRequest request,
                                                java.lang.Object target,
                                                java.lang.String parameterPrefix)

Finds all the request parameters that match attributes on the command object and sets each command attribute with the request paramter's value accordingly.

Parameters:
request - The request object that may have parameters with names matching those of command attributes.
target - The target object on which parameter values from the request will be applied.
paramaterPrefix - The optional prefix that precedes the parameter names on the request.

getPropertyDescriptors

public static java.beans.PropertyDescriptor[] getPropertyDescriptors(java.lang.Object source)

setAttribute

public static void setAttribute(java.lang.Object target,
                                java.beans.PropertyDescriptor pd,
                                java.lang.String attributeName,
                                java.lang.Object objectAttributeValue)

getObjectAttributeValue

public static java.lang.Object getObjectAttributeValue(java.lang.String[] stringParameterValues,
                                                       java.lang.Class attributeTypeClass)

applyCommandAttributesFromMap

public static void applyCommandAttributesFromMap(DynamicAttributeCommandInterface command,
                                                 java.util.Map attributesMap)

applyTbeanStringParameterValues

public static void applyTbeanStringParameterValues(javax.servlet.http.HttpServletRequest request,
                                                   TransformationInterface tbean,
                                                   java.util.Map parameterMap)
Apply String request attributes to tbean component.

Parameters:
request - current request object
tbean - viewer
parameterMap - mapping of attribute names to keys

getMnemonicLabel

public static java.lang.String getMnemonicLabel(java.lang.String label,
                                                int showMnemonic)
Returns a mnemonic label created from the passed in text, the text with the & removed or the character in the text immediately after the &. Valid values for showMnemonic are BaseUtil.MNEMONIC_ONLY, BaseUtil.LABEL_ONLY, and BaseUtil.MNEMONIC_AND_LABEL.

Parameters:
label - the original string
showMnemonic - indicates the form of the requested return string
Returns:
the requested form of the string

setLabelAndAccessKeyOnButton

public static void setLabelAndAccessKeyOnButton(BaseButton button,
                                                java.lang.String text)
Sets the access key and mnemonic label for the given BaseButton given the text. The access key is the character following an & in the text string.

Parameters:
button - the button that is going to have the access key and mnemonic label set
text - the string that contains the mnemonic

getFormattedMessage

public static java.lang.StringBuffer getFormattedMessage(java.lang.Exception ex,
                                                         java.util.Locale locale)

getDataTypeFromString

protected static com.sas.datatypes.DataTypeInterface getDataTypeFromString(java.lang.String typeStr)

getApplicationSettings

public static java.util.Properties getApplicationSettings(javax.servlet.http.HttpServletRequest request)

isTimeoutWarningEnabled

public static boolean isTimeoutWarningEnabled(javax.servlet.http.HttpServletRequest request)

getTimeoutWarningDuration

public static int getTimeoutWarningDuration(javax.servlet.http.HttpServletRequest request)

getTimeoutScript

public static java.lang.StringBuffer getTimeoutScript(javax.servlet.http.HttpServletRequest request,
                                                      java.lang.String url,
                                                      int refreshInterval,
                                                      java.lang.String function,
                                                      boolean dialog,
                                                      boolean disableWarning,
                                                      boolean frames,
                                                      boolean centerWarning)
Returns the timeout script used for checking if the session is timed out and redirect the page to the timeout url. If used for dialogs, the dialog will be closed the the opener window will be refreshed with the timeout url.

Parameters:
request - The request object
url - timeout url for the application
refreshInterval - session timeout in seconds
function - custom function
dialog - flag for indicating that the script is used for a dialog.
disableWarning - override metadata settings for showing the warning.
frames - write out javascript if inside a frame environment
centerWarning - center warning div if present, otherwise place at top of window/frame
Returns:
StringBuffer containing the timeout script for handling application timeouts.



Copyright © 2009 SAS Institute Inc. All Rights Reserved.