public class ResourceResolver extends Object
| Modifier and Type | Field and Description |
|---|---|
static String |
BASE64IDENTIFIER
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.
|
boolean |
isDataSrc(String src)
Checks if source is under data URI scheme.
|
boolean |
isImageTypeSupportedByImageDataFactory(String src)
Deprecated.
there is no need to perform laborious type checking because any resource extraction is wrapped in an try-catch block
|
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. |
PdfImageXObject |
retrieveImage(String src)
Deprecated.
will return
in pdfHTML 3.0.0 |
PdfXObject |
retrieveImageExtended(String src)
Retrieve image as either
PdfImageXObject, or PdfFormXObject. |
InputStream |
retrieveResourceAsInputStream(String src)
Retrieve the resource found in src as an InputStream
|
byte[] |
retrieveStream(String src)
Deprecated.
use
retrieveBytesFromResource(String) instead |
InputStream |
retrieveStyleSheet(String uri)
Deprecated.
use
retrieveResourceAsInputStream(String) instead |
ResourceResolver |
setRetriever(IResourceRetriever retriever)
Sets the resource retriever.
|
protected PdfXObject |
tryResolveBase64ImageSource(String src) |
protected PdfXObject |
tryResolveUrlImageSource(String uri) |
public static final String BASE64IDENTIFIER
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 instance@Deprecated public PdfImageXObject retrieveImage(String src)
in pdfHTML 3.0.0PdfImageXObject.src - either link to file or base64 encoded streampublic PdfXObject retrieveImageExtended(String src)
PdfImageXObject, or PdfFormXObject.src - either link to file or base64 encoded stream@Deprecated public InputStream retrieveStyleSheet(String uri) throws IOException
retrieveResourceAsInputStream(String) insteadInputStream to a style sheet URI.uri - the URIInputStreamIOException - Signals that an I/O exception has occurred@Deprecated public byte[] retrieveStream(String src)
retrieveBytesFromResource(String) instead
Retrieve a resource as a byte array from a source that
can either be a link to a file, or a base64 encoded String.
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 boolean isDataSrc(String src)
src - string to testpublic URL resolveAgainstBaseUri(String uri) throws MalformedURLException
uri - the uriMalformedURLException - the malformed URL exceptionpublic void resetCache()
@Deprecated public boolean isImageTypeSupportedByImageDataFactory(String src)
ImageDataFactory.src - location of the image resourceprotected PdfXObject tryResolveBase64ImageSource(String src)
protected PdfXObject tryResolveUrlImageSource(String uri)
protected PdfXObject createImageByUrl(URL url) throws Exception
url - location of the Image filePdfXObject containing the Image loaded inException - thrown if error occurred during fetching or constructing the imageCopyright © 1998–2020 iText Group NV. All rights reserved.