com.jalios.jcms.fileprocessor
Class FPUtil

java.lang.Object
  extended by com.jalios.jcms.fileprocessor.FPUtil

public class FPUtil
extends Object

This class provides a set of static methods which perform various utility operations used specifically in FileProcessor.

Version:
$Revision: 27882 $

Field Summary
static String REVISION
           
 
Constructor Summary
FPUtil()
           
 
Method Summary
static boolean arrayContainsIgnoreCase(String[] array, String key)
          Test if an array contains a given object.
static boolean checkIsGeneratedPDF(File file)
          Check if the file in parameter is the generated PDF associated to another document.
static boolean checkIsGeneratedPlainText(File file)
          Check if the file in parameter is the generated Plain text associated to another document.
static void createAssociatedTextFile(File file, String content)
          Create a file with name the name of file plus ".txt" and with content : content.
static String extractTextPDF(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 String fromInnerFileSeparatorToSystemFileSeparator(String filename)
          Returns filename using System separator caracter
static String fromSystemFileSeparatorToInnerFileSeparator(String filename)
          Returns filename using inner separator caracter
static Comparator<FileActionComponent> getActionComponentComparator()
          This comparator is to order FileActionComponent in regard with getOrder.
static FileActionComponent getActionComponentInstance(Class<? extends FileActionComponent> clazz)
          Returns a new instance of a FileActionComponent of the class specified in parameter.
static File getAssociatedTextFile(File file)
          Retrieve the File instance of the associated text file for the specified File
static Comparator<Class<?>> getClassComparator()
          Comparator for Classes, usefull to use TreeSet of Classes, then ObjectIntTreeMap with classes as keys.
static String getFileShortName(File file, Repository repository)
           
static String[] getFilesVeryShortName(String[] filesName)
          This method give the ending name of a file.
static String getFileVeryShortName(String fileName)
          This method give the ending name of a file.
static String getFirstWord(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 String getTextFileName(File file)
          Retrieve the absolute file name of the associated text file for the specified File
static ContentHandler getXmlTextContentHandler(OutputStream pout)
          Convenient Method to get a ContentHandler to parse XML stream and get only text inside element.
static boolean isPlainText(File file)
           
static String readAssociatedTextFileContent(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
 

Field Detail

REVISION

public static final String REVISION
See Also:
Constant Field Values
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 String getFirstWord(String phrase)
Return the substring of the phrase in parameter before the first dot, or itself if it contains no dot.

Parameters:
phrase -
Returns:
the subtring before the first dot

getXmlTextContentHandler

public static ContentHandler getXmlTextContentHandler(OutputStream pout)
Convenient Method to get a ContentHandler to parse XML stream and get only text inside element.

Parameters:
pout - XML stream
Returns:
return a SAX Handler taking all the string of the contents of an XML stream.

arrayContainsIgnoreCase

public static boolean arrayContainsIgnoreCase(String[] array,
                                              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(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 Comparator<FileActionComponent> getActionComponentComparator()
This comparator is to order FileActionComponent in regard with getOrder.

Returns:
a comparator for SortedSet containing only FileActionComponent

fromInnerFileSeparatorToSystemFileSeparator

public static String fromInnerFileSeparatorToSystemFileSeparator(String filename)
Returns filename using System separator caracter

Parameters:
filename - as stored (independant from OS)
Returns:
filename close to OS

fromSystemFileSeparatorToInnerFileSeparator

public static String fromSystemFileSeparatorToInnerFileSeparator(String filename)
Returns filename using inner separator caracter

Parameters:
filename - close to OS
Returns:
filename as stored (independant from OS)

getFileVeryShortName

public static String getFileVeryShortName(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 -
Returns:
the simple name of the file

getFilesVeryShortName

public static String[] getFilesVeryShortName(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 -
Returns:
the simple name of the file

getFileShortName

public static String getFileShortName(File file,
                                      Repository repository)

getClassComparator

public static Comparator<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(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 absolute name without ".pdf" extension. 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 -
Returns:
true if it is a generated PDF from another file.

checkIsGeneratedPlainText

public static boolean checkIsGeneratedPlainText(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 absolute name without ".txt" extension. 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 -
Returns:
true if it is a generated plain text from another file.

isPlainText

public static boolean isPlainText(File file)

createAssociatedTextFile

public static void createAssociatedTextFile(File file,
                                            String content)
Create a file with name the name of file plus ".txt" and with content : content.

Parameters:
file -
content -

readAssociatedTextFileContent

public static String readAssociatedTextFileContent(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 String getTextFileName(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 File getAssociatedTextFile(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 String extractTextPDF(File file,
                                    Map<String,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


Copyright © 2001-2010 Jalios SA. All Rights Reserved.