com.acsinet_solutions.cetia4.controller
Class ControllerTools

java.lang.Object
  extended by com.acsinet_solutions.cetia4.controller.ControllerTools
All Implemented Interfaces:
AttributeKeys, ControllerConstants

public final class ControllerTools
extends java.lang.Object
implements ControllerConstants

Servlet and controller-related utilities. TODO: Separar - crear un helper de locales

Author:
Santiago Arriaga

Field Summary
 
Fields inherited from interface com.acsinet_solutions.cetia4.controller.ControllerConstants
_METHOD_PARAM, _PAGE_PARAM, _ROOT_PARAM, DEFAULT_VIEW, ERROR_URL, ERROR_VIEW, LOAD_CANCEL, LOAD_CURRENT, LOAD_DEFAULT, LOAD_ERROR, LOAD_PREVIOUS
 
Fields inherited from interface com.acsinet_solutions.cetia4.controller.AttributeKeys
_BUNDLE_KEY, _CONFIGURATION_KEY, _DEFAULT_CONTROLLER_KEY, _FORM_ACTION_KEY, _FORM_ATTRIBUTE_KEY, _LOCALE_KEY, _MESSAGE_KEY, _NAVIGATION_FLOW_KEY, _PORTAL_PATH_KEY, _RENDER_PARAMETERS_KEY, _SERVICE_LOCATOR_KEY, _SESSION_KEY, _SYSTEM_EXCEPTION_KEY, _VALIDATION_EXCEPTION_KEY
 
Constructor Summary
ControllerTools()
           
 
Method Summary
static java.lang.String appendQueryString(java.lang.String page, java.lang.String suffix)
          Append the given suffix to the query string.
static Configuration getConfiguration(javax.servlet.ServletContext context)
          Get the configuration object reference to the global configuration of the current application, create it if it does not exist.
static Configuration getConfiguration(javax.servlet.ServletContext context, javax.servlet.ServletConfig config)
          Get a configuration object reference for the given context and config reference.
static Link getLink(javax.servlet.http.HttpServletRequest request)
          Create a link from a request instance, that contains all request parameters.
static Link getLink(RequestContext context)
          Create a link from a RequestContext instance.
static java.util.Locale getLocale(javax.servlet.jsp.PageContext context)
          Get the locale configured for the current context request.
static NavigationFlow getNavigationFlow(javax.servlet.http.HttpServletRequest request)
          Get the navigation flow for the current application.
static NavigationFlow getNavigationFlow(RequestContext context)
          Get the navigation flow for the current application.
static java.lang.String getPortalPath(javax.servlet.ServletContext context, javax.servlet.http.HttpServletRequest request)
          Get the basic portal path from the context and request instances.
static java.lang.String getRequestedController(javax.servlet.http.HttpServletRequest request)
          Get the original request string, not containing the context path and query string, but containing path info: http://host:8080/contextpath/server/pathinfo?query=string
static java.lang.String getRequestedPage(javax.servlet.http.HttpServletRequest request)
          Get the original request string URI, containing both path info and query String: http://host:8080/contextpath/server/pathinfo?query=string
static java.lang.String getRequestedServlet(javax.servlet.http.HttpServletRequest request)
          Get the original request string, not containing the context path, but containing both path info and query string: http://host:8080/contextpath/server/pathinfo?query=string
static ServiceLocator getServiceLocator(RequestContext context)
          Get the service locator, if any was configured.
static ServiceLocator getServiceLocator(javax.servlet.ServletContext context)
          Get the service locator, if any was configured.
static Link getSpecialLink(NavigationFlow flow, java.lang.String view)
          Get the link associated with the given special view in the given NavigationFlow instance.
static java.lang.String getText(javax.servlet.jsp.PageContext pageContext, java.lang.String key, java.lang.Object... params)
          Get a localized message using the default JSTL-configured locale.
static java.lang.String getText(RequestContext context, java.lang.String key, java.lang.Object... params)
          Get a localized message using the default JSTL-configured locale.
static void initLocaleAndBundle(javax.servlet.ServletContext context)
          Load the JSTL application resource bundle as a map in the context, if provided.
static void loadResourceBundleMap(javax.servlet.ServletContext context, java.util.Locale locale)
          Load the resource bundle configured for the current application as a map implementation.
static boolean requestAccepts(javax.servlet.http.HttpServletRequest request, java.lang.String type, java.lang.String subType)
          Check if the given HTTP request accepts the given MIME-type.
static void resetMap(RequestContext context, java.lang.String key)
          Convenience method for reseting a context map.
static void resetMap(javax.servlet.ServletContext context, java.lang.String key)
          Convenience method for reseting a context map.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ControllerTools

public ControllerTools()
Method Detail

appendQueryString

public static final java.lang.String appendQueryString(java.lang.String page,
                                                       java.lang.String suffix)
Append the given suffix to the query string.

Parameters:
page - A not-null String URI or URL. May have already a query string specified, this method will check if a leading '?' or '&' is needed for the new suffix.
suffix - A maybe-null, maybe-empty query string suffix with no '?' or '&' leading character.
Returns:
A not-null String

getLink

public static Link getLink(javax.servlet.http.HttpServletRequest request)
Create a link from a request instance, that contains all request parameters. The returned link does not contain protocol, server or port information, it's just an URI for internal use within an application. This method does not currently work well when using multiple parameters with the same name; this may be corrected if needed in the future.

Parameters:
request - A not-null HttpServletRequest instance

getLink

public static Link getLink(RequestContext context)
Create a link from a RequestContext instance. Similar to the other getLink() method, but operates on a RequestContext instance.

Parameters:
request - A not-null HttpServletRequest instance
See Also:
getLink(HttpServletRequest)

getSpecialLink

public static final Link getSpecialLink(NavigationFlow flow,
                                        java.lang.String view)
Get the link associated with the given special view in the given NavigationFlow instance.

Parameters:
view - one of LOAD_CURRENT, LOAD_PREVIOUS, LOAD_CANCEL or LOAD_DEFAULT.
See Also:
ControllerConstants.LOAD_CURRENT, ControllerConstants.LOAD_PREVIOUS, ControllerConstants.LOAD_CANCEL, ControllerConstants.LOAD_DEFAULT

getRequestedPage

public static final java.lang.String getRequestedPage(javax.servlet.http.HttpServletRequest request)
Get the original request string URI, containing both path info and query String: http://host:8080/contextpath/server/pathinfo?query=string

Parameters:
request - A not-null HttpServletRequest instance
Returns:
A not-null String value

getRequestedServlet

public static final java.lang.String getRequestedServlet(javax.servlet.http.HttpServletRequest request)
Get the original request string, not containing the context path, but containing both path info and query string: http://host:8080/contextpath/server/pathinfo?query=string

Parameters:
request - A not-null HttpServletRequest instance
Returns:
A not-null String value

getRequestedController

public static final java.lang.String getRequestedController(javax.servlet.http.HttpServletRequest request)
Get the original request string, not containing the context path and query string, but containing path info: http://host:8080/contextpath/server/pathinfo?query=string

Parameters:
request - A not-null HttpServletRequest instance
Returns:
A not-null String value

getNavigationFlow

public static final NavigationFlow getNavigationFlow(javax.servlet.http.HttpServletRequest request)
Get the navigation flow for the current application. Reads the _NAVIGATION_FLOW_KEY object from session

See Also:
AttributeKeys._NAVIGATION_FLOW_KEY

getNavigationFlow

public static final NavigationFlow getNavigationFlow(RequestContext context)
Get the navigation flow for the current application. Reads the _NAVIGATION_FLOW_KEY object from session

See Also:
AttributeKeys._NAVIGATION_FLOW_KEY

getServiceLocator

public static final ServiceLocator getServiceLocator(javax.servlet.ServletContext context)
Get the service locator, if any was configured.

See Also:
AttributeKeys._SERVICE_LOCATOR_KEY

getServiceLocator

public static final ServiceLocator getServiceLocator(RequestContext context)
Get the service locator, if any was configured.

See Also:
AttributeKeys._SERVICE_LOCATOR_KEY

getPortalPath

public static final java.lang.String getPortalPath(javax.servlet.ServletContext context,
                                                   javax.servlet.http.HttpServletRequest request)
Get the basic portal path from the context and request instances. First the PORTAL_PATH_PARAM context init parameter is checked, if not null it is taken as the portal path configuration; if null, the request context path is used instead.

See Also:
Configuration.PORTAL_PATH_PARAM

requestAccepts

public static boolean requestAccepts(javax.servlet.http.HttpServletRequest request,
                                     java.lang.String type,
                                     java.lang.String subType)
Check if the given HTTP request accepts the given MIME-type. This is currently a very simple implementation.


resetMap

public static final void resetMap(RequestContext context,
                                  java.lang.String key)
Convenience method for reseting a context map. This will perform reset() on any map that was explicitly loaded as a LazyMap, or that was loaded in a ServiceInitializerBase subclass using a ContextAttribute annotation with lazyLoad=true.

See Also:
LazyMap, ServiceInitializerBase, ContextAttribute

resetMap

public static final void resetMap(javax.servlet.ServletContext context,
                                  java.lang.String key)
Convenience method for reseting a context map. This will perform reset() on any map that was explicitly loaded as a LazyMap, or that was loaded in a ServiceInitializerBase subclass using a ContextAttribute annotation with lazyLoad=true.

See Also:
LazyMap, ServiceInitializerBase, ContextAttribute

initLocaleAndBundle

public static final void initLocaleAndBundle(javax.servlet.ServletContext context)
Load the JSTL application resource bundle as a map in the context, if provided. This method also sets the default locale for the application, if provided in the /WEB-INF/web.xml file. This method is called by ServiceInitializerBase at application startup.

Initializations performed in this method are useful when a single locale and bundle is used application wide, otherwise storing a single bundle at context level won't help much.

See Also:
ServiceInitializerBase, loadResourceBundleMap(ServletContext,Locale)

getLocale

public static final java.util.Locale getLocale(javax.servlet.jsp.PageContext context)
Get the locale configured for the current context request. JSTL locale configuration is used for this method, if no JSTL locale is configured the request locale is returned instead. Locales are cached using the _LOCALE_KEY at page level, to avoid using this same procedure in each tag.

See Also:
AttributeKeys._LOCALE_KEY

getText

public static final java.lang.String getText(RequestContext context,
                                             java.lang.String key,
                                             java.lang.Object... params)
Get a localized message using the default JSTL-configured locale.

Parameters:
key - A not-null valid key in the default bundle
params - Optional parameters for the composition of the message

getText

public static final java.lang.String getText(javax.servlet.jsp.PageContext pageContext,
                                             java.lang.String key,
                                             java.lang.Object... params)
Get a localized message using the default JSTL-configured locale.

Parameters:
key - A not-null valid key in the default bundle
params - Optional parameters for the composition of the message

getConfiguration

public static final Configuration getConfiguration(javax.servlet.ServletContext context)
Get the configuration object reference to the global configuration of the current application, create it if it does not exist.


getConfiguration

public static final Configuration getConfiguration(javax.servlet.ServletContext context,
                                                   javax.servlet.ServletConfig config)
Get a configuration object reference for the given context and config reference.


loadResourceBundleMap

public static final void loadResourceBundleMap(javax.servlet.ServletContext context,
                                               java.util.Locale locale)
Load the resource bundle configured for the current application as a map implementation. This map may be used in a JSP page to obtain a locale-specific text from a non-JSP component. Some implementations may not want to perform this conversion of a resource bundle to a map, because of their use of multiple languages and bundles, or because the contemplate it as a waste of memory and processing. In that case, the must ensure:

For applications that require use of multiple locales for personalization on multiple requests and user profiles, the creation of a single bundle won't help much, but it may not harm also ( for bundles that don't have too many keys ).

See Also:
ResourceBundleMap, AttributeKeys._BUNDLE_KEY