Class ResourceResolver
java.lang.Object
com.itextpdf.styledxmlparser.resolver.resource.ResourceResolver
Utilities class to resolve resources.
-
Field Summary
-
Constructor Summary
ConstructorDescriptionResourceResolver
(String baseUri) Creates a newResourceResolver
instance.ResourceResolver
(String baseUri, IResourceRetriever retriever) Creates a newResourceResolver
instance. -
Method Summary
Modifier and TypeMethodDescriptionprotected PdfXObject
createImageByUrl
(URL url) Create a iText XObject based on the image stored at the passed location.Gets the resource retriever.static boolean
Checks if source is under data URI scheme.void
Resets the simple image cache.Resolves a given URI against the base URI.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 PdfXObject
protected PdfXObject
-
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:
-
-
Constructor Details
-
ResourceResolver
Creates a newResourceResolver
instance. IfbaseUri
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.
- Parameters:
-
baseUri
- base URI against which all relative resource URIs will be resolved
-
ResourceResolver
Creates a newResourceResolver
instance. IfbaseUri
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.
- Parameters:
-
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
-
-
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
ResourceResolver
instance
-
retrieveImage
Retrieve image as eitherPdfImageXObject
, orPdfFormXObject
.- Parameters:
-
src
- either link to file or base64 encoded stream - Returns:
- PdfXObject on success, otherwise null
-
retrieveBytesFromResource
Retrieve a resource as a byte array from a source that can either be a link to a file, or a base64 encodedString
.- Parameters:
-
src
- either link to file or base64 encoded stream - Returns:
- byte[] on success, otherwise null
-
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:[][;base64],). - 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
-
resetCache
public void resetCache()Resets the simple image cache. -
tryResolveBase64ImageSource
-
tryResolveUrlImageSource
-
createImageByUrl
Create a iText XObject based on the image stored at the passed location.- Parameters:
-
url
- location of the Image file. - Returns:
-
PdfXObject
containing the Image loaded in. - Throws:
-
Exception
- thrown if error occurred during fetching or constructing the image.
-