Class SampleProcessor

java.lang.Object
com.jalios.jcms.fileprocessor.test.SampleProcessor
All Implemented Interfaces:
FileActionComponent, FileParser, FileProcessor

public class SampleProcessor extends Object implements FileProcessor, FileParser
Sample FileProcessor and FileParse which can be used for testing.

1. Configure in custom.prop

 fileprocessor.repository.JCMSUpload.component.SampleParser.class: com.jalios.jcms.fileprocessor.test.SampleProcessor
 fileprocessor.repository.JCMSUpload.component.SampleParser.extensions: parseme processme processandparseme
 
2. Upload test file with the following filename to trigger the corresponding behavior :
An optional number can be added to end of each file basename (eg process1.processme, process2.processme).
An optional number can be added to end of each file extension, provided it has been configured for repository (eg ignore.processme1, ignore.processme2)
  • ignore.parseme
  • ignore.processme
  • process.parseme: Request succesfull parsing (immediate)
  • process.processme: Request succesfull processing (immediate)
  • process666.parseme: Request succesfull parsing, and take 666 ms to do so
  • process4242.processme: Request succesfull processing, and take 4242 ms to do so
  • exception.parseme
  • exception.processme
  • exception-long.parseme
  • exception-long.processme
  • partially-blacklist-exception.parseme
  • partially-blacklist-exception.processme
  • globally-blacklist-exception.parseme
  • globally-blacklist-exception.processme
  • unknown-exception.parseme
  • unknown-exception.processme
  • processerror-parsesuccess.processandparseme
  • processsuccess-parseerror.processandparseme
  • Constructor Details

    • SampleProcessor

      public SampleProcessor()
  • Method Details

    • getName

      public String getName()
      Description copied from interface: FileActionComponent
      Name of the Parser. Used in the logs, to identify the FileActionComponent.
      Specified by:
      getName in interface FileActionComponent
      Returns:
      The description.
    • getDescription

      public String getDescription()
      Description copied from interface: FileActionComponent
      More detailed description of the Parser.
      Specified by:
      getDescription in interface FileActionComponent
      Returns:
      The description.
    • process

      public boolean process(File file, Map<String,Object> ctxt) throws ProcessingException
      Description copied from interface: FileProcessor
      Method invoked to process a file.
      Specified by:
      process in interface FileProcessor
      Parameters:
      file - the file to process
      ctxt - a Map to share informations between processings.
      Returns:
      true if the process was successfully performed, false if no action was processed (do not return false in case of error, instead throw a ProcessingException).
      Throws:
      ProcessingException - if the processing operation failed or if the file should be blacklisted (for this or all processors)
    • extractText

      public String extractText(File file, Map<String,Object> ctxt) throws ProcessingException
      Description copied from interface: FileParser
      Parsers have to implement at least this method which extract the text from the specified file and returns it.
      Specified by:
      extractText in interface FileParser
      Parameters:
      file - the file to parse
      ctxt - a Map to share informations between processings.
      Returns:
      the text to index (can be empty) or null if no action was processed (do not return null in case of error, instead throw a ProcessingException).
      Throws:
      ProcessingException - if the text could not be extracted.
    • getOrder

      public int getOrder()
      Description copied from interface: FileActionComponent
      Used to schedule the FileProcessors while treating a file. Default is 0. FileActionComponent are called in the same order as their order values.
      Specified by:
      getOrder in interface FileActionComponent
      Returns:
      order
    • isAvailable

      public boolean isAvailable()
      Description copied from interface: FileActionComponent
      A processor or parser may be unavailable (for instance because of a network connection down).
      Specified by:
      isAvailable in interface FileActionComponent
      Returns:
      true is the processor or parser is available