Class FPUtil


  • public class FPUtil
    extends java.lang.Object
    This class provides a set of static methods which perform various utility operations used specifically in FileProcessor.
    Version:
    $Revision: 106034 $
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String REVISION  
    • Constructor Summary

      Constructors 
      Constructor Description
      FPUtil()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static boolean arrayContainsIgnoreCase​(java.lang.String[] array, java.lang.String key)
      Test if an array contains a given object.
      static boolean checkIsGeneratedPDF​(java.io.File file)
      Check if the file in parameter is the generated PDF associated to another document.
      static boolean checkIsGeneratedPlainText​(java.io.File file)
      Check if the file in parameter is the generated Plain text associated to another document.
      static void createAssociatedTextFile​(java.io.File file, java.lang.String content)
      Create a file with name the name of file plus ".txt" and with content : content.
      static java.lang.String extractTextPDF​(java.io.File file, java.util.Map<java.lang.String,​java.lang.Object> ctxt, FileParser parser)
      This methods extracts the text of specified PDF File (MUST be a pdf) to a String (using PDFBox).
      static java.lang.String fromInnerFileSeparatorToSystemFileSeparator​(java.lang.String filename)
      Returns filename using System separator caracter
      static java.lang.String fromSystemFileSeparatorToInnerFileSeparator​(java.lang.String filename)
      Returns filename using inner separator caracter
      static java.util.Comparator<FileActionComponent> getActionComponentComparator()
      This comparator is to order FileActionComponent in regard with getOrder.
      static FileActionComponent getActionComponentInstance​(java.lang.Class<? extends FileActionComponent> clazz)
      Returns a new instance of a FileActionComponent of the class specified in parameter.
      static java.io.File getAssociatedTextFile​(java.io.File file)
      Retrieve the File instance of the associated text file for the specified File
      static java.util.Comparator<java.lang.Class<?>> getClassComparator()
      Comparator for Classes, usefull to use TreeSet of Classes, then ObjectIntTreeMap with classes as keys.
      static java.lang.String getFileShortName​(java.io.File file, Repository repository)  
      static java.lang.String[] getFilesVeryShortName​(java.lang.String[] filesName)
      This method give the ending name of a file.
      static java.lang.String getFileVeryShortName​(java.lang.String fileName)
      This method give the ending name of a file.
      static java.lang.String getFirstWord​(java.lang.String phrase)
      Return the substring of the phrase in parameter before the first dot, or itself if it contains no dot.
      static Repository getJCMSMainRepository()
      Gives the main repository for JCMS upload files.
      static java.lang.String getTextFileName​(java.io.File file)
      Retrieve the absolute file name of the associated text file for the specified File
      static org.xml.sax.ContentHandler getXmlTextContentHandler​(java.io.OutputStream outStream)
      Convenient Method to get a ContentHandler to parse an UTF-8 XML stream and get only text inside element.
      static boolean isPlainText​(java.io.File file)  
      static java.lang.String readAssociatedTextFileContent​(java.io.File associatedTextFile)
      Read the content of the specified text file and return it as a string.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • FPUtil

        public FPUtil()
    • Method Detail

      • getJCMSMainRepository

        public static Repository getJCMSMainRepository()
        Gives the main repository for JCMS upload files.
        Returns:
        the classical JCMS upload repository
      • getFirstWord

        public static java.lang.String getFirstWord​(java.lang.String phrase)
        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

        public static org.xml.sax.ContentHandler getXmlTextContentHandler​(java.io.OutputStream outStream)
        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

        public static boolean arrayContainsIgnoreCase​(java.lang.String[] array,
                                                      java.lang.String key)
        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​(java.lang.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

        public static java.util.Comparator<FileActionComponent> getActionComponentComparator()
        This comparator is to order FileActionComponent in regard with getOrder.
        Returns:
        a comparator for SortedSet containing only FileActionComponent
      • fromInnerFileSeparatorToSystemFileSeparator

        public static java.lang.String fromInnerFileSeparatorToSystemFileSeparator​(java.lang.String filename)
        Returns filename using System separator caracter
        Parameters:
        filename - as stored (independant from OS)
        Returns:
        filename close to OS
      • fromSystemFileSeparatorToInnerFileSeparator

        public static java.lang.String fromSystemFileSeparatorToInnerFileSeparator​(java.lang.String filename)
        Returns filename using inner separator caracter
        Parameters:
        filename - close to OS
        Returns:
        filename as stored (independant from OS)
      • getFileVeryShortName

        public static java.lang.String getFileVeryShortName​(java.lang.String fileName)
        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

        public static java.lang.String[] getFilesVeryShortName​(java.lang.String[] filesName)
        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

        public static java.lang.String getFileShortName​(java.io.File file,
                                                        Repository repository)
      • getClassComparator

        public static java.util.Comparator<java.lang.Class<?>> 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

        public static boolean checkIsGeneratedPDF​(java.io.File file)
        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

        public static boolean checkIsGeneratedPlainText​(java.io.File file)
        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

        public static boolean isPlainText​(java.io.File file)
      • createAssociatedTextFile

        public static void createAssociatedTextFile​(java.io.File file,
                                                    java.lang.String content)
        Create a file with name the name of file plus ".txt" and with content : content.
        Parameters:
        file - the file
        content - the contenu
      • readAssociatedTextFileContent

        public static java.lang.String readAssociatedTextFileContent​(java.io.File associatedTextFile)
        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

        public static java.lang.String getTextFileName​(java.io.File file)
        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

        public static java.io.File getAssociatedTextFile​(java.io.File file)
        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 java.lang.String extractTextPDF​(java.io.File file,
                                                      java.util.Map<java.lang.String,​java.lang.Object> ctxt,
                                                      FileParser parser)
                                               throws ProcessingException
        This 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 map
        parser - 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