Class DocTool


  • public class DocTool
    extends java.lang.Object
    Document tools
    • Method Summary

      Modifier and Type Method Description
      static void clearCache()  
      static java.lang.String createIndex​(Grant g, java.lang.String docId, java.lang.String rpath, java.lang.String bookshelf, java.util.List<java.lang.String> fields)
      Create index
      static java.lang.String delete​(Grant g, java.lang.String docId, java.lang.String bookshelf, java.lang.String rpath)
      Delete a document
      static void delete​(java.lang.String rpath)
      Delete a single document
      static java.lang.String deleteBookshelf​(ObjectDB bookshelf)
      Delete booshelf
      static void deleteFile​(java.lang.String path)
      Delete a file in local file system
      static java.lang.String deleteIndex​(Grant g, java.lang.String docId, java.lang.String bookshelf, java.lang.String rpath)
      Delete index
      static boolean exists​(java.lang.String path)
      Check document existence
      static java.util.Map<java.lang.String,​Bookshelf> getAllBookshelfs()
      Cache of bookshelf definitions
      static java.util.List<java.lang.String> getAllGroups()  
      static Bookshelf getBookshelf​(java.lang.String name)
      Retrieve a bookshelf definition
      static java.lang.String getBookshelfOfDocId​(java.lang.String docId)
      Get the name of bookshelf linked to a doc, null otherwise
      static java.lang.String getBookshelfOfField​(java.lang.String fieldName)
      Get the name of bookshelf linked to a field, null otherwise
      static java.lang.String getContentType​(java.lang.String mime)
      Get content type from MIME type (adding chararcter encoding when required)
      static java.lang.String getDocContent​(DocumentDB doc)
      Retrieve the doc content using document content parsers
      (txt, xml, doc, docx, xls, xlsx, ppt, pptx, pdf...)
      static int[] getDocGrant​(Grant g, java.lang.String docId)  
      static java.lang.String getDocMime​(java.lang.String docId)
      Get document MIME type
      static DocumentDB getDocument​(Grant g, java.lang.String docId, boolean bIndex, boolean bGrant)
      Instantiate a document
      static java.lang.String getExtension​(java.lang.String mime)
      Get file extension from MIME type
      static java.util.Map<java.lang.String,​Bookshelf> getExternalBookshelfs()  
      static java.io.File getFile​(java.lang.String path)
      Get the document as a local file
      static Message getFileInfo​(java.lang.String docId)
      Deprecated. 
      static java.lang.String getFileName​(java.lang.String docId)
      Get file name
      static java.lang.String getFilePath​(java.lang.String docId)
      Get file path
      static java.util.List<java.lang.String> getIndexedDocObjects()
      Objects with simple indexable doc
      static int getIndexMode​(java.lang.String ext)
      Get indexation mode (one of DocTool.INDEX_MOD_* constant) from file extension
      static java.lang.String getMIMEType​(java.lang.String ext)
      Get MIME type from file extension
      static java.lang.String getThumbnailOrigin​(java.lang.String thumbnailPath)  
      static java.lang.String getThumbnailPath​(java.lang.String path)
      Get thumbnail image path from specified document path (only relevant for images with thumbnail)
      static java.lang.String getURL​(DocumentDB doc, java.lang.String cdisp, boolean cache, boolean thumbnail)
      Get URL for specified document
      static java.lang.String getURL​(ObjectDB obj, ObjectField field, boolean cache, boolean thumbnail)
      Get URL for specified document
      static java.lang.String getURL​(ObjectDB obj, ObjectField field, java.lang.String cdisp, boolean cache, boolean thumbnail)
      Get URL for specified document
      static void importBlobs()
      Bulk import for DOC_DIR => BLOB
      static boolean isGrantActive()  
      static boolean isGrantEnable​(java.lang.String docId)  
      static boolean isIndexActive()  
      static boolean isThumbnailPath​(java.lang.String path)
      Is a thumbnail ?
      static java.io.InputStream readFile​(java.lang.String path)
      Read a file from a document path
      static byte[] readFileAsBytes​(java.lang.String path)
      Read a file from a document path
      static java.io.InputStream readFileAsStream​(java.lang.String path)
      Deprecated.
      Use readFile
      static java.lang.String rebuildIndex​(ObjectDB docIndex, Grant g, java.lang.String bookshelf)
      Rebuild document index
      static java.lang.String saveGrant​(Grant g, java.lang.String docId, java.lang.String respLogin, java.util.Map<java.lang.String,​java.lang.String> grp, boolean ondemand)  
      static java.lang.String sendDocDemand​(Grant g, java.lang.String docId, java.lang.String email, java.lang.String message)
      Send document on demand
      static java.lang.String synchronize()
      Synchronize documents
      static Message upload​(Grant g, java.lang.String docId, java.lang.String path, byte[] data, java.io.File tmpFile, java.io.InputStream tmpStream, boolean vers, java.lang.String object, java.lang.String field, java.lang.String rowId, java.lang.String bookshelf, java.util.List<java.lang.String> indexValues, java.lang.String respLogin, java.util.Map<java.lang.String,​java.lang.String> group, boolean ondemand)
      Upload a document in DBDOC
      static void writeFile​(java.lang.String path, byte[] data)
      Write a file
      static void writeFile​(java.lang.String path, byte[] data, java.io.File src)
      Write a file
      static void writeFile​(java.lang.String path, byte[] data, java.io.InputStream src)
      Write a file
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • isIndexActive

        public static boolean isIndexActive()
      • isGrantActive

        public static boolean isGrantActive()
      • getIndexedDocObjects

        public static java.util.List<java.lang.String> getIndexedDocObjects()
        Objects with simple indexable doc
      • getBookshelf

        public static Bookshelf getBookshelf​(java.lang.String name)
        Retrieve a bookshelf definition
      • getBookshelfOfField

        public static java.lang.String getBookshelfOfField​(java.lang.String fieldName)
        Get the name of bookshelf linked to a field, null otherwise
      • getBookshelfOfDocId

        public static java.lang.String getBookshelfOfDocId​(java.lang.String docId)
        Get the name of bookshelf linked to a doc, null otherwise
      • getAllBookshelfs

        public static java.util.Map<java.lang.String,​Bookshelf> getAllBookshelfs()
        Cache of bookshelf definitions
      • getExternalBookshelfs

        public static java.util.Map<java.lang.String,​Bookshelf> getExternalBookshelfs()
      • getAllGroups

        public static java.util.List<java.lang.String> getAllGroups()
      • clearCache

        public static void clearCache()
      • getDocument

        public static DocumentDB getDocument​(Grant g,
                                             java.lang.String docId,
                                             boolean bIndex,
                                             boolean bGrant)
        Instantiate a document
        Parameters:
        g - User rights
        docId - Document Id
        bIndex - Load indexes ?
        bGrant - Load rights ?
        Returns:
        Document or null if unknown
      • upload

        public static Message upload​(Grant g,
                                     java.lang.String docId,
                                     java.lang.String path,
                                     byte[] data,
                                     java.io.File tmpFile,
                                     java.io.InputStream tmpStream,
                                     boolean vers,
                                     java.lang.String object,
                                     java.lang.String field,
                                     java.lang.String rowId,
                                     java.lang.String bookshelf,
                                     java.util.List<java.lang.String> indexValues,
                                     java.lang.String respLogin,
                                     java.util.Map<java.lang.String,​java.lang.String> group,
                                     boolean ondemand)
        Upload a document in DBDOC
        Parameters:
        g - User rights
        docId - Existing doc ID (optional to create or find the doc with the object row ID)
        path - Original path to the file
        data - or bytes array when the path is not accessible
        tmpFile - or optional source file when data is not set (ZZZ will be deleted after reading !)
        tmpStream - or optional stream when data is not set
        vers - True to increment the version if doc already exists
        object - Object name (optional)
        field - Object field name (optional)
        rowId - Object row ID(optional)
        bookshelf - Bookshelf name (optional)
        indexValues - Indexed fields (optional)
        respLogin - Owner login (optional)
        group - Doc grants
        ondemand - Manage the doc requests
        Returns:
        Message with docId and name (path in DBDOC), or errors
      • getThumbnailPath

        public static java.lang.String getThumbnailPath​(java.lang.String path)
        Get thumbnail image path from specified document path (only relevant for images with thumbnail)
      • isThumbnailPath

        public static boolean isThumbnailPath​(java.lang.String path)
        Is a thumbnail ?
      • getThumbnailOrigin

        public static java.lang.String getThumbnailOrigin​(java.lang.String thumbnailPath)
      • createIndex

        public static java.lang.String createIndex​(Grant g,
                                                   java.lang.String docId,
                                                   java.lang.String rpath,
                                                   java.lang.String bookshelf,
                                                   java.util.List<java.lang.String> fields)
        Create index
        Parameters:
        g - Grant
        docId - Document ID
        rpath - Relative path
        bookshelf - Bookshelf
        fields - List of field names
      • deleteBookshelf

        public static java.lang.String deleteBookshelf​(ObjectDB bookshelf)
                                                throws java.lang.Exception
        Delete booshelf
        Parameters:
        bookshelf - Booshelf
        Throws:
        java.lang.Exception
      • delete

        public static void delete​(java.lang.String rpath)
        Delete a single document
        Parameters:
        rpath - Relative path
      • delete

        public static java.lang.String delete​(Grant g,
                                              java.lang.String docId,
                                              java.lang.String bookshelf,
                                              java.lang.String rpath)
                                       throws java.lang.Exception
        Delete a document
        Parameters:
        g - User rights
        docId - Document ID (rpath must be specified if null)
        bookshelf - Optional bookshelf
        rpath - Document path (docId must be specified if null)
        Returns:
        null or error
        Throws:
        java.lang.Exception
      • deleteIndex

        public static java.lang.String deleteIndex​(Grant g,
                                                   java.lang.String docId,
                                                   java.lang.String bookshelf,
                                                   java.lang.String rpath)
                                            throws java.lang.Exception
        Delete index
        Parameters:
        g - Grant
        docId - Document ID
        bookshelf - Bookshelf
        rpath - Relative path
        Throws:
        java.lang.Exception
      • saveGrant

        public static java.lang.String saveGrant​(Grant g,
                                                 java.lang.String docId,
                                                 java.lang.String respLogin,
                                                 java.util.Map<java.lang.String,​java.lang.String> grp,
                                                 boolean ondemand)
      • getDocGrant

        public static int[] getDocGrant​(Grant g,
                                        java.lang.String docId)
      • isGrantEnable

        public static boolean isGrantEnable​(java.lang.String docId)
      • getDocMime

        public static java.lang.String getDocMime​(java.lang.String docId)
        Get document MIME type
        Parameters:
        docId - Document ID
        Returns:
        MIME type
      • getFileName

        public static java.lang.String getFileName​(java.lang.String docId)
        Get file name
        Parameters:
        docId - Document ID
        Returns:
        File name
      • getFilePath

        public static java.lang.String getFilePath​(java.lang.String docId)
        Get file path
        Parameters:
        docId - Document ID
      • getFile

        public static java.io.File getFile​(java.lang.String path)
        Get the document as a local file
        Parameters:
        path - Path
      • getFileInfo

        @Deprecated
        public static Message getFileInfo​(java.lang.String docId)
        Deprecated.
      • getURL

        public static java.lang.String getURL​(DocumentDB doc,
                                              java.lang.String cdisp,
                                              boolean cache,
                                              boolean thumbnail)
        Get URL for specified document
        Parameters:
        doc - Document
        cdisp - Content disposition
        cache - Allow HTTP cache
        thumbnail - Thumbnail URL
        Returns:
        Document URL
      • getURL

        public static java.lang.String getURL​(ObjectDB obj,
                                              ObjectField field,
                                              boolean cache,
                                              boolean thumbnail)
        Get URL for specified document
        Parameters:
        obj - Object
        field - Field
        cache - Allow HTTP cache
        thumbnail - Thumbnail URL
        Returns:
        Document URL
      • getURL

        public static java.lang.String getURL​(ObjectDB obj,
                                              ObjectField field,
                                              java.lang.String cdisp,
                                              boolean cache,
                                              boolean thumbnail)
        Get URL for specified document
        Parameters:
        obj - Object
        field - Field
        cdisp - Content disposition
        cache - Allow HTTP cache
        thumbnail - Thumbnail URL
        Returns:
        Document URL
      • exists

        public static boolean exists​(java.lang.String path)
        Check document existence
        Parameters:
        path - Document path
        Returns:
        True if exists
      • readFileAsBytes

        public static byte[] readFileAsBytes​(java.lang.String path)
                                      throws java.lang.Exception
        Read a file from a document path
        Parameters:
        path - Document path
        Returns:
        bytes or null
        Throws:
        java.lang.Exception
      • readFile

        public static java.io.InputStream readFile​(java.lang.String path)
                                            throws java.lang.Exception
        Read a file from a document path
        Parameters:
        path - Document path
        Returns:
        stream or null
        Throws:
        java.lang.Exception
      • readFileAsStream

        @Deprecated
        public static java.io.InputStream readFileAsStream​(java.lang.String path)
                                                    throws java.lang.Exception
        Deprecated.
        Use readFile
        Throws:
        java.lang.Exception
      • writeFile

        public static void writeFile​(java.lang.String path,
                                     byte[] data)
                              throws java.lang.Exception
        Write a file
        Parameters:
        path - Document path
        data - Optional data
        Throws:
        java.lang.Exception
      • writeFile

        public static void writeFile​(java.lang.String path,
                                     byte[] data,
                                     java.io.File src)
                              throws java.lang.Exception
        Write a file
        Parameters:
        path - Document path
        data - Optional data
        src - Or source file
        Throws:
        java.lang.Exception
      • writeFile

        public static void writeFile​(java.lang.String path,
                                     byte[] data,
                                     java.io.InputStream src)
                              throws java.lang.Exception
        Write a file
        Parameters:
        path - Document path
        data - Optional data
        src - Or source file
        Throws:
        java.lang.Exception
      • deleteFile

        public static void deleteFile​(java.lang.String path)
                               throws java.lang.Exception
        Delete a file in local file system
        Parameters:
        path - Document path
        Throws:
        java.lang.Exception
      • synchronize

        public static java.lang.String synchronize()
                                            throws java.lang.Exception
        Synchronize documents
        Returns:
        Synchronize report
        Throws:
        java.lang.Exception
      • importBlobs

        public static void importBlobs()
        Bulk import for DOC_DIR => BLOB
      • rebuildIndex

        public static java.lang.String rebuildIndex​(ObjectDB docIndex,
                                                    Grant g,
                                                    java.lang.String bookshelf)
                                             throws java.lang.Exception
        Rebuild document index
        Parameters:
        docIndex - Document index
        g - Grant
        bookshelf - Bookshelf
        Throws:
        java.lang.Exception
      • getDocContent

        public static java.lang.String getDocContent​(DocumentDB doc)
                                              throws java.lang.Exception
        Retrieve the doc content using document content parsers
        (txt, xml, doc, docx, xls, xlsx, ppt, pptx, pdf...)
        Parameters:
        doc - Document
        Returns:
        doc content if parsing successful
        Throws:
        java.lang.Exception
      • getExtension

        public static java.lang.String getExtension​(java.lang.String mime)
        Get file extension from MIME type
        Parameters:
        mime - MIME type
      • getContentType

        public static java.lang.String getContentType​(java.lang.String mime)
        Get content type from MIME type (adding chararcter encoding when required)
        Parameters:
        mime - Raw MIME type
        Returns:
        Formatted MIME type (with platform charset in case of text content)
      • getMIMEType

        public static java.lang.String getMIMEType​(java.lang.String ext)
        Get MIME type from file extension
        Parameters:
        ext - Extension or path
      • getIndexMode

        public static int getIndexMode​(java.lang.String ext)
        Get indexation mode (one of DocTool.INDEX_MOD_* constant) from file extension
        Parameters:
        ext - Extension
      • sendDocDemand

        public static java.lang.String sendDocDemand​(Grant g,
                                                     java.lang.String docId,
                                                     java.lang.String email,
                                                     java.lang.String message)
                                              throws java.lang.Exception
        Send document on demand
        Parameters:
        g - Grant
        docId - Document ID
        email - Email
        message - Message
        Throws:
        java.lang.Exception