Class DocumentPagedTextExtractor
The file is copied to a temporary file and parsed from it. A Word document, a presentation, a PDF and a spreadsheet get their outline from the same walk that writes their text, the PDF being parsed with its buffers in temporary files and the spreadsheet streamed a row at a time, its shared strings held in memory. Any other supported type, an older Office or an OpenDocument file for instance, is read by the platform's document readers, without an outline; most of them load the whole file, so reading one takes a heap of at least the file's size, up to the largest file read, the same limit as the largest file a user can attach in the UI; and the one that builds its whole text before giving any is not stopped at the timeout, which is checked as the text is written: it keeps the extraction thread until it ends. One file is extracted at a time; a caller waits for its extraction a bounded time, the extraction going on after it so a later call finds the text. The text is stored as UTF-16, two bytes a character, so a part is read at its offset without reading what comes before it. The cache is a node's own: another node of a cluster extracts the file again on its first part.
-
Constructor Summary
ConstructorsConstructorDescriptionDocumentPagedTextExtractor(org.exoplatform.services.jcr.RepositoryService repositoryService, org.exoplatform.services.document.DocumentReaderService documentReaderService, DocumentTextExtractor formats, long maxFileSizeBytes, long maxChars, long timeoutMillis, long waitMillis, long maxCacheBytes, Path cacheDirectory) Builds the extractor. -
Method Summary
Modifier and TypeMethodDescriptionprotected PagedTextExtractionExtracts the whole text of a file into a cache file.org.exoplatform.documents.model.DocumentTextPageReads a part of a document's text, with its length and its outline.protected javax.jcr.SessionOpens a system session on the collaboration workspace, the caller having checked the user can read the document.voidshutdown()Stops the extraction thread.
-
Constructor Details
-
DocumentPagedTextExtractor
public DocumentPagedTextExtractor(org.exoplatform.services.jcr.RepositoryService repositoryService, org.exoplatform.services.document.DocumentReaderService documentReaderService, DocumentTextExtractor formats, long maxFileSizeBytes, long maxChars, long timeoutMillis, long waitMillis, long maxCacheBytes, Path cacheDirectory) throws IOException Builds the extractor.- Parameters:
repositoryService- the repository holding the filesdocumentReaderService- the platform's document readersformats- the on-the-fly extractor, whose supported types and type resolution are sharedmaxFileSizeBytes- the largest file readmaxChars- the most characters kept from one filetimeoutMillis- the longest one extraction runswaitMillis- the longest a caller waits for an extractionmaxCacheBytes- the most bytes the cache files takecacheDirectory- the directory of the cache files, emptied here- Throws:
IOException- when the directory can't be created or emptied
-
-
Method Details
-
getPage
public org.exoplatform.documents.model.DocumentTextPage getPage(String documentId, long offset, int length) Reads a part of a document's text, with its length and its outline.- Parameters:
documentId- the document idoffset- the first character to readlength- the most characters to read, 0 for none; a part that would hold only halves of surrogate pairs gets one more character, so it gives a pair whole- Returns:
- the part, or why there is no text
-
shutdown
public void shutdown()Stops the extraction thread. -
extract
Extracts the whole text of a file into a cache file.- Parameters:
documentId- the file idkey- the version key naming the cache file- Returns:
- the extraction
- Throws:
Exception- when the repository fails
-
openSystemSession
protected javax.jcr.Session openSystemSession() throws javax.jcr.RepositoryExceptionOpens a system session on the collaboration workspace, the caller having checked the user can read the document.- Returns:
- the session
- Throws:
javax.jcr.RepositoryException- when the repository fails
-