Class AbstractWebContext
- All Implemented Interfaces:
WebContext,Adaptable
- Direct Known Subclasses:
DefaultContext
- Author:
- Bogdan Stefanescu
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Stringprotected static final Localeprotected final WebEngineprotected Resourceprotected final jakarta.ws.rs.core.HttpHeadersstatic final Stringprotected Moduleprotected Stringprotected final jakarta.servlet.http.HttpServletRequestprotected final jakarta.ws.rs.container.ResourceContextprotected final jakarta.servlet.http.HttpServletResponseprotected Resourceprotected final LinkedList<File> protected Resourceprotected final jakarta.ws.rs.core.UriInfoprotected UserSessionFields inherited from interface org.nuxeo.ecm.webengine.model.WebContext
NUXEO_WEBENGINE_BASE_PATH -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractWebContext(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, jakarta.ws.rs.core.HttpHeaders headers, jakarta.ws.rs.core.UriInfo uriInfo, jakarta.ws.rs.container.ResourceContext resourceContext) -
Method Summary
Modifier and TypeMethodDescriptionbooleancheckGuard(String guard) Check the given expression in this context and return true if the expression is verified or false otherwise.createBindings(Map<String, Object> vars) <T> TgetAdapter(Class<T> adapter) Returns an object which is an instance of the given class associated with this object.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.template and script resolverjakarta.ws.rs.core.HttpHeadersGets HTTP Headers.Gets the context locale.org.apache.logging.log4j.LoggergetLog()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 asWebContext.getMessage(String)but with parameter supportgetMessage(String key, List<Object> args) The same asWebContext.getMessage(String)but with parameter supportgetMessageL(String key, String language) Same asWebContext.getMessage(String)but uses the given locale.getMessageL(String key, String locale, Object... args) The same asWebContext.getMessage(String)but uses the given locale, with parameter supportgetMessageL(String key, String locale, List<Object> args) The same asWebContext.getMessage(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.jakarta.servlet.http.HttpServletRequestGets the underlying HTTP servlet request object.jakarta.servlet.http.HttpServletResponseGets the underlying HTTP servlet response object.getRoot()Gets the root resource if any resource was defined as being the rootGets 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.jakarta.ws.rs.core.UriInfoGets the UriInfo.getURL()Gets the URL requested by the client.Gets the path portion of the request URL.getUrlPath(DocumentModel document) This method is working only for root objects that implementModuleResourceGets the current user session.head()protected voidinitializeBindings(Map<String, Object> bindings) static boolean<A extends AdapterResource>
AnewAdapter(Resource ctx, String serviceName, Object... args) <R extends Resource>
R<R extends Resource>
RnewObject(ResourceType type, Object... args) pop()voidpushScriptFile(File file) voidRenders the given template using the rendering engine registered in that web engine.voidRenders the given template using the rendering engine registered in that web engine.voidrender(ScriptFile script, Object ctx, 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 argumentsstatic voidsetIsRepositorySupportDisabled(boolean isRepositoryDisabled) Can be used by the application to disable injecting repository sessions in scripting context.voidSets the current locale, that will be kept in context.voidSets the module of this contextvoidsetProperty(String key, Object value) Sets a context variable.voidsetRepositoryName(String repoName) Sets the repository name that will be used byWebContext.getCoreSession().voidSet the root resource of this contexttail()
-
Field Details
-
DEFAULT_LOCALE
-
LOCALE_SESSION_KEY
- See Also:
-
request
protected final jakarta.servlet.http.HttpServletRequest request -
response
protected final jakarta.servlet.http.HttpServletResponse response -
headers
protected final jakarta.ws.rs.core.HttpHeaders headers -
uriInfo
protected final jakarta.ws.rs.core.UriInfo uriInfo -
resourceContext
protected final jakarta.ws.rs.container.ResourceContext resourceContext -
engine
-
scriptExecutionStack
-
vars
-
us
-
head
-
tail
-
root
-
module
-
basePath
-
repoName
-
-
Constructor Details
-
AbstractWebContext
protected AbstractWebContext(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, jakarta.ws.rs.core.HttpHeaders headers, jakarta.ws.rs.core.UriInfo uriInfo, jakarta.ws.rs.container.ResourceContext resourceContext)
-
-
Method Details
-
getModule
Description copied from interface:WebContextGets the current web application.- Specified by:
getModulein interfaceWebContext- Returns:
- the web root.
-
setModule
Description copied from interface:WebContextSets the module of this context- Specified by:
setModulein interfaceWebContext
-
getRoot
Description copied from interface:WebContextGets the root resource if any resource was defined as being the rootA root resource can be any resource from the resource chain.
- Specified by:
getRootin interfaceWebContext- Returns:
- the root resource or null if no root was defined
-
setRoot
Description copied from interface:WebContextSet the root resource of this context- Specified by:
setRootin interfaceWebContext
-
getAdapter
Description copied from interface:AdaptableReturns an object which is an instance of the given class associated with this object. Returnsnullif no such object can be found.- Specified by:
getAdapterin interfaceAdaptable- Parameters:
adapter- the adapter class to look up- Returns:
- a object castable to the given class, or
nullif this object does not have an adapter for the given class
-
getEngine
Description copied from interface:WebContextGets the web engine instance.- Specified by:
getEnginein interfaceWebContext- Returns:
- the web engine instance. Cannot return null
-
getUserSession
Description copied from interface:WebContextGets 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:
getUserSessionin interfaceWebContext- Returns:
- the user session. Never returns null.
-
getCoreSession
Description copied from interface:WebContextGets the Core Session (or Repository Session) corresponding to that request.- Specified by:
getCoreSessionin interfaceWebContext- Returns:
- the core session. Cannot return null
-
getPrincipal
Description copied from interface:WebContextGets the principal identifying the user that originated the request.- Specified by:
getPrincipalin interfaceWebContext- Returns:
- the current principal. Can return null if the user has not been authenticated.
-
getRequest
public jakarta.servlet.http.HttpServletRequest getRequest()Description copied from interface:WebContextGets the underlying HTTP servlet request object.- Specified by:
getRequestin interfaceWebContext- Returns:
- the HTTP Request object. Cannot return null
-
getResponse
public jakarta.servlet.http.HttpServletResponse getResponse()Description copied from interface:WebContextGets the underlying HTTP servlet response object.- Specified by:
getResponsein interfaceWebContext- Returns:
- the HTTP Response object. Cannot return null
-
getUriInfo
public jakarta.ws.rs.core.UriInfo getUriInfo()Description copied from interface:WebContextGets the UriInfo.- Specified by:
getUriInfoin interfaceWebContext- Returns:
- the uri info
-
getHttpHeaders
public jakarta.ws.rs.core.HttpHeaders getHttpHeaders()Description copied from interface:WebContextGets HTTP Headers.- Specified by:
getHttpHeadersin interfaceWebContext- Returns:
- HTTP headers object
-
getMethod
Description copied from interface:WebContextGet HTTP Method.- Specified by:
getMethodin interfaceWebContext- Returns:
- the method
-
getModulePath
Description copied from interface:WebContextGet the path prefix that identify the current web application.The application path will include the base path (context + servlet path).
- Specified by:
getModulePathin interfaceWebContext- Returns:
- the application path. Cannot be null
-
getMessage
Description copied from interface:WebContextGets 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:
getMessagein interfaceWebContext- Parameters:
key- the message key- Returns:
- the message
-
getMessage
Description copied from interface:WebContextThe same asWebContext.getMessage(String)but with parameter support- Specified by:
getMessagein interfaceWebContext
-
getMessage
Description copied from interface:WebContextThe same asWebContext.getMessage(String)but with parameter support- Specified by:
getMessagein interfaceWebContext
-
getMessageL
Description copied from interface:WebContextSame asWebContext.getMessage(String)but uses the given locale.- Specified by:
getMessageLin interfaceWebContext- Parameters:
key- the message keylanguage- the locale to use- Returns:
- the message
-
getMessageL
Description copied from interface:WebContextThe same asWebContext.getMessage(String)but uses the given locale, with parameter support- Specified by:
getMessageLin interfaceWebContext
-
getMessageL
Description copied from interface:WebContextThe same asWebContext.getMessage(String)but uses the given locale, with parameter support.- Specified by:
getMessageLin interfaceWebContext
-
getLocale
Description copied from interface:WebContextGets 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, usingServletRequest.getLocale().- Specified by:
getLocalein interfaceWebContext- Returns:
- the context locale
-
setLocale
Description copied from interface:WebContextSets the current locale, that will be kept in context.- Specified by:
setLocalein interfaceWebContext
-
newObject
- Specified by:
newObjectin interfaceWebContext
-
newObject
- Specified by:
newObjectin interfaceWebContext
-
newAdapter
- Specified by:
newAdapterin interfaceWebContext
-
setProperty
Description copied from interface:WebContextSets a context variable.- Specified by:
setPropertyin interfaceWebContext- Parameters:
key- the variable keyvalue- the variable value- See Also:
-
getProperty
Description copied from interface:WebContextGets 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:
getPropertyin interfaceWebContext- Parameters:
key- the variable key- Returns:
- the variable value or null if none
-
getProperty
Description copied from interface:WebContextGets 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:
getPropertyin interfaceWebContext- 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
Description copied from interface:WebContextConvenience method to get a cookie value.- Specified by:
getCookiein interfaceWebContext- Parameters:
name- the cookie name- Returns:
- the cookie value if any null otherwise
-
getCookie
Description copied from interface:WebContextConvenience method to get a cookie value using a default value.- Specified by:
getCookiein interfaceWebContext- 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
-
getBasePath
Description copied from interface:WebContextGets the path of the servlet. Same as servlet context path + servlet path.- Specified by:
getBasePathin interfaceWebContext- Returns:
- the site path
-
getBaseURL
Description copied from interface:WebContextGets the URL of the base path. This is the same asWebContext.getURL()after removing the path segments over the base path.- Specified by:
getBaseURLin interfaceWebContext- Returns:
- the base URL
-
getServerURL
Description copied from interface:WebContextGets 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:
getServerURLin interfaceWebContext- Returns:
- a string builder
-
getURI
Description copied from interface:WebContextReturns 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().- Specified by:
getURIin interfaceWebContext- Returns:
- the request URI. Cannot return null.
-
getURL
Description copied from interface:WebContextGets the URL requested by the client. Same asHttpServletRequest.getRequestURL().- Specified by:
getURLin interfaceWebContext- Returns:
- the request URL. Cannot return null.
-
getUrlPathBuffer
-
getUrlPath
Description copied from interface:WebContextGets the path portion of the request URL.- Specified by:
getUrlPathin interfaceWebContext- Returns:
- the path portion of the request URL. Cannot return null.
-
getLoginPath
Description copied from interface:WebContextGets 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:
getLoginPathin interfaceWebContext
-
getUrlPath
This method is working only for root objects that implementModuleResource- Specified by:
getUrlPathin interfaceWebContext- 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 org.apache.logging.log4j.Logger getLog()Description copied from interface:WebContextGets a logger to be used by scripts for logging.- Specified by:
getLogin interfaceWebContext- Returns:
- a logger
-
push
- Specified by:
pushin interfaceWebContext
-
pop
- Specified by:
popin interfaceWebContext
-
tail
- Specified by:
tailin interfaceWebContext
-
head
- Specified by:
headin interfaceWebContext
-
getFile
template and script resolver- Specified by:
getFilein interfaceWebContext- Parameters:
path- the path to resolve into a file- Returns:
- the file or null if the path couldn't be resolved
-
pushScriptFile
-
popScriptFile
-
getCurrentScriptFile
-
getCurrentScriptDirectory
-
render
Description copied from interface:WebContextRenders 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:
renderin interfaceWebContext- 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
Description copied from interface:WebContextRenders 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:
renderin interfaceWebContext- Parameters:
template- the template to renderctx- the arguments to passwriter- the writer to use
-
render
Description copied from interface:WebContextRenders 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:
renderin interfaceWebContext- Parameters:
script- the template to renderctx- the arguments to passwriter- the writer to use
-
runScript
Description copied from interface:WebContextRuns the given script.This is similar to
WebContext.runScript(String, Map)with a null value for the args argument- Specified by:
runScriptin interfaceWebContext- 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
Description copied from interface:WebContextRuns the given script.- Specified by:
runScriptin interfaceWebContext- 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
Description copied from interface:WebContextRuns the script using given argumentsThis is similar to
WebContext.runScript(String, Map)with a null value for the args argument- Specified by:
runScriptin interfaceWebContext- 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
Description copied from interface:WebContextCheck 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:
checkGuardin interfaceWebContext- Parameters:
guard- the guard to check- Throws:
ParseException- See Also:
-
createBindings
-
getTargetObject
- Specified by:
getTargetObjectin interfaceWebContext
-
getTargetAdapter
- Specified by:
getTargetAdapterin interfaceWebContext
-
initializeBindings
-
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
-
setRepositoryName
Description copied from interface:WebContextSets the repository name that will be used byWebContext.getCoreSession().- Specified by:
setRepositoryNamein interfaceWebContext
-