to.etc.domui.server
Class DomApplication

java.lang.Object
  extended by to.etc.domui.server.DomApplication

public abstract class DomApplication
extends java.lang.Object

Author:
Frits Jalvingh Created on May 22, 2008

Nested Class Summary
static class DomApplication.ExceptionEntry
          An entry in the exception table.
 
Field Summary
static org.slf4j.Logger LOG
           
 
Constructor Summary
DomApplication()
          The only constructor.
 
Method Summary
 void addDefaultErrorComponent(NodeContainer page)
          When a page has no error handling components (no component has registered an error listener) then errors will not be visible.
 void addExceptionListener(java.lang.Class<? extends java.lang.Exception> xclass, IExceptionListener l)
          Adds an exception handler for a given exception type.
 void addHeaderContributor(HeaderContributor hc, int order)
          Call from within the onHeaderContributor call on a node to register any header contributors needed by a node.
 void addInterceptor(IRequestInterceptor r)
           
 void addLoginListener(ILoginListener l)
           
 void addNewPageInstantiatedListener(INewPageInstantiated l)
           
 void addRenderFactory(IHtmlRenderFactory f)
           
 void addSessionListener(IAppSessionListener l)
           
 void addUIStateListener(IDomUIStateListener sl)
          Register a listener for internal DomUI events.
protected  void augmentThemeMap(java.util.Map<java.lang.String,java.lang.Object> themeMap)
          This method can be overridden to add extra stuff to the theme map, after it has been loaded from properties or whatnot.
 void clearListCache(ICachedListMaker<?> maker)
           
 void clearListCaches()
          Discard all cached stuff in the list cache.
 IResourceRef createClasspathReference(java.lang.String name)
          Create a resource ref to a class based resource.
<T> T
createInstance(java.lang.Class<T> clz, java.lang.Object... args)
          FIXME Needs a proper, injected implementation instead of a quicky.
protected  AppSession createSession()
          Can be overridden to create your own instance of a session.
protected  void destroy()
          Override to destroy resources when the application terminates.
 IExceptionListener findExceptionListenerFor(java.lang.Exception x)
          This locates the handler for the specfied exception type, if it has been registered.
 java.lang.String findLocalizedResourceName(java.lang.String basename, java.lang.String suffix, java.util.Locale loc)
          This returns the name of an existing resource for the given name/suffix and locale.
 HtmlFullRenderer findRendererFor(BrowserVersion bv, IBrowserOutput o)
          Creates the appropriate full renderer for the specified browser version.
 IFilterRequestHandler findRequestHandler(IRequestContext ctx)
           
 IResourceFactory findResourceFactory(java.lang.String name)
          Get the best factory to resolve the specified resource name.
 java.lang.String findRightsDescription(java.lang.String right)
          Translates a right name to a description from the registered bundle, if registered.
 HtmlTagRenderer findTagRendererFor(BrowserVersion bv, IBrowserOutput o)
           
static DomApplication get()
          Returns the single DomApplication instance in use for the webapp.
 AjaxRequestHandler getAjaxHandler()
           
 java.io.File getAppFile(java.lang.String path)
          Return a file from the webapp's root directory.
 IResourceRef getAppFileOrResource(java.lang.String name)
          Primitive to return either a File-based resource from the web content files or a classpath resource (below /resources/) for the same path.
 java.lang.String getApplicationURL()
           
<T> java.util.List<T>
getCachedList(IListMaker<T> maker)
           
 ControlBuilder getControlBuilder()
          Return the component that knows everything you ever wanted to know about controls - but were afraid to ask...
 int getDefaultExpiryTime()
          Returns the default browser cache resource expiry time in seconds.
 BasePageTitleBar getDefaultPageTitleBar(java.lang.String title)
          Deprecated. 
 java.util.List<HeaderContributorEntry> getHeaderContributorList()
           
 IPageInjector getInjector()
          Get the page injector.
 java.util.List<IRequestInterceptor> getInterceptorList()
           
 ILoginAuthenticator getLoginAuthenticator()
           
 ILoginDialogFactory getLoginDialogFactory()
           
 java.util.List<ILoginListener> getLoginListenerList()
           
 java.util.List<INewPageInstantiated> getNewPageInstantiatedListeners()
           
 java.util.List<java.lang.String> getRegisteredRights()
          Return a list of all currently registered right names.
 java.util.Locale getRequestLocale(javax.servlet.http.HttpServletRequest request)
          This returns the locale to use for the request passed.
 IResourceRef getResource(java.lang.String name, IResourceDependencyList rdl)
          Get an application resource.
 java.util.List<IResourceFactory> getResourceFactories()
           
 java.lang.String getRightsDescription(java.lang.String right)
          Translates a right name to a description from the registered bundle, if registered.
abstract  java.lang.Class<? extends UrlPage> getRootPage()
          Must return the "root" class of the application; the class rendered when the application's root URL is entered without a class name.
 java.lang.String getScriptVersion()
           
 ITheme getTheme(IResourceDependencyList rdl)
          Get the theme that is used for this application.
 java.lang.String getThemedResourceRURL(java.lang.String path)
           
 java.util.Map<java.lang.String,java.lang.Object> getThemeMap(IResourceDependencyList rdlin)
          Return the current theme map (a readonly map), cached from the last time.
 IThemeFactory getThemer()
           
 java.lang.String getThemeReplacedString(IResourceDependencyList rdl, java.lang.String rurl)
           
 java.lang.String getThemeReplacedString(IResourceDependencyList rdl, java.lang.String rurl, BrowserVersion bv)
          EXPENSIVE CALL - ONLY USE TO CREATE CACHED RESOURCES This loads a theme resource as an utf-8 encoded template, then does expansion using the current theme's variable map.
 java.lang.String getUrlExtension()
          Returns the defined extension for DomUI pages.
 java.io.File getWebAppFileRoot()
          Returns the root of the webapp's installation directory on the local file system.
 int getWindowSessionTimeout()
          The #of minutes that a WindowSession remains valid; defaults to 15 minutes.
 java.lang.String handleNotLoggedInException(RequestContextImpl ci, Page page, NotLoggedInException x)
          Responsible for redirecting to the appropriate login page.
 boolean hasApplicationResource(java.lang.String name)
          Quickly determines if a given resource exists.
 boolean inDevelopmentMode()
          Returns T when running in development mode; this is defined as a mode where web.xml contains reloadable classes.
protected  void initHeaderContributors()
           
protected  void initialize(ConfigParameters pp)
          Override to initialize the application, called as soon as the webabb starts by the filter's initialization code.
 void internalCallConversationCreated(ConversationContext ws)
           
 void internalCallConversationDestroyed(ConversationContext ws)
           
 void internalCallPageAction(RequestContextImpl ctx, Page ws)
           
 void internalCallPageComplete(IRequestContext ctx, Page ws)
           
 void internalCallPageFullRender(RequestContextImpl ctx, Page ws)
           
 void internalCallWindowSessionCreated(WindowSession ws)
           
 void internalCallWindowSessionDestroyed(WindowSession ws)
           
 void internalInitialize(ConfigParameters pp, boolean development)
           
static int internalNextPageTag()
           
 java.lang.Class<? extends UrlPage> loadPageClass(java.lang.String name)
           
 boolean logOutput()
           
 void register(ILookupControlFactory f)
          Register a new LookupControl factory.
protected  void registerControlFactories()
           
 void registerControlFactory(ControlFactory cf)
          Add a new control factory to the registry.
protected  void registerPartFactories()
           
 void registerResourceFactory(IResourceFactory f)
           
 void registerRight(BundleRef bundle, java.lang.String... rights)
          Registers a set of possible rights and their names/translation bundle.
 void registerRights(BundleRef bundle, java.lang.Class<?> constantsclass)
          Takes a class (or interface) and scans all static public final String fields therein.
 void registerUrlPart(IUrlPart factory)
          FIXME Mechanism is slow
 void removeNewPageInstantiatedListener(INewPageInstantiated l)
           
 void removeSessionListener(IAppSessionListener l)
           
 void removeUIStateListener(IDomUIStateListener sl)
          Remove a registered UI state listener.
 void setDefaultExpiryTime(int defaultExpiryTime)
          Set the static resource browser cache expiry time, in seconds.
 void setInjector(IPageInjector injector)
           
 void setLoginAuthenticator(ILoginAuthenticator loginAuthenticator)
           
 void setLoginDialogFactory(ILoginDialogFactory loginDialogFactory)
           
 void setThemeFactory(IThemeFactory themer)
          Set the factory for handling the theme.
 void setWindowSessionTimeout(int windowSessionTimeout)
          Sets the windowSession timeout, in minutes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOG

public static final org.slf4j.Logger LOG
Constructor Detail

DomApplication

public DomApplication()
The only constructor.

Method Detail

getRootPage

public abstract java.lang.Class<? extends UrlPage> getRootPage()
Must return the "root" class of the application; the class rendered when the application's root URL is entered without a class name.

Returns:

registerControlFactories

protected void registerControlFactories()

registerPartFactories

protected void registerPartFactories()

get

public static DomApplication get()
Returns the single DomApplication instance in use for the webapp.

Returns:

addSessionListener

public void addSessionListener(IAppSessionListener l)

removeSessionListener

public void removeSessionListener(IAppSessionListener l)

getUrlExtension

public java.lang.String getUrlExtension()
Returns the defined extension for DomUI pages. This returns the extension without the dot, i.e. "ui" for [classname].ui pages.

Returns:

findRequestHandler

public IFilterRequestHandler findRequestHandler(IRequestContext ctx)

createSession

protected AppSession createSession()
Can be overridden to create your own instance of a session.

Returns:

destroy

protected void destroy()
Override to destroy resources when the application terminates.


initialize

protected void initialize(ConfigParameters pp)
                   throws java.lang.Exception
Override to initialize the application, called as soon as the webabb starts by the filter's initialization code.

Parameters:
pp -
Throws:
java.lang.Exception

internalInitialize

public final void internalInitialize(ConfigParameters pp,
                                     boolean development)
                              throws java.lang.Exception
Throws:
java.lang.Exception

internalNextPageTag

public static final int internalNextPageTag()

loadPageClass

public java.lang.Class<? extends UrlPage> loadPageClass(java.lang.String name)

getScriptVersion

public java.lang.String getScriptVersion()

findRendererFor

public HtmlFullRenderer findRendererFor(BrowserVersion bv,
                                        IBrowserOutput o)
Creates the appropriate full renderer for the specified browser version.

Parameters:
bv -
o -
Returns:

findTagRendererFor

public HtmlTagRenderer findTagRendererFor(BrowserVersion bv,
                                          IBrowserOutput o)

addRenderFactory

public void addRenderFactory(IHtmlRenderFactory f)

inDevelopmentMode

public boolean inDevelopmentMode()
Returns T when running in development mode; this is defined as a mode where web.xml contains reloadable classes.

Returns:

getWindowSessionTimeout

public int getWindowSessionTimeout()
The #of minutes that a WindowSession remains valid; defaults to 15 minutes.

Returns:

setWindowSessionTimeout

public void setWindowSessionTimeout(int windowSessionTimeout)
Sets the windowSession timeout, in minutes.

Parameters:
windowSessionTimeout -

getDefaultExpiryTime

public int getDefaultExpiryTime()
Returns the default browser cache resource expiry time in seconds. When running in production mode all "static" resources are sent to the browser with an "Expiry" header. This causes the browser to cache the resources until the expiry time has been reached. This is important for performance.

Returns:

setDefaultExpiryTime

public void setDefaultExpiryTime(int defaultExpiryTime)
Set the static resource browser cache expiry time, in seconds.

Parameters:
defaultExpiryTime -

getRequestLocale

@Nonnull
public java.util.Locale getRequestLocale(javax.servlet.http.HttpServletRequest request)
This returns the locale to use for the request passed. It defaults to the locale in the request itself, as returned by ServletRequest.getLocale(). You can override this method to define the locale by yourself.

Parameters:
request -
Returns:

initHeaderContributors

protected void initHeaderContributors()

addHeaderContributor

public final void addHeaderContributor(HeaderContributor hc,
                                       int order)
Call from within the onHeaderContributor call on a node to register any header contributors needed by a node. The order value determines the order for contributors which is mostly important for Javascript ones; higher order items are written later than lower order items. All DomUI required Javascript code has orders < 0; user code should start at 0 and go up.

Parameters:
hc -
order -

getHeaderContributorList

public java.util.List<HeaderContributorEntry> getHeaderContributorList()

addDefaultErrorComponent

public void addDefaultErrorComponent(NodeContainer page)
When a page has no error handling components (no component has registered an error listener) then errors will not be visible. If such a page encounters an error it will call this method; the default implementation will add an ErrorPanel as the first component in the Body; this panel will then accept and render the errors.

Parameters:
page -

getDefaultPageTitleBar

@Deprecated
public BasePageTitleBar getDefaultPageTitleBar(java.lang.String title)
Deprecated. 

FIXME This code requires an absolute title which is not needed for the DomUI framework. It's also only needed for the "BasicPage" and has no meaning for any other part of the framework. It should move to some BasicPage factory. This returns default page title component. AppPageTitleBar is default one used by framework. To set some custom page title component override this method in your application specific class.

Parameters:
title -
Returns:

getControlBuilder

public final ControlBuilder getControlBuilder()
Return the component that knows everything you ever wanted to know about controls - but were afraid to ask...


registerControlFactory

public final void registerControlFactory(ControlFactory cf)
Add a new control factory to the registry.

Parameters:
cf - The new factory

register

public void register(ILookupControlFactory f)
Register a new LookupControl factory.

Parameters:
f -

createInstance

public <T> T createInstance(java.lang.Class<T> clz,
                            java.lang.Object... args)
FIXME Needs a proper, injected implementation instead of a quicky.


getAppFile

public java.io.File getAppFile(java.lang.String path)
Return a file from the webapp's root directory. Example: passing WEB-INF/web.xml would return the file for the web.xml.

Parameters:
path -
Returns:

getAppFileOrResource

public IResourceRef getAppFileOrResource(java.lang.String name)
Primitive to return either a File-based resource from the web content files or a classpath resource (below /resources/) for the same path. The result will implement IModifyableResource. This will not use any kind of resource factory.

Parameters:
name -
Returns:

registerResourceFactory

public void registerResourceFactory(IResourceFactory f)

getResourceFactories

public java.util.List<IResourceFactory> getResourceFactories()

findResourceFactory

public IResourceFactory findResourceFactory(java.lang.String name)
Get the best factory to resolve the specified resource name.

Parameters:
name -
Returns:

getWebAppFileRoot

public final java.io.File getWebAppFileRoot()
Returns the root of the webapp's installation directory on the local file system.

Returns:

getApplicationURL

public java.lang.String getApplicationURL()

createClasspathReference

public IResourceRef createClasspathReference(java.lang.String name)
Create a resource ref to a class based resource. If we are running in DEBUG mode this will generate something which knows the source of the resource, so it can handle changes to that source while developing.

Parameters:
name -
Returns:

getResource

@Nonnull
public IResourceRef getResource(@Nonnull
                                        java.lang.String name,
                                        @Nonnull
                                        IResourceDependencyList rdl)
                         throws java.lang.Exception
Get an application resource. This usually means either a web file with the specified name or a class resource with this name below /resources/. But IResourceFactory instances registered with DomApplication can provide other means to locate resources.

Parameters:
name -
rdl - The dependency list. Pass ResourceDependencyList.NULL if you do not need the dependencies.
Returns:
Throws:
java.lang.Exception

hasApplicationResource

public boolean hasApplicationResource(java.lang.String name)
                               throws java.lang.Exception
Quickly determines if a given resource exists. Enter with the full resource path, like $js/xxx, THEME/xxx and the like; it mirrors the logic of #getApplicationResourceByName(String).

Parameters:
name -
Returns:
Throws:
java.lang.Exception

findLocalizedResourceName

public java.lang.String findLocalizedResourceName(java.lang.String basename,
                                                  java.lang.String suffix,
                                                  java.util.Locale loc)
                                           throws java.lang.Exception
This returns the name of an existing resource for the given name/suffix and locale. It uses the default DomUI/webapp.core resource resolution pattern.

Parameters:
basename - The base name: the part before the locale info
suffix - The suffix: the part after the locale info. This usually includes a ., like .js
loc - The locale to get the resource for.
Returns:
Throws:
java.lang.Exception
See Also:
BundleRef.loadBundleList(Locale)

getCachedList

public <T> java.util.List<T> getCachedList(IListMaker<T> maker)
                                throws java.lang.Exception
Type Parameters:
T -
Parameters:
key -
maker -
Returns:
Throws:
java.lang.Exception

clearListCaches

public void clearListCaches()
Discard all cached stuff in the list cache.


clearListCache

public void clearListCache(ICachedListMaker<?> maker)

logOutput

public boolean logOutput()

addInterceptor

public void addInterceptor(IRequestInterceptor r)

getInterceptorList

public java.util.List<IRequestInterceptor> getInterceptorList()

addExceptionListener

public void addExceptionListener(java.lang.Class<? extends java.lang.Exception> xclass,
                                 IExceptionListener l)
Adds an exception handler for a given exception type. The handler is inserted ordered, exceptions that are a superclass of other exceptions in the list are sorted AFTER their subclass (this prevents the handler for the superclass from being called all the time). Any given exception type may occur in this list only once or an exception occurs.

Parameters:
l -

findExceptionListenerFor

public IExceptionListener findExceptionListenerFor(java.lang.Exception x)
This locates the handler for the specfied exception type, if it has been registered. It currently uses a loop to locate the appropriate handler.

Parameters:
x -
Returns:
null if the handler was not registered.

addNewPageInstantiatedListener

public void addNewPageInstantiatedListener(INewPageInstantiated l)

removeNewPageInstantiatedListener

public void removeNewPageInstantiatedListener(INewPageInstantiated l)

getNewPageInstantiatedListeners

public java.util.List<INewPageInstantiated> getNewPageInstantiatedListeners()

getLoginAuthenticator

public ILoginAuthenticator getLoginAuthenticator()

setLoginAuthenticator

public void setLoginAuthenticator(ILoginAuthenticator loginAuthenticator)

getLoginDialogFactory

public ILoginDialogFactory getLoginDialogFactory()

setLoginDialogFactory

public void setLoginDialogFactory(ILoginDialogFactory loginDialogFactory)

addLoginListener

public void addLoginListener(ILoginListener l)

getLoginListenerList

public java.util.List<ILoginListener> getLoginListenerList()

handleNotLoggedInException

public java.lang.String handleNotLoggedInException(RequestContextImpl ci,
                                                   Page page,
                                                   NotLoggedInException x)
Responsible for redirecting to the appropriate login page. This default implementation checks to see if there is an authenticator registered and uses it's result to redirect. If no authenticator is registered this returns null, asking the caller to do normal exception handling.

Parameters:
ci -
page -
nlix -

getInjector

public IPageInjector getInjector()
Get the page injector.

Returns:

setInjector

public void setInjector(IPageInjector injector)

registerRight

public void registerRight(BundleRef bundle,
                          java.lang.String... rights)
Registers a set of possible rights and their names/translation bundle.

Parameters:
bundle -
rights -

registerRights

public void registerRights(BundleRef bundle,
                           java.lang.Class<?> constantsclass)
Takes a class (or interface) and scans all static public final String fields therein. For each field it's literal string value is used as a rights name and associated with the bundle. If a right already exists it is skipped, meaning the first ever definition of a right wins.

Parameters:
bundle -
constantsclass -

getRegisteredRights

public java.util.List<java.lang.String> getRegisteredRights()
Return a list of all currently registered right names.

Returns:

findRightsDescription

public java.lang.String findRightsDescription(java.lang.String right)
Translates a right name to a description from the registered bundle, if registered.

Parameters:
right -
Returns:

getRightsDescription

public java.lang.String getRightsDescription(java.lang.String right)
Translates a right name to a description from the registered bundle, if registered. Returns the right name if no bundle or description is found.

Parameters:
right -
Returns:

getAjaxHandler

public AjaxRequestHandler getAjaxHandler()

getThemer

public IThemeFactory getThemer()

setThemeFactory

public void setThemeFactory(IThemeFactory themer)
Set the factory for handling the theme.

Parameters:
themer -

registerUrlPart

public void registerUrlPart(IUrlPart factory)
FIXME Mechanism is slow

Parameters:
factory -

getThemeReplacedString

public java.lang.String getThemeReplacedString(@Nonnull
                                               IResourceDependencyList rdl,
                                               java.lang.String rurl)
                                        throws java.lang.Exception
Throws:
java.lang.Exception

getThemeReplacedString

public java.lang.String getThemeReplacedString(@Nonnull
                                               IResourceDependencyList rdl,
                                               @Nonnull
                                               java.lang.String rurl,
                                               @Nullable
                                               BrowserVersion bv)
                                        throws java.lang.Exception
EXPENSIVE CALL - ONLY USE TO CREATE CACHED RESOURCES This loads a theme resource as an utf-8 encoded template, then does expansion using the current theme's variable map. This map is either a "style.properties" file inside the theme's folder, or can be configured dynamically using a IThemeMapFactory. The result is returned as a string.

Parameters:
rdl -
key -
Returns:
Throws:
java.lang.Exception

getTheme

public ITheme getTheme(@Nullable
                       IResourceDependencyList rdl)
                throws java.lang.Exception
Get the theme that is used for this application. The dependencies for the theme will be added to the dependency list. This allows users of the theme to update themselves when (parts of) the theme change.

Parameters:
rdl -
Returns:
Throws:
java.lang.Exception

augmentThemeMap

protected void augmentThemeMap(java.util.Map<java.lang.String,java.lang.Object> themeMap)
This method can be overridden to add extra stuff to the theme map, after it has been loaded from properties or whatnot.

Parameters:
themeMap -

getThemeMap

public java.util.Map<java.lang.String,java.lang.Object> getThemeMap(IResourceDependencyList rdlin)
                                                             throws java.lang.Exception
Return the current theme map (a readonly map), cached from the last time. It will refresh automatically when the resource dependencies for the theme are updated.

Parameters:
rdl -
Returns:
Throws:
java.lang.Exception

getThemedResourceRURL

@Nullable
public java.lang.String getThemedResourceRURL(java.lang.String path)

addUIStateListener

public void addUIStateListener(IDomUIStateListener sl)
Register a listener for internal DomUI events.

Parameters:
sl -

removeUIStateListener

public void removeUIStateListener(IDomUIStateListener sl)
Remove a registered UI state listener.

Parameters:
sl -

internalCallWindowSessionCreated

public final void internalCallWindowSessionCreated(WindowSession ws)

internalCallWindowSessionDestroyed

public final void internalCallWindowSessionDestroyed(WindowSession ws)

internalCallConversationCreated

public final void internalCallConversationCreated(ConversationContext ws)

internalCallConversationDestroyed

public final void internalCallConversationDestroyed(ConversationContext ws)

internalCallPageFullRender

public final void internalCallPageFullRender(RequestContextImpl ctx,
                                             Page ws)

internalCallPageAction

public final void internalCallPageAction(RequestContextImpl ctx,
                                         Page ws)

internalCallPageComplete

public final void internalCallPageComplete(IRequestContext ctx,
                                           Page ws)