public abstract class AbstractWebContext extends Object implements WebContext
Modifier and Type | Field and Description |
---|---|
static Locale |
DEFAULT_LOCALE |
static String |
LOCALE_SESSION_KEY |
NUXEO_WEBENGINE_BASE_PATH
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.
|
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() |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getHttpHeaders, getUriInfo
public static Locale DEFAULT_LOCALE
public static final String LOCALE_SESSION_KEY
public void setModule(Module module)
public Resource getRoot()
WebContext
A root resource can be any resource from the resource chain.
getRoot
in interface WebContext
public void setRoot(Resource root)
WebContext
setRoot
in interface WebContext
public <T> T getAdapter(Class<T> adapter)
Adaptable
null
if
no such object can be found.getAdapter
in interface Adaptable
adapter
- the adapter class to look upnull
if this object does not
have an adapter for the given classpublic Module getModule()
WebContext
getModule
in interface WebContext
public WebEngine getEngine()
WebContext
getEngine
in interface WebContext
public UserSession getUserSession()
WebContext
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.
getUserSession
in interface WebContext
public CoreSession getCoreSession()
WebContext
getCoreSession
in interface WebContext
public Principal getPrincipal()
WebContext
getPrincipal
in interface WebContext
public HttpServletRequest getRequest()
WebContext
getRequest
in interface WebContext
public String getMethod()
WebContext
getMethod
in interface WebContext
public String getModulePath()
WebContext
The application path will include the base path (context + servlet path).
getModulePath
in interface WebContext
public String getMessage(String key)
WebContext
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.
getMessage
in interface WebContext
key
- the message keypublic String getMessage(String key, Object... args)
WebContext
WebContext.getMessage(String)
but with parameter supportgetMessage
in interface WebContext
public String getMessage(String key, List<Object> args)
WebContext
WebContext.getMessage(String)
but with parameter supportgetMessage
in interface WebContext
public String getMessageL(String key, String language)
WebContext
WebContext.getMessage(String)
but uses the given locale.getMessageL
in interface WebContext
key
- the message keylanguage
- the locale to usepublic String getMessageL(String key, String locale, Object... args)
WebContext
WebContext.getMessage(String)
but uses the given locale, with
parameter supportgetMessageL
in interface WebContext
public String getMessageL(String key, String locale, List<Object> args)
WebContext
WebContext.getMessage(String)
but uses the given locale, with
parameter support.getMessageL
in interface WebContext
public 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 WebContext
public void setLocale(Locale locale)
WebContext
setLocale
in interface WebContext
public Resource newObject(String typeName, Object... args)
newObject
in interface WebContext
public Resource newObject(ResourceType type, Object... args)
newObject
in interface WebContext
public AdapterResource newAdapter(Resource ctx, String serviceName, Object... args)
newAdapter
in interface WebContext
public void setProperty(String key, Object value)
WebContext
setProperty
in interface WebContext
key
- the variable keyvalue
- the variable valueWebContext.getProperty(String)
public Object getProperty(String key)
WebContext
Context 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 WebContext
key
- the variable keypublic Object getProperty(String key, Object defaultValue)
WebContext
Context 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 WebContext
key
- the variable keydefaultValue
- the default value to use if the property doesn't
existspublic String getCookie(String name)
WebContext
getCookie
in interface WebContext
name
- the cookie namepublic String getCookie(String name, String defaultValue)
WebContext
getCookie
in interface WebContext
name
- the cookie namedefaultValue
- the value to return when cookie is not setpublic FormData getForm()
WebContext
This provides access to both POST and GET parameters, or to multipart form data requests.
getForm
in interface WebContext
public String getBasePath()
WebContext
getBasePath
in interface WebContext
public String getBaseURL()
WebContext
WebContext.getURL()
after removing the path segments over the base path.getBaseURL
in interface WebContext
public StringBuilder getServerURL()
WebContext
getServerURL
in interface WebContext
public String getURI()
WebContext
HttpServletRequest.getRequestURI()
.getURI
in interface WebContext
public String getURL()
WebContext
HttpServletRequest.getRequestURL()
.getURL
in interface WebContext
public StringBuilder getUrlPathBuffer()
public String getUrlPath()
WebContext
getUrlPath
in interface WebContext
public String getLoginPath()
WebContext
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.
getLoginPath
in interface WebContext
public String getUrlPath(DocumentModel document)
ModuleResource
getUrlPath
in interface WebContext
document
- the nuxeo documentpublic Log getLog()
WebContext
getLog
in interface WebContext
public Resource push(Resource rs)
push
in interface WebContext
public Resource pop()
pop
in interface WebContext
public Resource tail()
tail
in interface WebContext
public Resource head()
head
in interface WebContext
public ScriptFile getFile(String path)
getFile
in interface WebContext
path
- 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 WebContext
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 useWebContext.render(String, Object, Writer)
public void render(String template, Object ctx, Writer writer)
WebContext
render
in interface WebContext
template
- the template to renderctx
- the arguments to passwriter
- the writer to usepublic void render(ScriptFile script, Object ctx, Writer writer)
WebContext
The given arguments are passed to the rendering process as context variables.
render
in interface WebContext
script
- 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 WebContext
script
- 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)
WebContext
runScript
in interface WebContext
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 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 WebContext
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 argumentsWebContext.runScript(String, Map)
public boolean checkGuard(String guard) throws ParseException
WebContext
checkGuard
in interface WebContext
guard
- the guard to checkParseException
Guard
public Resource getTargetObject()
getTargetObject
in interface WebContext
public AdapterResource getTargetAdapter()
getTargetAdapter
in interface WebContext
public static boolean isRepositorySupportDisabled()
public static void setIsRepositorySupportDisabled(boolean isRepositoryDisabled)
isRepositoryDisabled
- true to disable repository session injection,
false otherwiseCopyright © 2011 Nuxeo SA. All Rights Reserved.