org.alfresco.web.ui.common
Class Utils

java.lang.Object
  extended by org.springframework.extensions.webscripts.ui.common.StringUtils
      extended by org.alfresco.web.ui.common.Utils

public final class Utils
extends org.springframework.extensions.webscripts.ui.common.StringUtils

Class containing misc helper methods used by the JSF components.


Nested Class Summary
static class Utils.URLMode
          Enum representing the client URL type to generate
 
Field Summary
static java.lang.String USER_AGENT_FIREFOX
           
static java.lang.String USER_AGENT_MSIE
           
 
Fields inherited from class org.springframework.extensions.webscripts.ui.common.StringUtils
safeTags, unsafeAttrs
 
Method Summary
static void addErrorMessage(java.lang.String msg)
          Adds a global error message
static void addErrorMessage(java.lang.String msg, java.lang.Throwable err)
          Adds a global error message and logs exception details
static void addStatusMessage(javax.faces.application.FacesMessage.Severity severity, java.lang.String msg)
          Adds a global status message that will be displayed by a Status Message UI component
static java.lang.String buildImageTag(javax.faces.context.FacesContext context, java.lang.String image, int width, int height, java.lang.String alt)
          Build a context path safe image tag for the supplied image path.
static java.lang.String buildImageTag(javax.faces.context.FacesContext context, java.lang.String image, int width, int height, java.lang.String alt, java.lang.String onclick)
          Build a context path safe image tag for the supplied image path.
static java.lang.String buildImageTag(javax.faces.context.FacesContext context, java.lang.String image, int width, int height, java.lang.String alt, java.lang.String onclick, java.lang.String verticalAlign)
          Build a context path safe image tag for the supplied image path.
static java.lang.String buildImageTag(javax.faces.context.FacesContext context, java.lang.String image, int width, int height, java.lang.String alt, java.lang.String onclick, java.lang.String verticalAlign, java.lang.String style)
          Build a context path safe image tag for the supplied image path.
static java.lang.String buildImageTag(javax.faces.context.FacesContext context, java.lang.String image, java.lang.String alt)
          Build a context path safe image tag for the supplied image path.
static java.lang.String buildImageTag(javax.faces.context.FacesContext context, java.lang.String image, java.lang.String alt, java.lang.String verticalAlign)
          Build a context path safe image tag for the supplied image path.
static void encodeRecursive(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component)
          Helper to recursively render a component and it's child components
static java.lang.String generateFormSubmit(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component)
          Generate the JavaScript to submit the parent Form.
static java.lang.String generateFormSubmit(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component, java.lang.String fieldId, java.lang.String fieldValue)
          Generate the JavaScript to submit set the specified hidden Form field to the supplied value and submit the parent Form.
static java.lang.String generateFormSubmit(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component, java.lang.String fieldId, java.lang.String fieldValue, boolean valueIsParam, java.util.Map params)
          Generate the JavaScript to submit set the specified hidden Form field to the supplied value and submit the parent Form.
static java.lang.String generateFormSubmit(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component, java.lang.String fieldId, java.lang.String fieldValue, java.util.Map params)
          Generate the JavaScript to submit set the specified hidden Form field to the supplied value and submit the parent Form.
static java.util.List generatePersonFilter(java.lang.String term)
          Generate the QName filter for a standard Person lookup.
static void generatePersonSearch(java.lang.StringBuilder query, java.lang.String term)
          Deprecated. Use Utils.generatePersonFilter(String) and PersonService.getPeople(List, boolean, List, org.alfresco.query.PagingRequest) instead
static java.util.List generatePersonSort()
          Generate the QName sort for a standard Person lookup.
static java.lang.String generateURL(javax.faces.context.FacesContext context, Node node, java.lang.String name, Utils.URLMode usage)
          Generates a URL for the given usage for the given node.
static java.lang.String generateURL(javax.faces.context.FacesContext context, Node node, Utils.URLMode usage)
          Generates a URL for the given usage for the given node.
static java.lang.String getActionHiddenFieldName(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component)
          Get the hidden field name for any action component.
static java.text.DateFormat getDateFormat(javax.faces.context.FacesContext fc)
           
static java.text.DateFormat getDateTimeFormat(javax.faces.context.FacesContext fc)
           
static java.lang.String getDescription(javax.faces.context.FacesContext context, org.springframework.extensions.config.ConfigElement configElement)
          Given a ConfigElement instance retrieve the description, this could be dervied from a message bundle key or a literal string
static java.lang.String getDisplayLabel(javax.faces.context.FacesContext context, org.springframework.extensions.config.ConfigElement configElement)
          Given a ConfigElement instance retrieve the display label, this could be dervied from a message bundle key or a literal string
static IDataContainer getParentDataContainer(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component)
          Return the parent UIComponent implementing the IDataContainer interface for the specified UIComponent.
static javax.faces.component.UIForm getParentForm(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component)
          Return the parent UIForm component for the specified UIComponent
static javax.faces.component.UIComponent getParentNamingContainer(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component)
          Return the parent UIComponent implementing the NamingContainer interface for the specified UIComponent.
static int getPersonMaxResults()
          How many results should a person search return up to? This is needed because the JSF components do paging differently.
static java.text.DateFormat getTimeFormat(javax.faces.context.FacesContext fc)
           
static java.lang.String getUserAgent(javax.faces.context.FacesContext context)
           
static boolean isComponentDisabledOrReadOnly(javax.faces.component.UIComponent component)
          Determines whether the given component is disabled or readonly
static void outputAttribute(javax.faces.context.ResponseWriter out, java.lang.Object attr, java.lang.String mapping)
          Helper to output an attribute to the output stream
static java.util.Date parseXMLDateFormat(java.lang.String isoDate)
          Parse XML format date YYYY-MM-DDTHH:MM:SS
static void processActionMethod(javax.faces.context.FacesContext context, javax.faces.el.MethodBinding method, javax.faces.event.ActionEvent event)
          Invoke the method encapsulated by the supplied MethodBinding
 
Methods inherited from class org.springframework.extensions.webscripts.ui.common.StringUtils
cropEncode, cropEncode, encode, encodeJavascript, join, join, remove, replace, replaceLineBreaks, stripUnsafeHTMLTags, stripUnsafeHTMLTags
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

USER_AGENT_FIREFOX

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

USER_AGENT_MSIE

public static final java.lang.String USER_AGENT_MSIE
See Also:
Constant Field Values
Method Detail

outputAttribute

public static void outputAttribute(javax.faces.context.ResponseWriter out,
                                   java.lang.Object attr,
                                   java.lang.String mapping)
                            throws java.io.IOException
Helper to output an attribute to the output stream

Parameters:
out - ResponseWriter
attr - attribute value object (cannot be null)
mapping - mapping to output as e.g. style="..."
Throws:
java.io.IOException

getActionHiddenFieldName

public static java.lang.String getActionHiddenFieldName(javax.faces.context.FacesContext context,
                                                        javax.faces.component.UIComponent component)
Get the hidden field name for any action component. All components that wish to simply encode a form value with their client ID can reuse the same hidden field within the parent form. NOTE: components which use this method must only encode their client ID as the value and nothing else! Build a shared field name from the parent form name and the string "act".

Returns:
hidden field name shared by all action components within the Form.

encodeRecursive

public static void encodeRecursive(javax.faces.context.FacesContext context,
                                   javax.faces.component.UIComponent component)
                            throws java.io.IOException
Helper to recursively render a component and it's child components

Parameters:
context - FacesContext
component - UIComponent
Throws:
java.io.IOException

generateFormSubmit

public static java.lang.String generateFormSubmit(javax.faces.context.FacesContext context,
                                                  javax.faces.component.UIComponent component,
                                                  java.lang.String fieldId,
                                                  java.lang.String fieldValue)
Generate the JavaScript to submit set the specified hidden Form field to the supplied value and submit the parent Form. NOTE: the supplied hidden field name is added to the Form Renderer map for output.

Parameters:
context - FacesContext
component - UIComponent to generate JavaScript for
fieldId - Hidden field id to set value for
fieldValue - Hidden field value to set hidden field too on submit
Returns:
JavaScript event code

generateFormSubmit

public static java.lang.String generateFormSubmit(javax.faces.context.FacesContext context,
                                                  javax.faces.component.UIComponent component,
                                                  java.lang.String fieldId,
                                                  java.lang.String fieldValue,
                                                  java.util.Map params)
Generate the JavaScript to submit set the specified hidden Form field to the supplied value and submit the parent Form. NOTE: the supplied hidden field name is added to the Form Renderer map for output.

Parameters:
context - FacesContext
component - UIComponent to generate JavaScript for
fieldId - Hidden field id to set value for
fieldValue - Hidden field value to set hidden field too on submit
params - Optional map of param name/values to output
Returns:
JavaScript event code

generateFormSubmit

public static java.lang.String generateFormSubmit(javax.faces.context.FacesContext context,
                                                  javax.faces.component.UIComponent component,
                                                  java.lang.String fieldId,
                                                  java.lang.String fieldValue,
                                                  boolean valueIsParam,
                                                  java.util.Map params)
Generate the JavaScript to submit set the specified hidden Form field to the supplied value and submit the parent Form. NOTE: the supplied hidden field name is added to the Form Renderer map for output.

Parameters:
context - FacesContext
component - UIComponent to generate JavaScript for
fieldId - Hidden field id to set value for
fieldValue - Hidden field value to set hidden field too on submit
valueIsParam - Determines whether the fieldValue parameter should be treated as a parameter in the generated JavaScript, false will treat the value i.e. surround it with single quotes
params - Optional map of param name/values to output
Returns:
JavaScript event code

generateFormSubmit

public static java.lang.String generateFormSubmit(javax.faces.context.FacesContext context,
                                                  javax.faces.component.UIComponent component)
Generate the JavaScript to submit the parent Form.

Parameters:
context - FacesContext
component - UIComponent to generate JavaScript for
Returns:
JavaScript event code

generateURL

public static java.lang.String generateURL(javax.faces.context.FacesContext context,
                                           Node node,
                                           java.lang.String name,
                                           Utils.URLMode usage)
Generates a URL for the given usage for the given node. If the URL cannot be generated then null is returned. The supported values for the usage parameter are of URLMode enum type

Parameters:
context - Faces context
node - The node to generate the URL for
name - Name to use for the download file part of the link if any
usage - What the URL is going to be used for
Returns:
The URL for the requested usage without the context path
See Also:
Utils.URLMode

generateURL

public static java.lang.String generateURL(javax.faces.context.FacesContext context,
                                           Node node,
                                           Utils.URLMode usage)
Generates a URL for the given usage for the given node. The supported values for the usage parameter are of URLMode enum type

Parameters:
context - Faces context
node - The node to generate the URL for
usage - What the URL is going to be used for
Returns:
The URL for the requested usage without the context path
See Also:
Utils.URLMode

buildImageTag

public static java.lang.String buildImageTag(javax.faces.context.FacesContext context,
                                             java.lang.String image,
                                             int width,
                                             int height,
                                             java.lang.String alt,
                                             java.lang.String onclick)
Build a context path safe image tag for the supplied image path. Image path should be supplied with a leading slash '/'.

Parameters:
context - FacesContext
image - The local image path from the web folder with leading slash '/'
width - Width in pixels
height - Height in pixels
alt - Optional alt/title text
onclick - JavaScript onclick event handler code
Returns:
Populated img tag

buildImageTag

public static java.lang.String buildImageTag(javax.faces.context.FacesContext context,
                                             java.lang.String image,
                                             int width,
                                             int height,
                                             java.lang.String alt,
                                             java.lang.String onclick,
                                             java.lang.String verticalAlign)
Build a context path safe image tag for the supplied image path. Image path should be supplied with a leading slash '/'.

Parameters:
context - FacesContext
image - The local image path from the web folder with leading slash '/'
width - Width in pixels
height - Height in pixels
alt - Optional alt/title text
onclick - JavaScript onclick event handler code
verticalAlign - Optional HTML alignment value
Returns:
Populated img tag

buildImageTag

public static java.lang.String buildImageTag(javax.faces.context.FacesContext context,
                                             java.lang.String image,
                                             int width,
                                             int height,
                                             java.lang.String alt,
                                             java.lang.String onclick,
                                             java.lang.String verticalAlign,
                                             java.lang.String style)
Build a context path safe image tag for the supplied image path. Image path should be supplied with a leading slash '/'.

Parameters:
context - FacesContext
image - The local image path from the web folder with leading slash '/'
width - Width in pixels
height - Height in pixels
alt - Optional alt/title text
onclick - JavaScript onclick event handler code
verticalAlign - Optional HTML alignment value
style - Optional inline CSS styling
Returns:
Populated img tag

buildImageTag

public static java.lang.String buildImageTag(javax.faces.context.FacesContext context,
                                             java.lang.String image,
                                             int width,
                                             int height,
                                             java.lang.String alt)
Build a context path safe image tag for the supplied image path. Image path should be supplied with a leading slash '/'.

Parameters:
context - FacesContext
image - The local image path from the web folder with leading slash '/'
width - Width in pixels
height - Height in pixels
alt - Optional alt/title text
Returns:
Populated img tag

buildImageTag

public static java.lang.String buildImageTag(javax.faces.context.FacesContext context,
                                             java.lang.String image,
                                             java.lang.String alt)
Build a context path safe image tag for the supplied image path. Image path should be supplied with a leading slash '/'.

Parameters:
context - FacesContext
image - The local image path from the web folder with leading slash '/'
alt - Optional alt/title text
Returns:
Populated img tag

buildImageTag

public static java.lang.String buildImageTag(javax.faces.context.FacesContext context,
                                             java.lang.String image,
                                             java.lang.String alt,
                                             java.lang.String verticalAlign)
Build a context path safe image tag for the supplied image path. Image path should be supplied with a leading slash '/'.

Parameters:
context - FacesContext
image - The local image path from the web folder with leading slash '/'
alt - Optional alt/title text
verticalAlign - Optional HTML alignment value
Returns:
Populated img tag

getParentForm

public static javax.faces.component.UIForm getParentForm(javax.faces.context.FacesContext context,
                                                         javax.faces.component.UIComponent component)
Return the parent UIForm component for the specified UIComponent

Parameters:
context - FaceContext
component - The UIComponent to find parent Form for
Returns:
UIForm parent or null if none found in hiearachy

getParentNamingContainer

public static javax.faces.component.UIComponent getParentNamingContainer(javax.faces.context.FacesContext context,
                                                                         javax.faces.component.UIComponent component)
Return the parent UIComponent implementing the NamingContainer interface for the specified UIComponent.

Parameters:
context - FaceContext
component - The UIComponent to find parent Form for
Returns:
NamingContainer parent or null if none found in hiearachy

getParentDataContainer

public static IDataContainer getParentDataContainer(javax.faces.context.FacesContext context,
                                                    javax.faces.component.UIComponent component)
Return the parent UIComponent implementing the IDataContainer interface for the specified UIComponent.

Parameters:
context - FaceContext
component - The UIComponent to find parent IDataContainer for
Returns:
IDataContainer parent or null if none found in hiearachy

isComponentDisabledOrReadOnly

public static boolean isComponentDisabledOrReadOnly(javax.faces.component.UIComponent component)
Determines whether the given component is disabled or readonly

Parameters:
component - The component to test
Returns:
true if the component is either disabled or set to readonly

processActionMethod

public static void processActionMethod(javax.faces.context.FacesContext context,
                                       javax.faces.el.MethodBinding method,
                                       javax.faces.event.ActionEvent event)
Invoke the method encapsulated by the supplied MethodBinding

Parameters:
context - FacesContext
method - MethodBinding to invoke
event - ActionEvent to pass to the method of signature: public void myMethodName(ActionEvent event)

addErrorMessage

public static void addErrorMessage(java.lang.String msg)
Adds a global error message

Parameters:
msg - The error message

addErrorMessage

public static void addErrorMessage(java.lang.String msg,
                                   java.lang.Throwable err)
Adds a global error message and logs exception details

Parameters:
msg - The error message
err - The exception to log

addStatusMessage

public static void addStatusMessage(javax.faces.application.FacesMessage.Severity severity,
                                    java.lang.String msg)
Adds a global status message that will be displayed by a Status Message UI component

Parameters:
severity - Severity of the message
msg - Text of the message

getTimeFormat

public static java.text.DateFormat getTimeFormat(javax.faces.context.FacesContext fc)
Returns:
the formatter for locale sensitive Time formatting

getDateFormat

public static java.text.DateFormat getDateFormat(javax.faces.context.FacesContext fc)
Returns:
the formatter for locale sensitive Date formatting

getDateTimeFormat

public static java.text.DateFormat getDateTimeFormat(javax.faces.context.FacesContext fc)
Returns:
the formatter for locale sensitive Date & Time formatting

parseXMLDateFormat

public static java.util.Date parseXMLDateFormat(java.lang.String isoDate)
Parse XML format date YYYY-MM-DDTHH:MM:SS

Parameters:
isoDate -
Returns:
Date or null if failed to parse

getDisplayLabel

public static java.lang.String getDisplayLabel(javax.faces.context.FacesContext context,
                                               org.springframework.extensions.config.ConfigElement configElement)
Given a ConfigElement instance retrieve the display label, this could be dervied from a message bundle key or a literal string

Parameters:
context - FacesContext
configElement - The ConfigElement to test
Returns:
The resolved display label

getDescription

public static java.lang.String getDescription(javax.faces.context.FacesContext context,
                                              org.springframework.extensions.config.ConfigElement configElement)
Given a ConfigElement instance retrieve the description, this could be dervied from a message bundle key or a literal string

Parameters:
context - FacesContext
configElement - The ConfigElement to test
Returns:
The resolved description

getUserAgent

public static java.lang.String getUserAgent(javax.faces.context.FacesContext context)
Returns:
the browser User-Agent header value trimmed to either "Firefox" or "MSIE" as appropriate.

generatePersonSort

public static java.util.List generatePersonSort()
Generate the QName sort for a standard Person lookup. The filter is standardised across multiple JSF components and beans, and used with PersonService.getPeople(List, boolean, List, org.alfresco.query.PagingRequest)


generatePersonFilter

public static java.util.List generatePersonFilter(java.lang.String term)
Generate the QName filter for a standard Person lookup. The filter is standardised across multiple JSF components and beans, and used with PersonService.getPeople(List, boolean, List, org.alfresco.query.PagingRequest)

Parameters:
term - Search term

getPersonMaxResults

public static int getPersonMaxResults()
How many results should a person search return up to? This is needed because the JSF components do paging differently. For now, hard coded at 1000, may be configurable later


generatePersonSearch

public static void generatePersonSearch(java.lang.StringBuilder query,
                                        java.lang.String term)
Deprecated. Use Utils.generatePersonFilter(String) and PersonService.getPeople(List, boolean, List, org.alfresco.query.PagingRequest) instead

Generate the Lucene query for a standard Person search. The query used is standardised across multiple JSF components and beans.

Parameters:
query - Buffer for the query
term - Search term


Copyright © 2005 - 2010 Alfresco Software, Inc. All Rights Reserved.