org.apache.tapestry
Class Tapestry

java.lang.Object
  extended by org.apache.tapestry.Tapestry

public final class Tapestry
extends Object

A placeholder for a number of (static) methods that don't belong elsewhere, as well as a global location for static constants.

Since:
1.0.1
Version:
$Id: Tapestry.java 243955 2004-09-01 13:18:38Z ehatcher $
Author:
Howard Lewis Ship

Field Summary
static String ABSTRACTPAGE_DETACH_METHOD_ID
          Method id used to check that IPage.detach() is invoked.
static String ABSTRACTPAGE_VALIDATE_METHOD_ID
          Method id used to check that IPage.validate(IRequestCycle) is invoked.
static String ACTION_SERVICE
          The name ("action") of a service that allows behavior to be associated with an IAction component, such as ActionLink or Form.
static String ASSET_SERVICE
          The name ("asset") of a service used to access internal assets.
static String DEFAULT_TEMPLATE_EXTENSION
          The default extension for templates, "html".
static String DIRECT_SERVICE
          The name ("direct") of a service that allows stateless behavior for an DirectLink component.
static String EXTERNAL_SERVICE
          The name ("external") of a service that a allows IExternalPage to be selected.
static String HOME_SERVICE
          The name ("home") of a service that jumps to the home page.
static String LINK_COMPONENT_ATTRIBUTE_NAME
          The name of an IRequestCycle attribute in which the currently rendering ILinkComponent is stored.
static String MONITOR_FACTORY_EXTENSION_NAME
          Name of an application extension used as a factory for IMonitor instances.
static String MULTIPART_DECODER_EXTENSION_NAME
          Name of optional application extension for the multipart decoder used by the application.
static String OGNL_TYPE_CONVERTER
          Class name of an TypeConverter implementing class to use as a type converter for ExpressionBinding
static String PAGE_SERVICE
          The name ("page") of a service that allows a new page to be selected.
static String PARAMETER_PROPERTY_NAME_SUFFIX
          Suffix appended to a parameter name to form the name of a property that stores the binding for the parameter.
static String PARAMETERS_QUERY_PARAMETER_NAME
          The query parameter for application specific parameters to the service (this is used with the direct service).
static String REQUEST_DECODER_EXTENSION_NAME
          Key used to obtain an extension from the application specification.
static String RESET_SERVICE
          The name ("reset") of a service used to clear cached template and specification data and remove all pooled pages.
static String RESTART_SERVICE
          The name ("restart") of a service that invalidates the session and restarts the application.
static String SERVICE_QUERY_PARAMETER_NAME
          Query parameter that identfies the service for the request.
static String SIMPLE_PROPERTY_NAME_PATTERN
          Regular expression defining a simple property name.
static String SPECIFICATION_RESOLVER_DELEGATE_EXTENSION_NAME
          Name of application extension used to resolve page and component specifications that can't be located by the normal means.
static String TAG_SUPPORT_PARAMETERS_ATTRIBUTE
          Name of a request attribute used with the TAGSUPPORT_SERVICE service.
static String TAG_SUPPORT_SERVICE_ATTRIBUTE
          Name of a request attribute used with the TAGSUPPORT_SERVICE service.
static String TAG_SUPPORT_SERVLET_PATH_ATTRIBUTE
          Name of a request attribute used with the TAGSUPPORT_SERVICE service.
static String TAGSUPPORT_SERVICE
          Service used to support rendering of JSP tags.
static String TEMPLATE_EXTENSION_PROPERTY
          Property name used to get the extension used for templates.
static String TEMPLATE_SOURCE_DELEGATE_EXTENSION_NAME
          Name of application extension used to resolve page and component templates that can't be located by the normal means.
static String VERSION
          The version of the framework; this is updated for major releases.
 
Method Summary
static void addMethodInvocation(Object methodId)
          Adds a method invocation to the list of invocations.
static void checkMethodInvocation(Object methodId, String methodName, Object object)
          Checks to see if a particular method has been invoked.
static void clearMethodInvocations()
          Clears the list of method invocations.
static void close(InputStream stream)
          Closes the stream (if not null), ignoring any IOException thrown.
static Iterator coerceToIterator(Object value)
          Converts an Object into an Iterator, following some basic rules.
static Map convertArrayToMap(Object[] array)
          Converts an even-sized array of objects back into a Map.
static Object[] convertMapToArray(Map map)
          Converts a Map to an even-sized array of key/value pairs.
static void copyInformalBindings(IComponent source, IComponent destination)
          Copys all informal bindings from a source component to the destination component.
static ApplicationRuntimeException createNoSuchComponentException(IComponent component, String id, ILocation location)
           
static BindingException createNullBindingException(IBinding binding)
          Creates an exception indicating the binding value is null.
static ApplicationRuntimeException createRenderOnlyPropertyException(IComponent component, String propertyName)
           
static BindingException createRequiredParameterException(IComponent component, String parameterName)
           
static boolean evaluateBoolean(Object value)
          Evaluates an object to determine its boolean value.
static ILocation findLocation(Object[] locations)
          Selects the first ILocation in an array of objects.
static void fireObservedChange(IComponent component, String propertyName, boolean newValue)
          Method used by pages and components to send notifications about property changes.
static void fireObservedChange(IComponent component, String propertyName, byte newValue)
          Method used by pages and components to send notifications about property changes.
static void fireObservedChange(IComponent component, String propertyName, char newValue)
          Method used by pages and components to send notifications about property changes.
static void fireObservedChange(IComponent component, String propertyName, double newValue)
          Method used by pages and components to send notifications about property changes.
static void fireObservedChange(IComponent component, String propertyName, float newValue)
          Method used by pages and components to send notifications about property changes.
static void fireObservedChange(IComponent component, String propertyName, int newValue)
          Method used by pages and components to send notifications about property changes.
static void fireObservedChange(IComponent component, String propertyName, long newValue)
          Method used by pages and components to send notifications about property changes.
static void fireObservedChange(IComponent component, String propertyName, Object newValue)
          Method used by pages and components to send notifications about property changes.
static void fireObservedChange(IComponent component, String propertyName, short newValue)
          Method used by pages and components to send notifications about property changes.
static String format(String key, Object arg)
          Convienience method for invoking format(String, Object[]).
static String format(String key, Object[] args)
          Gets a string from the TapestryStrings resource bundle.
static String format(String key, Object arg1, Object arg2)
          Convienience method for invoking format(String, Object[]).
static String format(String key, Object arg1, Object arg2, Object arg3)
          Convienience method for invoking format(String, Object[]).
static IResourceLocation getApplicationRootLocation(IRequestCycle cycle)
          Returns the application root location, which is in the ServletContext, based on the servlet path.
static String getClassName(Class subject)
          Given a Class, creates a presentable name for the class, even if the class is a scalar type or Array type.
static Locale getLocale(String s)
          Gets the Locale for the given string, which is the result of Locale.toString().
static String getMessage(String key)
          Convienience method for invoking format(String, Object[]).
static boolean isBlank(String input)
          Returns true if the input is null or contains only whitespace.
static boolean isEmpty(Collection c)
          Returns true if the Collection is null or empty.
static boolean isEmpty(Map map)
          Returns true if the Map is null or empty.
static boolean isNonBlank(String input)
          Returns true if the input is not null and not empty (or only whitespace).
static int size(Collection c)
          Returns the size of a collection, or zero if the collection is null.
static int size(Object[] array)
          Returns the length of the array, or 0 if the array is null.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TAG_SUPPORT_SERVICE_ATTRIBUTE

public static final String TAG_SUPPORT_SERVICE_ATTRIBUTE
Name of a request attribute used with the TAGSUPPORT_SERVICE service. The attribute defines the underlying service to for which a URL will be generated.

Since:
3.0
See Also:
Constant Field Values

TAG_SUPPORT_SERVLET_PATH_ATTRIBUTE

public static final String TAG_SUPPORT_SERVLET_PATH_ATTRIBUTE
Name of a request attribute used with the TAGSUPPORT_SERVICE service. The attribute defines the correct servlet path for the Tapestry application (which, for the odd-man-out TAGSUPPORT_SERVICE may not match HttpServletRequest.getServletPath() because of the use of an include.

Since:
3.0
See Also:
Constant Field Values

TAG_SUPPORT_PARAMETERS_ATTRIBUTE

public static final String TAG_SUPPORT_PARAMETERS_ATTRIBUTE
Name of a request attribute used with the TAGSUPPORT_SERVICE service. The attribute defines an array of objects to be converted into service parameters (i.e., for use with the EXTERNAL_SERVICE).

Since:
3.0
See Also:
Constant Field Values

TAGSUPPORT_SERVICE

public static final String TAGSUPPORT_SERVICE
Service used to support rendering of JSP tags. tagsupport is provided with a service and service parameters via request attributes and creates a URI from the result, which is output to the response.

Since:
3.0
See Also:
Constant Field Values

ACTION_SERVICE

public static final String ACTION_SERVICE
The name ("action") of a service that allows behavior to be associated with an IAction component, such as ActionLink or Form.

This service is used with actions that are tied to the dynamic state of the page, and which require a rewind of the page.

See Also:
Constant Field Values

DIRECT_SERVICE

public static final String DIRECT_SERVICE
The name ("direct") of a service that allows stateless behavior for an DirectLink component.

This service rolls back the state of the page but doesn't rewind the the dynamic state of the page the was the action service does, which is more efficient but less powerful.

An array of String parameters may be included with the service URL; these will be made available to the DirectLink component's listener.

See Also:
Constant Field Values

EXTERNAL_SERVICE

public static final String EXTERNAL_SERVICE
The name ("external") of a service that a allows IExternalPage to be selected. Associated with a ExternalLink component.

This service enables IExternalPages to be accessed via a URL. External pages may be booked marked using their URL for future reference.

An array of Object parameters may be included with the service URL; these will be passed to the IExternalPage.activateExternalPage(Object[], IRequestCycle) method.

See Also:
Constant Field Values

PAGE_SERVICE

public static final String PAGE_SERVICE
The name ("page") of a service that allows a new page to be selected. Associated with a PageLink component.

The service requires a single parameter: the name of the target page.

See Also:
Constant Field Values

HOME_SERVICE

public static final String HOME_SERVICE
The name ("home") of a service that jumps to the home page. A stand-in for when no service is provided, which is typically the entrypoint to the application.

See Also:
Constant Field Values

RESTART_SERVICE

public static final String RESTART_SERVICE
The name ("restart") of a service that invalidates the session and restarts the application. Typically used just to recover from an exception.

See Also:
Constant Field Values

ASSET_SERVICE

public static final String ASSET_SERVICE
The name ("asset") of a service used to access internal assets.

See Also:
Constant Field Values

RESET_SERVICE

public static final String RESET_SERVICE
The name ("reset") of a service used to clear cached template and specification data and remove all pooled pages. This is only used when debugging as a quick way to clear the out cached data, to allow updated versions of specifications and templates to be loaded (without stopping and restarting the servlet container).

This service is only available if the Java system property org.apache.tapestry.enable-reset-service is set to true.

See Also:
Constant Field Values

SERVICE_QUERY_PARAMETER_NAME

public static final String SERVICE_QUERY_PARAMETER_NAME
Query parameter that identfies the service for the request.

Since:
1.0.3
See Also:
Constant Field Values

PARAMETERS_QUERY_PARAMETER_NAME

public static final String PARAMETERS_QUERY_PARAMETER_NAME
The query parameter for application specific parameters to the service (this is used with the direct service). Each of these values is encoded with URLEncoder.encode(String) before being added to the URL. Multiple values are handle by repeatedly establishing key/value pairs (this is a change from behavior in 2.1 and earlier).

Since:
1.0.3
See Also:
Constant Field Values

TEMPLATE_EXTENSION_PROPERTY

public static final String TEMPLATE_EXTENSION_PROPERTY
Property name used to get the extension used for templates. This may be set in the page or component specification, or in the page (or component's) immediate container (library or application specification). Unlike most properties, value isn't inherited all the way up the chain. The default template extension is "html".

Since:
3.0
See Also:
Constant Field Values

DEFAULT_TEMPLATE_EXTENSION

public static final String DEFAULT_TEMPLATE_EXTENSION
The default extension for templates, "html".

Since:
3.0
See Also:
Constant Field Values

LINK_COMPONENT_ATTRIBUTE_NAME

public static final String LINK_COMPONENT_ATTRIBUTE_NAME
The name of an IRequestCycle attribute in which the currently rendering ILinkComponent is stored. Link components do not nest.

See Also:
Constant Field Values

PARAMETER_PROPERTY_NAME_SUFFIX

public static final String PARAMETER_PROPERTY_NAME_SUFFIX
Suffix appended to a parameter name to form the name of a property that stores the binding for the parameter.

Since:
3.0
See Also:
Constant Field Values

SPECIFICATION_RESOLVER_DELEGATE_EXTENSION_NAME

public static final String SPECIFICATION_RESOLVER_DELEGATE_EXTENSION_NAME
Name of application extension used to resolve page and component specifications that can't be located by the normal means. The extension must implement ISpecificationResolverDelegate.

Since:
3.0
See Also:
Constant Field Values

TEMPLATE_SOURCE_DELEGATE_EXTENSION_NAME

public static final String TEMPLATE_SOURCE_DELEGATE_EXTENSION_NAME
Name of application extension used to resolve page and component templates that can't be located by the normal means. The extension must implement ITemplateSourceDelegate.

Since:
3.0
See Also:
Constant Field Values

REQUEST_DECODER_EXTENSION_NAME

public static final String REQUEST_DECODER_EXTENSION_NAME
Key used to obtain an extension from the application specification. The extension, if it exists, implements IRequestDecoder.

Since:
2.2
See Also:
Constant Field Values

MULTIPART_DECODER_EXTENSION_NAME

public static final String MULTIPART_DECODER_EXTENSION_NAME
Name of optional application extension for the multipart decoder used by the application. The extension must implement IMultipartDecoder (and is generally a configured instance of DefaultMultipartDecoder).

Since:
3.0
See Also:
Constant Field Values

ABSTRACTPAGE_VALIDATE_METHOD_ID

public static final String ABSTRACTPAGE_VALIDATE_METHOD_ID
Method id used to check that IPage.validate(IRequestCycle) is invoked.

Since:
3.0
See Also:
checkMethodInvocation(Object, String, Object), Constant Field Values

ABSTRACTPAGE_DETACH_METHOD_ID

public static final String ABSTRACTPAGE_DETACH_METHOD_ID
Method id used to check that IPage.detach() is invoked.

Since:
3.0
See Also:
checkMethodInvocation(Object, String, Object), Constant Field Values

SIMPLE_PROPERTY_NAME_PATTERN

public static final String SIMPLE_PROPERTY_NAME_PATTERN
Regular expression defining a simple property name. Used by several different parsers. Simple property names match Java variable names; a leading letter (or underscore), followed by letters, numbers and underscores.

Since:
3.0
See Also:
Constant Field Values

MONITOR_FACTORY_EXTENSION_NAME

public static final String MONITOR_FACTORY_EXTENSION_NAME
Name of an application extension used as a factory for IMonitor instances. The extension must implement IMonitorFactory.

Since:
3.0
See Also:
Constant Field Values

OGNL_TYPE_CONVERTER

public static final String OGNL_TYPE_CONVERTER
Class name of an TypeConverter implementing class to use as a type converter for ExpressionBinding

See Also:
Constant Field Values

VERSION

public static final String VERSION
The version of the framework; this is updated for major releases.

Method Detail

copyInformalBindings

public static void copyInformalBindings(IComponent source,
                                        IComponent destination)
Copys all informal bindings from a source component to the destination component. Informal bindings are bindings for informal parameters. This will overwrite parameters (formal or informal) in the destination component if there is a naming conflict.


evaluateBoolean

public static boolean evaluateBoolean(Object value)
Evaluates an object to determine its boolean value.
Class Test
Boolean Self explanatory.
Number True if non-zero, false otherwise.
Collection True if contains any elements (non-zero size), false otherwise.
String True if contains any non-whitespace characters, false otherwise.
Any Object array type True if contains any elements (non-zero length), false otherwise.

Any other non-null object evaluates to true.


coerceToIterator

public static Iterator coerceToIterator(Object value)
Converts an Object into an Iterator, following some basic rules.
Input Class Result
array Converted to a List and iterator returned. null returned if the array is empty. This works with both object arrays and arrays of scalars.
Iterator Returned as-is.
Collection Iterator returned, or null if the Collection is empty
Any other Iterator for singleton collection returned
null null returned


getLocale

public static Locale getLocale(String s)
Gets the Locale for the given string, which is the result of Locale.toString(). If no such locale is already registered, a new instance is created, registered and returned.


close

public static void close(InputStream stream)
Closes the stream (if not null), ignoring any IOException thrown.

Since:
1.0.2

format

public static String format(String key,
                            Object[] args)
Gets a string from the TapestryStrings resource bundle. The string in the bundle is treated as a pattern for MessageFormat.format(java.lang.String, java.lang.Object[]).

Since:
1.0.8

getMessage

public static String getMessage(String key)
Convienience method for invoking format(String, Object[]).

Since:
3.0

format

public static String format(String key,
                            Object arg)
Convienience method for invoking format(String, Object[]).

Since:
3.0

format

public static String format(String key,
                            Object arg1,
                            Object arg2)
Convienience method for invoking format(String, Object[]).

Since:
3.0

format

public static String format(String key,
                            Object arg1,
                            Object arg2,
                            Object arg3)
Convienience method for invoking format(String, Object[]).

Since:
3.0

size

public static int size(Collection c)
Returns the size of a collection, or zero if the collection is null.

Since:
2.2

size

public static int size(Object[] array)
Returns the length of the array, or 0 if the array is null.

Since:
2.2

isEmpty

public static boolean isEmpty(Map map)
Returns true if the Map is null or empty.

Since:
3.0

isEmpty

public static boolean isEmpty(Collection c)
Returns true if the Collection is null or empty.

Since:
3.0

convertMapToArray

public static Object[] convertMapToArray(Map map)
Converts a Map to an even-sized array of key/value pairs. This may be useful when using a Map as service parameters (with DirectLink. Assuming the keys and values are simple objects (String, Boolean, Integer, etc.), then the representation as an array will encode more efficiently (via DataSqueezer than serializing the Map and its contents.

Returns:
the array of keys and values, or null if the input Map is null or empty
Since:
2.2

convertArrayToMap

public static Map convertArrayToMap(Object[] array)
Converts an even-sized array of objects back into a Map.

Returns:
a Map, or null if the array is null or empty
Since:
2.2
See Also:
convertMapToArray(Map)

getApplicationRootLocation

public static IResourceLocation getApplicationRootLocation(IRequestCycle cycle)
Returns the application root location, which is in the ServletContext, based on the servlet path.

Since:
3.0

getClassName

public static String getClassName(Class subject)
Given a Class, creates a presentable name for the class, even if the class is a scalar type or Array type.

Since:
3.0

findLocation

public static ILocation findLocation(Object[] locations)
Selects the first ILocation in an array of objects. Skips over nulls. The objects may be instances of {Location or ILocatable. May return null if no Location found found.


createNullBindingException

public static BindingException createNullBindingException(IBinding binding)
Creates an exception indicating the binding value is null.

Since:
3.0

createNoSuchComponentException

public static ApplicationRuntimeException createNoSuchComponentException(IComponent component,
                                                                         String id,
                                                                         ILocation location)
Since:
3.0

createRequiredParameterException

public static BindingException createRequiredParameterException(IComponent component,
                                                                String parameterName)
Since:
3.0

createRenderOnlyPropertyException

public static ApplicationRuntimeException createRenderOnlyPropertyException(IComponent component,
                                                                            String propertyName)
Since:
3.0

clearMethodInvocations

public static void clearMethodInvocations()
Clears the list of method invocations.

Since:
3.0
See Also:
checkMethodInvocation(Object, String, Object)

addMethodInvocation

public static void addMethodInvocation(Object methodId)
Adds a method invocation to the list of invocations. This is done in a super-class implementations.

Since:
3.0
See Also:
checkMethodInvocation(Object, String, Object)

checkMethodInvocation

public static void checkMethodInvocation(Object methodId,
                                         String methodName,
                                         Object object)
Checks to see if a particular method has been invoked. The method is identified by a methodId (usually a String). The methodName and object are used to create an error message.

The caller should invoke clearMethodInvocations(), then invoke a method on the object. The super-class implementation should invoke addMethodInvocation(Object) to indicate that it was, in fact, invoked. The caller then invokes this method to vlaidate that the super-class implementation was invoked.

The list of method invocations is stored in a ThreadLocal variable.

Since:
3.0

fireObservedChange

public static void fireObservedChange(IComponent component,
                                      String propertyName,
                                      Object newValue)
Method used by pages and components to send notifications about property changes.

Parameters:
component - the component containing the property
propertyName - the name of the property which changed
newValue - the new value for the property
Since:
3.0

fireObservedChange

public static void fireObservedChange(IComponent component,
                                      String propertyName,
                                      boolean newValue)
Method used by pages and components to send notifications about property changes.

Parameters:
component - the component containing the property
propertyName - the name of the property which changed
newValue - the new value for the property
Since:
3.0

fireObservedChange

public static void fireObservedChange(IComponent component,
                                      String propertyName,
                                      double newValue)
Method used by pages and components to send notifications about property changes.

Parameters:
component - the component containing the property
propertyName - the name of the property which changed
newValue - the new value for the property
Since:
3.0

fireObservedChange

public static void fireObservedChange(IComponent component,
                                      String propertyName,
                                      float newValue)
Method used by pages and components to send notifications about property changes.

Parameters:
component - the component containing the property
propertyName - the name of the property which changed
newValue - the new value for the property
Since:
3.0

fireObservedChange

public static void fireObservedChange(IComponent component,
                                      String propertyName,
                                      int newValue)
Method used by pages and components to send notifications about property changes.

Parameters:
component - the component containing the property
propertyName - the name of the property which changed
newValue - the new value for the property
Since:
3.0

fireObservedChange

public static void fireObservedChange(IComponent component,
                                      String propertyName,
                                      long newValue)
Method used by pages and components to send notifications about property changes.

Parameters:
component - the component containing the property
propertyName - the name of the property which changed
newValue - the new value for the property
Since:
3.0

fireObservedChange

public static void fireObservedChange(IComponent component,
                                      String propertyName,
                                      char newValue)
Method used by pages and components to send notifications about property changes.

Parameters:
component - the component containing the property
propertyName - the name of the property which changed
newValue - the new value for the property
Since:
3.0

fireObservedChange

public static void fireObservedChange(IComponent component,
                                      String propertyName,
                                      byte newValue)
Method used by pages and components to send notifications about property changes.

Parameters:
component - the component containing the property
propertyName - the name of the property which changed
newValue - the new value for the property
Since:
3.0

fireObservedChange

public static void fireObservedChange(IComponent component,
                                      String propertyName,
                                      short newValue)
Method used by pages and components to send notifications about property changes.

Parameters:
component - the component containing the property
propertyName - the name of the property which changed
newValue - the new value for the property
Since:
3.0

isBlank

public static boolean isBlank(String input)
Returns true if the input is null or contains only whitespace.

Note: Yes, you'd think we'd use StringUtils, but with the change in names and behavior between releases, it is smarter to just implement our own little method!

Since:
3.0

isNonBlank

public static boolean isNonBlank(String input)
Returns true if the input is not null and not empty (or only whitespace).

Since:
3.0