Class FileResource

java.lang.Object
se.idsec.signservice.integration.core.FileResource
All Implemented Interfaces:
Serializable

public class FileResource extends Object implements 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:
  • 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 resource
      description - optional descriptive string for the file resource
      resource - the resource string for the file/resource
      eagerlyLoadContents - whether to load contents directly (see setEagerlyLoadContents(boolean))
  • Method Details

    • getContents

      public String 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

      public void setContents(String contents)
      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

      public String getDescription()
      Gets the description of the file resource.
      Returns:
      the description of the file resource or null if none is available
    • setDescription

      public void setDescription(String description)
      Assigns the description of the file resource.
      Parameters:
      description - the description of the file resource
    • getResource

      public String getResource()
      If the FileResource object was initialized with a resource string this method returns this string.
      Returns:
      the file resource string or null if none is set
    • setResource

      public void setResource(String resource)
      Assigns a resource string.

      Note: The Spring Framework style of representing a resource should be used. For example: classpath:xyz.svg and file:/path/xyz.svg.

      Parameters:
      resource - the resource string
    • setEagerlyLoadContents

      public void setEagerlyLoadContents(boolean eagerlyLoadContents)
      If the FileResource 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 using afterPropertiesSet() (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

      @PostConstruct public void afterPropertiesSet() throws Exception
      Checks that the file resource is correctly initialized, and if eagerlyLoadContents is true 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

      public String toString()
      Overrides:
      toString in class Object
    • builder

      public static FileResource.FileResourceBuilder builder()