Nuxeo ECM Projects 5.4.3-SNAPSHOT

org.nuxeo.ecm.webengine.model.impl
Class AbstractWebContext

java.lang.Object
  extended by org.nuxeo.ecm.webengine.model.impl.AbstractWebContext
All Implemented Interfaces:
WebContext, Adaptable
Direct Known Subclasses:
DefaultContext

public abstract class AbstractWebContext
extends Object
implements WebContext

Author:
Bogdan Stefanescu

Field Summary
static Locale DEFAULT_LOCALE
           
static String LOCALE_SESSION_KEY
           
 
Fields inherited from interface org.nuxeo.ecm.webengine.model.WebContext
NUXEO_WEBENGINE_BASE_PATH
 
Method Summary
 boolean checkGuard(String guard)
          Check the given expression in this context and return true if the expression is verified or false otherwise.
 Map<String,Object> createBindings(Map<String,Object> vars)
           
<T> T
getAdapter(Class<T> adapter)
          Returns an object which is an instance of the given class associated with this object.
 String getBasePath()
          Gets the path of the servlet.
 String getBaseURL()
          Gets the URL of the base path.
 String getCookie(String name)
          Convenience method to get a cookie value.
 String getCookie(String name, String defaultValue)
          Convenience method to get a cookie value using a default value.
 CoreSession getCoreSession()
          Gets the Core Session (or Repository Session) corresponding to that request.
 File getCurrentScriptDirectory()
           
 File getCurrentScriptFile()
           
 WebEngine getEngine()
          Gets the web engine instance.
 ScriptFile getFile(String path)
          template and script resolver
 FormData getForm()
          Gets the representation of the data form submitted by the user.
 Locale getLocale()
          Gets the context locale.
 Log getLog()
          Gets a logger to be used by scripts for logging.
 String getLoginPath()
          Gets the login path for the current context.
 String getMessage(String key)
          Gets the i18n message for the given key.
 String getMessage(String key, List<Object> args)
          The same as WebContext.getMessage(String) but with parameter support
 String getMessage(String key, Object... args)
          The same as WebContext.getMessage(String) but with parameter support
 String getMessageL(String key, String language)
          Same as WebContext.getMessage(String) but uses the given locale.
 String getMessageL(String key, String locale, List<Object> args)
          The same as WebContext.getMessage(String) but uses the given locale, with parameter support.
 String getMessageL(String key, String locale, Object... args)
          The same as WebContext.getMessage(String) but uses the given locale, with parameter support
 String getMethod()
          Get HTTP Method.
 Module getModule()
          Gets the current web application.
 String getModulePath()
          Get the path prefix that identify the current web application.
 Principal getPrincipal()
          Gets the principal identifying the user that originated the request.
 Object getProperty(String key)
          Gets a context variable.
 Object getProperty(String key, Object defaultValue)
          Gets a context variable.
 HttpServletRequest getRequest()
          Gets the underlying HTTP servlet request object.
 Resource getRoot()
          Gets the root resource if any resource was defined as being the root
 StringBuilder getServerURL()
          Gets the server URL without any path or trailing /.
 AdapterResource getTargetAdapter()
           
 Resource getTargetObject()
           
 String getURI()
          Returns the part of this request's URL from the protocol name up to the query string in the first line of the HTTP request.
 String getURL()
          Gets the URL requested by the client.
 String getUrlPath()
          Gets the path portion of the request URL.
 String getUrlPath(DocumentModel document)
          This method is working only for root objects that implement ModuleResource
 StringBuilder getUrlPathBuffer()
           
 UserSession getUserSession()
          Gets the current user session.
 Resource head()
           
static boolean isRepositorySupportDisabled()
           
 AdapterResource newAdapter(Resource ctx, String serviceName, Object... args)
           
 Resource newObject(ResourceType type, Object... args)
           
 Resource newObject(String typeName, Object... args)
           
 Resource pop()
           
 File popScriptFile()
           
 Resource push(Resource rs)
           
 void pushScriptFile(File file)
           
 void render(ScriptFile script, Object ctx, Writer writer)
          Renders the given template using the rendering engine registered in that web engine.
 void render(String template, Object ctx, Writer writer)
          Renders the given template using the rendering engine registered in that web engine.
 void render(String template, Writer writer)
          Renders the given template using the rendering engine registered in that web engine.
 Object runScript(ScriptFile script, Map<String,Object> args)
          Runs the script using given arguments
 Object runScript(String script)
          Runs the given script.
 Object runScript(String script, Map<String,Object> args)
          Runs the given script.
static void setIsRepositorySupportDisabled(boolean isRepositoryDisabled)
          Can be used by the application to disable injecting repository sessions in scripting context.
 void setLocale(Locale locale)
          Sets the current locale, that will be kept in context.
 void setModule(Module module)
           
 void setProperty(String key, Object value)
          Sets a context variable.
 void setRoot(Resource root)
          Set the root resource of this context
 Resource tail()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.nuxeo.ecm.webengine.model.WebContext
getHttpHeaders, getUriInfo
 

Field Detail

DEFAULT_LOCALE

public static Locale DEFAULT_LOCALE

LOCALE_SESSION_KEY

public static final String LOCALE_SESSION_KEY
See Also:
Constant Field Values
Method Detail

setModule

public void setModule(Module module)

getRoot

public Resource getRoot()
Description copied from interface: WebContext
Gets the root resource if any resource was defined as being the root

A root resource can be any resource from the resource chain.

Specified by:
getRoot in interface WebContext
Returns:
the root resource or null if no root was defined

setRoot

public void setRoot(Resource root)
Description copied from interface: WebContext
Set the root resource of this context

Specified by:
setRoot in interface WebContext

getAdapter

public <T> T getAdapter(Class<T> adapter)
Description copied from interface: Adaptable
Returns an object which is an instance of the given class associated with this object. Returns null if no such object can be found.

Specified by:
getAdapter in interface Adaptable
Parameters:
adapter - the adapter class to look up
Returns:
a object castable to the given class, or null if this object does not have an adapter for the given class

getModule

public Module getModule()
Description copied from interface: WebContext
Gets the current web application.

Specified by:
getModule in interface WebContext
Returns:
the web root. Cannot return null.

getEngine

public WebEngine getEngine()
Description copied from interface: WebContext
Gets the web engine instance.

Specified by:
getEngine in interface WebContext
Returns:
the web engine instance. Cannot return null

getUserSession

public UserSession getUserSession()
Description copied from interface: WebContext
Gets the current user session.

The user session is a WebEngine abstraction for the current user session and can be used to retrieve current login, core session, and to set or get user session variables.

Specified by:
getUserSession in interface WebContext
Returns:
the user session. Never returns null.

getCoreSession

public CoreSession getCoreSession()
Description copied from interface: WebContext
Gets the Core Session (or Repository Session) corresponding to that request.

Specified by:
getCoreSession in interface WebContext
Returns:
the core session. Cannot return null

getPrincipal

public Principal getPrincipal()
Description copied from interface: WebContext
Gets the principal identifying the user that originated the request.

Specified by:
getPrincipal in interface WebContext
Returns:
the current principal. Cannot return null.

getRequest

public HttpServletRequest getRequest()
Description copied from interface: WebContext
Gets the underlying HTTP servlet request object.

Specified by:
getRequest in interface WebContext
Returns:
the HTTP Request object. Cannot return null

getMethod

public String getMethod()
Description copied from interface: WebContext
Get HTTP Method.

Specified by:
getMethod in interface WebContext
Returns:
the method

getModulePath

public String getModulePath()
Description copied from interface: WebContext
Get the path prefix that identify the current web application.

The application path will include the base path (context + servlet path).

Specified by:
getModulePath in interface WebContext
Returns:
the application path. Cannot be null

getMessage

public String getMessage(String key)
Description copied from interface: WebContext
Gets the i18n message for the given key.

The current module i18n messages are queried first then if no message is found the global message pool is queried (the one living in WEB-INF/i18n). If no message is found the key surrounded by exclamation marks is returned.

Specified by:
getMessage in interface WebContext
Parameters:
key - the message key
Returns:
the message

getMessage

public String getMessage(String key,
                         Object... args)
Description copied from interface: WebContext
The same as WebContext.getMessage(String) but with parameter support

Specified by:
getMessage in interface WebContext

getMessage

public String getMessage(String key,
                         List<Object> args)
Description copied from interface: WebContext
The same as WebContext.getMessage(String) but with parameter support

Specified by:
getMessage in interface WebContext

getMessageL

public String getMessageL(String key,
                          String language)
Description copied from interface: WebContext
Same as WebContext.getMessage(String) but uses the given locale.

Specified by:
getMessageL in interface WebContext
Parameters:
key - the message key
language - the locale to use
Returns:
the message

getMessageL

public String getMessageL(String key,
                          String locale,
                          Object... args)
Description copied from interface: WebContext
The same as WebContext.getMessage(String) but uses the given locale, with parameter support

Specified by:
getMessageL in interface WebContext

getMessageL

public String getMessageL(String key,
                          String locale,
                          List<Object> args)
Description copied from interface: WebContext
The same as WebContext.getMessage(String) but uses the given locale, with parameter support.

Specified by:
getMessageL in interface WebContext

getLocale

public Locale getLocale()
Description copied from interface: WebContext
Gets the context locale.

If the locale has been set using WebContext.setLocale(Locale), returns the last locale set. Otherwise, compute it from the Accept-Language language sent by the client, using ServletRequest.getLocale().

Specified by:
getLocale in interface WebContext
Returns:
the context locale

setLocale

public void setLocale(Locale locale)
Description copied from interface: WebContext
Sets the current locale, that will be kept in context.

Specified by:
setLocale in interface WebContext

newObject

public Resource newObject(String typeName,
                          Object... args)
Specified by:
newObject in interface WebContext

newObject

public Resource newObject(ResourceType type,
                          Object... args)
Specified by:
newObject in interface WebContext

newAdapter

public AdapterResource newAdapter(Resource ctx,
                                  String serviceName,
                                  Object... args)
Specified by:
newAdapter in interface WebContext

setProperty

public void setProperty(String key,
                        Object value)
Description copied from interface: WebContext
Sets a context variable.

Specified by:
setProperty in interface WebContext
Parameters:
key - the variable key
value - the variable value
See Also:
WebContext.getProperty(String)

getProperty

public Object getProperty(String key)
Description copied from interface: WebContext
Gets a context variable.

Context variables can be used to share data between the scripts that are called in that request (and between Java code too of course).

Specified by:
getProperty in interface WebContext
Parameters:
key - the variable key
Returns:
the variable value or null if none

getProperty

public Object getProperty(String key,
                          Object defaultValue)
Description copied from interface: WebContext
Gets a context variable.

Context variables can be used to share data between the scripts that are called in that request (and between java code too of course).

Specified by:
getProperty in interface WebContext
Parameters:
key - the variable key
defaultValue - the default value to use if the property doesn't exists
Returns:
the variable value or the given default value if none

getCookie

public String getCookie(String name)
Description copied from interface: WebContext
Convenience method to get a cookie value.

Specified by:
getCookie in interface WebContext
Parameters:
name - the cookie name
Returns:
the cookie value if any null otherwise

getCookie

public String getCookie(String name,
                        String defaultValue)
Description copied from interface: WebContext
Convenience method to get a cookie value using a default value.

Specified by:
getCookie in interface WebContext
Parameters:
name - the cookie name
defaultValue - the value to return when cookie is not set
Returns:
the cookie value if any or the default if none

getForm

public FormData getForm()
Description copied from interface: WebContext
Gets the representation of the data form submitted by the user.

This provides access to both POST and GET parameters, or to multipart form data requests.

Specified by:
getForm in interface WebContext
Returns:
the request form data. Cannot return null

getBasePath

public String getBasePath()
Description copied from interface: WebContext
Gets the path of the servlet. Same as servlet context path + servlet path.

Specified by:
getBasePath in interface WebContext
Returns:
the site path

getBaseURL

public String getBaseURL()
Description copied from interface: WebContext
Gets the URL of the base path. This is the same as WebContext.getURL() after removing the path segments over the base path.

Specified by:
getBaseURL in interface WebContext
Returns:
the base URL

getServerURL

public StringBuilder getServerURL()
Description copied from interface: WebContext
Gets the server URL without any path or trailing /. The returned string builder can be used to build the wanted URL. If the server is behind a proxy, return the server url of the proxy so writing the url in a webpage is safe.

Specified by:
getServerURL in interface WebContext
Returns:
a string builder

getURI

public String getURI()
Description copied from interface: WebContext
Returns the part of this request's URL from the protocol name up to the query string in the first line of the HTTP request. This is the same as HttpServletRequest.getRequestURI().

Specified by:
getURI in interface WebContext
Returns:
the request URI. Cannot return null.

getURL

public String getURL()
Description copied from interface: WebContext
Gets the URL requested by the client. Same as HttpServletRequest.getRequestURL().

Specified by:
getURL in interface WebContext
Returns:
the request URL. Cannot return null.

getUrlPathBuffer

public StringBuilder getUrlPathBuffer()

getUrlPath

public String getUrlPath()
Description copied from interface: WebContext
Gets the path portion of the request URL.

Specified by:
getUrlPath in interface WebContext
Returns:
the path portion of the request URL. Cannot return null.

getLoginPath

public String getLoginPath()
Description copied from interface: WebContext
Gets the login path for the current context.

This is the path you can use as a login form action to perform a login or a logout. After the login/logout is done the current page in that context will be served.

Specified by:
getLoginPath in interface WebContext
Returns:

getUrlPath

public String getUrlPath(DocumentModel document)
This method is working only for root objects that implement ModuleResource

Specified by:
getUrlPath in interface WebContext
Parameters:
document - the nuxeo document
Returns:
the path if any or null if no suitable path can be found XXX can this method return null?

getLog

public Log getLog()
Description copied from interface: WebContext
Gets a logger to be used by scripts for logging.

Specified by:
getLog in interface WebContext
Returns:
a logger

push

public Resource push(Resource rs)
Specified by:
push in interface WebContext

pop

public Resource pop()
Specified by:
pop in interface WebContext

tail

public Resource tail()
Specified by:
tail in interface WebContext

head

public Resource head()
Specified by:
head in interface WebContext

getFile

public ScriptFile getFile(String path)
template and script resolver

Specified by:
getFile in interface WebContext
Parameters:
path - the path to resolve into a file
Returns:
the file or null if the path couldn't be resolved

pushScriptFile

public void pushScriptFile(File file)

popScriptFile

public File popScriptFile()

getCurrentScriptFile

public File getCurrentScriptFile()

getCurrentScriptDirectory

public File getCurrentScriptDirectory()

render

public void render(String template,
                   Writer writer)
Description copied from interface: WebContext
Renders the given template using the rendering engine registered in that web engine.

This is similar to the WebContext.render(String, Object, Writer) method with a null value for the args argument.

Specified by:
render in interface WebContext
Parameters:
template - the template to render. Can be a path absolute to the web directory or relative to the caller script if any.
writer - the writer to use
See Also:
WebContext.render(String, Object, Writer)

render

public void render(String template,
                   Object ctx,
                   Writer writer)
Description copied from interface: WebContext
Renders the given template using the rendering engine registered in that web engine. The given arguments are passed to the rendering process as context variables

Specified by:
render in interface WebContext
Parameters:
template - the template to render
ctx - the arguments to pass
writer - the writer to use

render

public void render(ScriptFile script,
                   Object ctx,
                   Writer writer)
Description copied from interface: WebContext
Renders the given template using the rendering engine registered in that web engine.

The given arguments are passed to the rendering process as context variables.

Specified by:
render in interface WebContext
Parameters:
script - the template to render
ctx - the arguments to pass
writer - the writer to use

runScript

public Object runScript(String script)
Description copied from interface: WebContext
Runs the given script.

This is similar to WebContext.runScript(String, Map) with a null value for the args argument

Specified by:
runScript in interface WebContext
Parameters:
script - the script path. Can be a path absolute to the web directory or relative to the caller script if any.
See Also:
WebContext.runScript(String, Map)

runScript

public Object runScript(String script,
                        Map<String,Object> args)
Description copied from interface: WebContext
Runs the given script.

Specified by:
runScript in interface WebContext
Parameters:
script - the script path. Can be a path absolute to the web directory or relative to the caller script if any.
args - the arguments to pass

runScript

public Object runScript(ScriptFile script,
                        Map<String,Object> args)
Description copied from interface: WebContext
Runs the script using given arguments

This is similar to WebContext.runScript(String, Map) with a null value for the args argument

Specified by:
runScript in interface WebContext
Parameters:
script - the script path. Can be a path absolute to the web directory or relative to the caller script if any.
args - a map of arguments
See Also:
WebContext.runScript(String, Map)

checkGuard

public boolean checkGuard(String guard)
                   throws ParseException
Description copied from interface: WebContext
Check the given expression in this context and return true if the expression is verified or false otherwise. Any valid guard expression is accepted

Specified by:
checkGuard in interface WebContext
Parameters:
guard - the guard to check
Throws:
ParseException
See Also:
Guard

createBindings

public Map<String,Object> createBindings(Map<String,Object> vars)

getTargetObject

public Resource getTargetObject()
Specified by:
getTargetObject in interface WebContext

getTargetAdapter

public AdapterResource getTargetAdapter()
Specified by:
getTargetAdapter in interface WebContext

isRepositorySupportDisabled

public static boolean isRepositorySupportDisabled()

setIsRepositorySupportDisabled

public static void setIsRepositorySupportDisabled(boolean isRepositoryDisabled)
Can be used by the application to disable injecting repository sessions in scripting context. If the application is not deploying a repository injecting a repository session will throw exceptions each time rendering is used.

Parameters:
isRepositoryDisabled - true to disable repository session injection, false otherwise

Nuxeo ECM Projects 5.4.3-SNAPSHOT

Copyright © 2011 Nuxeo SAS. All Rights Reserved.