Class Base64Resource


  • public class Base64Resource
    extends Resource
    Child class of Resource. A class representing a resource (file) with base64-encoded data for the Cloud Office Print server.
    • Constructor Summary

      Constructors 
      Constructor Description
      Base64Resource()
      Constructor for creating an uninitialised object of this class.
      Base64Resource​(java.lang.String filetype, java.lang.String database64)
      Constructor for creating an object of this class where the database64 can be supplied as a string.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.String getFileBase64()  
      com.google.gson.JsonObject getJSONForSecondaryFile()
      Needs to be used to get the JSON of a resource for a secondary file (file to prepend, to append, to insert or subtemplate), because their JSON has a different format then for a template.
      com.google.gson.JsonObject getJSONForTemplate()
      Needs to be called to get the JSON of a resource for a template.
      void setFileBase64​(java.lang.String fileBase64)
      Sets the data of the resource to the given parameter.
      void setFileFromLocalFile​(java.lang.String filePath)
      Sets the filetype of this resource to the extension of the file, sets the mimetype as well.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Base64Resource

        public Base64Resource()
        Constructor for creating an uninitialised object of this class. Needs to be populated with setFileFromLocalFile.
      • Base64Resource

        public Base64Resource​(java.lang.String filetype,
                              java.lang.String database64)
                       throws java.lang.Exception
        Constructor for creating an object of this class where the database64 can be supplied as a string.
        Parameters:
        filetype - Type (extension) of the resource e.g. : docx (not docx. !).
        database64 - Data of the resource base64 encoded.
        Throws:
        java.lang.Exception - If the mimetype is not found.
    • Method Detail

      • getFileBase64

        public java.lang.String getFileBase64()
        Returns:
        a string of the resource base64 encoded.
      • setFileBase64

        public void setFileBase64​(java.lang.String fileBase64)
        Sets the data of the resource to the given parameter.
        Parameters:
        fileBase64 - base64 encoded version of the file.
      • getJSONForTemplate

        public com.google.gson.JsonObject getJSONForTemplate()
        Description copied from class: Resource
        Needs to be called to get the JSON of a resource for a template.
        Specified by:
        getJSONForTemplate in class Resource
        Returns:
        JSONObject with the tags for a base64 resource as template for the Cloud Office Print server ("file","template_type").
      • getJSONForSecondaryFile

        public com.google.gson.JsonObject getJSONForSecondaryFile()
        Description copied from class: Resource
        Needs to be used to get the JSON of a resource for a secondary file (file to prepend, to append, to insert or subtemplate), because their JSON has a different format then for a template.
        Specified by:
        getJSONForSecondaryFile in class Resource
        Returns:
        JSONObject with the tags ("mime_type","file_content","file_source") for a base 64 resource as a secondary file (subtemplates, files to prepend, files to append and files to insert) for the Cloud Office Print server.
      • setFileFromLocalFile

        public void setFileFromLocalFile​(java.lang.String filePath)
                                  throws java.lang.Exception
        Sets the filetype of this resource to the extension of the file, sets the mimetype as well. Reads all bytes of the file, coverts them to base64 and stores them in this.fileBase64.
        Parameters:
        filePath - Path of the local file.
        Throws:
        java.io.IOException - If file not found.
        java.lang.Exception - If the extension of the file is not found.