public class ResourceResolver extends Object
| Modifier and Type | Field and Description |
|---|---|
static String |
BASE64_IDENTIFIER
Identifier string used when loading in base64 images.
|
static String |
DATA_SCHEMA_PREFIX
Identifier string used to detect that the source is under data URI scheme.
|
| Constructor and Description |
|---|
ResourceResolver(String baseUri)
Creates a new
ResourceResolver instance. |
ResourceResolver(String baseUri,
IResourceRetriever retriever)
Creates a new
ResourceResolver instance. |
| Modifier and Type | Method and Description |
|---|---|
protected PdfXObject |
createImageByUrl(URL url)
Create a iText XObject based on the image stored at the passed location.
|
IResourceRetriever |
getRetriever()
Gets the resource retriever.
|
static boolean |
isDataSrc(String src)
Checks if source is under data URI scheme.
|
void |
resetCache()
Resets the simple image cache.
|
URL |
resolveAgainstBaseUri(String uri)
Resolves a given URI against the base URI.
|
byte[] |
retrieveBytesFromResource(String src)
Retrieve a resource as a byte array from a source that
can either be a link to a file, or a base64 encoded
String. |
PdfXObject |
retrieveImage(String src)
Retrieve image as either
PdfImageXObject, or PdfFormXObject. |
InputStream |
retrieveResourceAsInputStream(String src)
Retrieve the resource found in src as an InputStream
|
ResourceResolver |
setRetriever(IResourceRetriever retriever)
Sets the resource retriever.
|
protected PdfXObject |
tryResolveBase64ImageSource(String src) |
protected PdfXObject |
tryResolveUrlImageSource(String uri) |
public static final String BASE64_IDENTIFIER
public static final String DATA_SCHEMA_PREFIX
public ResourceResolver(String baseUri)
ResourceResolver instance.
If baseUri is a string that represents an absolute URI with any schema except "file" - resources
url values will be resolved exactly as "new URL(baseUrl, uriString)". Otherwise base URI will be handled
as path in local file system.
If empty string or relative URI string is passed as base URI, then it will be resolved against current working directory of this application instance.
baseUri - base URI against which all relative resource URIs will be resolvedpublic ResourceResolver(String baseUri, IResourceRetriever retriever)
ResourceResolver instance.
If baseUri is a string that represents an absolute URI with any schema except "file" - resources
url values will be resolved exactly as "new URL(baseUrl, uriString)". Otherwise base URI will be handled
as path in local file system.
If empty string or relative URI string is passed as base URI, then it will be resolved against current working directory of this application instance.
baseUri - base URI against which all relative resource URIs will be resolvedretriever - the resource retriever with the help of which data from resources will be retrievedpublic IResourceRetriever getRetriever()
public ResourceResolver setRetriever(IResourceRetriever retriever)
retriever - the resource retrieverResourceResolver instancepublic PdfXObject retrieveImage(String src)
PdfImageXObject, or PdfFormXObject.src - either link to file or base64 encoded streampublic byte[] retrieveBytesFromResource(String src)
String.src - either link to file or base64 encoded streampublic InputStream retrieveResourceAsInputStream(String src)
src - path to the resourcepublic static boolean isDataSrc(String src)
src - string to testpublic URL resolveAgainstBaseUri(String uri) throws MalformedURLException
uri - the uriMalformedURLException - the malformed URL exceptionpublic void resetCache()
protected PdfXObject tryResolveBase64ImageSource(String src)
protected PdfXObject tryResolveUrlImageSource(String uri)
protected PdfXObject createImageByUrl(URL url) throws Exception
url - location of the Image file.PdfXObject containing the Image loaded in.Exception - thrown if error occurred during fetching or constructing the image.Copyright © 1998–2024 Apryse Group NV. All rights reserved.