Package org.opensextant.output
Class AbstractGenericFormatter
- java.lang.Object
-
- org.opensextant.output.AbstractGenericFormatter
-
- All Implemented Interfaces:
ResultsFormatter
- Direct Known Subclasses:
CSVGenericFormatter
public abstract class AbstractGenericFormatter extends java.lang.Object implements ResultsFormatter
Abstract class encapsulating basic results formatter functionality without prescribing schema- Author:
- Marc Ubaldino, MITRE Corp.
-
-
Field Summary
Fields Modifier and Type Field Description boolean
debug
protected java.util.List<java.lang.String>
fieldOrder
The field_order.protected java.util.HashSet<java.lang.String>
fieldSet
Distinct set of fields in your output schema.protected org.slf4j.Logger
log
java.lang.String
outputExtension
File extension for callers to know.protected Parameters
outputParams
The output params.protected java.lang.String
outputType
reflected by extension; an enum in OpenSextantboolean
overwrite
The overwrite.protected static int
TEXT_WIDTH
Size of text window around matches -- to use as excerpts
-
Constructor Summary
Constructors Constructor Description AbstractGenericFormatter()
-
Method Summary
Modifier and Type Method Description void
addField(java.lang.String f)
Adds the field.protected void
checkOverwrite(java.io.File item)
uniform helper for overwrite check.protected abstract void
closeOutputStreams()
Close output streams.protected java.lang.String
createOutputFileName()
Creates the output file name.protected abstract void
createOutputStreams()
Create the output stream appropriate for the output type.protected void
defaultFields()
Default fields for generic CSV output.protected void
deleteOutput(java.io.File prevOutput)
This is checked only by internal classes as they create output streams.abstract void
finish()
Finish.java.lang.String
getJobName()
A basic job name that reflects file name.java.lang.String
getOutputFilepath()
Gets the output filepath.java.lang.String
getOutputType()
Gets the output type.void
removeField(java.lang.String f)
Removes the field.void
setOutputDir(java.lang.String path)
Sets the output dir.void
setOutputFilename(java.lang.String fname)
Sets the output filename.void
setParameters(Parameters params)
Sets the parameters.abstract void
start(java.lang.String nm)
Start.abstract void
writeRow(java.util.Map<java.lang.String,java.lang.Object> values)
Write the data to the output stream.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.opensextant.output.ResultsFormatter
formatResults
-
-
-
-
Field Detail
-
outputParams
protected Parameters outputParams
The output params.
-
overwrite
public boolean overwrite
The overwrite.
-
log
protected final org.slf4j.Logger log
-
outputExtension
public java.lang.String outputExtension
File extension for callers to know.
-
outputType
protected java.lang.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 java.util.HashSet<java.lang.String> fieldSet
Distinct set of fields in your output schema.
-
fieldOrder
protected java.util.List<java.lang.String> fieldOrder
The field_order.
-
-
Method Detail
-
setParameters
public void setParameters(Parameters params)
Sets the parameters.- Specified by:
setParameters
in interfaceResultsFormatter
- Parameters:
params
- job parameters
-
addField
public void addField(java.lang.String f) throws ConfigException
Adds the field.- Specified by:
addField
in interfaceResultsFormatter
- Parameters:
f
- field name- Throws:
ConfigException
-
removeField
public void removeField(java.lang.String f) throws ConfigException
Removes the field.- Specified by:
removeField
in interfaceResultsFormatter
- 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 java.lang.String getJobName()
A basic job name that reflects file name.- Specified by:
getJobName
in interfaceResultsFormatter
- Returns:
- the job name
-
setOutputFilename
public void setOutputFilename(java.lang.String fname)
Sets the output filename.- Specified by:
setOutputFilename
in interfaceResultsFormatter
- Parameters:
fname
- the new output filename
-
setOutputDir
public void setOutputDir(java.lang.String path)
Sets the output dir.- Specified by:
setOutputDir
in interfaceResultsFormatter
- Parameters:
path
- the new output dir
-
getOutputFilepath
public java.lang.String getOutputFilepath()
Gets the output filepath.- Specified by:
getOutputFilepath
in interfaceResultsFormatter
- Returns:
- the output filepath
-
createOutputFileName
protected java.lang.String createOutputFileName()
Creates the output file name.- Returns:
- the string
-
getOutputType
public java.lang.String getOutputType()
Gets the output type.- Specified by:
getOutputType
in interfaceResultsFormatter
- Returns:
- the output type
-
deleteOutput
protected void deleteOutput(java.io.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(java.io.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(java.lang.String nm) throws ProcessingException
Start.- Specified by:
start
in interfaceResultsFormatter
- Parameters:
nm
- output file name/worksheet name- Throws:
ProcessingException
-
writeRow
public abstract void writeRow(java.util.Map<java.lang.String,java.lang.Object> values)
Write the data to the output stream.- Parameters:
values
- Map of data
-
finish
public abstract void finish()
Finish.- Specified by:
finish
in interfaceResultsFormatter
-
createOutputStreams
protected abstract void createOutputStreams() throws java.lang.Exception
Create the output stream appropriate for the output type. IO is created using the filename represented by getOutputFilepath()- Throws:
java.lang.Exception
- when unable to create output stream
-
closeOutputStreams
protected abstract void closeOutputStreams() throws java.lang.Exception
Close output streams.- Throws:
java.lang.Exception
-
-