Top Description Fields Constructors Methods
com.sun.faces.application.resource

public Class ResourceImpl

extends Resource
implements Externalizable
Class Inheritance
All Implemented Interfaces
java.io.Externalizable, java.io.Serializable
Static Imports
com.sun.faces.util.Util.getFacesMapping, .Util.getFirstWildCardMappingToFacesServlet, .Util.getLastModified, .Util.isExactMapped, .Util.isPrefixMapped, .Util.isResourceExactMappedToFacesServlet, java.util.Collections.emptyMap, .Locale.US, java.util.logging.Level.FINEST, javax.faces.application.ProjectStage.Development, .ProjectStage.Production, .ResourceHandler.JSF_SCRIPT_LIBRARY_NAME, .ResourceHandler.JSF_SCRIPT_RESOURCE_NAME, .ResourceHandler.RESOURCE_IDENTIFIER

Default implementation of javax.faces.application.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.

Field Summary

Modifier and TypeField and Description
private static final TimeZone
private static final String
private long
initialTime

Time when this application was started.

private static final Logger
private long
maxAge

Lifespan of this resource for caching purposes.

private transient ResourceInfo
private transient Map<String, String>
private static final String
Inherited from javax.faces.application.Resource:
COMPONENT_RESOURCE_KEY

Constructor Summary

AccessConstructor and Description
public
ResourceImpl()

Necessary for serialization.

public
ResourceImpl(ResourceInfo resourceInfo, String contentType, long initialTime, long maxAge)

Creates a new instance of ResourceBase

Method Summary

Modifier and TypeMethod and Description
public boolean
equals(Object
the reference object with which to compare.
o
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.
private long
public InputStream
getInputStream()

Implements abstract javax.faces.application.Resource.getInputStream.

If the current request is a resource request, (that is, ResourceHandler#isResourceRequest returns true), return an InputStream containing the bytes of the resource.

public String
getRequestPath()

Implements abstract javax.faces.application.Resource.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.

public Map<String, String>
getResponseHeaders()

Implements abstract javax.faces.application.Resource.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).

public URL
getURL()

Implements abstract javax.faces.application.Resource.getURL.

Return an actual URL instance that refers to this resource instance.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for the object.
private void
private boolean
public void
readExternal(ObjectInput
the stream to read data from in order to restore the object
in
)

Implements java.io.Externalizable.readExternal.

The object implements the readExternal method to restore its contents by calling the methods of DataInput for primitive types and readObject for objects, strings and arrays.
public boolean
userAgentNeedsUpdate(FacesContext
the Faces context.
context
)

Implements abstract javax.faces.application.Resource.userAgentNeedsUpdate.

Return true if the user-agent requesting this resource needs an update.

public void
writeExternal(ObjectOutput
the stream to write the object to
out
)

Implements java.io.Externalizable.writeExternal.

The object implements the writeExternal method to save its contents by calling the methods of DataOutput for its primitive values or calling the writeObject method of ObjectOutput for objects, strings, and arrays.
Inherited from javax.faces.application.Resource:
getContentTypegetLibraryNamegetResourceNamesetContentTypesetLibraryNamesetResourceNametoString

Field Detail

GMTback to summary
private static final TimeZone GMT
IF_MODIFIED_SINCEback to summary
private static final String IF_MODIFIED_SINCE
initialTimeback to summary
private long initialTime

Time when this application was started. This is used to generate expiration headers.

LOGGERback to summary
private static final Logger LOGGER
maxAgeback to summary
private long maxAge

Lifespan of this resource for caching purposes.

resourceInfoback to summary
private transient ResourceInfo resourceInfo
responseHeadersback to summary
private transient Map<String, String> responseHeaders
RFC1123_DATE_PATTERNback to summary
private static final String RFC1123_DATE_PATTERN

Constructor Detail

ResourceImplback to summary
public ResourceImpl()

Necessary for serialization.

Annotations
@SuppressWarnings:UnusedDeclaration
ResourceImplback to summary
public ResourceImpl(ResourceInfo resourceInfo, String contentType, long initialTime, long maxAge)

Creates a new instance of ResourceBase

Method Detail

equalsback to summary
public boolean equals(Object o)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
o:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
getIfModifiedHeaderback to summary
private long getIfModifiedHeader(ExternalContext extcontext)
getInputStreamback to summary
public InputStream getInputStream() throws IOException

Implements abstract javax.faces.application.Resource.getInputStream.

Doc from javax.faces.application.Resource.getInputStream.

If the current request is a resource request, (that is, ResourceHandler#isResourceRequest returns true), return an InputStream containing the bytes of the resource. Otherwise, throw an IOException.

Returns:InputStream

an InputStream containing the bytes of the resource.

Any EL expressions present in the resource must be evaluated before serving the bytes of the resource. Note that due to browser and server caching, EL expressions in a resource file will generally only be evaluated once, when the resource is first served up. Therefore, using EL expressions that refer to per-request data is not advisable since this data can become stale.

Annotations
@Override
Exceptions
IOException:
if the current request is not a resource request.
See Also
javax.faces.application.Resource#getInputStream()
getRequestPathback to summary
public String getRequestPath()

Implements abstract javax.faces.application.Resource.getRequestPath.

Doc from javax.faces.application.Resource.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.

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 + getResourceName

    result = contextRoot + ResourceHandler#RESOURCE_IDENTIFIER + getResourceName

    If exact mapped, and the FacesServlet is not mapped to the exact URL pattern ResourceHandler#RESOURCE_IDENTIFIER + 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 + '/' + getResourceName

    If extension mapped, result must be

    result = contextRoot + ResourceHandler#RESOURCE_IDENTIFIER + 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 getLibraryName returns non-null, resourceMetaData must include "ln=" + the return from getLibraryName

    If there is a localePrefix for this application, as defined in ResourceHandler#LOCALE_PREFIX, resourceMetaData must include "loc=" + the localePrefix.

    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.

Returns:String

the path to this resource, intended to be included in the encoded view that is sent to the browser when sending a faces response.

Annotations
@Override
See Also
javax.faces.application.Resource#getRequestPath()
getResponseHeadersback to summary
public Map<String, String> getResponseHeaders()

Implements abstract javax.faces.application.Resource.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.

Returns:Map<String, String>

Doc from javax.faces.application.Resource.getResponseHeaders.

a mutable Map<String, String> of headers that will be included with the response.

Annotations
@Override
See Also
javax.faces.application.Resource#getResponseHeaders()
getURLback to summary
public URL getURL()

Implements abstract javax.faces.application.Resource.getURL.

Doc from javax.faces.application.Resource.getURL.

Return an actual URL instance that refers to this resource instance.

Returns:URL

Return an actual URL instance that refers to this resource instance.

Annotations
@Override
See Also
javax.faces.application.Resource#getURL()
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for the object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object.

Annotations
@Override
initResourceInfoback to summary
private void initResourceInfo()
isResourceRequestback to summary
private boolean isResourceRequest()
readExternalback to summary
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException

Implements java.io.Externalizable.readExternal.

Doc from java.io.Externalizable.readExternal.

The object implements the readExternal method to restore its contents by calling the methods of DataInput for primitive types and readObject for objects, strings and arrays. The readExternal method must read the values in the same sequence and with the same types as were written by writeExternal.

Parameters
in:ObjectInput

the stream to read data from in order to restore the object

Annotations
@Override
Exceptions
IOException:
if I/O errors occur
ClassNotFoundException:
If the class for an object being restored cannot be found.
userAgentNeedsUpdateback to summary
public boolean userAgentNeedsUpdate(FacesContext context)

Implements abstract javax.faces.application.Resource.userAgentNeedsUpdate.

Doc from javax.faces.application.Resource.userAgentNeedsUpdate.

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.

Parameters
context:FacesContext

the Faces context.

Returns:boolean

true or false depending on whether or not the user-agent needs an update of this resource.

Annotations
@Override
See Also
javax.faces.application.Resource#userAgentNeedsUpdate(javax.faces.context.FacesContext)
writeExternalback to summary
public void writeExternal(ObjectOutput out) throws IOException

Implements java.io.Externalizable.writeExternal.

Doc from java.io.Externalizable.writeExternal.

The object implements the writeExternal method to save its contents by calling the methods of DataOutput for its primitive values or calling the writeObject method of ObjectOutput for objects, strings, and arrays.

Parameters
out:ObjectOutput

the stream to write the object to

Annotations
@Override
Exceptions
IOException:
Includes any I/O exceptions that may occur