Package org.omnifaces.resourcehandler
Class GraphicResource
- java.lang.Object
-
- jakarta.faces.application.ViewResource
-
- jakarta.faces.application.Resource
-
- org.omnifaces.resourcehandler.DynamicResource
-
- org.omnifaces.resourcehandler.GraphicResource
-
public class GraphicResource extends DynamicResource
This
Resource
implementation is used by theGraphicImage
component.- Since:
- 2.0
- Author:
- Bauke Scholtz
-
-
Field Summary
-
Fields inherited from class jakarta.faces.application.Resource
COMPONENT_RESOURCE_KEY
-
-
Constructor Summary
Constructors Constructor Description GraphicResource(Object content, String contentType)
Construct a new graphic resource which uses the given content as data URI.GraphicResource(String name, String[] params, Object lastModified)
Construct a new graphic resource based on the given name, EL method parameters converted as string, and the "last modified" representation.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static GraphicResource
create(FacesContext context, ValueExpression value, String type, Object lastModified)
Create a new graphic resource based on the given value expression.InputStream
getInputStream()
String
getRequestPath()
An override which either returns the data URI or appends the converted method parameters to the query string.static void
registerGraphicImageBeans()
Register graphic image scoped beans discovered so far.-
Methods inherited from class org.omnifaces.resourcehandler.DynamicResource
getLastModified, getResponseHeaders, getURL, setLastModified, userAgentNeedsUpdate
-
Methods inherited from class jakarta.faces.application.Resource
getContentType, getLibraryName, getResourceName, setContentType, setLibraryName, setResourceName, toString
-
-
-
-
Constructor Detail
-
GraphicResource
public GraphicResource(Object content, String contentType)
Construct a new graphic resource which uses the given content as data URI. This constructor is called during render time of<o:graphicImage ... dataURI="true">
.- Parameters:
content
- The graphic resource content, to be represented as data URI.contentType
- The graphic resource content type. If this isnull
, then it will be guessed based on the content type signature in the content header. So far, WEBP, JPEG, PNG, GIF, ICO, SVG, BMP and TIFF are recognized. Else if this represents the file extension, then it will be resolved based on mime mappings.
-
GraphicResource
public GraphicResource(String name, String[] params, Object lastModified)
Construct a new graphic resource based on the given name, EL method parameters converted as string, and the "last modified" representation. This constructor is called during render time of<o:graphicImage value="..." dataURI="false">
and during handling the resource request byGraphicResourceHandler
.- Parameters:
name
- The graphic resource name, usually representing the base and method of EL method expression.params
- The graphic resource method parameters.lastModified
- The "last modified" representation of the graphic resource, can beLong
orDate
, or otherwise an attempt will be made to parse it asLong
.- Throws:
IllegalArgumentException
- If "last modified" can not be parsed to a timestamp.
-
-
Method Detail
-
create
public static GraphicResource create(FacesContext context, ValueExpression value, String type, Object lastModified)
Create a new graphic resource based on the given value expression.- Parameters:
context
- The involved faces context.value
- The value expression representing content to create a new graphic resource for.type
- The image type, represented as file extension. E.g. "webp", "jpg", "png", "gif", "ico", "svg", "bmp", "tiff", etc.lastModified
- The "last modified" representation of the graphic resource, can beLong
orDate
, or otherwise an attempt will be made to parse it asLong
.- Returns:
- The new graphic resource.
- Throws:
IllegalArgumentException
- When the "value" attribute of the given component is absent or does not represent a method expression referring an existing method taking at least one argument. Or, when the "type" attribute does not represent a valid file extension (you can add unrecognized ones as<mime-mapping>
inweb.xml
).
-
getRequestPath
public String getRequestPath()
An override which either returns the data URI or appends the converted method parameters to the query string.- Overrides:
getRequestPath
in classDynamicResource
-
getInputStream
public InputStream getInputStream() throws IOException
- Specified by:
getInputStream
in classResource
- Throws:
IOException
-
registerGraphicImageBeans
public static void registerGraphicImageBeans()
Register graphic image scoped beans discovered so far.- Throws:
IllegalArgumentException
- When bean method is missing.
-
-