org.jsxp.framework
Class Application

java.lang.Object
  extended by org.jsxp.framework.Application
All Implemented Interfaces:
ResourceResolver, ViewControllerLifeCycleExceptionHandler

public class Application
extends java.lang.Object
implements ResourceResolver, ViewControllerLifeCycleExceptionHandler

The Class Application. Default implementation of an application. It is recommend to create a subclass for your webapps. The application is automatically instantiated by the jsxp framework. You can access it with getApplication(). Do not create an instance yourself.


Field Summary
protected static java.lang.String DIRECT_DELIVERY_ALLOWED_FILE_REGULAR_EXPRESSIONS
           
protected static java.lang.String DIRECT_DELIVERY_DENIED_FILE_REGULAR_EXPRESSIONS
           
protected static java.lang.String FILE_UPLOAD_ADAPTER
           
protected static java.lang.String PROJECT_STAGE_NAME
           
protected static java.lang.String SUPPORTED_LOCALES
           
protected static java.lang.String VIEW_CONTROL_BASE_PACKAGE
           
 
Constructor Summary
protected Application()
          Instantiates a new application.
 
Method Summary
protected  void contextInitialized(Context context)
          Called by the jsxp framework if the Context was initialized.
protected  Context createContext()
          Creates the context.
protected  ProjectStage createProjectStage(java.lang.String name)
          Create a project stage for a given project stage name.
protected  UserContext createUserContext()
          Creates the user context.
 java.lang.String delocalizeUriAndInitContextLocale(java.lang.String uri)
          Should set the locale that should be used for this request to the context and return an uri that may be delocalized (e.g.
static
<T extends Application>
T
getApplication()
          Gets the application.
 java.util.Locale getDefaultApplicationLocale()
          Gets the default application locale.
 java.lang.String getDefaultCharacterEncoding()
          Gets default the character encoding.
 java.lang.String getDefaultContentType()
          Gets the default content type of the rendered output.
protected  java.util.List<java.lang.String> getDirectDeliveryAllowedList()
          Gets the direct delivery allowed list.
protected  java.util.List<java.lang.String> getDirectDeliveryDeniedList()
          Gets the direct delivery denied list.
 java.lang.String getParameter(java.lang.String key, java.lang.String defaultValue)
          Gets the parameter.
 ProjectStage getProjectStage()
          Gets the current project stage.
 java.io.InputStream getResourceInputStream(java.lang.String uri, java.lang.Object objectForClassLoader)
          Gets the resource input stream.
 long getResourceModifiedTimeStamp(java.lang.String uri, java.lang.Object objectForClassLoader)
          Gets the resource modified time stamp.
 int getSessionTimeout()
          Override to specify another session timeout duration
protected  java.util.List<java.util.Locale> getSupportedApplicationLocales()
          Gets the supported application locales.
protected  ViewController getTemplate()
          Gets the application template.
 ViewAlias getViewAliasFor(java.lang.String sourcePath, java.lang.String targetPath, java.util.Map<java.lang.String,java.lang.Object[]> parameter)
          Gets the ViewAlias alias for the current call.
 ViewController getViewController(java.lang.String uri)
          Gets the view control for an uri.
 java.lang.String[] getViewControllerBasePackages()
          These returns the packages where the framework looks for die ViewController classes.
 ViewController getViewForbiddenViewController()
          Gets the view forbidden view control.
 ViewController getViewNotFoundViewController()
          Gets the view not found view control.
 ViewParser getViewParser()
          Gets the factory for the process of view design files.
 void handleExecutingException(java.lang.Exception e, ViewController source)
          Throws the given exception encapsulated in a runtime exception per default.
 void handleInitException(java.lang.Exception e, ViewController source)
          Throws the given exception encapsulated in a runtime exception per default.
 void handleInputProcessingException(java.lang.Exception e, ViewController source)
          Throws the given exception encapsulated in a runtime exception per default.
 void handlePreparingException(java.lang.Exception e, ViewController source)
          Throws the given exception encapsulated in a runtime exception per default.
 void handleRenderingException(java.lang.Exception e, ViewController source)
          Throws the given exception encapsulated in a runtime exception per default.
 void handleTemplatingException(java.lang.Exception e, ViewController source)
          Throws the given exception encapsulated in a runtime exception per default.
 void handleValidatingException(java.lang.Exception e, ViewController source)
          Throws the given exception encapsulated in a runtime exception per default.
 void initialize()
          Initializer.
 java.util.Map<java.lang.String,java.lang.Object[]> initInputParameter()
          Process input parameter.
 boolean isAllowedToViewPage(ViewController view, java.lang.String uri)
          Checks if is allowed to view page.
protected  boolean isDirectDeliveryAllowed(java.lang.String url)
          Checks if direct delivery is allowed.
 void lifeCycleStartsForViewController(ViewController ViewController)
          Called by the jsxp framework each time a view controller is added to the life cycle manager.
protected  java.lang.String localizeUri(java.lang.String uri)
          Override to change translation behaviour.
protected  ViewController resolveViewController(java.lang.String uri, boolean translateUri)
          resolves a view control.
protected  void sessionRestored(java.util.Map<java.lang.String,java.lang.Object> sessionScope)
          Called by the jsxp framework if a Session was restored.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DIRECT_DELIVERY_ALLOWED_FILE_REGULAR_EXPRESSIONS

protected static final java.lang.String DIRECT_DELIVERY_ALLOWED_FILE_REGULAR_EXPRESSIONS
See Also:
Constant Field Values

DIRECT_DELIVERY_DENIED_FILE_REGULAR_EXPRESSIONS

protected static final java.lang.String DIRECT_DELIVERY_DENIED_FILE_REGULAR_EXPRESSIONS
See Also:
Constant Field Values

FILE_UPLOAD_ADAPTER

protected static final java.lang.String FILE_UPLOAD_ADAPTER
See Also:
Constant Field Values

PROJECT_STAGE_NAME

protected static final java.lang.String PROJECT_STAGE_NAME
See Also:
Constant Field Values

SUPPORTED_LOCALES

protected static final java.lang.String SUPPORTED_LOCALES
See Also:
Constant Field Values

VIEW_CONTROL_BASE_PACKAGE

protected static final java.lang.String VIEW_CONTROL_BASE_PACKAGE
See Also:
Constant Field Values
Constructor Detail

Application

protected Application()
Instantiates a new application.

Method Detail

getApplication

public static <T extends Application> T getApplication()
Gets the application.

Returns:
the application

contextInitialized

protected void contextInitialized(Context context)
Called by the jsxp framework if the Context was initialized. Override this method to do anything with the context.

Parameters:
context - the context

createContext

protected Context createContext()
Creates the context. Override to create instances from special Context classes.

Returns:
the context

createProjectStage

protected ProjectStage createProjectStage(java.lang.String name)
Create a project stage for a given project stage name. Override this method to define which project stages your application knows and how they are configured.

Parameters:
name - the name of the project stage.
Returns:
the project stage instance

createUserContext

protected UserContext createUserContext()
Creates the user context. Override to create instances from special UserContext classes.

Returns:
the user context

delocalizeUriAndInitContextLocale

public java.lang.String delocalizeUriAndInitContextLocale(java.lang.String uri)
Should set the locale that should be used for this request to the context and return an uri that may be delocalized (e.g. index.html instead of en/index.html in the default implementation) regarding to the way localization should be done (if it is done via the uri). Override to change translation behaviour.

Parameters:
uri - the incoming uri from the client
Returns:
the uri that is without locale information

getDefaultApplicationLocale

public java.util.Locale getDefaultApplicationLocale()
Gets the default application locale.

Returns:
the default application locale

getDefaultCharacterEncoding

public java.lang.String getDefaultCharacterEncoding()
Gets default the character encoding. Override this method if you want to change the type for all the views in your application. Or override ViewController.getCharacterEncoding() to set it for one view only. This will give your view a special character encoding. Default is UTF-8.

Returns:
the character encoding

getDefaultContentType

public java.lang.String getDefaultContentType()
Gets the default content type of the rendered output. Override it to change the type for all the views in your application. Default is "text/html". Can also be overridden in a view controller for that special view controller.

Returns:
the content type

getDirectDeliveryAllowedList

protected java.util.List<java.lang.String> getDirectDeliveryAllowedList()
Gets the direct delivery allowed list. Override this method to allow direct delivery for special file types in your webapp. Per default it allows the direct delivery of stylesheet, images, ... (".\*\.css", ".\*\.js",".\*\.jpg", ".\*\.jpeg",".\*\.gif", ".\*\.png"); The allow list is a list of regular expression strings that can be matched to urls. This is used by the default implementation of the isDirectDeliveryAllowed(String).

Returns:
the direct delivery allowed list (null in default application)
See Also:
isDirectDeliveryAllowed(String)

getDirectDeliveryDeniedList

protected java.util.List<java.lang.String> getDirectDeliveryDeniedList()
Gets the direct delivery denied list. Like the direct delivery allow list it can be used to disable the direct delivery of requested urls. This is used by the default implementation of the isDirectDeliveryAllowed(String). The deny list is a list of regular expression strings that can be matched to urls.

Returns:
the direct delivery denied list (null in default application)
See Also:
isDirectDeliveryAllowed(String)

getParameter

public java.lang.String getParameter(java.lang.String key,
                                     java.lang.String defaultValue)
Gets the parameter. Override to use application parameter (key/value pairs) for your application. Per default the parameters from web.xml (the servlet config parameters) are used.

Parameters:
key - the key
defaultValue - the default value
Returns:
the parameter

getProjectStage

public ProjectStage getProjectStage()
Gets the current project stage. Override this method to define in which project stage your application is. Default implementation uses getParameter(String, String) with key PROJECT_STAGE_NAME and the "development" string as defaultValue to get the project stage name and will than use the method createProjectStage(String) to get the project stage when initialized.

Returns:
the current project stage

getResourceInputStream

public java.io.InputStream getResourceInputStream(java.lang.String uri,
                                                  java.lang.Object objectForClassLoader)
Description copied from interface: ResourceResolver
Gets the resource input stream.

Specified by:
getResourceInputStream in interface ResourceResolver
Parameters:
uri - the uri
objectForClassLoader - the object for class loader
Returns:
the resource input stream

getResourceModifiedTimeStamp

public long getResourceModifiedTimeStamp(java.lang.String uri,
                                         java.lang.Object objectForClassLoader)
Description copied from interface: ResourceResolver
Gets the resource modified time stamp.

Specified by:
getResourceModifiedTimeStamp in interface ResourceResolver
Parameters:
uri - the uri
objectForClassLoader - the object for class loader
Returns:
the resource modified time stamp

getSessionTimeout

public int getSessionTimeout()
Override to specify another session timeout duration

Returns:
the default session timeout in ms (300)

getSupportedApplicationLocales

protected java.util.List<java.util.Locale> getSupportedApplicationLocales()
Gets the supported application locales.

Returns:
the supported application locales

getTemplate

protected ViewController getTemplate()
Gets the application template. If your application should use an application wide template for your views, you have to override this method and return the template ViewController. A view controller can have it own template. Templates can be used hierarchical.

Returns:
the template
See Also:
ViewController

getViewAliasFor

public ViewAlias getViewAliasFor(java.lang.String sourcePath,
                                 java.lang.String targetPath,
                                 java.util.Map<java.lang.String,java.lang.Object[]> parameter)
Gets the ViewAlias alias for the current call.

Parameters:
sourcePath - the source path (origin/referer of the request)
targetPath - the target path (requested target)
parameter - the parameter (request parameter)
Returns:
the alias for

getViewController

public ViewController getViewController(java.lang.String uri)
Gets the view control for an uri. You can override this method to implement a very special behavior but you should not need to do this.

Gets a view if no view is matching the uri in getViewController(String). As default if no view is matching the uri it tries to append first "index.xhtml" than "index.html" to the uri to find a view control for this new uri.

Uses resolveViewController(String, boolean) internally.

Parameters:
uri - the uri
Returns:
the view control

getViewControllerBasePackages

public java.lang.String[] getViewControllerBasePackages()
These returns the packages where the framework looks for die ViewController classes. Uses getParameter(String, String) with key VIEW_CONTROL_BASE_PACKAGE and the empty string as defaultValue to load the view control base packages (as a comma separated string) when initialized. You can override this method to define more detailed how the framework should look for your ViewController classes.

Returns:
the view control base packages

getViewForbiddenViewController

public ViewController getViewForbiddenViewController()
Gets the view forbidden view control. In the default implementation this returns a view to render the http error 403. You can override this method to implement your own behavior.

Returns:
the view forbidden view control

getViewNotFoundViewController

public ViewController getViewNotFoundViewController()
Gets the view not found view control. In the default implementation this returns a view to render the http error 404. You can override this method to implement your own behavior.

Returns:
the view not found view control

getViewParser

public ViewParser getViewParser()
Gets the factory for the process of view design files. If you want to use another implementation instead of the current DOM-implementation you have to override this method.

Returns:
the factory

handleExecutingException

public void handleExecutingException(java.lang.Exception e,
                                     ViewController source)
Throws the given exception encapsulated in a runtime exception per default.

Specified by:
handleExecutingException in interface ViewControllerLifeCycleExceptionHandler
Parameters:
e - the e
source - the source
See Also:
ViewControllerLifeCycleExceptionHandler.handleExecutingException(java.lang.Exception, org.jsxp.framework.ViewController)

handleInitException

public void handleInitException(java.lang.Exception e,
                                ViewController source)
Throws the given exception encapsulated in a runtime exception per default.

Specified by:
handleInitException in interface ViewControllerLifeCycleExceptionHandler
Parameters:
e - the e
source - the source
See Also:
ViewControllerLifeCycleExceptionHandler.handleInitException(java.lang.Exception, org.jsxp.framework.ViewController)

handleInputProcessingException

public void handleInputProcessingException(java.lang.Exception e,
                                           ViewController source)
Throws the given exception encapsulated in a runtime exception per default.

Specified by:
handleInputProcessingException in interface ViewControllerLifeCycleExceptionHandler
Parameters:
e - the e
source - the source
See Also:
ViewControllerLifeCycleExceptionHandler.handleInputProcessingException(java.lang.Exception, org.jsxp.framework.ViewController)

handlePreparingException

public void handlePreparingException(java.lang.Exception e,
                                     ViewController source)
Throws the given exception encapsulated in a runtime exception per default.

Specified by:
handlePreparingException in interface ViewControllerLifeCycleExceptionHandler
Parameters:
e - the e
source - the source
See Also:
ViewControllerLifeCycleExceptionHandler.handlePreparingException(java.lang.Exception, org.jsxp.framework.ViewController)

handleRenderingException

public void handleRenderingException(java.lang.Exception e,
                                     ViewController source)
Throws the given exception encapsulated in a runtime exception per default.

Specified by:
handleRenderingException in interface ViewControllerLifeCycleExceptionHandler
Parameters:
e - the e
source - the source
See Also:
ViewControllerLifeCycleExceptionHandler.handleRenderingException(java.lang.Exception, org.jsxp.framework.ViewController)

handleTemplatingException

public void handleTemplatingException(java.lang.Exception e,
                                      ViewController source)
Throws the given exception encapsulated in a runtime exception per default.

Specified by:
handleTemplatingException in interface ViewControllerLifeCycleExceptionHandler
Parameters:
e - the e
source - the source
See Also:
ViewControllerLifeCycleExceptionHandler.handleTemplatingException(java.lang.Exception, org.jsxp.framework.ViewController)

handleValidatingException

public void handleValidatingException(java.lang.Exception e,
                                      ViewController source)
Throws the given exception encapsulated in a runtime exception per default.

Specified by:
handleValidatingException in interface ViewControllerLifeCycleExceptionHandler
Parameters:
e - the e
source - the source
See Also:
ViewControllerLifeCycleExceptionHandler.handleValidatingException(java.lang.Exception, org.jsxp.framework.ViewController)

initialize

public void initialize()
Initializer. This method is called by the jsxp framework to initialize the application. The default implementation initializes the default. You can override it in your application class if you want to initialize the application instance. It is recommend to call this (super) method then.


initInputParameter

public java.util.Map<java.lang.String,java.lang.Object[]> initInputParameter()
Process input parameter. Defines how the application will handle input. Per default it processes multipart form data and uploaded files.

Returns:
the map< string, string[]>

isAllowedToViewPage

public boolean isAllowedToViewPage(ViewController view,
                                   java.lang.String uri)
Checks if is allowed to view page. In the default implementation this calls UserContext.isAllowedToViewPage(ViewController, String)

Parameters:
view - the view (can be null if only a uri is checked)
uri - the uri
Returns:
true, if is allowed to view page

isDirectDeliveryAllowed

protected final boolean isDirectDeliveryAllowed(java.lang.String url)
Checks if direct delivery is allowed. Uses getDirectDeliveryAllowedList() and getDirectDeliveryDeniedList() to match with the url. The denied rules are stronger than the allowed rules.

Parameters:
url - the url
Returns:
true, if is direct delivery allowed

lifeCycleStartsForViewController

public void lifeCycleStartsForViewController(ViewController ViewController)
Called by the jsxp framework each time a view controller is added to the life cycle manager. E.g. you can add a listener to the life cycle phases of a view control if you want need to do something application wide.

Parameters:
ViewController - the view control

localizeUri

protected java.lang.String localizeUri(java.lang.String uri)
Override to change translation behaviour. This will result in an uri that is used to find stuff on the server. Use a combination of this method and the delocalizeUriAndInitContextLocale(String) method to implement how uri that are requested from the client should result in uri used on the server.

Parameters:
uri - the uri that is used after using delocalizeUriAndInitContextLocale(String) before
Returns:
uri that has all necessary information in it to find the information for the current locale

resolveViewController

protected ViewController resolveViewController(java.lang.String uri,
                                               boolean translateUri)
resolves a view control. creates a package and classname from the given uri to get an instance of the corresponding view controller.

Parameters:
uri -
translateUri - will use the localizeUri(String) method to localize the uri if true
Returns:
the corresponding view controller or null (if no view controller class was found) or getViewForbiddenViewController() if the found view controller is forbidden

sessionRestored

protected void sessionRestored(java.util.Map<java.lang.String,java.lang.Object> sessionScope)
Called by the jsxp framework if a Session was restored. Override this method to do anything with the session.

Parameters:
sessionScope - the session scope


Copyright © 2012 Oliver Szymanski & David Tanzer