Class DocumentDB

  • All Implemented Interfaces:
    java.io.Serializable

    public class DocumentDB
    extends java.lang.Object
    implements java.io.Serializable

    Document instance

    See Also:
    Serialized Form
    • Constructor Summary

      Constructors 
      Constructor Description
      DocumentDB​(java.lang.String docId, java.lang.String path, byte[] b, java.lang.String objName, java.lang.String fieldName, java.lang.String rowId)
      Simplified constructor (used to retrieve an existing document or create a new document and create or update it)
      DocumentDB​(java.lang.String docId, java.lang.String path, java.io.File tmpFile, java.lang.String objName, java.lang.String fieldName, java.lang.String rowId)
      Simplified constructor (used to create a new document)
      DocumentDB​(java.lang.String docId, java.lang.String path, java.io.InputStream stream, java.lang.String objName, java.lang.String fieldName, java.lang.String rowId)
      Simplified constructor (used to create a new document)
      DocumentDB​(java.lang.String name, java.lang.String rpath, java.lang.String mime, long size, int vers)
      Simplified constructor
      DocumentDB​(java.lang.String name, java.lang.String rpath, java.lang.String mime, long size, int vers, java.lang.String index, java.lang.String respId, java.lang.String respLogin, java.util.Map<java.lang.String,​java.lang.String> groups, java.util.Map<java.lang.String,​java.lang.String> fields, boolean ondemand, java.lang.String objName, java.lang.String fldName, java.lang.String rowId, java.lang.String lastupd)
      Indexed document constructor
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      static void addAccess​(Grant g, java.lang.String docId)
      Add a read access to the document in user's session (param _SESSION_DOC_ACCESS_)
      static boolean checkAccess​(Grant g, java.lang.String docId)
      Check a read access to the document in user's session (param _SESSION_DOC_ACCESS_)
      void copyTo​(java.lang.String path)
      Copy document to specified path
      void copyToDir​(java.lang.String path)
      Deprecated.
      Use copyTo
      static void copyToRecycleBin​(DocumentDB doc)
      Copy to recycle bin
      java.util.List<java.lang.String> getAccessGroup()
      Get bookshelf groups
      java.lang.String getBookshelfName()
      Get bookshelf name
      byte[] getBytes()
      Get binary content (current content, not forced to read from file)
      byte[] getBytes​(boolean read)
      Get binary content
      java.lang.String getContentType()
      Get content type (from MIME type)
      static java.lang.String getContentType​(java.lang.String path)
      Get content type from MIME type for file name
      java.lang.String getDataURL​(boolean thumbnail)
      Get data URL
      static DocumentDB getDocument​(java.lang.String docId, Grant grant)
      Retrieve document data from ID: dbdoc path, name, size, mime-type, version, etc.
      static java.lang.String getDocumentId​(Grant g, java.lang.String object, java.lang.String field, java.lang.String rowId)
      Get document ID that matches specified object name, field name and row ID
      static java.lang.String getDocumentId​(ObjectDB obj, java.lang.String field, java.lang.String rowId)
      Get document ID that matches specified object field name and row ID
      static java.lang.String getDocumentIdFromCondition​(java.lang.String condition)
      Get first document ID that matches specified SQL condition
      static java.lang.String getDocumentIdFromName​(java.lang.String name)
      Get first document ID that matches specified name
      static java.lang.String getDocumentIdFromPath​(java.lang.String path)
      Get first document ID that matches specified path
      java.lang.String getError()
      Get error
      java.lang.String getExtension()
      Get document extension from name or path
      java.lang.String getFieldRef()
      Get field name associated to the document
      java.util.Map<java.lang.String,​java.lang.String> getFields()
      Get indexed fields
      java.io.File getFile()
      Get the document as a local file
      java.lang.String getId()
      Get document ID
      java.io.InputStream getInputStream()
      Get content as input stream
      java.lang.String getLastUpdated()
      Get last updated date time
      java.lang.String getMIME()
      Get MIME type
      static java.lang.String getMIME​(java.lang.String path)
      Get MIME type
      java.lang.String getName()
      Get file name
      java.lang.String getObjectRef()
      Get object name associated to the document
      java.lang.String getPath()
      Get path (= document unique key in document table)
      java.lang.String getRelativePath()
      Deprecated.
      Use getPath instead
      java.lang.String getRespId()
      Get document owner
      java.lang.String getRespLogin()
      get user login managing the document requests
      java.lang.String getRowIdRef()
      Get object record row ID associated to the document
      long getSize()
      Get file size (bytes)
      java.lang.String getTextTypeFromExtension()
      Get editor/preview type from extension
      byte[] getThumbnailBytes​(boolean read)
      Get thumbnail binary content (only relevant for images with thumbnail)
      java.io.File getThumbnailFile()
      Get thumbnail file with absolute path (only relevant for images with thumbnail)
      java.io.InputStream getThumbnailInputStream()
      Get thumbnail content as input stream (only relevant for images with thumbnail)
      java.lang.String getThumbnailPath()
      Get thumbnail image path (only relevant for images with thumbnail)
      java.lang.String getThumbnailURL​(java.lang.String cdisp)
      Get image document thumbnail URL (only relevant for images with thumbnail)
      java.io.File getUploadFile()
      Get temporary file to upload file without bytes in memory
      java.io.InputStream getUploadStream()
      Get input stream to upload file without bytes in memory
      java.lang.String getURL​(java.lang.String cdisp)
      Get document URL (only relevant for generic web UI)
      int getVersion()
      Version (automatically increased when saving)
      java.lang.String inline()
      Convert the document to a String (XML usage).
      static java.lang.String inline​(DocumentDB d)
      Convert a document to a inlined document string (XML usage).
      boolean isEmpty()
      Is document empty ?
      boolean isGroupGrant​(java.lang.String group, char grt)
      Is the group granted ?
      boolean isImage()
      Is an image?
      static boolean isImage​(java.lang.String mime)
      Is an image?
      boolean isOnDemand()
      Is request allowed ?
      boolean isZIP()
      Is a ZIP file?
      static boolean isZIP​(java.lang.String mime)
      Is a ZIP file?
      static java.lang.Object[] parse​(java.lang.String doc)
      Parse a document (from XML import)
      static byte[] read​(java.lang.String path)
      Read a document content
      static void removeAccess​(Grant g, java.lang.String docId)
      Remove a read access to the document in user's session (param _SESSION_DOC_ACCESS_)
      static byte[] select​(java.lang.String docId)
      Read a document content from the ID
      void setBytes​(byte[] b)
      Set binary content
      ZZZ will use lot of memory, try to use setTmpStream ZZZ
      void setBytes​(byte[] b, boolean append)
      Set binary content
      ZZZ will use lot of memory, try to use setTmpStream ZZZ
      void setError​(java.lang.String error)
      Set error
      void setFieldRef​(java.lang.String field)
      Set field name associated to the document
      void setId​(java.lang.String id)
      Set document ID
      void setMIME​(java.lang.String mime)
      Set MIME type
      void setName​(java.lang.String name)
      Set file name
      void setObjectRef​(java.lang.String object)
      Set object name associated to the document
      void setPath​(java.lang.String path)
      Set path (= document unique key in document table)
      void setRowIdRef​(java.lang.String rowId)
      Set object record row ID associated to the document
      void setSize​(long size)
      Set file size (bytes)
      void setUploadFile​(java.io.File file)
      Set temporary file to upload file without bytes in memory
      void setUploadStream​(java.io.InputStream in)
      Set input stream to upload file without bytes in memory
      static java.lang.String toBase64​(java.lang.String docId)
      Read a document content into a Base64 encoded String
      static java.lang.String toBase64​(java.lang.String docId, Grant g)
      Deprecated. 
      org.json.JSONObject toJSONObject()
      Generates a JSON object representation of the business object
      java.lang.String toString()
      Generates a string representation of the business object
      static java.lang.String toString​(java.lang.String docId)
      Read a document content into a plain String.
      static void write​(java.lang.String path, byte[] data)
      Deprecated.
      Use DocTool.writeFile
      static void write​(java.lang.String docId, Grant grant, byte[] data)
      Deprecated.
      Use DocTool.writeFile
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • DEFAULT_DOCUMENT_VERSION

        public static final int DEFAULT_DOCUMENT_VERSION
        Default document version
        See Also:
        Constant Field Values
      • SESSION_DOC_ACCESS

        public static final java.lang.String SESSION_DOC_ACCESS
        Session doc access
        See Also:
        Constant Field Values
    • Constructor Detail

      • DocumentDB

        public DocumentDB​(java.lang.String name,
                          java.lang.String rpath,
                          java.lang.String mime,
                          long size,
                          int vers,
                          java.lang.String index,
                          java.lang.String respId,
                          java.lang.String respLogin,
                          java.util.Map<java.lang.String,​java.lang.String> groups,
                          java.util.Map<java.lang.String,​java.lang.String> fields,
                          boolean ondemand,
                          java.lang.String objName,
                          java.lang.String fldName,
                          java.lang.String rowId,
                          java.lang.String lastupd)
        Indexed document constructor
        Parameters:
        name - Name
        rpath - Relative Path
        mime - Mime Type
        size - Size
        vers - Version
        index - Index
        respId - respId
        respLogin - respLogin
        groups - Groups
        fields - Fields
        ondemand - On demand ?
        objName - Object Name
        fldName - Field Name
        rowId - Row Id
        lastupd - Last Update
      • DocumentDB

        public DocumentDB​(java.lang.String name,
                          java.lang.String rpath,
                          java.lang.String mime,
                          long size,
                          int vers)
        Simplified constructor
        Parameters:
        name - Name
        rpath - Relative path
        mime - Mime Type
        size - Size
        vers - Version
      • DocumentDB

        public DocumentDB​(java.lang.String docId,
                          java.lang.String path,
                          byte[] b,
                          java.lang.String objName,
                          java.lang.String fieldName,
                          java.lang.String rowId)
        Simplified constructor (used to retrieve an existing document or create a new document and create or update it)
        Parameters:
        docId - Document ID or null (or ObjectField.DEFAULT_ROW_ID) for a new document
        path - File relative path or file name (used to determine MIME type and size)
        b - Bytes
        objName - Object name
        fieldName - Object field name
        rowId - Object row ID (can be null or ObjectField.DEFAULT_ROW_ID at creation of object)
      • DocumentDB

        public DocumentDB​(java.lang.String docId,
                          java.lang.String path,
                          java.io.File tmpFile,
                          java.lang.String objName,
                          java.lang.String fieldName,
                          java.lang.String rowId)
        Simplified constructor (used to create a new document)
        Parameters:
        docId - Document ID or null (or ObjectField.DEFAULT_ROW_ID) for a new document
        path - File relative path or file name
        tmpFile - Temporary source file
        objName - Object name
        fieldName - Object field name
        rowId - Object row ID (can be null or ObjectField.DEFAULT_ROW_ID at creation of object)
      • DocumentDB

        public DocumentDB​(java.lang.String docId,
                          java.lang.String path,
                          java.io.InputStream stream,
                          java.lang.String objName,
                          java.lang.String fieldName,
                          java.lang.String rowId)
        Simplified constructor (used to create a new document)
        Parameters:
        docId - Document ID or null (or ObjectField.DEFAULT_ROW_ID) for a new document
        path - File relative path or file name
        stream - source stream
        objName - Object name
        fieldName - Object field name
        rowId - Object row ID (can be null or ObjectField.DEFAULT_ROW_ID at creation of object)
    • Method Detail

      • getId

        public java.lang.String getId()
        Get document ID
        Returns:
        document Id
      • setId

        public void setId​(java.lang.String id)
        Set document ID
        Parameters:
        id - document Id
      • getName

        public java.lang.String getName()
        Get file name
        Returns:
        file name
      • setName

        public void setName​(java.lang.String name)
        Set file name
        Parameters:
        name - file name
      • getRelativePath

        @Deprecated
        public final java.lang.String getRelativePath()
        Deprecated.
        Use getPath instead
      • getPath

        public java.lang.String getPath()
        Get path (= document unique key in document table)
        Returns:
        Path
      • setPath

        public void setPath​(java.lang.String path)
        Set path (= document unique key in document table)
        Parameters:
        path - Path
      • getError

        public java.lang.String getError()
        Get error
        Returns:
        Error
      • setError

        public void setError​(java.lang.String error)
        Set error
        Parameters:
        error - Error
      • getExtension

        public java.lang.String getExtension()
        Get document extension from name or path
        Returns:
        extension
      • getTextTypeFromExtension

        public java.lang.String getTextTypeFromExtension()
        Get editor/preview type from extension
        Returns:
        Editor/preview type from extension
      • getFile

        public java.io.File getFile()
        Get the document as a local file
        Returns:
        Get the document as a local file
      • getInputStream

        public java.io.InputStream getInputStream()
                                           throws java.io.IOException
        Get content as input stream
        Returns:
        Get content as input stream
        Throws:
        java.io.IOException
      • getBytes

        public byte[] getBytes()
        Get binary content (current content, not forced to read from file)
        Returns:
        Get binary content
      • getBytes

        public byte[] getBytes​(boolean read)
                        throws java.io.IOException
        Get binary content
        Parameters:
        read - Force read bytes from file ?
        Returns:
        Get binary content
        Throws:
        java.io.IOException
      • isEmpty

        public boolean isEmpty()
        Is document empty ?
        Returns:
        True when bytes are unset or empty
      • setBytes

        public void setBytes​(byte[] b)
        Set binary content
        ZZZ will use lot of memory, try to use setTmpStream ZZZ
        Parameters:
        b - Binary content
      • setBytes

        public void setBytes​(byte[] b,
                             boolean append)
        Set binary content
        ZZZ will use lot of memory, try to use setTmpStream ZZZ
        Parameters:
        b - binary content
        append - Append?
      • getUploadFile

        public java.io.File getUploadFile()
        Get temporary file to upload file without bytes in memory
        Returns:
        Temporary upload file
      • setUploadFile

        public void setUploadFile​(java.io.File file)
        Set temporary file to upload file without bytes in memory
        Parameters:
        file - Temporary upload file
      • getUploadStream

        public java.io.InputStream getUploadStream()
        Get input stream to upload file without bytes in memory
        Returns:
        Input stream to upload file
      • setUploadStream

        public void setUploadStream​(java.io.InputStream in)
        Set input stream to upload file without bytes in memory
        Parameters:
        in - Input stream to upload file
      • getURL

        public java.lang.String getURL​(java.lang.String cdisp)
        Get document URL (only relevant for generic web UI)
        Parameters:
        cdisp - Current disposition
        Returns:
        document URL
      • getThumbnailPath

        public java.lang.String getThumbnailPath()
        Get thumbnail image path (only relevant for images with thumbnail)
        Returns:
        thumbnail image path
      • getThumbnailFile

        public java.io.File getThumbnailFile()
        Get thumbnail file with absolute path (only relevant for images with thumbnail)
        Returns:
        thumbnail file
      • getThumbnailBytes

        public byte[] getThumbnailBytes​(boolean read)
                                 throws java.io.IOException
        Get thumbnail binary content (only relevant for images with thumbnail)
        Parameters:
        read - Force read bytes from file ?
        Returns:
        thumbnail binary content
        Throws:
        java.io.IOException
      • getThumbnailInputStream

        public java.io.InputStream getThumbnailInputStream()
                                                    throws java.io.IOException
        Get thumbnail content as input stream (only relevant for images with thumbnail)
        Returns:
        Thumbnail content as input stream
        Throws:
        java.io.IOException
      • getThumbnailURL

        public java.lang.String getThumbnailURL​(java.lang.String cdisp)
        Get image document thumbnail URL (only relevant for images with thumbnail)
        Parameters:
        cdisp - Disposition
        Returns:
        User picture thumbnail URL
      • getDataURL

        public java.lang.String getDataURL​(boolean thumbnail)
        Get data URL
        Parameters:
        thumbnail - Thumbnail or document content (true is only relevant for images with thumbnail)?
        Returns:
        Data URL for document or null if there was an exception reading thubnail or document content
      • getMIME

        public java.lang.String getMIME()
        Get MIME type
        Returns:
        MIME type
      • setMIME

        public void setMIME​(java.lang.String mime)
        Set MIME type
        Parameters:
        mime - MIME type
      • getContentType

        public java.lang.String getContentType()
        Get content type (from MIME type)
        Returns:
        content type
      • getMIME

        public static java.lang.String getMIME​(java.lang.String path)
        Get MIME type
        Parameters:
        path - Path
        Returns:
        MIME type extracted from file extension (or empty string if not found)
      • getContentType

        public static java.lang.String getContentType​(java.lang.String path)
        Get content type from MIME type for file name
        Parameters:
        path - Path
        Returns:
        Content type from MIME type extracted from file extension (or empty string if not found)
      • isZIP

        public static boolean isZIP​(java.lang.String mime)
        Is a ZIP file?
        Parameters:
        mime - MIME
        Returns:
        True if MIME type is ZIPF
      • isZIP

        public boolean isZIP()
        Is a ZIP file?
        Returns:
        True if MIME type is ZIP
      • isImage

        public static boolean isImage​(java.lang.String mime)
        Is an image?
        Parameters:
        mime - MIME
        Returns:
        true if MIME type is PNG, JPEG, SVG or GIF
      • isImage

        public boolean isImage()
        Is an image?
        Returns:
        true if MIME type is PNG, JPEG, SVG or GIF
      • inline

        public java.lang.String inline()
        Convert the document to a String (XML usage). Use base64 encoding for non textual contents.
        Returns:
        DATA:<docname>:[base64:]:<content...>
      • inline

        public static java.lang.String inline​(DocumentDB d)
        Convert a document to a inlined document string (XML usage). Use base64 encoding for non textual contents.
        Parameters:
        d - Document
        Returns:
        Inlined document string (DATA:<docname>:[base64:]:<content...>)
      • parse

        public static java.lang.Object[] parse​(java.lang.String doc)
        Parse a document (from XML import)
        Parameters:
        doc - Document
        Returns:
        Document path + bytes array when document is inlined
      • getSize

        public long getSize()
        Get file size (bytes)
        Returns:
        file size (bytes)
      • setSize

        public void setSize​(long size)
        Set file size (bytes)
        Parameters:
        size - file size (bytes)
      • getVersion

        public int getVersion()
        Version (automatically increased when saving)
        Returns:
        Version
      • getLastUpdated

        public java.lang.String getLastUpdated()
        Get last updated date time
        Returns:
        Last updated date time
      • getBookshelfName

        public java.lang.String getBookshelfName()
        Get bookshelf name
        Returns:
        Bookshelf name
      • getRespId

        public java.lang.String getRespId()
        Get document owner
        Returns:
        Document owner
      • getRespLogin

        public java.lang.String getRespLogin()
        get user login managing the document requests
        Returns:
        User login
      • isOnDemand

        public boolean isOnDemand()
        Is request allowed ?
        Returns:
        Request allowed ?
      • getAccessGroup

        public java.util.List<java.lang.String> getAccessGroup()
        Get bookshelf groups
        Returns:
        Groups list
      • isGroupGrant

        public boolean isGroupGrant​(java.lang.String group,
                                    char grt)
        Is the group granted ?
        Parameters:
        group - Group name
        grt - Grant type (U)pload (D)ownload (M)Update index (G)Update grant (S)Delete
        Returns:
        True if the group is granted to the type
      • getFields

        public java.util.Map<java.lang.String,​java.lang.String> getFields()
        Get indexed fields
        Returns:
        Indexed fields
      • getObjectRef

        public java.lang.String getObjectRef()
        Get object name associated to the document
        Returns:
        object name associated to the document
      • setObjectRef

        public void setObjectRef​(java.lang.String object)
        Set object name associated to the document
        Parameters:
        object - object name associated to the document
      • getFieldRef

        public java.lang.String getFieldRef()
        Get field name associated to the document
        Returns:
        field name associated to the document
      • setFieldRef

        public void setFieldRef​(java.lang.String field)
        Set field name associated to the document
        Parameters:
        field - field name associated to the document
      • getRowIdRef

        public java.lang.String getRowIdRef()
        Get object record row ID associated to the document
        Returns:
        object record row ID
      • setRowIdRef

        public void setRowIdRef​(java.lang.String rowId)
        Set object record row ID associated to the document
        Parameters:
        rowId - object record row ID
      • getDocumentIdFromCondition

        public static java.lang.String getDocumentIdFromCondition​(java.lang.String condition)
        Get first document ID that matches specified SQL condition
        Parameters:
        condition - Condition
        Returns:
        ObjectField.DEFAULT_ROW_ID if no matching document is found
      • getDocumentIdFromPath

        public static java.lang.String getDocumentIdFromPath​(java.lang.String path)
        Get first document ID that matches specified path
        Parameters:
        path - Path
        Returns:
        ObjectField.DEFAULT_ROW_ID if no matching document is found
      • getDocumentIdFromName

        public static java.lang.String getDocumentIdFromName​(java.lang.String name)
        Get first document ID that matches specified name
        Parameters:
        name - Name
        Returns:
        ObjectField.DEFAULT_ROW_ID if no matching document is found
      • getDocumentId

        public static java.lang.String getDocumentId​(Grant g,
                                                     java.lang.String object,
                                                     java.lang.String field,
                                                     java.lang.String rowId)
        Get document ID that matches specified object name, field name and row ID
        Parameters:
        g - Grant
        object - Object name
        field - Field name
        rowId - Row ID
        Returns:
        null if no document is found or object is not granted
      • getDocumentId

        public static java.lang.String getDocumentId​(ObjectDB obj,
                                                     java.lang.String field,
                                                     java.lang.String rowId)
        Get document ID that matches specified object field name and row ID
        Parameters:
        obj - Object
        field - Field name
        rowId - Row ID
        Returns:
        null if no document is found
      • write

        @Deprecated
        public static void write​(java.lang.String docId,
                                 Grant grant,
                                 byte[] data)
        Deprecated.
        Use DocTool.writeFile
      • write

        @Deprecated
        public static void write​(java.lang.String path,
                                 byte[] data)
        Deprecated.
        Use DocTool.writeFile
      • select

        public static byte[] select​(java.lang.String docId)
        Read a document content from the ID
        Parameters:
        docId - Document ID
        Returns:
        Document content
      • read

        public static byte[] read​(java.lang.String path)
        Read a document content
        Parameters:
        path - Document path
        Returns:
        Document content
      • toString

        public static java.lang.String toString​(java.lang.String docId)
        Read a document content into a plain String.
        Parameters:
        docId - Document ID
        Returns:
        Document content as a plain String
      • toBase64

        public static java.lang.String toBase64​(java.lang.String docId)
        Read a document content into a Base64 encoded String
        Parameters:
        docId - Document ID
        Returns:
        Document content as a Base64 encoded String
      • toBase64

        @Deprecated
        public static java.lang.String toBase64​(java.lang.String docId,
                                                Grant g)
        Deprecated.
      • getDocument

        public static DocumentDB getDocument​(java.lang.String docId,
                                             Grant grant)
        Retrieve document data from ID: dbdoc path, name, size, mime-type, version, etc.
        Parameters:
        docId - Document ID
        grant - User grants
        Returns:
        Document data
      • addAccess

        public static void addAccess​(Grant g,
                                     java.lang.String docId)
        Add a read access to the document in user's session (param _SESSION_DOC_ACCESS_)
        Parameters:
        g - User rights
        docId - Document id
      • removeAccess

        public static void removeAccess​(Grant g,
                                        java.lang.String docId)
        Remove a read access to the document in user's session (param _SESSION_DOC_ACCESS_)
        Parameters:
        g - User rights
        docId - Document id
      • checkAccess

        public static boolean checkAccess​(Grant g,
                                          java.lang.String docId)
        Check a read access to the document in user's session (param _SESSION_DOC_ACCESS_)
        Parameters:
        g - User rights
        docId - Document id
        Returns:
        true is accessible
      • copyToRecycleBin

        public static void copyToRecycleBin​(DocumentDB doc)
        Copy to recycle bin
        Parameters:
        doc - Document
      • copyToDir

        @Deprecated
        public void copyToDir​(java.lang.String path)
        Deprecated.
        Use copyTo
      • copyTo

        public void copyTo​(java.lang.String path)
        Copy document to specified path
        Parameters:
        path - Absolute path to copy document to
      • toJSONObject

        public org.json.JSONObject toJSONObject()
        Generates a JSON object representation of the business object
        Returns:
        business object as JSON object
      • toString

        public java.lang.String toString()
        Generates a string representation of the business object
        Overrides:
        toString in class java.lang.Object
        Returns:
        business object as string