Package com.jalios.jcms.fileprocessor
Class FPUtil
java.lang.Object
com.jalios.jcms.fileprocessor.FPUtil
This class provides a set of static methods which perform various
utility operations used specifically in FileProcessor.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanarrayContainsIgnoreCase(String[] array, String key) Test if an array contains a given object.static booleancheckIsGeneratedPDF(File file) Check if the file in parameter is the generated PDF associated to another document.static booleanCheck if the file in parameter is the generated Plain text associated to another document.static voidcreateAssociatedTextFile(File file, String content) Create a file with name the name of file plus ".txt" and with content : content.static StringextractTextPDF(File file, Map<String, Object> ctxt, FileParser parser) This methods extracts the text of specified PDF File (MUST be a pdf) to a String (using PDFBox).static StringReturns filename using System separator caracterstatic StringReturns filename using inner separator caracterstatic Comparator<FileActionComponent> This comparator is to order FileActionComponent in regard with getOrder.static FileActionComponentgetActionComponentInstance(Class<? extends FileActionComponent> clazz) Returns a new instance of a FileActionComponent of the class specified in parameter.static FilegetAssociatedTextFile(File file) Retrieve the File instance of the associated text file for the specified Filestatic Comparator<Class<?>> Comparator for Classes, usefull to use TreeSet of Classes, then ObjectIntTreeMap with classes as keys.static StringgetFileShortName(File file, Repository repository) static String[]getFilesVeryShortName(String[] filesName) This method give the ending name of a file.static StringgetFileVeryShortName(String fileName) This method give the ending name of a file.static StringgetFirstWord(String phrase) Return the substring of the phrase in parameter before the first dot, or itself if it contains no dot.static RepositoryGives the main repository for JCMS upload files.static StringgetTextFileName(File file) Retrieve the absolute file name of the associated text file for the specified Filestatic ContentHandlergetXmlTextContentHandler(OutputStream outStream) Convenient Method to get a ContentHandler to parse an UTF-8 XML stream and get only text inside element.static booleanisPlainText(File file) static StringreadAssociatedTextFileContent(File associatedTextFile) Read the content of the specified text file and return it as a string.
-
Constructor Details
-
FPUtil
public FPUtil()
-
-
Method Details
-
getJCMSMainRepository
Gives the main repository for JCMS upload files.- Returns:
- the classical JCMS upload repository
-
getFirstWord
Return the substring of the phrase in parameter before the first dot, or itself if it contains no dot.- Parameters:
phrase- the phrase- Returns:
- the subtring before the first dot
-
getXmlTextContentHandler
Convenient Method to get a ContentHandler to parse an UTF-8 XML stream and get only text inside element.- Parameters:
outStream- the stream in which to write extracted text content- Returns:
- return a SAX Handler taking all the string of the contents of an XML stream.
-
arrayContainsIgnoreCase
Test if an array contains a given object. Return true if the test with '==' operator or 'equals' or 'equalsIgnoreCase' method returns true.- Parameters:
array- the array to be searched.key- the value to be searched for.- Returns:
- true if the array contains the given object.
-
getActionComponentInstance
public static FileActionComponent getActionComponentInstance(Class<? extends FileActionComponent> clazz) Returns a new instance of a FileActionComponent of the class specified in parameter.- Parameters:
clazz- the FileActionComponent class to instanciate- Returns:
- a new instance of the given class or null if could not be created
-
getActionComponentComparator
This comparator is to order FileActionComponent in regard with getOrder.- Returns:
- a comparator for SortedSet containing only FileActionComponent
-
fromInnerFileSeparatorToSystemFileSeparator
Returns filename using System separator caracter- Parameters:
filename- as stored (independant from OS)- Returns:
- filename close to OS
-
fromSystemFileSeparatorToInnerFileSeparator
Returns filename using inner separator caracter- Parameters:
filename- close to OS- Returns:
- filename as stored (independant from OS)
-
getFileVeryShortName
This method give the ending name of a file. The separator used is the one stored ('/' == FPUtil.FILE_SEPARATOR_IN_PERSISTED_FILE)- Parameters:
fileName- the filename- Returns:
- the simple name of the file
-
getFilesVeryShortName
This method give the ending name of a file. The separator used is the one stored ('/' == FPUtil.FILE_SEPARATOR_IN_PERSISTED_FILE)- Parameters:
filesName- the filename- Returns:
- the simple name of the file
-
getFileShortName
-
getClassComparator
Comparator for Classes, usefull to use TreeSet of Classes, then ObjectIntTreeMap with classes as keys.- Returns:
- Comparator based on classname first, then on class hashcode
-
checkIsGeneratedPDF
Check if the file in parameter is the generated PDF associated to another document. This PDF may have been generate by JUniversal or the PDFConverterPlugin. A file is supposed to be a PDF generated PDF if a file exists with the same name without ".pdf" extension outside associated directory. There is no test on files date : if the PDF is older than the other file, we suppose it has been generated from an old version of the original file.- Parameters:
file- the file- Returns:
- true if it is a generated PDF from another file.
-
checkIsGeneratedPlainText
Check if the file in parameter is the generated Plain text associated to another document. A file is supposed to be a Plain text generated file if a file exists with the same name without ".txt" extension outside the associated directory. There is no test on files date : if the plain text is older than the other file, we suppose it has been generated from an old version of the original file.- Parameters:
file- the file- Returns:
- true if it is a generated plain text from another file.
-
isPlainText
-
createAssociatedTextFile
Create a file with name the name of file plus ".txt" and with content : content.- Parameters:
file- the filecontent- the contenu
-
readAssociatedTextFileContent
Read the content of the specified text file and return it as a string.- Parameters:
associatedTextFile- the associated text File to read- Returns:
- null if the content could not be read
- Since:
- fpp-3.0
-
getTextFileName
Retrieve the absolute file name of the associated text file for the specified File- Parameters:
file- any file for which to retrieve the associated text file path.- Returns:
- an absolute path of a text file
-
getAssociatedTextFile
Retrieve the File instance of the associated text file for the specified File- Parameters:
file- any file for which to retrieve the associated text File.- Returns:
- the File instance for the associated text file
-
extractTextPDF
public static String extractTextPDF(File file, Map<String, Object> ctxt, FileParser parser) throws ProcessingExceptionThis methods extracts the text of specified PDF File (MUST be a pdf) to a String (using PDFBox).This methods is meant to be used in a FileParser implementation and requires all parameters
- Parameters:
file- the PDF file (must be a valid and existing PDF file)ctxt- the FileParser extractText context mapparser- the FileParser instance performing the parsing process- Returns:
- the textual content of the PDF file or null if the file was empty
- Throws:
ProcessingException- if an error occurs
-