Interface WebContext

    • Field Detail

      • NUXEO_WEBENGINE_BASE_PATH

        static final String 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:
        Constant Field Values
    • Method Detail

      • 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 root

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

        Returns:
        the root resource or null if no root was defined
      • setRoot

        void setRoot​(Resource root)
        Set the root resource of this context
      • getMessage

        String getMessage​(String key)
        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
      • getMessageL

        String getMessageL​(String key,
                           String locale)
        Same as getMessage(String) but uses the given locale.
        Parameters:
        key - the message key
        locale - the locale to use
        Returns:
        the message
      • 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, using ServletRequest.getLocale().

        Returns:
        the context locale
      • setLocale

        void setLocale​(Locale locale)
        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 as HttpServletRequest.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 as HttpServletRequest.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 as getURL() 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

        String getUrlPath​(DocumentModel document)
        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 implement ModuleResource
        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 implementing ModuleResource
      • setProperty

        void setProperty​(String key,
                         Object value)
        Sets a context variable.
        Parameters:
        key - the variable key
        value - the variable value
        See Also:
        getProperty(String)
      • getProperty

        Object getProperty​(String key)
        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

        Object getProperty​(String key,
                           Object defaultValue)
        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
        defaultValue - the default value to use if the property doesn't exists
        Returns:
        the variable value or the given default value if none
      • getCookie

        String getCookie​(String name)
        Convenience method to get a cookie value.
        Parameters:
        name - the cookie name
        Returns:
        the cookie value if any null otherwise
      • getCookie

        String getCookie​(String name,
                         String defaultValue)
        Convenience method to get a cookie value using a default value.
        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
      • getLog

        Log getLog()
        Gets a logger to be used by scripts for logging.
        Returns:
        a logger
      • getTargetObject

        Resource getTargetObject()
      • getFile

        ScriptFile getFile​(String path)
        Resolves the given path into a file.

        The path is resolved as following:

        1. 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.
        2. 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

        void render​(String template,
                    Writer writer)
        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(String, Object, Writer)
      • render

        void render​(String template,
                    Object args,
                    Writer writer)
        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 render
        args - the arguments to pass
        writer - the writer to use
      • render

        void render​(ScriptFile script,
                    Object args,
                    Writer writer)
        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 render
        args - the arguments to pass
        writer - the writer to use
      • runScript

        Object runScript​(String script,
                         Map<String,​Object> args)
        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

        Object runScript​(String script)
        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(String, Map)
      • runScript

        Object runScript​(ScriptFile script,
                         Map<String,​Object> args)
        Runs the script using given arguments

        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.
        args - a map of arguments
        See Also:
        runScript(String, Map)
      • checkGuard

        boolean checkGuard​(String guard)
                    throws ParseException
        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:
        Guard