Package eu.europa.esig.dss.tsl.sha2
Class Sha2FileCacheDataLoader
java.lang.Object
eu.europa.esig.dss.tsl.sha2.Sha2FileCacheDataLoader
- All Implemented Interfaces:
DSSCacheFileLoader
,DSSFileLoader
,Serializable
This class implements a document loading logic, defined within ETSI TS 119 612 "6.1 TL publication"
for Trusted Lists.
The class will try to access a corresponding .sha2 file for every requested document available in the cache,
compare its digest, and will enforce a document update if the document has expired.
The class provides constructors allowing manual configuration of the object, as well as static methods
allowing to instantiate pre-configured objects for Trusted Lists validation. See:
-
#initSha2StrictDataLoader
method to create a dataloader, enforcing refresh of a Trusted List
only when a new .sha2 document is obtained or NextUpdate has been reached;
- #initSha2DailyUpdateDataLoader
method to create a dataloader, enforcing refresh of a Trusted List
when a new .sha2 document is obtained, NextUpdate has been reached or when the document
has not been updated for at least 24 hours;
- #initSha2CustomExpirationDataLoader
method to create a dataloader, enforcing refresh of a Trusted List
when a new .sha2 document is obtained, NextUpdate has been reached or when the document
has not been updated for the indicated time period;
- #initSha2IgnoredDataLoader
method to create a dataloader, enforcing refresh of a Trusted List
in all cases.- See Also:
-
Constructor Summary
ConstructorDescriptionCreates an object with an empty configuration (shall be provided with a setter)Sha2FileCacheDataLoader
(DSSCacheFileLoader dataLoader) Creates an object with a definedDSSCacheFileLoader
. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
This method verifies whether the configuration of the class is complete to proceed with executionprotected void
assertExtensionIsSupported
(String fileExtension) This method verifies whether the remote document'sfileExtension
is supported by the implementation.protected boolean
checkRefreshRequired
(DocumentWithSha2 documentWithSha2) This method checks whether the cached document should be refreshedReturns the file cache data loader used to load the documentsgetDocument
(String url) Returns DSSDocument from the provided urlgetDocument
(String url, boolean refresh) This method allows to download aDSSDocument
from a specifiedurl
with a custom setting indicating whether therefresh
of the document's cache shall be enforced, when applicableAllows to load a document for a given url from the cache folder.protected DSSDocument
getRefreshedDocument
(String documentUrl) This method returns a document from cache, when applicable.protected DSSDocument
getSha2File
(String documentUrl) This method returns a sha2 file for the givendocumentUrl
.protected String
getSha2FileUrl
(String documentUrl) Method transforms a givendocumentUrl
to a corresponding URL location containing a sha2 documentstatic Sha2FileCacheDataLoader
initSha2CustomExpirationDataLoader
(DSSCacheFileLoader dataLoader, long cacheExpirationTime) This method instantiates a Sha2FileCacheDataLoader with a pre-configured predicate, forcing a Trusted List refresh in case of an updated .sha2 document, when a NextUpdate has been reached, or when the cached document expired according to the providedcacheExpirationTime
value.static Sha2FileCacheDataLoader
initSha2DailyUpdateDataLoader
(DSSCacheFileLoader dataLoader) This method instantiates a Sha2FileCacheDataLoader with a pre-configured predicate, forcing a Trusted List refresh in case of an updated .sha2 document, when a NextUpdate has been reached, or when the document has not been re-downloaded for at least a day.static Sha2FileCacheDataLoader
initSha2IgnoredDataLoader
(DSSCacheFileLoader dataLoader) This method instantiates a Sha2FileCacheDataLoader with a pre-configured predicate, forcing a Trusted List refresh in all cases despite the .sha2 file document content.static Sha2FileCacheDataLoader
initSha2StrictDataLoader
(DSSCacheFileLoader dataLoader) This method instantiates a Sha2FileCacheDataLoader with a pre-configured predicate, forcing a Trusted List refresh in case of an updated .sha2 document, or when a NextUpdate has been reached.protected DocumentWithSha2
mergeDocumentWithSha2
(DSSDocument cachedDocument, DSSDocument sha2Document) This class creates aeu.europa.esig.dss.tsl.sha2.DocumentWithSha2
object by merging acachedDocument
andsha2Document
togetherboolean
Removes the file from cache with the given urlvoid
setDataLoader
(DSSCacheFileLoader dataLoader) Sets the file cache data loader to be used to load the documentsvoid
setPredicate
(Predicate<DocumentWithSha2> predicate) This method sets a predicate evaluating a condition for a document to be refreshed.
-
Constructor Details
-
Sha2FileCacheDataLoader
public Sha2FileCacheDataLoader()Creates an object with an empty configuration (shall be provided with a setter) -
Sha2FileCacheDataLoader
Creates an object with a definedDSSCacheFileLoader
. Thepredicate
shall be provided with a setter.- Parameters:
dataLoader
-DSSCacheFileLoader
to use
-
-
Method Details
-
initSha2StrictDataLoader
This method instantiates a Sha2FileCacheDataLoader with a pre-configured predicate, forcing a Trusted List refresh in case of an updated .sha2 document, or when a NextUpdate has been reached. The created object does not enforce refresh after a specific time period.- Parameters:
dataLoader
-DSSCacheFileLoader
to be used to load the document- Returns:
Sha2FileCacheDataLoader
-
initSha2DailyUpdateDataLoader
This method instantiates a Sha2FileCacheDataLoader with a pre-configured predicate, forcing a Trusted List refresh in case of an updated .sha2 document, when a NextUpdate has been reached, or when the document has not been re-downloaded for at least a day.- Parameters:
dataLoader
-DSSCacheFileLoader
to be used to load the document- Returns:
Sha2FileCacheDataLoader
-
initSha2CustomExpirationDataLoader
public static Sha2FileCacheDataLoader initSha2CustomExpirationDataLoader(DSSCacheFileLoader dataLoader, long cacheExpirationTime) This method instantiates a Sha2FileCacheDataLoader with a pre-configured predicate, forcing a Trusted List refresh in case of an updated .sha2 document, when a NextUpdate has been reached, or when the cached document expired according to the providedcacheExpirationTime
value.- Parameters:
dataLoader
-DSSCacheFileLoader
to be used to load the documentcacheExpirationTime
- value in milliseconds indicating a maximum time after which a document shall be re-downloaded- Returns:
Sha2FileCacheDataLoader
-
initSha2IgnoredDataLoader
This method instantiates a Sha2FileCacheDataLoader with a pre-configured predicate, forcing a Trusted List refresh in all cases despite the .sha2 file document content.- Parameters:
dataLoader
-DSSCacheFileLoader
to be used to load the document- Returns:
Sha2FileCacheDataLoader
-
getDataLoader
Returns the file cache data loader used to load the documents- Returns:
DSSCacheFileLoader
-
setDataLoader
Sets the file cache data loader to be used to load the documents- Parameters:
dataLoader
-DSSCacheFileLoader
-
setPredicate
This method sets a predicate evaluating a condition for a document to be refreshed. The predicate returns TRUE when the condition is valid and no document refresh is required, FALSE otherwise- Parameters:
predicate
-Predicate
-
getDocument
Description copied from interface:DSSFileLoader
Returns DSSDocument from the provided url- Specified by:
getDocument
in interfaceDSSFileLoader
- Parameters:
url
-String
url of the document to obtain- Returns:
DSSDocument
retrieved document- Throws:
DSSException
- in case of DataLoader error
-
getDocument
Description copied from interface:DSSCacheFileLoader
This method allows to download aDSSDocument
from a specifiedurl
with a custom setting indicating whether therefresh
of the document's cache shall be enforced, when applicable- Specified by:
getDocument
in interfaceDSSCacheFileLoader
- Parameters:
url
-String
remote location of the document to downloadrefresh
- indicates whether the refresh of the cached document shall be enforced- Returns:
DSSDocument
-
getRefreshedDocument
This method returns a document from cache, when applicable. If no document is available in the cache, returns NULL.- Parameters:
documentUrl
-String
representing document's access point- Returns:
DSSDocument
-
getSha2File
This method returns a sha2 file for the givendocumentUrl
. If not sha2 document found, returns NULL.- Parameters:
documentUrl
-String
URL of the document, for which to retrieve a sha2 file- Returns:
DSSDocument
representing a sha2 file
-
getSha2FileUrl
-
assertExtensionIsSupported
-
mergeDocumentWithSha2
protected DocumentWithSha2 mergeDocumentWithSha2(DSSDocument cachedDocument, DSSDocument sha2Document) This class creates aeu.europa.esig.dss.tsl.sha2.DocumentWithSha2
object by merging acachedDocument
andsha2Document
together- Parameters:
cachedDocument
-DSSDocument
representing an original cached documentsha2Document
-DSSDocument
representing a sha2 document- Returns:
DocumentWithSha2
-
checkRefreshRequired
This method checks whether the cached document should be refreshed- Parameters:
documentWithSha2
-DocumentWithSha2
representing the original document with sha2 file content- Returns:
- TRUE if the document shall be refreshed, FALSE otherwise
-
getDocumentFromCache
Description copied from interface:DSSCacheFileLoader
Allows to load a document for a given url from the cache folder. If the document is not found in the cache, returns NULL.- Specified by:
getDocumentFromCache
in interfaceDSSCacheFileLoader
- Parameters:
url
-String
url of the file- Returns:
DSSDocument
or NULL if the file does not exist
-
remove
Description copied from interface:DSSCacheFileLoader
Removes the file from cache with the given url- Specified by:
remove
in interfaceDSSCacheFileLoader
- Specified by:
remove
in interfaceDSSFileLoader
- Parameters:
url
-String
url of the remote file location (the same what was used on file saving)- Returns:
- TRUE when file was successfully deleted, FALSE otherwise
-
assertConfigurationIsValid
protected void assertConfigurationIsValid()This method verifies whether the configuration of the class is complete to proceed with execution
-