Interface WebContext
- All Superinterfaces:
Adaptable
- All Known Implementing Classes:
AbstractWebContext
,DefaultContext
- Author:
- Bogdan Stefanescu
-
Field Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
checkGuard
(String guard) Check the given expression in this context and return true if the expression is verified or false otherwise.Gets the path of the servlet.Gets the URL of the base path.Convenience method to get a cookie value.Convenience method to get a cookie value using a default value.Gets the Core Session (or Repository Session) corresponding to that request.Gets the web engine instance.Resolves the given path into a file.getForm()
Gets the representation of the data form submitted by the user.javax.ws.rs.core.HttpHeaders
Gets HTTP Headers as defined by JAX-RS.Gets the context locale.org.apache.logging.log4j.Logger
getLog()
Gets a logger to be used by scripts for logging.Gets the login path for the current context.getMessage
(String key) Gets the i18n message for the given key.getMessage
(String key, Object... args) The same asgetMessage(String)
but with parameter supportgetMessage
(String key, List<Object> args) The same asgetMessage(String)
but with parameter supportgetMessageL
(String key, String locale) Same asgetMessage(String)
but uses the given locale.getMessageL
(String key, String locale, Object... args) The same asgetMessage(String)
but uses the given locale, with parameter supportgetMessageL
(String key, String locale, List<Object> args) The same asgetMessage(String)
but uses the given locale, with parameter support.Get HTTP Method.Gets the current web application.Get the path prefix that identify the current web application.Gets the principal identifying the user that originated the request.getProperty
(String key) Gets a context variable.getProperty
(String key, Object defaultValue) Gets a context variable.javax.servlet.http.HttpServletRequest
Gets the underlying HTTP servlet request object.getRoot()
Gets the root resource if any resource was defined as being the rootcom.sun.jersey.api.core.HttpContext
Gets the jersey server http contextcom.sun.jersey.server.impl.inject.ServerInjectableProviderContext
Gets the jersey server injection contextGets the server URL without any path or trailing /.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.javax.ws.rs.core.UriInfo
Gets the JAX-RS UriInfo.getURL()
Gets the URL requested by the client.Gets the path portion of the request URL.getUrlPath
(DocumentModel document) Get a suitable URI path for the given Nuxeo document, that can be used to invoke this document.Gets the current user session.head()
newAdapter
(Resource ctx, String adapterName, Object... args) newObject
(ResourceType type, Object... args) pop()
void
Renders the given template using the rendering engine registered in that web engine.void
Renders the given template using the rendering engine registered in that web engine.void
render
(ScriptFile script, Object args, Writer writer) Renders the given template using the rendering engine registered in that web engine.Runs the given script.Runs the given script.runScript
(ScriptFile script, Map<String, Object> args) Runs the script using given argumentsvoid
Sets the current locale, that will be kept in context.void
setProperty
(String key, Object value) Sets a context variable.void
setRepositoryName
(String repoName) Sets the repository name that will be used bygetCoreSession()
.void
Set the root resource of this contexttail()
Methods inherited from interface org.nuxeo.runtime.model.Adaptable
getAdapter
-
Field Details
-
NUXEO_WEBENGINE_BASE_PATH
This variable is used in a proxy setting. The proxy should send a header with this name. Webengine will assume that the base path of the application is this value.
If your application is on server localhost:8080/nuxeo/site/myapp and you proxy it via mysite.com/myapp, then the header should have an empty string value.
- See Also:
-
-
Method Details
-
getModule
Module getModule()Gets the current web application.- Returns:
- the web root. Cannot return null.
-
getServerInjectableProviderContext
com.sun.jersey.server.impl.inject.ServerInjectableProviderContext getServerInjectableProviderContext()Gets the jersey server injection context- Since:
- 9.1
-
getServerHttpContext
com.sun.jersey.api.core.HttpContext getServerHttpContext()Gets the jersey server http context- Since:
- 9.1
-
getRoot
Resource getRoot()Gets the root resource if any resource was defined as being the rootA root resource can be any resource from the resource chain.
- Returns:
- the root resource or null if no root was defined
-
setRoot
Set the root resource of this context -
getMessage
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.
- Parameters:
key
- the message key- Returns:
- the message
-
getMessage
The same asgetMessage(String)
but with parameter support -
getMessage
The same asgetMessage(String)
but with parameter support -
getMessageL
Same asgetMessage(String)
but uses the given locale.- Parameters:
key
- the message keylocale
- the locale to use- Returns:
- the message
-
getMessageL
The same asgetMessage(String)
but uses the given locale, with parameter support -
getMessageL
The same asgetMessage(String)
but uses the given locale, with parameter support. -
getLocale
Locale getLocale()Gets the context locale.If the locale has been set using
setLocale(Locale)
, returns the last locale set. Otherwise, compute it from the Accept-Language language sent by the client, usingServletRequest.getLocale()
.- Returns:
- the context locale
-
setLocale
Sets the current locale, that will be kept in context. -
getEngine
WebEngine getEngine()Gets the web engine instance.- Returns:
- the web engine instance. Cannot return null
-
getUserSession
UserSession getUserSession()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.
- Returns:
- the user session. Never returns null.
-
getCoreSession
CoreSession getCoreSession()Gets the Core Session (or Repository Session) corresponding to that request.- Returns:
- the core session. Cannot return null
-
getPrincipal
NuxeoPrincipal getPrincipal()Gets the principal identifying the user that originated the request.- Returns:
- the current principal. Can return null if the user has not been authenticated.
-
getUriInfo
javax.ws.rs.core.UriInfo getUriInfo()Gets the JAX-RS UriInfo.- Returns:
- the uri info
-
getHttpHeaders
javax.ws.rs.core.HttpHeaders getHttpHeaders()Gets HTTP Headers as defined by JAX-RS.- Returns:
- HTTP headers object
-
getRequest
javax.servlet.http.HttpServletRequest getRequest()Gets the underlying HTTP servlet request object.- Returns:
- the HTTP Request object. Cannot return null
-
getMethod
String getMethod()Get HTTP Method.- Returns:
- the method
-
getForm
FormData getForm()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.
- Returns:
- the request form data. Cannot return null
-
getURL
String getURL()Gets the URL requested by the client. Same asHttpServletRequest.getRequestURL()
.- Returns:
- the request URL. Cannot return null.
-
getURI
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. This is the same asHttpServletRequest.getRequestURI()
.- Returns:
- the request URI. Cannot return null.
-
getUrlPath
String getUrlPath()Gets the path portion of the request URL.- Returns:
- the path portion of the request URL. Cannot return null.
-
getLoginPath
String getLoginPath()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.
-
getModulePath
String getModulePath()Get the path prefix that identify the current web application.The application path will include the base path (context + servlet path).
- Returns:
- the application path. Cannot be null
-
getBasePath
String getBasePath()Gets the path of the servlet. Same as servlet context path + servlet path.- Returns:
- the site path
-
getBaseURL
String getBaseURL()Gets the URL of the base path. This is the same asgetURL()
after removing the path segments over the base path.- Returns:
- the base URL
-
getServerURL
StringBuilder getServerURL()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.- Returns:
- a string builder
-
getUrlPath
Get a suitable URI path for the given Nuxeo document, that can be used to invoke this document. This method is working only for root objects that implementModuleResource
- 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?
- Throws:
ClassCastException
- if the module root does not implementingModuleResource
-
setProperty
Sets a context variable.- Parameters:
key
- the variable keyvalue
- the variable value- See Also:
-
getProperty
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).
- Parameters:
key
- the variable key- Returns:
- the variable value or null if none
-
getProperty
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).
- Parameters:
key
- the variable keydefaultValue
- the default value to use if the property doesn't exists- Returns:
- the variable value or the given default value if none
-
getCookie
Convenience method to get a cookie value.- Parameters:
name
- the cookie name- Returns:
- the cookie value if any null otherwise
-
getCookie
Convenience method to get a cookie value using a default value.- Parameters:
name
- the cookie namedefaultValue
- the value to return when cookie is not set- Returns:
- the cookie value if any or the default if none
-
getLog
org.apache.logging.log4j.Logger getLog()Gets a logger to be used by scripts for logging.- Returns:
- a logger
-
newObject
-
newObject
-
newAdapter
-
push
-
pop
Resource pop() -
tail
Resource tail() -
head
Resource head() -
getTargetObject
Resource getTargetObject() -
getTargetAdapter
AdapterResource getTargetAdapter() -
getFile
Resolves the given path into a file.The path is resolved as following:
- if the path begin with a dot '.' then a local path is assumed and the path will be resolved relative to the current executed script if any. Note that the directory stack will be consulted as well. If there is no current executed script then the path will be transformed into an absolute path and next step is entered.
- the resolving is delegated to the current
Module.getFile(String)
that will try to resolve the path relative to each directory in the directory stack
- Parameters:
path
- the path to resolve into a file- Returns:
- the file or null if the path couldn't be resolved
-
render
Renders the given template using the rendering engine registered in that web engine.This is similar to the
render(String, Object, Writer)
method with a null value for the args argument.- 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:
-
render
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- Parameters:
template
- the template to renderargs
- the arguments to passwriter
- the writer to use
-
render
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.
- Parameters:
script
- the template to renderargs
- the arguments to passwriter
- the writer to use
-
runScript
Runs the given script.- 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
Runs the given script.This is similar to
runScript(String, Map)
with a null value for the args argument- Parameters:
script
- the script path. Can be a path absolute to the web directory or relative to the caller script if any.- See Also:
-
runScript
Runs the script using given argumentsThis is similar to
runScript(String, Map)
with a null value for the args argument- 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:
-
checkGuard
Check the given expression in this context and return true if the expression is verified or false otherwise. Any valid guard expression is accepted- Parameters:
guard
- the guard to check- Throws:
ParseException
- See Also:
-
setRepositoryName
Sets the repository name that will be used bygetCoreSession()
.- Throws:
IllegalArgumentException
- if the repository is not found.- Since:
- 5.7.3
-