Class ResourceResolver
java.lang.Object
com.itextpdf.styledxmlparser.resolver.resource.ResourceResolver
Utilities class to resolve resources.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringIdentifier string used when loading in base64 images.static final StringIdentifier string used to detect that the source is under data URI scheme.private SimpleImageCacheTheSimpleImageCacheinstance.private static final org.slf4j.Loggerprivate IResourceRetrieverprivate UriResolverTheUriResolverinstance. -
Constructor Summary
ConstructorsConstructorDescriptionResourceResolver(String baseUri) Creates a newResourceResolverinstance.ResourceResolver(String baseUri, IResourceRetriever retriever) Creates a newResourceResolverinstance. -
Method Summary
Modifier and TypeMethodDescriptionprotected PdfXObjectcreateImageByUrl(URL url) Create a iText XObject based on the image stored at the passed location.Gets the base URI.Gets the resource retriever.private booleanisContains64Mark(String src) Checks if string contains base64 mark.static booleanChecks if source is under data URI scheme.voidResets the simple image cache.Resolves a given URI against the base URI.private byte[]byte[]Retrieve a resource as a byte array from a source that can either be a link to a file, or a base64 encodedString.retrieveImage(String src) Retrieve image as eitherPdfImageXObject, orPdfFormXObject.Retrieve the resource found in src as an InputStreamsetRetriever(IResourceRetriever retriever) Sets the resource retriever.protected PdfXObjectCreatesPdfXObjectbased on passed base64 encoded string.protected PdfXObjectCreatesPdfXObjectbased on the string which defines the path to local image.
-
Field Details
-
BASE64_IDENTIFIER
Identifier string used when loading in base64 images.- See Also:
-
DATA_SCHEMA_PREFIX
Identifier string used to detect that the source is under data URI scheme.- See Also:
-
logger
private static final org.slf4j.Logger logger -
uriResolver
TheUriResolverinstance. -
imageCache
TheSimpleImageCacheinstance. -
retriever
-
-
Constructor Details
-
ResourceResolver
Creates a newResourceResolverinstance. IfbaseUriis 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.
- Parameters:
baseUri- base URI against which all relative resource URIs will be resolved
-
ResourceResolver
Creates a newResourceResolverinstance. IfbaseUriis 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.
- Parameters:
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 retrieved
-
-
Method Details
-
getRetriever
Gets the resource retriever. The retriever is used to retrieve data from resources by URL.- Returns:
- the resource retriever
-
setRetriever
Sets the resource retriever. The retriever is used to retrieve data from resources by URL.- Parameters:
retriever- the resource retriever- Returns:
- the
ResourceResolverinstance
-
retrieveImage
Retrieve image as eitherPdfImageXObject, orPdfFormXObject.- Parameters:
src- either link to file or base64 encoded stream- Returns:
- PdfXObject on success, otherwise null
-
retrieveBytesFromResource
-
retrieveResourceAsInputStream
Retrieve the resource found in src as an InputStream- Parameters:
src- path to the resource- Returns:
- InputStream for the resource on success, otherwise null
-
isDataSrc
Checks if source is under data URI scheme. (eg data:[<media type>][;base64],<data>).- Parameters:
src- string to test- Returns:
- true if source is under data URI scheme
-
resolveAgainstBaseUri
Resolves a given URI against the base URI.- Parameters:
uri- the uri- Returns:
- the url
- Throws:
MalformedURLException- the malformed URL exception
-
getBaseUri
-
resetCache
public void resetCache()Resets the simple image cache. -
tryResolveBase64ImageSource
CreatesPdfXObjectbased on passed base64 encoded string.- Parameters:
src- the base64 encoded string- Returns:
- the
PdfXObjectbased on passed base64 encoded string ornull
-
tryResolveUrlImageSource
CreatesPdfXObjectbased on the string which defines the path to local image.- Parameters:
uri- the path to the local image- Returns:
- the
PdfXObjectbased on local image ornull
-
createImageByUrl
Create a iText XObject based on the image stored at the passed location.- Parameters:
url- location of the Image file.- Returns:
PdfXObjectcontaining the Image loaded in.- Throws:
Exception- thrown if error occurred during fetching or constructing the image.
-
retrieveBytesFromBase64Src
-
isContains64Mark
Checks if string contains base64 mark. It does not guarantee that src is a correct base64 data-string.- Parameters:
src- string to test- Returns:
- true if string contains base64 mark
-