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 |
BASE64IDENTIFIER
Deprecated.
This variable will be replaced by
BASE64_IDENTIFIER in 7.2 release
|
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 BASE64_IDENTIFIER
@Deprecated public static final String BASE64IDENTIFIER
BASE64_IDENTIFIER
in 7.2 release
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 resolved
public 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 resolved
retriever
- the resource retriever with the help of which data from resources will be retrieved
public IResourceRetriever getRetriever()
public ResourceResolver setRetriever(IResourceRetriever retriever)
retriever
- the resource retriever
ResourceResolver
instance
@Deprecated public PdfImageXObject retrieveImage(String src)
in pdfHTML 3.0.0
PdfImageXObject
.
src
- either link to file or base64 encoded stream
public 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)
instead
InputStream
to a style sheet URI.
uri
- the URI
InputStream
IOException
- 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 stream
public byte[] retrieveBytesFromResource(String src)
String
.
src
- either link to file or base64 encoded stream
public InputStream retrieveResourceAsInputStream(String src)
src
- path to the resource
public boolean isDataSrc(String src)
src
- string to test
public URL resolveAgainstBaseUri(String uri) throws MalformedURLException
uri
- the uri
MalformedURLException
- the malformed URL exception
public void resetCache()
@Deprecated public boolean isImageTypeSupportedByImageDataFactory(String src)
ImageDataFactory
.
src
- location of the image resource
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–2023 iText Group NV. All rights reserved.