Package com.simplicite.util.tools
Class DocTool
- java.lang.Object
-
- com.simplicite.util.tools.DocTool
-
public class DocTool extends java.lang.Object
Document tools
This class only provides static variables and methods
-
-
Field Summary
Fields Modifier and Type Field Description static int
INDEX_MODE_NONE
static int
INDEX_MODE_RICH
static int
INDEX_MODE_TEXT
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static void
clearCache()
Clear cachestatic 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 indexstatic java.lang.String
delete(Grant g, java.lang.String docId, java.lang.String bookshelf, java.lang.String rpath)
Delete a documentstatic void
delete(java.lang.String rpath)
Delete a single documentstatic java.lang.String
deleteBookshelf(ObjectDB bookshelf)
Delete booshelfstatic void
deleteFile(java.lang.String path)
Delete a file in local file systemstatic java.lang.String
deleteIndex(Grant g, java.lang.String docId, java.lang.String bookshelf, java.lang.String rpath)
Delete indexstatic boolean
exists(java.lang.String path)
Check document existencestatic java.util.Map<java.lang.String,Bookshelf>
getAllBookshelfs()
Cache of bookshelf definitionsstatic java.util.List<java.lang.String>
getAllGroups()
static Bookshelf
getBookshelf(java.lang.String name)
Retrieve a bookshelf definitionstatic java.lang.String
getBookshelfOfDocId(java.lang.String docId)
Get the name of bookshelf linked to a doc, null otherwisestatic java.lang.String
getBookshelfOfField(java.lang.String fieldName)
Get the name of bookshelf linked to a field, null otherwisestatic 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 typestatic DocumentDB
getDocument(Grant g, java.lang.String docId, boolean bIndex, boolean bGrant)
Instantiate a documentstatic java.lang.String
getExtension(java.lang.String mime)
Get file extension from MIME typestatic java.util.Map<java.lang.String,Bookshelf>
getExternalBookshelfs()
static java.io.File
getFile(java.lang.String path)
Get the document as a local filestatic Message
getFileInfo(java.lang.String docId)
Deprecated.static java.lang.String
getFileName(java.lang.String docId)
Get file namestatic java.lang.String
getFilePath(java.lang.String docId)
Get file pathstatic java.util.List<java.lang.String>
getIndexedDocObjects()
Objects with simple indexable docstatic int
getIndexMode(java.lang.String ext)
Get indexation mode (one of DocTool.INDEX_MOD_* constant) from file extensionstatic java.lang.String
getMIMEType(java.lang.String ext)
Get MIME type from file extensionstatic 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 documentstatic java.lang.String
getURL(ObjectDB obj, ObjectField field, boolean cache, boolean thumbnail)
Get URL for specified documentstatic java.lang.String
getURL(ObjectDB obj, ObjectField field, java.lang.String cdisp, boolean cache, boolean thumbnail)
Get URL for specified documentstatic void
importBlobs()
Bulk import for DOC_DIR => BLOBstatic 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 pathstatic byte[]
readFileAsBytes(java.lang.String path)
Read a file from a document pathstatic java.io.InputStream
readFileAsStream(java.lang.String path)
Deprecated.Use readFilestatic java.lang.String
rebuildIndex(ObjectDB docIndex, Grant g, java.lang.String bookshelf)
Rebuild document indexstatic 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 demandstatic java.lang.String
synchronize()
Synchronize documentsstatic 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 DBDOCstatic void
writeFile(java.lang.String path, byte[] data)
Write a filestatic void
writeFile(java.lang.String path, byte[] data, java.io.File src)
Write a filestatic void
writeFile(java.lang.String path, byte[] data, java.io.InputStream in)
Write a file
-
-
-
Field Detail
-
INDEX_MODE_NONE
public static final int INDEX_MODE_NONE
- See Also:
- Constant Field Values
-
INDEX_MODE_RICH
public static final int INDEX_MODE_RICH
- See Also:
- Constant Field Values
-
INDEX_MODE_TEXT
public static final int INDEX_MODE_TEXT
- See Also:
- Constant Field Values
-
-
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()
Clear cache
-
getDocument
public static DocumentDB getDocument(Grant g, java.lang.String docId, boolean bIndex, boolean bGrant)
Instantiate a document- Parameters:
g
- User rightsdocId
- Document IdbIndex
- 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 rightsdocId
- Existing doc ID (optional to create or find the doc with the object row ID)path
- Original path to the filedata
- or bytes array when the path is not accessibletmpFile
- or optional source file when data is not set (ZZZ will be deleted after reading !)tmpStream
- or optional stream when data is not setvers
- True to increment the version if doc already existsobject
- 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 grantsondemand
- 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
- GrantdocId
- Document IDrpath
- Relative pathbookshelf
- Bookshelffields
- 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 rightsdocId
- Document ID (rpath must be specified if null)bookshelf
- Optional bookshelfrpath
- 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
- GrantdocId
- Document IDbookshelf
- Bookshelfrpath
- 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
- Documentcdisp
- Content dispositioncache
- Allow HTTP cachethumbnail
- 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
- Objectfield
- Fieldcache
- Allow HTTP cachethumbnail
- 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
- Objectfield
- Fieldcdisp
- Content dispositioncache
- Allow HTTP cachethumbnail
- 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.io.IOException
Read a file from a document path- Parameters:
path
- Document path- Returns:
- bytes or null
- Throws:
java.io.IOException
-
readFile
public static java.io.InputStream readFile(java.lang.String path) throws java.io.IOException
Read a file from a document path- Parameters:
path
- Document path- Returns:
- stream or null
- Throws:
java.io.IOException
-
readFileAsStream
@Deprecated public static java.io.InputStream readFileAsStream(java.lang.String path) throws java.io.IOException
Deprecated.Use readFile- Throws:
java.io.IOException
-
writeFile
public static void writeFile(java.lang.String path, byte[] data) throws java.io.IOException
Write a file- Parameters:
path
- Document pathdata
- Optional data- Throws:
java.io.IOException
-
writeFile
public static void writeFile(java.lang.String path, byte[] data, java.io.File src) throws java.io.IOException
Write a file- Parameters:
path
- Document pathdata
- Optional datasrc
- Or source file- Throws:
java.io.IOException
-
writeFile
public static void writeFile(java.lang.String path, byte[] data, java.io.InputStream in) throws java.io.IOException
Write a file- Parameters:
path
- Document pathdata
- Optional byte array data (exclusive with in)in
- Optional source input stream (exclusive with data)- Throws:
java.io.IOException
-
deleteFile
public static void deleteFile(java.lang.String path) throws java.io.IOException
Delete a file in local file system- Parameters:
path
- Document path- Throws:
java.io.IOException
-
synchronize
public static java.lang.String synchronize() throws java.io.IOException
Synchronize documents- Returns:
- Synchronize report
- Throws:
java.io.IOException
-
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 indexg
- Grantbookshelf
- 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
- GrantdocId
- Document IDemail
- Emailmessage
- Message- Throws:
java.lang.Exception
-
-