- java.lang.Object
-
- javax.faces.application.ViewResource
-
- javax.faces.application.Resource
-
- Direct Known Subclasses:
- ResourceWrapper
public abstract class Resource extends ViewResource
An instance of
Resource
is a Java object representation of the artifact that is served up in response to a resource request from the client. Instances ofResource
are normally created and initialized via calls toResourceHandler.createResource(java.lang.String)
. See the documentation forResourceHandler
for more information.- Since:
- 2.0
-
-
Field Summary
Fields Modifier and Type Field and Description static String
COMPONENT_RESOURCE_KEY
This constant is used as the key in the component attribute map of a composite component to associate the component with its
Resource
instance.
-
Constructor Summary
Constructors Constructor and Description Resource()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method and Description String
getContentType()
Return the MIME content-type for this resource.
abstract InputStream
getInputStream()
If the current request is a resource request, (that is,
ResourceHandler.isResourceRequest(javax.faces.context.FacesContext)
returnstrue
), return anInputStream
containing the bytes of the resource.String
getLibraryName()
Return the libraryName for this resource.
abstract 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.
String
getResourceName()
Return the resourceName for this resource.
abstract Map<String,String>
getResponseHeaders()
Returns a mutable
Map<String, String>
whose entries will be sent as response headers duringResourceHandler.handleResourceRequest(javax.faces.context.FacesContext)
.abstract URL
getURL()
Return an actual
URL
instance that refers to this resource instance.void
setContentType(String contentType)
Set the MIME content-type for this resource.
void
setLibraryName(String libraryName)
Set the libraryName for this resource.
void
setResourceName(String resourceName)
Set the resourceName for this resource.
String
toString()
Call through to
getRequestPath()
and return the result.abstract boolean
userAgentNeedsUpdate(FacesContext context)
Return
true
if the user-agent requesting this resource needs an update.
-
-
-
Field Detail
-
COMPONENT_RESOURCE_KEY
public static final String COMPONENT_RESOURCE_KEY
This constant is used as the key in the component attribute map of a composite component to associate the component with its
Resource
instance. The value for this key is the actualResource
instance.- See Also:
- Constant Field Values
-
-
Method Detail
-
getContentType
public String getContentType()
Return the MIME content-type for this resource.
- Returns:
- the MIME content-type for this resource.
-
setContentType
public void setContentType(String contentType)
Set the MIME content-type for this resource. The default implementation performs no validation on the argument.
- Parameters:
contentType
- the MIME content-type for this resource. The default implementation must acceptnull
as a parameter.
-
getLibraryName
public String getLibraryName()
Return the libraryName for this resource. May be
null
. The libraryName for a resource is an optional String that indicates membership in a "resource library". All resources with the same libraryName belong to the same "resource library". The "resource library" concept allows disambiguating resources that have the same resourceName. SeeResourceHandler
for more information.- Returns:
- Return the libraryName for this resource. May be
null
.
-
setLibraryName
public void setLibraryName(String libraryName)
Set the libraryName for this resource.
- Parameters:
libraryName
- the libraryName for this resource. The default implementation must acceptnull
for the libraryName.
-
getResourceName
public String getResourceName()
Return the resourceName for this resource. Will never be null. All
Resource
instances must have a resourceName.- Returns:
- Return the resourceName for this resource. Will never be null.
-
setResourceName
public void setResourceName(String resourceName)
Set the resourceName for this resource.
- Parameters:
resourceName
- a non-null String.- Throws:
NullPointerException
- if argumentresourceName
is null.
-
getInputStream
public abstract InputStream getInputStream() throws IOException
If the current request is a resource request, (that is,
ResourceHandler.isResourceRequest(javax.faces.context.FacesContext)
returnstrue
), return anInputStream
containing the bytes of the resource. Otherwise, throw anIOException
.- Returns:
- 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.
- Throws:
IOException
- if the current request is not a resource request.
-
getResponseHeaders
public abstract Map<String,String> getResponseHeaders()
Returns a mutable
Map<String, String>
whose entries will be sent as response headers duringResourceHandler.handleResourceRequest(javax.faces.context.FacesContext)
. The entries in this map must not persist beyond the scope of a single request. Any modifications made to the map after the resource has been served will be ignored by the run-time.- Returns:
- a mutable
Map<String, String>
of headers that will be included with the response.
-
getRequestPath
public abstract 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.
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 or extension mapped, and the value of the mapping (including the leading '.' in the case of extension mapping). For discussion, this will be facesServletMapping.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()
+ facesServletMappingBuild 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 fromgetLibraryName()
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)
.
- Returns:
- the path to this resource, intended to be included in the encoded view that is sent to the browser when sending a faces response.
-
getURL
public abstract URL getURL()
Return an actual
URL
instance that refers to this resource instance.- Specified by:
getURL
in classViewResource
- Returns:
- Return an actual
URL
instance that refers to this resource instance.
-
toString
public String toString()
Call through to
getRequestPath()
and return the result.- Overrides:
toString
in classObject
- Returns:
- Call through to
getRequestPath()
and return the result.
-
userAgentNeedsUpdate
public abstract boolean userAgentNeedsUpdate(FacesContext context)
Return
true
if the user-agent requesting this resource needs an update. If theIf-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. Returnsfalse
if the user-agent does not need an update for this resource.- Returns:
true
orfalse
depending on whether or not the user-agent needs an update of this resource.
-
-
Deutsche Übersetzung
Sie haben gebeten, diese Seite auf Deutsch zu besuchen. Momentan ist nur die Oberfläche übersetzt, aber noch nicht der gesamte Inhalt.Wenn Sie mir bei Übersetzungen helfen wollen, ist Ihr Beitrag willkommen. Alles, was Sie tun müssen, ist, sich auf der Website zu registrieren und mir eine Nachricht zu schicken, in der Sie gebeten werden, Sie der Gruppe der Übersetzer hinzuzufügen, die Ihnen die Möglichkeit gibt, die gewünschten Seiten zu übersetzen. Ein Link am Ende jeder übersetzten Seite zeigt an, dass Sie der Übersetzer sind und einen Link zu Ihrem Profil haben.
Vielen Dank im Voraus.
Dokument erstellt 11/06/2005, zuletzt geändert 18/08/2025
Quelle des gedruckten Dokuments:https://www.gaudry.be/de/java-api-javaee-rf-javax/faces/application/Resource.html
Die Infobro ist eine persönliche Seite, deren Inhalt in meiner alleinigen Verantwortung liegt. Der Text ist unter der CreativeCommons-Lizenz (BY-NC-SA) verfügbar. Weitere Informationen auf die Nutzungsbedingungen und dem Autor.
Referenzen
Diese Verweise und Links verweisen auf Dokumente, die während des Schreibens dieser Seite konsultiert wurden, oder die zusätzliche Informationen liefern können, aber die Autoren dieser Quellen können nicht für den Inhalt dieser Seite verantwortlich gemacht werden.
Der Autor dieser Website ist allein dafür verantwortlich, wie die verschiedenen Konzepte und Freiheiten, die mit den Nachschlagewerken gemacht werden, hier dargestellt werden. Denken Sie daran, dass Sie mehrere Quellinformationen austauschen müssen, um das Risiko von Fehlern zu reduzieren.