Class ExecutionImpl
- All Implemented Interfaces:
Execution,Scope,ExecutionCtrl
Execution implementation for HTTP request
and response.- Author:
- tomyeh
-
Field Summary
Fields inherited from class org.zkoss.zk.ui.impl.AbstractExecution
Add_ON_ACTIVATE, Add_ON_DEACTIVATEFields inherited from interface org.zkoss.zk.ui.Execution
APPEND_PARAM, IGNORE_PARAM, OVERWRITE_URI, PASS_THRU_ATTR -
Constructor Summary
ConstructorsConstructorDescriptionExecutionImpl(jakarta.servlet.ServletContext ctx, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, Desktop desktop, Page creating) Constructs an execution for the given HTTP request. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddResponseHeader(String name, String value) Adds a response header with the give name and value.voidaddResponseHeader(String name, Date value) Adds a response header with the given name and date-value.booleanaddScopeListener(ScopeListener listener) Adds a listener to listen whether this scope is changed.booleancontainsResponseHeader(String name) Returns whether the named response header has already been set.Encodes an URL.Evaluates the specified expression with ${link #getVariableResolver} andPage.getFunctionMapper()of the page of the specified component.Evaluates the specified expression with ${link #getVariableResolver} andPage.getFunctionMapper()of the specified page.voidForwards to another page.voidA shortcut of forward(null, page, null, 0).getAttribute(String name) Returns the value of the specified request attribute.Returns a map of request attributes associated with this session.Returns the name of the browser, or null if not identifiable.getBrowser(String name) Returns the version of the given browser name, or null if the client is not the given browsers.Returns the portion of the request URI that indicates the context of the current execution.Returns the context uri from the current execution.getEvaluator(Component comp, Class<? extends org.zkoss.xel.ExpressionFactory> expfcls) Returns the evaluator of the current execution.getEvaluator(Page page, Class<? extends org.zkoss.xel.ExpressionFactory> expfcls) Returns the evaluator (never null).Returns the value of the specified header as aString, or null if not found.Returns all header names this request contains.getHeaders(String name) Returns all the values of the specified header as an iterableStringobjects.Returns the Internet Protocol (IP) address of the interface on which the request was received.Returns the host name of the Internet Protocol (IP) interface on which the request was received.intReturns the Internet Protocol (IP) port number of the interface on which the request was received.Returns the native request, or null if not available.Returns the native response, or null if not available.getPageDefinition(String uri) Returns the page definition from the page file specified by an URI.getPageDefinitionDirectly(Reader reader, String ext) Reads the raw content from a reader and converts it into a page definition.getPageDefinitionDirectly(String content, String ext) Converts the specified page content to a page definition.getPageDefinitionDirectly(org.zkoss.idom.Document content, String ext) Converts the specified page content, in DOM, to a page definition.getParameter(String name) Returns the value of a request parameter as a String, or null if the parameter does not existReturns a Map of the parameters of this request.String[]getParameterValues(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.Returns the Internet Protocol (IP) address of the client or last proxy that sent the request.Returns the fully qualified name of the client or the last proxy that sent the request.Returns the login of the user making this request, if the user has been authenticated, or null if the user has not been authenticated.Returns the name of the scheme used to make this request, for example, http, https, or ftp.Returns the host name of the server to which the request was sent.intReturns the port number to which the request was sent.Returns the user-agent header, which indicates what the client is, or an empty string if not available.Returns a java.security.Principal object containing the name of the current authenticated user.org.zkoss.xel.VariableResolverReturns the variable resolver for this execution, or null if not available.booleanhasAttribute(String name) Returns if a custom attribute is associated with this object (scope).voidIncludes a page.voidA shortcut of include(null, page, null, 0).booleanReturns whether the execution is forwarded from other pages.booleanReturns whether this execution is included by some other pages.booleanisUserInRole(String role) Returns a boolean indicating whether the authenticated user is included in the specified logical "role".booleanisVoided()Returns whether the execution is voided.Locates a page based on the current Locale.voidCalled when this execution is about to become the current executionExecutions.getCurrent().voidCalled when this execution is about to become a non-current execution.removeAttribute(String name) Removes the specified request attribute.booleanremoveScopeListener(ScopeListener listener) Removes a change listener from this scope.setAttribute(String name, Object value) Sets the value of the specified request attribute.voidsetContentType(String contentType) Sets the content type.voidsetResponseHeader(String name, String value) Sets a response header with the give name and value.voidsetResponseHeader(String name, Date value) Sets a response header with the given name and date-value.voidsetVoided(boolean voided) Sets whether the execution is voided.Methods inherited from class org.zkoss.zk.ui.impl.AbstractExecution
addAuResponse, addAuResponse, addOnActivate, addOnDeactivate, addVariableResolver, createComponents, createComponents, createComponents, createComponents, createComponents, createComponents, createComponents, createComponents, createComponentsDirectly, createComponentsDirectly, createComponentsDirectly, createComponentsDirectly, createComponentsDirectly, createComponentsDirectly, createComponentsDirectly, createComponentsDirectly, createComponentsDirectly, getArg, getAttribute, getCurrentPage, getCurrentPageDefinition, getDesktop, getExecutionInfo, getExtraXelVariable, getExtraXelVariable, getNextEvent, getRequestId, getResponses, getSession, getVisualizer, hasAttribute, hasVariableResolver, hasVariableResolver, isActivated, isAsyncUpdate, isRecovering, log, log, onBeforeDeactivate, popArg, postEvent, postEvent, postEvent, pushArg, removeAttribute, removeVariableResolver, sendRedirect, sendRedirect, sendRedirect, setAttribute, setCurrentPage, setCurrentPageDefinition, setDesktop, setExecutionInfo, setRequestId, setResponses, toAbsoluteURI, toString
-
Constructor Details
-
ExecutionImpl
public ExecutionImpl(jakarta.servlet.ServletContext ctx, jakarta.servlet.http.HttpServletRequest request, jakarta.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 Details
-
onActivate
public void onActivate()Description copied from interface:ExecutionCtrlCalled when this execution is about to become the current executionExecutions.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:
onActivatein interfaceExecutionCtrl- Overrides:
onActivatein classAbstractExecution
-
onDeactivate
public void onDeactivate()Description copied from interface:ExecutionCtrlCalled 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:
onDeactivatein interfaceExecutionCtrl- Overrides:
onDeactivatein classAbstractExecution- See Also:
-
getParameterValues
Description copied from interface:ExecutionReturns an array of String objects containing all of the values the given request parameter has, or null if the parameter does not exist. -
getParameter
Description copied from interface:ExecutionReturns the value of a request parameter as a String, or null if the parameter does not exist -
getParameterMap
Description copied from interface:ExecutionReturns 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:ExecutionReturns 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.
-
getEvaluator
Description copied from interface:ExecutionReturns the evaluator (never null). It is usually used to parse the expression intoExpressionor used withExValue. 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 ofExpressionFactory, or null to use the default (Configuration.getExpressionFactoryClass().
-
getEvaluator
public Evaluator getEvaluator(Component comp, Class<? extends org.zkoss.xel.ExpressionFactory> expfcls) Description copied from interface:ExecutionReturns 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 evaluatorexpfcls- the implementation ofExpressionFactory, or null to use the default (Configuration.getExpressionFactoryClass().
-
evaluate
Description copied from interface:ExecutionEvaluates the specified expression with ${link #getVariableResolver} andPage.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<? extends org.zkoss.xel.ExpressionFactory>)to parse and cached the parsed expression.ExValueis 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:
-
evaluate
Description copied from interface:ExecutionEvaluates the specified expression with ${link #getVariableResolver} andPage.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<? extends org.zkoss.xel.ExpressionFactory>)to parse and cached the parsed expression.ExValueis 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:
-
include
Description copied from interface:ExecutionIncludes 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 requestmode- one ofExecution.OVERWRITE_URI,Execution.IGNORE_PARAM,Execution.APPEND_PARAMandExecution.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:
IOException
-
include
Description copied from interface:ExecutionA shortcut of include(null, page, null, 0).- Throws:
IOException
-
forward
Description copied from interface:ExecutionForwards 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 requestmode- one ofExecution.OVERWRITE_URI,Execution.IGNORE_PARAM,Execution.APPEND_PARAMandExecution.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:
IOException
-
forward
Description copied from interface:ExecutionA shortcut of forward(null, page, null, 0).- Throws:
IOException
-
isIncluded
public boolean isIncluded()Description copied from interface:ExecutionReturns whether this execution is included by some other pages. -
isForwarded
public boolean isForwarded()Description copied from interface:ExecutionReturns whether the execution is forwarded from other pages. -
locate
Description copied from interface:ExecutionLocates 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:ExecutionReturns 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:ExecutionSets 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 jakarta.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) -
encodeURL
Description copied from interface:ExecutionEncodes 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
Description copied from interface:ExecutionReturns 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
Description copied from interface:ExecutionReturns 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
Description copied from interface:ExecutionReturns 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
Description copied from interface:ExecutionReturns 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
Description copied from interface:ExecutionReturns the Internet Protocol (IP) address of the client or last proxy that sent the request. -
getServerName
Description copied from interface:ExecutionReturns 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:
-
getServerPort
public int getServerPort()Description copied from interface:ExecutionReturns 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:
-
getLocalName
Description copied from interface:ExecutionReturns 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:
-
getLocalAddr
Description copied from interface:ExecutionReturns the Internet Protocol (IP) address of the interface on which the request was received. -
getLocalPort
public int getLocalPort()Description copied from interface:ExecutionReturns the Internet Protocol (IP) port number of the interface on which the request was received.- See Also:
-
getContextPath
Description copied from interface:ExecutionReturns 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:
-
getScheme
Description copied from interface:ExecutionReturns 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. -
getPageDefinition
Description copied from interface:ExecutionReturns the page definition from the page file specified by an URI.Implementation Notes: this method must invoke
UiFactory.getPageDefinition(org.zkoss.zk.ui.sys.RequestInfo, String)- Parameters:
uri- the URI of the page file.- See Also:
-
getPageDefinitionDirectly
Description copied from interface:ExecutionConverts the specified page content to a page definition.Implementation 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:
-
getPageDefinitionDirectly
Description copied from interface:ExecutionConverts 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:
-
getPageDefinitionDirectly
Description copied from interface:ExecutionReads 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:
IOException- See Also:
-
setContentType
Description copied from interface:ExecutionCtrlSets the content type. -
getBrowser
Description copied from interface:ExecutionReturns 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
Description copied from interface:ExecutionReturns the name of the browser, or null if not identifiable. -
getUserAgent
Description copied from interface:ExecutionReturns 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
Description copied from interface:ExecutionReturns 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 jakarta.servlet.ServletRequest is returned.
-
getNativeResponse
Description copied from interface:ExecutionReturns 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 jakarta.servlet.ServletResponse is returned.
-
getAttribute
Description copied from interface:ExecutionReturns the value of the specified request attribute. -
hasAttribute
Description copied from interface:ScopeReturns if a custom attribute is associated with this object (scope).Notice that
nullis a valid value, so you can tell if an attribute is associated by examining the return value ofScope.getAttribute(java.lang.String). -
setAttribute
Description copied from interface:ExecutionSets 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
Description copied from interface:ExecutionRemoves the specified request attribute.- Returns:
- the previous value if any (since ZK5)
-
getAttributes
Description copied from interface:ExecutionReturns a map of request attributes associated with this session. -
addScopeListener
Description copied from interface:ScopeAdds 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
Description copied from interface:ScopeRemoves a change listener from this scope.- Returns:
- false if listener is not added before.
-
getHeader
Description copied from interface:ExecutionReturns the value of the specified header as aString, or null if not found. -
getHeaders
Description copied from interface:ExecutionReturns all the values of the specified header as an iterableStringobjects.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
Description copied from interface:ExecutionReturns 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
Description copied from interface:ExecutionSets 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:
-
setResponseHeader
Description copied from interface:ExecutionSets a response header with the given name and date-value. -
addResponseHeader
Description copied from interface:ExecutionAdds 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
Description copied from interface:ExecutionAdds a response header with the given name and date-value. -
containsResponseHeader
Description copied from interface:ExecutionReturns whether the named response header has already been set. -
getContextURI
Description copied from interface:ExecutionReturns the context uri from the current execution.
-