public class ResourceImpl extends Resource implements Externalizable
Resource
.
The ResourceImpl instance itself has the same lifespan as the
request, however, the ResourceInfo instances that back this object
are cached by the ResourceManager to reduce the time spent scanning
for resources.COMPONENT_RESOURCE_KEY
Constructor and Description |
---|
ResourceImpl()
Necessary for serialization.
|
ResourceImpl(ResourceInfo resourceInfo,
String contentType,
long initialTime,
long maxAge)
Creates a new instance of ResourceBase
|
Modifier and Type | Method and Description |
---|---|
boolean |
equals(Object o) |
InputStream |
getInputStream()
If the current request is a resource request, (that
is, |
String |
getRequestPath()
Return a path to this resource such that, when the browser resolves it against the base URI for the view that includes the resource, and issues a GET request to the resultant fully qualified URL, the bytes of the resource are returned in response. |
Map<String,String> |
getResponseHeaders()
Implementation note.
|
URL |
getURL()
Return an actual |
int |
hashCode() |
void |
readExternal(ObjectInput in) |
boolean |
userAgentNeedsUpdate(FacesContext context)
Return |
void |
writeExternal(ObjectOutput out) |
getContentType, getLibraryName, getResourceName, setContentType, setLibraryName, setResourceName, toString
public ResourceImpl()
public ResourceImpl(ResourceInfo resourceInfo, String contentType, long initialTime, long maxAge)
public InputStream getInputStream() throws IOException
Resource
If the current request is a resource request, (that
is, ResourceHandler.isResourceRequest(javax.faces.context.FacesContext)
returns true
), return an
InputStream
containing the bytes of the resource. Otherwise, throw an
IOException
.
getInputStream
in class Resource
InputStream
containing the bytes of the resource.
Any Jakarta Expression Language expressions present in the resource must be evaluated before serving the bytes of the resource. Note that due to browser and server caching, Jakarta Expression Language expressions in a resource file will generally only be evaluated once, when the resource is first served up. Therefore, using Jakarta Expression Language expressions that refer to per-request data is not advisable since this data can become stale.
IOException
- if the current request is not a resource request.Resource.getInputStream()
public URL getURL()
Resource
Return an actual URL
instance that refers to this resource instance.
getURL
in class Resource
URL
instance that refers to this resource instance.Resource.getURL()
public Map<String,String> getResponseHeaders()
Implementation note. Any values added to getResponseHeaders()
will only be visible across multiple calls to this method when
servicing a resource request (i.e. ResourceHandler.isResourceRequest(javax.faces.context.FacesContext)
returns true
). If we're not servicing a resource request,
an empty Map will be returned and the values added are effectively thrown
away.
getResponseHeaders
in class Resource
Map<String, String>
of headers that will be included
with the response.Resource.getResponseHeaders()
public String getRequestPath()
Resource
Return a path to this resource such that, when the browser resolves it against the base URI for the view that includes the resource, and issues a GET request to the resultant fully qualified URL, the bytes of the resource are returned in response.
The default implementation must implement the following algorithm. For discussion, the return result from this method will be called result.
Get the context-root for this web application, not ending in slash. For discussion this will be called contextRoot.
Discover if the FacesServlet
is prefix (path) mapped, extension mapped, or exact
mapped (as defined by Servlet.12.2.) and the value of the mapping (including the leading '.'
in the case of extension mapping). For discussion, this will be facesServletMapping.
If exact mapped, result must be the following if and only if the FacesServlet is
mapped to the exact URL pattern ResourceHandler.RESOURCE_IDENTIFIER
+
Resource.getResourceName()
result = contextRoot +
ResourceHandler.RESOURCE_IDENTIFIER
+Resource.getResourceName()
If exact mapped, and the FacesServlet is not mapped to the exact URL pattern
ResourceHandler.RESOURCE_IDENTIFIER
+ Resource.getResourceName()
do the following:
Retrieve the existing mappings of the FacesServlet, e.g. using
ServletRegistration.getMappings()
, and from those pick any prefix mapping or
extension mapping. If no such mapping is found, throw an IllegalStateException
. If
such mapping is found remove the *
character from that mapping, take that as the
new facesServletMapping and continue with evaluating this mapping as specified below
for if prefix mapped and for if extension mapped
If prefix mapped, result must be
result = contextRoot + '/' + facesServletMapping +
ResourceHandler.RESOURCE_IDENTIFIER
+ '/' +Resource.getResourceName()
If extension mapped, result must be
result = contextRoot +
ResourceHandler.RESOURCE_IDENTIFIER
+Resource.getResourceName()
+ facesServletMapping
Build up a string, called resourceMetaData which is an & separated string of name=value pairs suitable for inclusion in a URL query string.
If
Resource.getLibraryName()
returns non-null
,resourceMetaData
must include "ln=" + the return fromResource.getLibraryName()
If there is a
localePrefix
for this application, as defined inResourceHandler.LOCALE_PREFIX
,resourceMetaData
must include "loc=" + thelocalePrefix
.If this resource is contained in a resource library contract,
resourceMetaData
must include "con=" + the name of the resource library contract.
Append "?" + resourceMetaData to result.
Make it portlet safe by passing the result through ViewHandler.getResourceURL(javax.faces.context.FacesContext, java.lang.String)
.
getRequestPath
in class Resource
Resource.getRequestPath()
public boolean userAgentNeedsUpdate(FacesContext context)
Resource
Return true
if the user-agent
requesting this resource needs an update. If the
If-Modified-Since
HTTP header is available for this request, its value must be
consulted, as specified in Section 14.25 of IETF RFC 2616, to determine the result.
Returns false
if the user-agent does not need an update for this resource.
userAgentNeedsUpdate
in class Resource
context
- the Faces context.true
or false
depending on whether or not the user-agent
needs an update of this resource.Resource.userAgentNeedsUpdate(javax.faces.context.FacesContext)
public void writeExternal(ObjectOutput out) throws IOException
writeExternal
in interface Externalizable
IOException
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
readExternal
in interface Externalizable
IOException
ClassNotFoundException
Comments to: faces-dev@eclipse.org.
Copyright © 2019 Eclipse Foundation. All rights reserved.
Use is subject to license terms.