public abstract class AbstractWebContext extends Object implements WebContext
| Modifier and Type | Field and Description |
|---|---|
protected String |
basePath |
static Locale |
DEFAULT_LOCALE |
protected WebEngine |
engine |
protected FormData |
form |
protected Resource |
head |
static String |
LOCALE_SESSION_KEY |
protected Module |
module |
protected javax.servlet.http.HttpServletRequest |
request |
protected Resource |
root |
protected LinkedList<File> |
scriptExecutionStack |
protected Resource |
tail |
protected Map<String,Object> |
vars |
NUXEO_WEBENGINE_BASE_PATH| Modifier | Constructor and Description |
|---|---|
protected |
AbstractWebContext(javax.servlet.http.HttpServletRequest request) |
| Modifier and Type | Method and Description |
|---|---|
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.
|
org.apache.commons.logging.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.
|
javax.servlet.http.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() |
protected void |
initializeBindings(Map<String,Object> bindings) |
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 |
setRepositoryName(String repoName)
Sets the repository name that will be used by
WebContext.getCoreSession(). |
void |
setRoot(Resource root)
Set the root resource of this context
|
Resource |
tail() |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitgetHttpHeaders, getUriInfopublic static Locale DEFAULT_LOCALE
public static final String LOCALE_SESSION_KEY
protected final LinkedList<File> scriptExecutionStack
protected final javax.servlet.http.HttpServletRequest request
protected AbstractWebContext(javax.servlet.http.HttpServletRequest request)
public Resource getRoot()
WebContextA root resource can be any resource from the resource chain.
getRoot in interface WebContextpublic void setRoot(Resource root)
WebContextsetRoot in interface WebContextpublic <T> T getAdapter(Class<T> adapter)
Adaptablenull
if no such object can be found.getAdapter in interface Adaptableadapter - the adapter class to look upnull if this object does not have an adapter for
the given classpublic Module getModule()
WebContextgetModule in interface WebContextpublic WebEngine getEngine()
WebContextgetEngine in interface WebContextpublic UserSession getUserSession()
WebContextThe 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.
getUserSession in interface WebContextpublic CoreSession getCoreSession()
WebContextgetCoreSession in interface WebContextpublic Principal getPrincipal()
WebContextgetPrincipal in interface WebContextpublic javax.servlet.http.HttpServletRequest getRequest()
WebContextgetRequest in interface WebContextpublic String getMethod()
WebContextgetMethod in interface WebContextpublic String getModulePath()
WebContextThe application path will include the base path (context + servlet path).
getModulePath in interface WebContextpublic String getMessage(String key)
WebContextThe 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.
getMessage in interface WebContextkey - the message keypublic String getMessage(String key, Object... args)
WebContextWebContext.getMessage(String) but with parameter supportgetMessage in interface WebContextpublic String getMessage(String key, List<Object> args)
WebContextWebContext.getMessage(String) but with parameter supportgetMessage in interface WebContextpublic String getMessageL(String key, String language)
WebContextWebContext.getMessage(String) but uses the given locale.getMessageL in interface WebContextkey - the message keylanguage - the locale to usepublic String getMessageL(String key, String locale, Object... args)
WebContextWebContext.getMessage(String) but uses the given locale, with parameter supportgetMessageL in interface WebContextpublic String getMessageL(String key, String locale, List<Object> args)
WebContextWebContext.getMessage(String) but uses the given locale, with parameter support.getMessageL in interface WebContextpublic Locale getLocale()
WebContext
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().
getLocale in interface WebContextpublic void setLocale(Locale locale)
WebContextsetLocale in interface WebContextpublic Resource newObject(String typeName, Object... args)
newObject in interface WebContextpublic Resource newObject(ResourceType type, Object... args)
newObject in interface WebContextpublic AdapterResource newAdapter(Resource ctx, String serviceName, Object... args)
newAdapter in interface WebContextpublic void setProperty(String key, Object value)
WebContextsetProperty in interface WebContextkey - the variable keyvalue - the variable valueWebContext.getProperty(String)public Object getProperty(String key)
WebContextContext variables can be used to share data between the scripts that are called in that request (and between Java code too of course).
getProperty in interface WebContextkey - the variable keypublic Object getProperty(String key, Object defaultValue)
WebContextContext variables can be used to share data between the scripts that are called in that request (and between java code too of course).
getProperty in interface WebContextkey - the variable keydefaultValue - the default value to use if the property doesn't existspublic String getCookie(String name)
WebContextgetCookie in interface WebContextname - the cookie namepublic String getCookie(String name, String defaultValue)
WebContextgetCookie in interface WebContextname - the cookie namedefaultValue - the value to return when cookie is not setpublic FormData getForm()
WebContextThis provides access to both POST and GET parameters, or to multipart form data requests.
getForm in interface WebContextpublic String getBasePath()
WebContextgetBasePath in interface WebContextpublic String getBaseURL()
WebContextWebContext.getURL() after removing the path segments over the
base path.getBaseURL in interface WebContextpublic StringBuilder getServerURL()
WebContextgetServerURL in interface WebContextpublic String getURI()
WebContextHttpServletRequest.getRequestURI().getURI in interface WebContextpublic String getURL()
WebContextHttpServletRequest.getRequestURL().getURL in interface WebContextpublic StringBuilder getUrlPathBuffer()
public String getUrlPath()
WebContextgetUrlPath in interface WebContextpublic String getLoginPath()
WebContextThis 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.
getLoginPath in interface WebContextpublic String getUrlPath(DocumentModel document)
ModuleResourcegetUrlPath in interface WebContextdocument - the nuxeo documentpublic org.apache.commons.logging.Log getLog()
WebContextgetLog in interface WebContextpublic Resource push(Resource rs)
push in interface WebContextpublic Resource pop()
pop in interface WebContextpublic Resource tail()
tail in interface WebContextpublic Resource head()
head in interface WebContextpublic ScriptFile getFile(String path)
getFile in interface WebContextpath - the path to resolve into a filepublic void pushScriptFile(File file)
public File popScriptFile()
public File getCurrentScriptFile()
public File getCurrentScriptDirectory()
public void render(String template, Writer writer)
WebContext
This is similar to the WebContext.render(String, Object, Writer) method with a null value for the args
argument.
render in interface WebContexttemplate - 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 useWebContext.render(String, Object, Writer)public void render(String template, Object ctx, Writer writer)
WebContextrender in interface WebContexttemplate - the template to renderctx - the arguments to passwriter - the writer to usepublic void render(ScriptFile script, Object ctx, Writer writer)
WebContextThe given arguments are passed to the rendering process as context variables.
render in interface WebContextscript - the template to renderctx - the arguments to passwriter - the writer to usepublic Object runScript(String script)
WebContext
This is similar to WebContext.runScript(String, Map) with a null value for the args argument
runScript in interface WebContextscript - the script path. Can be a path absolute to the web directory or relative to the caller script if
any.WebContext.runScript(String, Map)public Object runScript(String script, Map<String,Object> args)
WebContextrunScript in interface WebContextscript - the script path. Can be a path absolute to the web directory or relative to the caller script if
any.args - the arguments to passpublic Object runScript(ScriptFile script, Map<String,Object> args)
WebContext
This is similar to WebContext.runScript(String, Map) with a null value for the args argument
runScript in interface WebContextscript - the script path. Can be a path absolute to the web directory or relative to the caller script if
any.args - a map of argumentsWebContext.runScript(String, Map)public boolean checkGuard(String guard) throws ParseException
WebContextcheckGuard in interface WebContextguard - the guard to checkParseExceptionGuardpublic Resource getTargetObject()
getTargetObject in interface WebContextpublic AdapterResource getTargetAdapter()
getTargetAdapter in interface WebContextprotected void initializeBindings(Map<String,Object> bindings)
public static boolean isRepositorySupportDisabled()
public static void setIsRepositorySupportDisabled(boolean isRepositoryDisabled)
isRepositoryDisabled - true to disable repository session injection, false otherwisepublic void setRepositoryName(String repoName)
WebContextWebContext.getCoreSession().setRepositoryName in interface WebContextCopyright © 2016 Nuxeo SA. All rights reserved.