org.zkoss.zk.ui.http
Class ExecutionImpl

java.lang.Object
  extended by org.zkoss.zk.ui.impl.AbstractExecution
      extended by org.zkoss.zk.ui.http.ExecutionImpl
All Implemented Interfaces:
Execution, ExecutionCtrl

public class ExecutionImpl
extends AbstractExecution

An Execution implementation for HTTP request and response.

Author:
tomyeh

Field Summary
 
Fields inherited from interface org.zkoss.zk.ui.Execution
APPEND_PARAM, IGNORE_PARAM, OVERWRITE_URI, PASS_THRU_ATTR
 
Constructor Summary
ExecutionImpl(javax.servlet.ServletContext ctx, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, Desktop desktop, Page creating)
          Constructs an execution for HTTP request.
 
Method Summary
 void addDateHeader(java.lang.String name, long value)
          Adds a response header with the given name and date-value.
 void addHeader(java.lang.String name, java.lang.String value)
          Adds a responseheader with the given name and value.
 java.lang.String encodeURL(java.lang.String uri)
          Encodes an URL.
 java.lang.Object evaluate(Component comp, java.lang.String expr, java.lang.Class expectedType)
          Evluates the specified expression with ${link #getVariableResolver} and Page.getFunctionMapper() of the page of the specified component.
 java.lang.Object evaluate(Page page, java.lang.String expr, java.lang.Class expectedType)
          Evluates the specified expression with ${link #getVariableResolver} and Page.getFunctionMapper() of the specified page.
 void forward(java.lang.String page)
          A shortcut of forward(null, page, null, 0).
 void forward(java.io.Writer out, java.lang.String page, java.util.Map params, int mode)
          Forwards to another page.
 java.lang.Object getAttribute(java.lang.String name)
          Returns the value of the specified request attribute.
 java.util.Map getAttributes()
          Returns a map of request attributes associated with this session.
 java.lang.String getContextPath()
          Returns the portion of the request URI that indicates the context of the current execution.
 Evaluator getEvaluator(Component comp, java.lang.Class expfcls)
          Returns the evaluator of the current execution.
 Evaluator getEvaluator(Page page, java.lang.Class expfcls)
          Returns the evaluator (never null).
 java.lang.String getLocalAddr()
          Returns the Internet Protocol (IP) address of the interface on which the request was received.
 java.lang.String getLocalName()
          Returns the host name of the Internet Protocol (IP) interface on which the request was received.
 int getLocalPort()
          Returns the Internet Protocol (IP) port number of the interface on which the request was received.
 java.lang.Object getNativeRequest()
          Returns the native request, or null if not available.
 java.lang.Object getNativeResponse()
          Returns the native response, or null if not available.
 PageDefinition getPageDefinition(java.lang.String uri)
          Returns the page definition from the page file specified by an URI.
 PageDefinition getPageDefinitionDirectly(org.zkoss.idom.Document content, java.lang.String ext)
          Converts the specified page content, in DOM, to a page definition.
 PageDefinition getPageDefinitionDirectly(java.io.Reader reader, java.lang.String ext)
          Reads the raw content from a reader and converts it into a page definition.
 PageDefinition getPageDefinitionDirectly(java.lang.String content, java.lang.String ext)
          Converts the specified page content to a page definition.
 java.lang.String getParameter(java.lang.String name)
          Returns the value of a request parameter as a String, or null if the parameter does not exist
 java.util.Map getParameterMap()
          Returns a Map of the parameters of this request.
 java.lang.String[] getParameterValues(java.lang.String name)
          Returns an array of String objects containing all of the values the given request parameter has, or null if the parameter does not exist.
 java.lang.String getRemoteAddr()
          Returns the Internet Protocol (IP) address of the client or last proxy that sent the request.
 java.lang.String getRemoteName()
          Returns the fully qualified name of the client or the last proxy that sent the request.
 java.lang.String getRemoteUser()
          Returns the login of the user making this request, if the user has been authenticated, or null if the user has not been authenticated.
 java.lang.Object getRequestAttribute(java.lang.String name)
          Returns the value of an attribute in the client request (e.g., HTTP request) that creates this execution.
 java.lang.String getServerName()
          Returns the host name of the server to which the request was sent.
 int getServerPort()
          Returns the port number to which the request was sent.
 java.security.Principal getUserPrincipal()
          Returns a java.security.Principal object containing the name of the current authenticated user.
 org.zkoss.xel.VariableResolver getVariableResolver()
          Returns the variable resolver for this execution, or null if not available.
 void include(java.lang.String page)
          A shortcut of include(null, page, null, 0).
 void include(java.io.Writer out, java.lang.String page, java.util.Map params, int mode)
          Includes a page.
 boolean isBrowser()
          Returns whether the client is a browser.
 boolean isExplorer()
          Returns whether the client is Internet Explorer.
 boolean isExplorer7()
          Returns whether the client is Internet Explorer 7 or later.
 boolean isForwarded()
          Returns whether the execution is forwarded from other pages.
 boolean isGecko()
          Returns whether the client is Gecko based, such as Mozilla, Firefox and Camino.
 boolean isIncluded()
          Returns whether this execution is included by some other pages.
 boolean isMilDevice()
          Returns whether the client is a mobile device supporting MIL (Mobile Interactive Language).
 boolean isRobot()
          Returns whether the client is a robot (such as Web crawlers).
 boolean isSafari()
          Returns whether the client is Safari.
 boolean isUserInRole(java.lang.String role)
          Returns a boolean indicating whether the authenticated user is included in the specified logical "role".
 boolean isVoided()
          Returns whether the execution is voided.
 void onActivate()
          Called when this execution is about to become the current execution Executions.getCurrent().
 void onDeactivate()
          Called when this execution is about to become a non-current execution.
 void removeAttribute(java.lang.String name)
          Removes the specified request attribute.
 void setAttribute(java.lang.String name, java.lang.Object value)
          Sets the value of the specified request attribute.
 void setDateHeader(java.lang.String name, long value)
          Sets a response header with the given name and date-value.
 void setHeader(java.lang.String name, java.lang.String value)
          Sets a responseheader with the given name and value.
 void setRequestAttribute(java.lang.String name, java.lang.Object value)
          Sets the value of an attribute to the client request (e.g., HTTP request) that creates this execution.
 void setVoided(boolean voided)
          Sets whether the execution is voided.
 
Methods inherited from class org.zkoss.zk.ui.impl.AbstractExecution
addAuResponse, createComponents, createComponents, createComponents, createComponents, createComponentsDirectly, createComponentsDirectly, createComponentsDirectly, createComponentsDirectly, createComponentsDirectly, createComponentsDirectly, getArg, getCurrentPage, getCurrentPageDefinition, getDesktop, getNextEvent, getVisualizer, isActivated, isAsyncUpdate, isRecovering, popArg, postEvent, pushArg, sendRedirect, sendRedirect, setCurrentPage, setCurrentPageDefinition, setDesktop, setVisualizer, toAbsoluteURI, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

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 HTTP request.

Parameters:
creating - which page is being creating for this execution, or null if none is being created. AbstractExecution.isAsyncUpdate(org.zkoss.zk.ui.Page) returns based on this.
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

onDeactivate

public void onDeactivate()
Description copied from interface: ExecutionCtrl
Called when this execution is about to become a non-current execution.

It is used as callback notification.

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

Specified by:
onDeactivate in interface ExecutionCtrl
Overrides:
onDeactivate in class AbstractExecution
See Also:
ExecutionCtrl.onActivate()

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 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 org.zkoss.xel.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)

getEvaluator

public Evaluator getEvaluator(Page page,
                              java.lang.Class expfcls)
Description copied from interface: Execution
Returns the evaluator (never null). It is usually used to parse the expression into Expression or used with ExValue. for performance improvement.

Parameters:
page - the page that this evaluator is associated. If null, the current page and then the first page is assumed.
expfcls - the implementation of ExpressionFactory, or null to use the default (Configuration.getExpressionFactoryClass().

getEvaluator

public Evaluator getEvaluator(Component comp,
                              java.lang.Class expfcls)
Description copied from interface: Execution
Returns the evaluator of the current execution. It is a shortcut of getEvaluator(comp != null ? comp.getPage(): null)

Parameters:
comp - the component to retrieve the page for the evaluator
expfcls - the implementation of ExpressionFactory, or null to use the default (Configuration.getExpressionFactoryClass().

evaluate

public java.lang.Object evaluate(Component comp,
                                 java.lang.String expr,
                                 java.lang.Class expectedType)
Description copied from interface: Execution
Evluates the specified expression with ${link #getVariableResolver} and Page.getFunctionMapper() of the page of the specified component.

The function mapper is retrieved from component's page's function mapper (Page.getFunctionMapper()). If null, the current page, if any, is used to retrieve the mapper.

For better performance, you can use the instance returned by Execution.getEvaluator(org.zkoss.zk.ui.Page, java.lang.Class) to parse and cached the parsed expression. ExValue is a utility class to simply the task.

Parameters:
comp - used as the self variable and to retrieve the function mapper. Ignored if null.
See Also:
Execution.getVariableResolver(), Execution.getEvaluator(org.zkoss.zk.ui.Page, java.lang.Class)

evaluate

public java.lang.Object evaluate(Page page,
                                 java.lang.String expr,
                                 java.lang.Class expectedType)
Description copied from interface: Execution
Evluates the specified expression with ${link #getVariableResolver} and Page.getFunctionMapper() of the specified page.

The function mapper is retrieved from component's page's function mapper (Page.getFunctionMapper()). If null, the current page, if any, is used to retrieve the mapper.

For better performance, you can use the instance returned by Execution.getEvaluator(org.zkoss.zk.ui.Page, java.lang.Class) to parse and cached the parsed expression. ExValue is a utility class to simply the task.

Parameters:
page - used as the self variable and to retrieve the function mapper. Ignored if null.
See Also:
Execution.getVariableResolver(), Execution.getEvaluator(org.zkoss.zk.ui.Page, java.lang.Class)

include

public void include(java.io.Writer out,
                    java.lang.String page,
                    java.util.Map 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 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.


isVoided

public boolean isVoided()
Description copied from interface: Execution
Returns whether the execution is voided. By void we mean the request is taken charged by other servlet. The execution shall not do anything more. In other words, the execution is avoided and won't generate any ouput.

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


setVoided

public void setVoided(boolean voided)
Description copied from interface: Execution
Sets whether the execution is voided. By void we mean the request is taken charged by other servlet.

If you invoke Execution.forward(java.io.Writer, java.lang.String, java.util.Map, 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.


encodeURL

public java.lang.String encodeURL(java.lang.String uri)
Description copied from interface: Execution
Encodes an URL.

It resolves "*" contained in URI, if any, to the proper Locale, and the browser code. Refer to Servlets.locate(ServletContext, ServletRequest, String, Locator) for details.


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.


getRemoteName

public java.lang.String getRemoteName()
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()

getPageDefinition

public PageDefinition getPageDefinition(java.lang.String uri)
Description copied from interface: Execution
Returns the page definition from the page file specified by an URI.

Implemetation Notes: this method must invoke UiFactory.getPageDefinition(org.zkoss.zk.ui.sys.RequestInfo, String)

Parameters:
uri - the URI of the page file.
See Also:
Execution.getPageDefinitionDirectly(String, String), Execution.getPageDefinitionDirectly(Document, String), Execution.getPageDefinitionDirectly(Reader, String)

getPageDefinitionDirectly

public PageDefinition getPageDefinitionDirectly(java.lang.String content,
                                                java.lang.String ext)
Description copied from interface: Execution
Converts the specified page content to a page definition.

Implemetation Notes: this method must invoke UiFactory.getPageDefinitionDirectly(org.zkoss.zk.ui.sys.RequestInfo, String, String)

Parameters:
content - the raw content of the page. It must be in ZUML.
ext - the default extension if the content doesn't specify an language. In other words, if the content doesn't specify an language, LanguageDefinition.getByExtension(java.lang.String) is called. If extension is null and the content doesn't specify a language, the language called "xul/html" is assumed.
See Also:
Execution.getPageDefinitionDirectly(Document, String), Execution.getPageDefinitionDirectly(Reader, String), Execution.getPageDefinition(java.lang.String)

getPageDefinitionDirectly

public PageDefinition getPageDefinitionDirectly(org.zkoss.idom.Document content,
                                                java.lang.String ext)
Description copied from interface: Execution
Converts the specified page content, in DOM, to a page definition.

Parameters:
content - the raw content of the page in DOM.
ext - the default extension if the content doesn't specify an language. In other words, if the content doesn't specify an language, LanguageDefinition.getByExtension(java.lang.String) is called. If extension is null and the content doesn't specify a language, the language called "xul/html" is assumed.
See Also:
Execution.getPageDefinitionDirectly(String, String), Execution.getPageDefinitionDirectly(Reader, String), Execution.getPageDefinition(java.lang.String)

getPageDefinitionDirectly

public PageDefinition getPageDefinitionDirectly(java.io.Reader reader,
                                                java.lang.String ext)
                                         throws java.io.IOException
Description copied from interface: Execution
Reads the raw content from a reader and converts it into a page definition.

Parameters:
reader - used to input the raw content of the page. It must be in ZUML.
ext - the default extension if the content doesn't specify an language. In other words, if the content doesn't specify an language, LanguageDefinition.getByExtension(java.lang.String) is called. If extension is null and the content doesn't specify a language, the language called "xul/html" is assumed.
Throws:
java.io.IOException
See Also:
Execution.getPageDefinitionDirectly(String, String), Execution.getPageDefinitionDirectly(Document, String), Execution.getPageDefinition(java.lang.String)

setHeader

public void setHeader(java.lang.String name,
                      java.lang.String value)
Description copied from interface: ExecutionCtrl
Sets a responseheader with the given name and value.

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).

setDateHeader

public void setDateHeader(java.lang.String name,
                          long value)
Description copied from interface: ExecutionCtrl
Sets a response header with the given name and date-value. The date is specified in terms of milliseconds since the epoch. This method allows response headers to have multiple values.


addHeader

public void addHeader(java.lang.String name,
                      java.lang.String value)
Description copied from interface: ExecutionCtrl
Adds a responseheader with the given name and value.

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).

addDateHeader

public void addDateHeader(java.lang.String name,
                          long value)
Description copied from interface: ExecutionCtrl
Adds a response header with the given name and date-value. The date is specified in terms of milliseconds since the epoch. This method allows response headers to have multiple values.


getRequestAttribute

public java.lang.Object getRequestAttribute(java.lang.String name)
Description copied from interface: ExecutionCtrl
Returns the value of an attribute in the client request (e.g., HTTP request) that creates this execution.

Notice that a servlet might include serveral ZK pages, while an independent execution is created for adding a new page. It means, each client request might create several executions. Thus, the attribute set by this method might last for several executions (until the request ends).


setRequestAttribute

public void setRequestAttribute(java.lang.String name,
                                java.lang.Object value)
Description copied from interface: ExecutionCtrl
Sets the value of an attribute to the client request (e.g., HTTP request) that creates this execution.


isBrowser

public boolean isBrowser()
Description copied from interface: Execution
Returns whether the client is a browser.


isRobot

public boolean isRobot()
Description copied from interface: Execution
Returns whether the client is a robot (such as Web crawlers).

Because there are too many robots, it returns true if the user-agent is not recognized.


isExplorer

public boolean isExplorer()
Description copied from interface: Execution
Returns whether the client is Internet Explorer. If true, it also implies Execution.isExplorer7() is true.


isExplorer7

public boolean isExplorer7()
Description copied from interface: Execution
Returns whether the client is Internet Explorer 7 or later.


isGecko

public boolean isGecko()
Description copied from interface: Execution
Returns whether the client is Gecko based, such as Mozilla, Firefox and Camino.


isSafari

public boolean isSafari()
Description copied from interface: Execution
Returns whether the client is Safari.


isMilDevice

public boolean isMilDevice()
Description copied from interface: Execution
Returns whether the client is a mobile device supporting MIL (Mobile Interactive Language).


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.


setAttribute

public void 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.

removeAttribute

public void removeAttribute(java.lang.String name)
Description copied from interface: Execution
Removes the specified request attribute.


getAttributes

public java.util.Map getAttributes()
Description copied from interface: Execution
Returns a map of request attributes associated with this session.



Copyright © 2005-2007 Potix Corporation. All Rights Reserved.