Class AbstractGenericFormatter

java.lang.Object
org.opensextant.output.AbstractGenericFormatter
All Implemented Interfaces:
ResultsFormatter
Direct Known Subclasses:
CSVGenericFormatter

public abstract class AbstractGenericFormatter extends Object implements ResultsFormatter
Abstract class encapsulating basic results formatter functionality without prescribing schema
Author:
Marc Ubaldino, MITRE Corp.
  • Field Details

    • outputParams

      protected Parameters outputParams
      The output params.
    • overwrite

      public boolean overwrite
      The overwrite.
    • log

      protected final org.slf4j.Logger log
    • outputExtension

      public String outputExtension
      File extension for callers to know.
    • outputType

      protected String outputType
      reflected by extension; an enum in OpenSextant
    • TEXT_WIDTH

      protected static int TEXT_WIDTH
      Size of text window around matches -- to use as excerpts
    • debug

      public boolean debug
    • fieldSet

      protected HashSet<String> fieldSet
      Distinct set of fields in your output schema.
    • fieldOrder

      protected List<String> fieldOrder
      The field_order.
  • Constructor Details

    • AbstractGenericFormatter

      public AbstractGenericFormatter()
  • Method Details

    • setParameters

      public void setParameters(Parameters params)
      Sets the parameters.
      Specified by:
      setParameters in interface ResultsFormatter
      Parameters:
      params - job parameters
    • addField

      public void addField(String f) throws ConfigException
      Adds the field.
      Specified by:
      addField in interface ResultsFormatter
      Parameters:
      f - field name
      Throws:
      ConfigException
    • removeField

      public void removeField(String f) throws ConfigException
      Removes the field.
      Specified by:
      removeField in interface ResultsFormatter
      Parameters:
      f - field name
      Throws:
      ConfigException
    • defaultFields

      protected final void defaultFields()
      Default fields for generic CSV output. If GIS output is desired, then use GeoCSV formatter.
    • getJobName

      public String getJobName()
      A basic job name that reflects file name.
      Specified by:
      getJobName in interface ResultsFormatter
      Returns:
      the job name
    • setOutputFilename

      public void setOutputFilename(String fname)
      Sets the output filename.
      Specified by:
      setOutputFilename in interface ResultsFormatter
      Parameters:
      fname - the new output filename
    • setOutputDir

      public void setOutputDir(String path)
      Sets the output dir.
      Specified by:
      setOutputDir in interface ResultsFormatter
      Parameters:
      path - the new output dir
    • getOutputFilepath

      public String getOutputFilepath()
      Gets the output filepath.
      Specified by:
      getOutputFilepath in interface ResultsFormatter
      Returns:
      the output filepath
    • createOutputFileName

      protected String createOutputFileName()
      Creates the output file name.
      Returns:
      the string
    • getOutputType

      public String getOutputType()
      Gets the output type.
      Specified by:
      getOutputType in interface ResultsFormatter
      Returns:
      the output type
    • deleteOutput

      protected void deleteOutput(File prevOutput)
      This is checked only by internal classes as they create output streams.
      Parameters:
      prevOutput - file path of previous output
    • checkOverwrite

      protected void checkOverwrite(File item) throws ProcessingException
      uniform helper for overwrite check.
      Parameters:
      item - target output file
      Throws:
      ProcessingException - if unable to overwrite file
    • start

      public abstract void start(String nm) throws ProcessingException
      Start.
      Specified by:
      start in interface ResultsFormatter
      Parameters:
      nm - output file name/worksheet name
      Throws:
      ProcessingException
    • writeRow

      public abstract void writeRow(Map<String,Object> values)
      Write the data to the output stream.
      Parameters:
      values - Map of data
    • finish

      public abstract void finish()
      Finish.
      Specified by:
      finish in interface ResultsFormatter
    • createOutputStreams

      protected abstract void createOutputStreams() throws Exception
      Create the output stream appropriate for the output type. IO is created using the filename represented by getOutputFilepath()
      Throws:
      Exception - when unable to create output stream
    • closeOutputStreams

      protected abstract void closeOutputStreams() throws Exception
      Close output streams.
      Throws:
      Exception