/* * Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at * http://www.eclipse.org/legal/epl-2.0. * * This Source Code may also be made available under the following Secondary * Licenses when the conditions for such availability set forth in the * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, * version 2 with the GNU Classpath Exception, which is available at * https://www.gnu.org/software/classpath/license.html. * * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 */ package javax.faces.context; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.Writer; import java.net.MalformedURLException; import java.net.URL; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; /** *
* This class allows the Faces API to be unaware of the nature of its containing * application environment. In particular, this class allows Jakarta Server Faces based * applications to run in either a Jakarta Servlet or a Portlet environment.
* *The documentation for this class only
* specifies the behavior for the Jakarta Servlet implementation of
* ExternalContext. The Portlet implementation of
* ExternalContext is specified under the revision of the
* Portlet Bridge
* Specification for JavaServer Faces JSR that corresponds to
* this version of the Jakarta Server Faces specification. See the Preface of the
* "prose document", linked
* from the javadocs, for a reference.
If a reference to an
* ExternalContext is obtained during application startup or shutdown
* time, any method documented as "valid to call this method during
* application startup or shutdown" must be supported during application startup or shutdown
* time. The result of calling a method during application startup or shutdown time
* that does not have this designation is undefined.
An ExternalContext can be injected into a CDI
* managed bean using @Inject ExternalContext externalContext;
*
Adds the cookie represented by the * arguments to the response.
* *Jakarta Servlet: This must be accomplished by calling the
* javax.servlet.http.HttpServletResponse method
* addCookie(). The Cookie argument must
* be constructed by passing the name and
* value parameters. If the properties
* arugument is non-null and not empty, the
* Cookie instance must be initialized as described
* below.
Key in "values" Map |
*
* Expected type of value. | * *Name of setter method on Cookie instance to be
* set with the value from the Map. |
*
*
|---|---|---|
| comment | * *String | * *setComment | * *
| domain | * *String | * *setDomain | * *
| maxAge | * *Integer | * *setMaxAge | * *
| secure | * *Boolean | * *setSecure | * *
| path | * *String | * *setPath | * *
| httpOnly | * *Boolean | * *setHttpOnly | * *
The default implementation throws
* UnsupportedOperationException and is provided for
* the sole purpose of not breaking existing applications that
* extend this class.
Cookie constructor.
*
* @param value To be passed as the second argument to the
* Cookie constructor.
*
* @param properties A Map containg key/value pairs to be passed
* as arguments to the setter methods as described above.
*
* @throws IllegalArgumentException if the properties
* Map is not-null and not empty and contains
* any keys that are not one of the keys listed above.
*
* @since 2.0
*/
public void addResponseCookie(String name,
String value,
MapDispatch a request to the specified resource to create output * for this response.
* *Jakarta Servlet: This must be accomplished by calling the
* javax.servlet.ServletContext method
* getRequestDispatcher(path), and calling the
* forward() method on the resulting object.
If the call to getRequestDisatcher(path)
* returns null, send aServletResponse SC_NOT_FOUND
* error code.
ServletException occurs
* @throws IOException if an input/output error occurs
*/
public abstract void dispatch(String path) throws IOException;
/**
* Return the input URL, after performing any rewriting needed to * ensure that it will correctly identify an addressable action in the * current application.
* *Encoding the {@link javax.faces.lifecycle.ClientWindow}
* ** ** *Call {@link javax.faces.lifecycle.ClientWindow#isClientWindowRenderModeEnabled(javax.faces.context.FacesContext) }. * If the result is
* *falsetake no further action and return * the rewritten URL. If the result istrue, call {@link #getClientWindow()}. * If the result is non-null, call {@link javax.faces.lifecycle.ClientWindow#getId()} * and append the id to the query string of the URL, making the necessary * allowances for a pre-existing query string or no query-string.Call {@link javax.faces.lifecycle.ClientWindow#getQueryURLParameters}. * If the result is non-{@code null}, for each parameter in the map, * unconditionally add that parameter to the URL.
* *The name * of the query string parameter is given by the value of the constant * {@link javax.faces.render.ResponseStateManager#CLIENT_WINDOW_URL_PARAM}.
* *
Jakarta Servlet: This must be the value returned by the
* javax.servlet.http.HttpServletResponse method
* encodeURL(url).
url
* is null
*/
public abstract String encodeActionURL(String url);
/**
* Return the input URL, after performing any rewriting needed to * ensure that it will correctly identify an addressable resource in the * current application.
* *Jakarta Servlet: This must be the value returned by the
* javax.servlet.http.HttpServletResponse method
* encodeURL(url).
url
* is null
*/
// PENDING(craigmcc) - Currently identical to encodeActionURL()
public abstract String encodeResourceURL(String url);
/**
* * Return the websocket URL, after performing any rewriting needed to * ensure that it will correctly identify an addressable websocket in the * current application. *
* ** Jakarta Servlet: This must ensure that the input URL is prefixed * with the correct websocket scheme, domain and port and then * encoded by {@link #encodeResourceURL(String)}. *
* * @param url The input URL to be encoded. * * @return the encoded websocket URL. * * @throws NullPointerException ifurl is null.
*
* @since 2.3
*/
public abstract String encodeWebsocketURL(String url);
/**
* Returns the MIME type of the
* specified file or null if the MIME type is not
* known. The MIME type is determined by the container.
It is valid to call this method
* during application startup or shutdown. If called during application
* startup or shutdown, this method calls through to the
* getMimeType() method on the same container
* context instance (ServletContext or
* PortletContext) as the one used when calling
* getMimeType() on the
* ExternalContext returned by the
* FacesContext during an actual request.
Jakarta Servlet: This must be the value returned by the
* javax.servlet.ServletContext method
* getMimeType().
Return the * application environment object instance for the current * appication.
*It is valid to call this method
* during application startup or shutdown. If called during application
* startup or shutdown, this returns the same container context instance
* (ServletContext or PortletContext) as
* the one returned when calling getContext() on the
* ExternalContext returned by the
* FacesContext during an actual request.
Jakarta Servlet: This must be the current application's
* javax.servlet.ServletContext instance.
ServletContext.
*
*/
public abstract Object getContext();
/**
*
* Return the name of the container * context for this application.
* *Jakarta Servlet:
* Return the result of calling
* getContextPath() on the
* ServletContext instance for this application.
It is valid to call this method during application startup or * shutdown.
* *The default implementation throws
* UnsupportedOperationException and is provided for
* the sole purpose of not breaking existing applications that
* extend this class.
Return the value of * the specified application initialization parameter (if any).
* *Jakarta Servlet: This must be the result of the
* javax.servlet.ServletContext method
* getInitParameter(name).
It is valid to call this method * during application startup or shutdown. If called during application * startup or shutdown, this method calls through to the actual container * context to return the init parameter value.
* @param name Name of the requested initialization parameter * * @throws NullPointerException ifname
* is null
*
* @return the value of the specified parameter.
*
*/
public abstract String getInitParameter(String name);
/**
* Return an
* immutable Map whose keys are the set of application
* initialization parameter names configured for this application,
* and whose values are the corresponding parameter values. The
* returned Map must implement the entire contract for
* an unmodifiable map as described in the JavaDocs for
* java.util.Map.
It is valid to call this method
* during application startup or shutdown. If called during application
* startup or shutdown, this method returns a Map that is backed by
* the same container context instance (ServletContext
* or PortletContext) as the one returned by calling
* getInitParameterMap() on the
* ExternalContext returned by the
* FacesContext during an actual request.
Jakarta Servlet: This result must be as if it were synthesized
* by calling the javax.servlet.ServletContext
* method getInitParameterNames, and putting
* each configured parameter name/value pair into the result.
Return the login name of the user making the current request
* if any; otherwise, return null.
Jakarta Servlet: This must be the value returned by the
* javax.servlet.http.HttpServletRequest method
* getRemoteUser().
Return the environment-specific object instance for the current * request.
* *Jakarta Servlet: This must be the current request's
* javax.servlet.http.HttpServletRequest instance.
Set the environment-specific request to be returned by * subsequent calls to {@link #getRequest}. This may be used to * install a wrapper for the request.
* *The default implementation throws
* UnsupportedOperationException and is provided
* for the sole purpose of not breaking existing applications that extend
* this class.
Returns the name of the scheme used * to make this request, for example, http, https, or ftp.
* *Jakarta Servlet: This must be the value returned by the
* javax.servlet.ServletRequest method
* getScheme().
The default implementation throws
* UnsupportedOperationException and is provided for
* the sole purpose of not breaking existing applications that
* extend this class.
Returns the host name of the server * to which the request was sent.
* *Jakarta Servlet: This must be the value returned by the
* javax.servlet.ServletRequest method
* getServerName().
The default implementation throws
* UnsupportedOperationException and is provided for
* the sole purpose of not breaking existing applications that
* extend this class.
Returns the port number to which * the request was sent.
* *Jakarta Servlet: This must be the value returned by the
* javax.servlet.ServletRequest method
* getServerPort().
The default implementation throws
* UnsupportedOperationException and is provided for
* the sole purpose of not breaking existing applications that
* extend this class.
Returns a String containing the real * path for a given virtual path.
* *It is valid to call this method
* during application startup or shutdown. If called during application
* startup or shutdown, this method calls through to the
* getRealPath() method on the same container
* context instance (ServletContext or
* PortletContext) as the one used when calling
* getRealPath() on the
* ExternalContext returned by the
* FacesContext during an actual request.
*
Jakarta Servlet: This must be the value returned by the
* javax.servlet.ServletContext method
* getRealPath().
The default implementation throws
* UnsupportedOperationException and is provided
* for the sole purpose of not breaking existing applications that extend
* this class.
Return the portion of the request URI that identifies the web * application context for this request.
* *Jakarta Servlet: This must be the value returned by the
* javax.servlet.http.HttpServletRequest method
* getContextPath().
Return an immutable Map whose keys are the set of
* cookie names included in the current request, and whose
* values (of type javax.servlet.http.Cookie)
* are the first (or only) cookie for each cookie name
* returned by the underlying request. The returned
* Map must implement the entire contract for an unmodifiable
* map as described in the JavaDocs for java.util.Map.
Jakarta Servlet: This must be the value returned by the
* javax.servlet.http.HttpServletRequest method
* getCookies(), unless null was returned,
* in which case this must be a zero-length array.
Return an immutable Map whose keys are the set of
* request header names included in the current request, and whose
* values (of type String) are the first (or only) value for each
* header name returned by the underlying request. The returned
* Map must implement the entire contract for an unmodifiable
* map as described in the JavaDocs for java.util.Map. In
* addition, key comparisons must be performed in a case insensitive
* manner.
Jakarta Servlet: This must be the set of headers available via
* the javax.servlet.http.HttpServletRequest methods
* getHeader() and getHeaderNames().
Return an immutable Map whose keys are the set of
* request header names included in the current request, and whose
* values (of type String[]) are all of the value for each
* header name returned by the underlying request. The returned
* Map must implement the entire contract for an unmodifiable
* map as described in the JavaDocs for java.util.Map. In
* addition, key comparisons must be performed in a case insensitive
* manner.
Jakarta Servlet: This must be the set of headers available via
* the javax.servlet.http.HttpServletRequest methods
* getHeaders() and getHeaderNames().
Return a mutable Map representing the request
* scope attributes for the current application. The returned
* Map must implement the entire contract for a
* modifiable map as described in the JavaDocs for
* java.util.Map. Modifications made in the
* Map must cause the corresponding changes in the set
* of request scope attributes. Particularly the
* clear(), remove(), put(),
* putAll(), and get() operations must
* take the appropriate action on the underlying data structure.
For any of the Map methods that cause an element
* to be removed from the underlying data structure, the following
* action regarding managed-beans must be taken. If the element to
* be removed is a managed-bean, and it has one or more public
* no-argument void return methods annotated with
* javax.annotation.PreDestroy, each such method must
* be called before the element is removed from the underlying data
* structure. Elements that are not managed-beans, but do happen to
* have methods with that annotation must not have those methods
* called on removal. Any exception thrown by the
* PreDestroy annotated methods must by caught and not
* rethrown. The exception may be logged.
Jakarta Servlet: This must be the set of attributes available via
* the javax.servlet.ServletRequest methods
* getAttribute(), getAttributeNames(),
* removeAttribute(), and setAttribute().
Return an immutable Map whose keys are the set of
* request parameters names included in the current request, and whose
* values (of type String) are the first (or only) value for each
* parameter name returned by the underlying request. The returned
* Map must implement the entire contract for an unmodifiable
* map as described in the JavaDocs for java.util.Map.
Jakarta Servlet: This must be the set of parameters available via
* the javax.servlet.ServletRequest methods
* getParameter() and getParameterNames().
Return an Iterator over the names of all request
* parameters included in the current request.
Jakarta Servlet: This must be an Iterator over the
* values returned by the javax.servlet.ServletRequest
* method getParameterNames().
Iterator for the names of the current request parameters.
*
*/
public abstract IteratorReturn an immutable Map whose keys are the set of
* request parameters names included in the current request, and whose
* values (of type String[]) are all of the values for each
* parameter name returned by the underlying request. The returned
* Map must implement the entire contract for an unmodifiable
* map as described in the JavaDocs for java.util.Map.
Jakarta Servlet: This must be the set of parameters available via
* the javax.servlet.ServletRequest methods
* getParameterValues() and
* getParameterNames().
Return the extra path information (if any) included in the
* request URI; otherwise, return null.
Jakarta Servlet: This must be the value returned by the
* javax.servlet.http.HttpServletRequest method
* getPathInfo().
Return the Jakarta Servlet path information (if any) included in the
* request URI; otherwise, return null.
Jakarta Servlet: This must be the value returned by the
* javax.servlet.http.HttpServletRequest method
* getServletPath().
Return a
* URL for the application resource mapped to the
* specified path, if it exists; otherwise, return
* null.
It is valid to call this method
* during application startup or shutdown. If called during application
* startup or shutdown, this method calls through to the
* getResource() method on the same container
* context instance (ServletContext or
* PortletContext) as the one used when calling
* getResource() on the
* ExternalContext returned by the
* FacesContext during an actual request.
Jakarta Servlet: This must be the value returned by the
* javax.servlet.ServletContext method
* getResource(path).
path
* is null
*/
public abstract URL getResource(String path) throws MalformedURLException;
/**
* Return an
* InputStream for an application resource mapped to
* the specified path, if it exists; otherwise, return
* null.
It is valid to call this method
* during application startup or shutdown. If called during application
* startup or shutdown, this method calls through to the
* getResourceAsStream() method on the same container
* context instance (ServletContext or
* PortletContext) as the one used when calling
* getResourceAsStream() on the
* ExternalContext returned by the
* FacesContext during an actual request.
Jakarta Servlet: This must be the value returned by the
* javax.servlet.ServletContext method
* getResourceAsStream(path).
InputStream for the application resource.
*
* @throws NullPointerException if path
* is null
*/
public abstract InputStream getResourceAsStream(String path);
/**
* Return the
* Set of resource paths for all application resources
* whose resource path starts with the specified argument.
It is valid to call this method
* during application startup or shutdown. If called during application
* startup or shutdown, this method calls through to the
* getResourcePaths() method on the same container
* context instance (ServletContext or
* PortletContext) as the one used when calling
* getResourcePaths() on the
* ExternalContext returned by the
* FacesContext during an actual request.
Jakarta Servlet: This must be the value returned by the
* javax.servlet.ServletContext method
* getResourcePaths(path).
Set of resource paths for the application resources.
*
* @throws NullPointerException if path
* is null
*/
public abstract SetReturn the environment-specific object instance for the current * response.
* *Jakarta Servlet: This is the current request's
* javax.servlet.http.HttpServletResponse instance.
javax.servlet.http.HttpServletResponse.
*/
public abstract Object getResponse();
/**
* Set the environment-specific response to be returned by * subsequent calls to {@link #getResponse}. This may be used to * install a wrapper for the response.
* *The default implementation throws
* UnsupportedOperationException and is provided
* for the sole purpose of not breaking existing applications that extend
* this class.
Returns an OutputStream
* suitable for writing binary data to the user-agent.
Jakarta Servlet: This must return the value returned by the
* javax.servlet.ServletResponse method
* getOutputStream().
The default implementation throws
* UnsupportedOperationException and is provided for
* the sole purpose of not breaking existing applications that
* extend this class.
OutputStream for the current response.
*
* @throws IOException any IO related exception.
*
* @since 2.0
*/
public OutputStream getResponseOutputStream() throws IOException {
return null;
}
/**
* Returns a Writer
* suitable for writing character data to the user-agent.
Jakarta Servlet: This must return the value returned by the * {@link javax.servlet.ServletResponse#getWriter}.
* *The default implementation throws
* UnsupportedOperationException and is provided for
* the sole purpose of not breaking existing applications that
* extend this class.
Writer for the current response.
*
* @throws IOException any IO related exception.
*
* @since 2.0
*/
public Writer getResponseOutputWriter() throws IOException {
return null;
}
/**
* Redirect a request
* to the specified URL, and cause the
* responseComplete() method to be called on the
* {@link FacesContext} instance for the current request.
The implementation must determine if
* the request is an Ajax request by obtaining a
* {@link PartialViewContext} instance from the {@link FacesContext} and
* calling {@link PartialViewContext#isAjaxRequest()}.
Jakarta Servlet: For
* non Ajax requests, this must be accomplished by calling
* the javax.servlet.http.HttpServletResponse method
* sendRedirect().
text/xmlUTF-8Cache-Control,
* no-cacheurl
* argument.RenderResponse
* instead of an ActionResponse
* @throws IllegalStateException if, in a Jakarta Servlet environment,
* the current response has already been committed
* @throws IOException if an input/output error occurs
*/
public abstract void redirect(String url) throws IOException;
/**
* Set the response header with the given name and value.
* *Jakarta Servlet:This must be performed by calling the
* javax.servlet.http.HttpServletResponse setHeader
* method.
The default implementation throws
* UnsupportedOperationException and is provided for
* the sole purpose of not breaking existing applications that
* extend this class.
Add the given name and value to the response header.
* *Jakarta Servlet:This must be performed by calling the
* javax.servlet.http.HttpServletResponse addHeader
* method.
The default implementation throws
* UnsupportedOperationException and is provided for
* the sole purpose of not breaking existing applications that
* extend this class.
Sets the HTTP status code for the response.
* *Jakarta Servlet: This must be performed by calling the
* javax.servlet.http.HttpServletResponse setStatus
* method.
The default implementation throws
* UnsupportedOperationException and is provided for
* the sole purpose of not breaking existing applications that
* extend this class.
See {@link #encodeActionURL(java.lang.String)} * for the required specification of how to encode the {@link javax.faces.lifecycle.ClientWindow}. *
* * @param baseUrl The base URL onto which the query string generated by this method will be appended. The URL may contain query parameters. * @param parameters The collection of Parameter objects, representing name=value pairs that are used to produce a query string * * @return the result of encoding. * @since 2.0 */ public String encodeRedirectURL(String baseUrl, Map