Class ExecutionImpl

    • Constructor Detail

      • ExecutionImpl

        public ExecutionImpl​(javax.servlet.ServletContext ctx,
                             javax.servlet.http.HttpServletRequest request,
                             javax.servlet.http.HttpServletResponse response,
                             Desktop desktop,
                             Page creating)
        Constructs an execution for the given HTTP request.
        Parameters:
        creating - which page is being creating for this execution, or null if none is being created.
    • Method Detail

      • onActivate

        public void onActivate()
        Description copied from interface: ExecutionCtrl
        Called when this execution is about to become the current execution Executions.getCurrent().

        Note: an execution might spread over several threads, so this method might be called several times to activate the states in each thread. Also, an execution might be activated before another is deactivate. For example, when a component includes another page, the second exec is activated to render the included page.

        It is used as callback notification.

        Note: don't throw any exception in this method.

        Specified by:
        onActivate in interface ExecutionCtrl
        Overrides:
        onActivate in class AbstractExecution
      • getParameterValues

        public java.lang.String[] getParameterValues​(java.lang.String name)
        Description copied from interface: Execution
        Returns an array of String objects containing all of the values the given request parameter has, or null if the parameter does not exist.
      • getParameter

        public java.lang.String getParameter​(java.lang.String name)
        Description copied from interface: Execution
        Returns the value of a request parameter as a String, or null if the parameter does not exist
      • getParameterMap

        public java.util.Map<java.lang.String,​java.lang.String[]> getParameterMap()
        Description copied from interface: Execution
        Returns a Map of the parameters of this request. Request parameters are extra information sent with the request.
      • getVariableResolver

        public VariableResolver getVariableResolver()
        Description copied from interface: Execution
        Returns the variable resolver for this execution, or null if not available.

        Note: the resolver is similar to PageContext's if this execution is caused by a HTTP request.

        See Also:
        Execution.evaluate(Component,String,Class)
      • include

        public void include​(java.io.Writer out,
                            java.lang.String page,
                            java.util.Map<java.lang.String,​?> params,
                            int mode)
                     throws java.io.IOException
        Description copied from interface: Execution
        Includes a page.
        Parameters:
        out - the output to write. If null, the response's default writer is used.
        page - the page's uri; null to denote the same request
        mode - one of Execution.OVERWRITE_URI, Execution.IGNORE_PARAM, Execution.APPEND_PARAM and Execution.PASS_THRU_ATTR. It defines how to handle if both uri and params contains the same parameter. mode is used only if both uri contains query string and params is not empty.
        Throws:
        java.io.IOException
      • include

        public void include​(java.lang.String page)
                     throws java.io.IOException
        Description copied from interface: Execution
        A shortcut of include(null, page, null, 0).
        Throws:
        java.io.IOException
      • forward

        public void forward​(java.io.Writer out,
                            java.lang.String page,
                            java.util.Map<java.lang.String,​?> params,
                            int mode)
                     throws java.io.IOException
        Description copied from interface: Execution
        Forwards to another page.

        Note: this method can be called only when loading a page. Use Execution.sendRedirect(String) instead if you want to change to another desktop when processing a request from the client.

        Parameters:
        out - the output to write. If null, the response's default writer is used.
        page - the page's uri; null to denote the same request
        mode - one of Execution.OVERWRITE_URI, Execution.IGNORE_PARAM, Execution.APPEND_PARAM and Execution.PASS_THRU_ATTR. It defines how to handle if both uri and params contains the same parameter. mode is used only if both uri contains query string and params is not empty.
        Throws:
        java.io.IOException
      • forward

        public void forward​(java.lang.String page)
                     throws java.io.IOException
        Description copied from interface: Execution
        A shortcut of forward(null, page, null, 0).
        Throws:
        java.io.IOException
      • isIncluded

        public boolean isIncluded()
        Description copied from interface: Execution
        Returns whether this execution is included by some other pages.
      • isForwarded

        public boolean isForwarded()
        Description copied from interface: Execution
        Returns whether the execution is forwarded from other pages.
      • locate

        public java.lang.String locate​(java.lang.String path)
        Description copied from interface: Execution
        Locates a page based on the current Locale. It never returns null.

        If an URI contains "*", it will be replaced with a proper Locale. For example, if the current Locale is zh_TW and the resource is named "ab*.cd", then it searches "ab_zh_TW.cd", "ab_zh.cd" and then "ab.cd", until any of them is found.

        Note: "*" must be right before ".", or the last character. For example, "ab*.cd" and "ab*" are both correct, while "ab*cd" and "ab*\/cd" are ignored.

        If an URI contains two "*", the first "*" will be replaced with a browser code and the second with a proper locale. The browser code depends on what browser the user are used to visit the web site. Currently, the code for Internet Explorer is "ie", Safari is "saf", Opera is "opr" and all others are "moz". Thus, in the above example, if the resource is named "ab**.cd" and Firefox is used, then it searches "abmoz_zh_TW.cd", "abmoz_zh.cd" and then "abmoz.cd", until any of them is found.

        Note: it assumes the path as name_lang_cn_var.ext where ".ext" is optional. Example, my_zh_tw.html.jsp.

        If an URI starting with "~./", it assumes the resource is from the class path.

        Parameters:
        path - the page path excluding servlet name. It is OK to have the query string. It might contain "*" for current browser code and Locale.
        Returns:
        the path that matches the wildcard; path, otherwise
      • isVoided

        public boolean isVoided()
        Description copied from interface: Execution
        Returns whether the execution is voided. By void we mean ZK Loader shall stop evaluation of a ZUML document, since the request will be taken charged by other servlet or redirect to another page. The execution shall not do anything more. In other words, the execution is avoided and won't generate any output.

        The common cause of being voided is the invocation of Execution.forward(java.io.Writer, java.lang.String, java.util.Map<java.lang.String, ?>, int).

      • setVoided

        public void setVoided​(boolean voided)
        Description copied from interface: Execution
        Sets whether the execution is voided. By void we mean ZK Loader shall stop evaluation of a ZUML document, since the request will be taken charged by other servlet or redirect to another page.

        If you invoke Execution.forward(java.io.Writer, java.lang.String, java.util.Map<java.lang.String, ?>, int), this method is called automatically with true. Thus, you rarely need to invoke this method, unless you forward to other servlet by use javax.servlet.RequestDispatcher directly.

        The other case to invoke this method is if you'd like to redirect to another (by specifying the refresh header).

        If the ZK page has already been created, this method throws an IllegalStateException, i.e. you cannot invoke this method in Composer.doAfterCompose(Component). (@since 6.5.5)

      • getUserPrincipal

        public java.security.Principal getUserPrincipal()
        Description copied from interface: Execution
        Returns a java.security.Principal object containing the name of the current authenticated user. If the user has not been authenticated, the method returns null.
      • isUserInRole

        public boolean isUserInRole​(java.lang.String role)
        Description copied from interface: Execution
        Returns a boolean indicating whether the authenticated user is included in the specified logical "role". Roles and role membership can be defined using deployment descriptors. If the user has not been authenticated, the method returns false.
        Parameters:
        role - a String specifying the name of the role
      • getRemoteUser

        public java.lang.String getRemoteUser()
        Description copied from interface: Execution
        Returns the login of the user making this request, if the user has been authenticated, or null if the user has not been authenticated. Whether the user name is sent with each subsequent request depends on the browser and type of authentication.
      • getRemoteHost

        public java.lang.String getRemoteHost()
        Description copied from interface: Execution
        Returns the fully qualified name of the client or the last proxy that sent the request. If the engine cannot or chooses not to resolve the hostname (to improve performance), this method returns the dotted-string form of the IP address.
      • getRemoteAddr

        public java.lang.String getRemoteAddr()
        Description copied from interface: Execution
        Returns the Internet Protocol (IP) address of the client or last proxy that sent the request.
      • getServerName

        public java.lang.String getServerName()
        Description copied from interface: Execution
        Returns the host name of the server to which the request was sent. It is the value of the part before ":" in the Host header value, if any, or the resolved server name, or the server IP address.
        See Also:
        Execution.getLocalName()
      • getServerPort

        public int getServerPort()
        Description copied from interface: Execution
        Returns the port number to which the request was sent. It is the value of the part after ":" in the Host header value, if any, or the server port where the client connection was accepted on.
        See Also:
        Execution.getLocalPort()
      • getLocalName

        public java.lang.String getLocalName()
        Description copied from interface: Execution
        Returns the host name of the Internet Protocol (IP) interface on which the request was received.

        Note: it is the host name defined in the server. To retrieve the name in URL, use Execution.getServerName().

        See Also:
        Execution.getServerName()
      • getLocalAddr

        public java.lang.String getLocalAddr()
        Description copied from interface: Execution
        Returns the Internet Protocol (IP) address of the interface on which the request was received.
      • getLocalPort

        public int getLocalPort()
        Description copied from interface: Execution
        Returns the Internet Protocol (IP) port number of the interface on which the request was received.
        See Also:
        Execution.getServerPort()
      • getContextPath

        public java.lang.String getContextPath()
        Description copied from interface: Execution
        Returns the portion of the request URI that indicates the context of the current execution. The path starts with a "/" character but does not end with a "/" character. For servlets in the default (root) context, this method returns "".

        If the client is not using HTTP to access, this method return "";

        See Also:
        Page.getRequestPath()
      • getScheme

        public java.lang.String getScheme()
        Description copied from interface: Execution
        Returns the name of the scheme used to make this request, for example, http, https, or ftp. Different schemes have different rules for constructing URLs, as noted in RFC 1738.
      • setContentType

        public void setContentType​(java.lang.String contentType)
        Description copied from interface: ExecutionCtrl
        Sets the content type.
      • getBrowser

        public java.lang.Double getBrowser​(java.lang.String name)
        Description copied from interface: Execution
        Returns the version of the given browser name, or null if the client is not the given browsers.

        Notice that, after this method is called, an attribute named zk will be stored to the request, such that you can retrieve the browser information by use of EL, such as ${zk.ie > 7}.

        Parameters:
        name - the browser's name. It includes "ie", "ff", "gecko", "webkit", "safari" and "opera". And, "ff" is the same as "gecko", and "webit" is the same as "safari".
      • getBrowser

        public java.lang.String getBrowser()
        Description copied from interface: Execution
        Returns the name of the browser, or null if not identifiable.
      • getUserAgent

        public java.lang.String getUserAgent()
        Description copied from interface: Execution
        Returns the user-agent header, which indicates what the client is, or an empty string if not available.

        Note: it doesn't return null, so it is easy to test what the client is with String.indexOf(int).

      • getNativeRequest

        public java.lang.Object getNativeRequest()
        Description copied from interface: Execution
        Returns the native request, or null if not available.

        The returned object depends on the Web container. If it is based Java servlet container, an instance of javax.servlet.ServletRequest is returned.

      • getNativeResponse

        public java.lang.Object getNativeResponse()
        Description copied from interface: Execution
        Returns the native response, or null if not available.

        The returned object depends on the Web container. If it is based Java servlet container, an instance of javax.servlet.ServletResponse is returned.

      • getAttribute

        public java.lang.Object getAttribute​(java.lang.String name)
        Description copied from interface: Execution
        Returns the value of the specified request attribute.
      • hasAttribute

        public boolean hasAttribute​(java.lang.String name)
        Description copied from interface: Scope
        Returns if a custom attribute is associated with this object (scope).

        Notice that null is a valid value, so you can tell if an attribute is associated by examining the return value of Scope.getAttribute(java.lang.String).

      • setAttribute

        public java.lang.Object setAttribute​(java.lang.String name,
                                             java.lang.Object value)
        Description copied from interface: Execution
        Sets the value of the specified request attribute.
        value - the value. If null, the attribute is removed.
        Returns:
        the previous value if any (since ZK5)
      • removeAttribute

        public java.lang.Object removeAttribute​(java.lang.String name)
        Description copied from interface: Execution
        Removes the specified request attribute.
        Returns:
        the previous value if any (since ZK5)
      • getAttributes

        public java.util.Map<java.lang.String,​java.lang.Object> getAttributes()
        Description copied from interface: Execution
        Returns a map of request attributes associated with this session.
      • addScopeListener

        public boolean addScopeListener​(ScopeListener listener)
        Description copied from interface: Scope
        Adds a listener to listen whether this scope is changed. The listener is called when a custom attribute is added, removed, or the parent is changed.
        Returns:
        weather the listener is added successfully. Note: if the resolver was added before, it won't be added again and this method returns false.
      • removeScopeListener

        public boolean removeScopeListener​(ScopeListener listener)
        Description copied from interface: Scope
        Removes a change listener from this scope.
        Returns:
        false if listener is not added before.
      • getHeader

        public java.lang.String getHeader​(java.lang.String name)
        Description copied from interface: Execution
        Returns the value of the specified header as a String, or null if not found.
      • getHeaders

        public java.lang.Iterable<java.lang.String> getHeaders​(java.lang.String name)
        Description copied from interface: Execution
        Returns all the values of the specified header as an iterable String objects.

        If the request did not include any headers of the specified name, this method returns an empty iterable. If the container does not allow access to header information, it returns null.

      • getHeaderNames

        public java.lang.Iterable<java.lang.String> getHeaderNames()
        Description copied from interface: Execution
        Returns all header names this request contains. If the request has no headers, this method returns an empty iterable. If the container does not allow access to header information, it returns null.
      • setResponseHeader

        public void setResponseHeader​(java.lang.String name,
                                      java.lang.String value)
        Description copied from interface: Execution
        Sets a response header with the give name and value. If the header had already been set, the new value overwrites the previous one.
        value - the additional header value If it contains octet string, it should be encoded according to RFC 2047 (http://www.ietf.org/rfc/rfc2047.txt).
        See Also:
        Execution.containsResponseHeader(java.lang.String)
      • setResponseHeader

        public void setResponseHeader​(java.lang.String name,
                                      java.util.Date value)
        Description copied from interface: Execution
        Sets a response header with the given name and date-value.
      • addResponseHeader

        public void addResponseHeader​(java.lang.String name,
                                      java.lang.String value)
        Description copied from interface: Execution
        Adds a response header with the give name and value. This method allows response headers to have multiple values.
        value - the additional header value If it contains octet string, it should be encoded according to RFC 2047 (http://www.ietf.org/rfc/rfc2047.txt).
      • addResponseHeader

        public void addResponseHeader​(java.lang.String name,
                                      java.util.Date value)
        Description copied from interface: Execution
        Adds a response header with the given name and date-value.
      • containsResponseHeader

        public boolean containsResponseHeader​(java.lang.String name)
        Description copied from interface: Execution
        Returns whether the named response header has already been set.
      • getContextURI

        public java.lang.String getContextURI()
        Description copied from interface: Execution
        Returns the context uri from the current execution.