Package net.sf.okapi.common.filterwriter
Class GenericFilterWriter
- java.lang.Object
-
- net.sf.okapi.common.filterwriter.GenericFilterWriter
-
- All Implemented Interfaces:
AutoCloseable
,IFilterWriter
- Direct Known Subclasses:
MarkdownFilterWriter
public class GenericFilterWriter extends Object implements IFilterWriter
Implements the IFilterWriter interface for filters that use the GenericSkeleton skeleton.
-
-
Field Summary
Fields Modifier and Type Field Description protected OutputStreamWriter
writer
-
Constructor Summary
Constructors Constructor Description GenericFilterWriter()
GenericFilterWriter(ISkeletonWriter skelWriter, EncoderManager encoderManager)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
cancel()
Cancels the current process.void
close()
Closes the output.protected CharsetEncoder
createCharsetEncoder(String encodingtoUse)
Provides sub-classes an opportunity to creates the character set encoder for the output.protected void
createWriter(StartDocument resource)
String
getDefEncoding()
EncoderManager
getEncoderManager()
Gets the current encoder manager for this writer.protected String
getEncoding()
LocaleId
getLocale()
String
getName()
Gets the name of this writer.protected String
getOutputPath()
IParameters
getParameters()
Gets the current parameters for this writer.ISkeletonWriter
getSkeletonWriter()
Gets the skeleton writer associated with this writer.Event
handleEvent(Event event)
Handles the filter events.protected void
processDocumentPart(DocumentPart resource)
protected void
processEndDocument(Ending resource)
protected void
processEndGroup(Ending resource)
protected void
processEndSubDocument(Ending resource)
protected void
processEndSubfilter(EndSubfilter resource)
protected void
processStartDocument(LocaleId outputLocale, String outputEncoding, StartDocument resource)
protected void
processStartGroup(StartGroup resource)
protected void
processStartSubDocument(StartSubDocument resource)
protected void
processStartSubfilter(StartSubfilter resource)
protected void
processTextUnit(ITextUnit resource)
protected void
setEncoderManager(EncoderManager encoderManager)
protected void
setEncoding(String encoding)
protected void
setLocale(LocaleId locale)
void
setOptions(LocaleId locale, String defaultEncoding)
Sets the options for this writer.void
setOutput(OutputStream output)
Sets the output through its output stream.void
setOutput(String path)
Sets the output through the path of the output file.void
setParameters(IParameters params)
Sets new parameters for this writer.protected void
setSkelWriter(ISkeletonWriter skelWriter)
-
-
-
Field Detail
-
writer
protected OutputStreamWriter writer
-
-
Constructor Detail
-
GenericFilterWriter
public GenericFilterWriter()
-
GenericFilterWriter
public GenericFilterWriter(ISkeletonWriter skelWriter, EncoderManager encoderManager)
-
-
Method Detail
-
cancel
public void cancel()
Description copied from interface:IFilterWriter
Cancels the current process.- Specified by:
cancel
in interfaceIFilterWriter
-
close
public void close()
Description copied from interface:IFilterWriter
Closes the output. Developers must make sure this method is safe to call even if there is nothing to close.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceIFilterWriter
-
getName
public String getName()
Description copied from interface:IFilterWriter
Gets the name of this writer.- Specified by:
getName
in interfaceIFilterWriter
- Returns:
- The name of the writer.
-
getEncoderManager
public EncoderManager getEncoderManager()
Description copied from interface:IFilterWriter
Gets the current encoder manager for this writer. Some special implementation of IFilterWriter may not use an encoder manager (for example writers that do not use skeleton).- Specified by:
getEncoderManager
in interfaceIFilterWriter
- Returns:
- the current encoder manager for this writer, or null if none exists for this writer.
-
getSkeletonWriter
public ISkeletonWriter getSkeletonWriter()
Description copied from interface:IFilterWriter
Gets the skeleton writer associated with this writer. Some implementation of IFilterWriter may not use a skeleton writer.- Specified by:
getSkeletonWriter
in interfaceIFilterWriter
- Returns:
- the skeleton writer associated with this writer or null if none is associated.
-
setSkelWriter
protected void setSkelWriter(ISkeletonWriter skelWriter)
-
getParameters
public IParameters getParameters()
Description copied from interface:IFilterWriter
Gets the current parameters for this writer.- Specified by:
getParameters
in interfaceIFilterWriter
- Returns:
- The current parameters for this writer.
-
handleEvent
public Event handleEvent(Event event)
Description copied from interface:IFilterWriter
Handles the filter events.- Specified by:
handleEvent
in interfaceIFilterWriter
- Parameters:
event
- The event to process.- Returns:
- The event that was processed.
-
processStartDocument
protected void processStartDocument(LocaleId outputLocale, String outputEncoding, StartDocument resource) throws IOException
- Throws:
IOException
-
processEndDocument
protected void processEndDocument(Ending resource) throws IOException
- Throws:
IOException
-
processStartSubDocument
protected void processStartSubDocument(StartSubDocument resource) throws IOException
- Throws:
IOException
-
processEndSubDocument
protected void processEndSubDocument(Ending resource) throws IOException
- Throws:
IOException
-
processStartGroup
protected void processStartGroup(StartGroup resource) throws IOException
- Throws:
IOException
-
processEndGroup
protected void processEndGroup(Ending resource) throws IOException
- Throws:
IOException
-
processTextUnit
protected void processTextUnit(ITextUnit resource) throws IOException
- Throws:
IOException
-
processDocumentPart
protected void processDocumentPart(DocumentPart resource) throws IOException
- Throws:
IOException
-
processStartSubfilter
protected void processStartSubfilter(StartSubfilter resource) throws IOException
- Throws:
IOException
-
processEndSubfilter
protected void processEndSubfilter(EndSubfilter resource) throws IOException
- Throws:
IOException
-
setOptions
public void setOptions(LocaleId locale, String defaultEncoding)
Description copied from interface:IFilterWriter
Sets the options for this writer.- Specified by:
setOptions
in interfaceIFilterWriter
- Parameters:
locale
- the output locale.defaultEncoding
- Name of the character set encoding for the output.
-
setOutput
public void setOutput(String path)
Description copied from interface:IFilterWriter
Sets the output through the path of the output file.- Specified by:
setOutput
in interfaceIFilterWriter
- Parameters:
path
- Full path of the output file.
-
setOutput
public void setOutput(OutputStream output)
Description copied from interface:IFilterWriter
Sets the output through its output stream.- Specified by:
setOutput
in interfaceIFilterWriter
- Parameters:
output
- Output stream to use for the output.
-
setParameters
public void setParameters(IParameters params)
Description copied from interface:IFilterWriter
Sets new parameters for this writer.- Specified by:
setParameters
in interfaceIFilterWriter
- Parameters:
params
- The new parameters to use.
-
createCharsetEncoder
protected CharsetEncoder createCharsetEncoder(String encodingtoUse)
Provides sub-classes an opportunity to creates the character set encoder for the output.- Parameters:
encodingtoUse
- the name of the encoding to use.- Returns:
- the decoder to use for the output or null. When null is returned (default) the output uses the encoding.
-
createWriter
protected void createWriter(StartDocument resource)
-
getLocale
public final LocaleId getLocale()
-
getDefEncoding
public final String getDefEncoding()
-
getEncoding
protected String getEncoding()
-
setEncoding
protected void setEncoding(String encoding)
-
getOutputPath
protected String getOutputPath()
-
setLocale
protected void setLocale(LocaleId locale)
-
setEncoderManager
protected void setEncoderManager(EncoderManager encoderManager)
-
-