it.eng.spago.taglib
Class TagUtils

java.lang.Object
  extended by it.eng.spago.taglib.TagUtils

public class TagUtils
extends java.lang.Object

Provides helper methods for JSP tags.

Since:
Struts 1.2
Version:
$Rev: 421129 $

Field Summary
static java.lang.String CHARACTERS_KEY
          Constants used to ask the an envelop characters instead of a specific attribute.
protected static MessageBundleReference messages
          The message resources for this package.
 
Constructor Summary
protected TagUtils()
          Constructor for TagUtils.
 
Method Summary
 java.util.List computeParameters(PageContext pageContext, java.lang.String paramId, java.lang.String paramName, java.lang.String paramScope, java.lang.String property, java.lang.String scope, boolean transaction)
          Compute a set of query parameters that will be dynamically added to a generated URL.
 java.lang.String computeURL(PageContext pageContext, java.lang.String href, java.util.List params, java.lang.String anchor, boolean redirect)
           
 java.lang.String computeURL(PageContext pageContext, java.lang.String href, java.util.List params, java.lang.String anchor, boolean redirect, boolean encodeSeparator)
           
 java.lang.String computeURLWithCharEncoding(PageContext pageContext, java.lang.String href, java.util.List params, java.lang.String anchor, boolean redirect, boolean useLocalEncoding)
          Compute a hyperlink URL based on the href parameter that is not null.
 java.lang.String computeURLWithCharEncoding(PageContext pageContext, java.lang.String href, java.util.List params, java.lang.String anchor, boolean redirect, boolean encodeSeparator, boolean useLocalSeparator)
           
 java.lang.String computeURLWithCharEncoding(PageContext pageContext, java.lang.String href, java.util.List params, java.lang.String anchor, boolean redirect, java.lang.String alias, java.lang.String aliasRelative, boolean encodeSeparator, boolean useLocalEncoding)
          Compute a hyperlink URL based on the href parameter that is not null.
 java.lang.String encodeURL(java.lang.String url)
          URLencodes a string assuming the character encoding is UTF-8.
 java.lang.String encodeURL(java.lang.String url, java.lang.String enc)
          Use the new URLEncoder.encode() method from Java 1.4 if available, else use the old deprecated version.
 java.lang.String filter(java.lang.String value)
          Filter the specified string for characters that are senstive to HTML interpreters, returning the string with these characters replaced by the corresponding character entities.
 java.lang.String getActionMappingName(java.lang.String action)
          Return the form action converted into an action mapping path.
static TagUtils getInstance()
          Returns the Singleton instance of TagUtils.
 RequestContextIFace getRequestContext(PageContext pageContext)
           
 boolean isXhtml(PageContext pageContext)
          Returns true if the custom tags are in XHTML mode.
 java.util.List lookupMultipleProperty(PageContext pageContext, java.lang.String property, java.lang.String scopeName)
           
 java.util.List lookupMultipleProperty(PageContext pageContext, java.lang.String property, java.lang.String scopeName, java.lang.String paramName, java.lang.String paramValue, java.lang.String listAttribute)
           
 java.lang.Object lookupProperty(PageContext pageContext, java.lang.String property, java.lang.String scopeName)
           
 java.lang.Object lookupProperty(PageContext pageContext, java.lang.String property, java.lang.String scopeName, boolean emptyStringValue)
           
 java.lang.String message(java.lang.String bundle, java.util.Locale locale, java.lang.String key)
          Look up and return a message string, based on the specified parameters.
 java.lang.String message(java.lang.String bundle, java.lang.String key)
          Look up and return a message string, based on the specified parameters.
 java.lang.String message(java.lang.String bundle, java.lang.String key, java.lang.Object[] args)
          Look up and return a message string, based on the specified parameters.
 void saveException(PageContext pageContext, java.lang.Throwable exception)
          Save the specified exception as a request attribute for later use.
static void setInstance(TagUtils instance)
          Set the instance.
 void write(PageContext pageContext, java.lang.String text)
          Write the specified text as the response to the writer associated with this page.
 void writePrevious(PageContext pageContext, java.lang.String text)
          Write the specified text as the response to the writer associated with the body content for the tag within which we are currently nested.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CHARACTERS_KEY

public static final java.lang.String CHARACTERS_KEY
Constants used to ask the an envelop characters instead of a specific attribute.


messages

protected static MessageBundleReference messages
The message resources for this package. TODO We need to move the relevant messages out of this properties file.

Constructor Detail

TagUtils

protected TagUtils()
Constructor for TagUtils.

Method Detail

getInstance

public static TagUtils getInstance()
Returns the Singleton instance of TagUtils.


setInstance

public static void setInstance(TagUtils instance)
Set the instance. This blatently violates the Singleton pattern, but then some say Singletons are an anti-pattern.

Parameters:
instance - The instance to set.
Since:
1.3.5 Changed to non-final and added setInstance() so TagUtils may be overridden, use at your own risk (you've been warned!!)

computeParameters

public java.util.List computeParameters(PageContext pageContext,
                                        java.lang.String paramId,
                                        java.lang.String paramName,
                                        java.lang.String paramScope,
                                        java.lang.String property,
                                        java.lang.String scope,
                                        boolean transaction)
                                 throws JspException
Compute a set of query parameters that will be dynamically added to a generated URL. The returned List is composed of SourceBeans; every SourceBean rappresent a query string param and is composed of two attribute: name and value. If no query parameters are identified, return an empty List.

Parameters:
pageContext - PageContext we are operating in
paramId - Single-value request parameter name (if any)
paramName - service context data containing single-value parameter value
paramScope - Scope containing data named by paramName
property - Property in service context that identify a collection of parameters.
scope - Scope containing data named by property
transaction - Should we add our transaction control token?
Returns:
List of SourceBean rappresenting query parameters. An empty List if no query parameters are found.
Throws:
JspException - if we cannot look up the required data

computeURL

public java.lang.String computeURL(PageContext pageContext,
                                   java.lang.String href,
                                   java.util.List params,
                                   java.lang.String anchor,
                                   boolean redirect)
                            throws java.net.MalformedURLException,
                                   JspException
Parameters:
pageContext -
href -
params -
anchor -
redirect -
Returns:
Throws:
java.net.MalformedURLException
JspException
See Also:
computeURLWithCharEncoding(PageContext, String, List, String, boolean, boolean)

computeURLWithCharEncoding

public java.lang.String computeURLWithCharEncoding(PageContext pageContext,
                                                   java.lang.String href,
                                                   java.util.List params,
                                                   java.lang.String anchor,
                                                   boolean redirect,
                                                   boolean useLocalEncoding)
                                            throws java.net.MalformedURLException,
                                                   JspException
Compute a hyperlink URL based on the href parameter that is not null. The returned URL will have already been passed to response.encodeURL() for adding a session identifier.

Parameters:
pageContext - PageContext for the tag making this call
href - URL to be utilized unmodified (if specified)
params - List of SourceBean rappresenting parameters to be dynamically included (if any)
anchor - Anchor to be dynamically included (if any)
redirect - Is this URL for a response.sendRedirect()?
Returns:
URL with session identifier
Throws:
java.net.MalformedURLException - if a URL cannot be created for the specified parameters
JspException

computeURL

public java.lang.String computeURL(PageContext pageContext,
                                   java.lang.String href,
                                   java.util.List params,
                                   java.lang.String anchor,
                                   boolean redirect,
                                   boolean encodeSeparator)
                            throws java.net.MalformedURLException,
                                   JspException
Parameters:
pageContext -
href -
params -
anchor -
redirect -
encodeSeparator -
Returns:
Throws:
java.net.MalformedURLException
JspException
See Also:
computeURLWithCharEncoding(PageContext, String, List, String, boolean, boolean, boolean)

computeURLWithCharEncoding

public java.lang.String computeURLWithCharEncoding(PageContext pageContext,
                                                   java.lang.String href,
                                                   java.util.List params,
                                                   java.lang.String anchor,
                                                   boolean redirect,
                                                   boolean encodeSeparator,
                                                   boolean useLocalSeparator)
                                            throws java.net.MalformedURLException,
                                                   JspException
Throws:
java.net.MalformedURLException
JspException

computeURLWithCharEncoding

public java.lang.String computeURLWithCharEncoding(PageContext pageContext,
                                                   java.lang.String href,
                                                   java.util.List params,
                                                   java.lang.String anchor,
                                                   boolean redirect,
                                                   java.lang.String alias,
                                                   java.lang.String aliasRelative,
                                                   boolean encodeSeparator,
                                                   boolean useLocalEncoding)
                                            throws java.net.MalformedURLException,
                                                   JspException
Compute a hyperlink URL based on the href parameter that is not null. The returned URL will have already been passed to response.encodeURL() for adding a session identifier.

Parameters:
pageContext - PageContext for the tag making this call
href - URL to be utilized unmodified (if specified)
params - List of SourceBean rappresenting parameters to be dynamically included (if any)
anchor - Anchor to be dynamically included (if any)
redirect - Is this URL for a response.sendRedirect()?
alias - Logical name of a configured alias instead of th href parameter.
aliasRelative - String to append to the alias attribute if present.
encodeSeparator - This is only checked if redirect is set to false (never encoded for a redirect). If true, query string parameter separators are encoded as >amp;, else & is used.
useLocalEncoding - If set to true, urlencoding is done on the bytes of character encoding from ServletResponse#getCharacterEncoding. Use UTF-8 otherwise.
Returns:
URL with session identifier
Throws:
java.net.MalformedURLException - if a URL cannot be created for the specified parameters
JspException

encodeURL

public java.lang.String encodeURL(java.lang.String url)
URLencodes a string assuming the character encoding is UTF-8.

Parameters:
url -
Returns:
String The encoded url in UTF-8

encodeURL

public java.lang.String encodeURL(java.lang.String url,
                                  java.lang.String enc)
Use the new URLEncoder.encode() method from Java 1.4 if available, else use the old deprecated version. This method uses reflection to find the appropriate method; if the reflection operations throw exceptions, this will return the url encoded with the old URLEncoder.encode() method.

Parameters:
enc - The character encoding the urlencode is performed on.
Returns:
String The encoded url.

filter

public java.lang.String filter(java.lang.String value)
Filter the specified string for characters that are senstive to HTML interpreters, returning the string with these characters replaced by the corresponding character entities.

Parameters:
value - The string to be filtered and returned

getActionMappingName

public java.lang.String getActionMappingName(java.lang.String action)
Return the form action converted into an action mapping path. The value of the action property is manipulated as follows in computing the name of the requested mapping:


isXhtml

public boolean isXhtml(PageContext pageContext)
Returns true if the custom tags are in XHTML mode.


lookupProperty

public java.lang.Object lookupProperty(PageContext pageContext,
                                       java.lang.String property,
                                       java.lang.String scopeName)
                                throws JspException
Throws:
JspException

getRequestContext

public RequestContextIFace getRequestContext(PageContext pageContext)

lookupProperty

public java.lang.Object lookupProperty(PageContext pageContext,
                                       java.lang.String property,
                                       java.lang.String scopeName,
                                       boolean emptyStringValue)
                                throws JspException
Throws:
JspException

lookupMultipleProperty

public java.util.List lookupMultipleProperty(PageContext pageContext,
                                             java.lang.String property,
                                             java.lang.String scopeName)
                                      throws JspException
Throws:
JspException

lookupMultipleProperty

public java.util.List lookupMultipleProperty(PageContext pageContext,
                                             java.lang.String property,
                                             java.lang.String scopeName,
                                             java.lang.String paramName,
                                             java.lang.String paramValue,
                                             java.lang.String listAttribute)
                                      throws JspException
Throws:
JspException

message

public java.lang.String message(java.lang.String bundle,
                                java.lang.String key)
                         throws JspException
Look up and return a message string, based on the specified parameters.

Parameters:
bundle - Name of the servlet context attribute for our message resources bundle
key - Message key to be looked up and returned
Returns:
message string
Throws:
JspException - if a lookup error occurs (will have been saved in the request already)

message

public java.lang.String message(java.lang.String bundle,
                                java.util.Locale locale,
                                java.lang.String key)
Look up and return a message string, based on the specified parameters.

Parameters:
bundle -
locale -
key -
Returns:

message

public java.lang.String message(java.lang.String bundle,
                                java.lang.String key,
                                java.lang.Object[] args)
                         throws JspException
Look up and return a message string, based on the specified parameters.

Parameters:
bundle - Name of the servlet context attribute for our message resources bundle
key - Message key to be looked up and returned
args - Replacement parameters for this message
Returns:
message string
Throws:
JspException - if a lookup error occurs (will have been saved in the request already)

saveException

public void saveException(PageContext pageContext,
                          java.lang.Throwable exception)
Save the specified exception as a request attribute for later use.

Parameters:
pageContext - The PageContext for the current page
exception - The exception to be saved

write

public void write(PageContext pageContext,
                  java.lang.String text)
           throws JspException
Write the specified text as the response to the writer associated with this page. WARNING - If you are writing body content from the doAfterBody() method of a custom tag class that implements BodyTag, you should be calling writePrevious() instead.

Parameters:
pageContext - The PageContext object for this page
text - The text to be written
Throws:
JspException - if an input/output error occurs (already saved)

writePrevious

public void writePrevious(PageContext pageContext,
                          java.lang.String text)
                   throws JspException
Write the specified text as the response to the writer associated with the body content for the tag within which we are currently nested.

Parameters:
pageContext - The PageContext object for this page
text - The text to be written
Throws:
JspException - if an input/output error occurs (already saved)