Class FileResource
java.lang.Object
se.idsec.signservice.integration.core.FileResource
- All Implemented Interfaces:
Serializable
A
FileResource
class is a generic class for handling file resources used in configuration of a SignService
Integration Service. Depending on how the service is configured a FileResource
can be set up in two different
ways:
- By giving the contents of the file resource (using
setContents(String)
). - By giving a file resource string pointing at the file resource (see
setResource(String)
). This is typically the way a SignService Integration Service wants to configure its resources.
- Author:
- Martin Lindström (martin@idsec.se), Stefan Santesson (stefan@idsec.se)
- See Also:
-
Nested Class Summary
-
Constructor Summary
ConstructorDescriptionDefault constructor.FileResource
(String contents, String description, String resource, boolean eagerlyLoadContents) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Checks that the file resource is correctly initialized, and ifeagerlyLoadContents
istrue
it also loads the contents (if necessary).builder()
Gets the contents of the file resource as a base64 encoded string.Gets the description of the file resource.If theFileResource
object was initialized with aresource
string this method returns this string.void
setContents
(byte[] contents) Assigns the raw file resource contents.void
setContents
(String contents) Assigns the file resource contents as a base64 encoded string.void
setDescription
(String description) Assigns the description of the file resource.void
setEagerlyLoadContents
(boolean eagerlyLoadContents) If theFileResource
object is initialized by a resource string the object can function in two modes; it either loads the contents directly when the object is created usingafterPropertiesSet()
(eagerlyLoadContents = true
), or it loads the contents every time it is asked for (eagerlyLoadContents = false
).void
setResource
(String resource) Assigns a resource string.toString()
-
Constructor Details
-
FileResource
public FileResource()Default constructor. -
FileResource
public FileResource(String contents, String description, String resource, boolean eagerlyLoadContents) Constructor.- Parameters:
contents
- the base64 encoded contents of the file resourcedescription
- optional descriptive string for the file resourceresource
- the resource string for the file/resourceeagerlyLoadContents
- whether to load contents directly (seesetEagerlyLoadContents(boolean)
)
-
-
Method Details
-
getContents
Gets the contents of the file resource as a base64 encoded string.- Returns:
- the file resource content as a base64 encoded string or null if no content is available
-
setContents
Assigns the file resource contents as a base64 encoded string.- Parameters:
contents
- the base64 encoded contents of the file resource
-
setContents
public void setContents(byte[] contents) Assigns the raw file resource contents.- Parameters:
contents
- the raw file resource contents
-
getDescription
Gets the description of the file resource.- Returns:
- the description of the file resource or null if none is available
-
setDescription
Assigns the description of the file resource.- Parameters:
description
- the description of the file resource
-
getResource
If theFileResource
object was initialized with aresource
string this method returns this string.- Returns:
- the file resource string or null if none is set
-
setResource
Assigns a resource string.Note: The Spring Framework style of representing a resource should be used. For example:
classpath:xyz.svg
andfile:/path/xyz.svg
.- Parameters:
resource
- the resource string
-
setEagerlyLoadContents
public void setEagerlyLoadContents(boolean eagerlyLoadContents) If theFileResource
object is initialized by a resource string the object can function in two modes; it either loads the contents directly when the object is created usingafterPropertiesSet()
(eagerlyLoadContents = true
), or it loads the contents every time it is asked for (eagerlyLoadContents = false
). The latter is the default and should be used if large documents that are assigned to several configuration objects are handled. This will prevent a heavy memory usage at the cost of speed in fetching the document contents.- Parameters:
eagerlyLoadContents
- whether to load contents eagerly or not
-
afterPropertiesSet
Checks that the file resource is correctly initialized, and ifeagerlyLoadContents
istrue
it also loads the contents (if necessary).Note: If executing in a Spring Framework environment this method is automatically invoked after all properties have been assigned. Otherwise it should be explicitly invoked.
- Throws:
Exception
- for init errors
-
toString
-
builder
-