Package net.sf.okapi.filters.yaml
Class YamlFilter
- java.lang.Object
-
- net.sf.okapi.common.filters.AbstractFilter
-
- net.sf.okapi.filters.yaml.YamlFilter
-
- All Implemented Interfaces:
AutoCloseable
,Iterator<Event>
,IFilter
,IYamlHandler
public class YamlFilter extends AbstractFilter implements IYamlHandler
Implements the IFilter interface for YAML files.
-
-
Field Summary
Fields Modifier and Type Field Description static String
YAML_PARENT_INDENT_PROPERTY_NAME
static String
YAML_SCALAR_FLOW_PROPERTY_NAME
static String
YAML_SCALAR_TYPE_PROPERTY_NAME
-
Fields inherited from interface net.sf.okapi.common.filters.IFilter
SUB_FILTER
-
-
Constructor Summary
Constructors Constructor Description YamlFilter()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Closes the input document.ISkeletonWriter
createSkeletonWriter()
Default case.EncoderManager
getEncoderManager()
Gets the EncoderManager object for this filter.Parameters
getParameters()
Gets the current parameters for this filter.void
handleBlockSequenceNodeStart(String dash, int indent)
Called at the start of a block sequence element (e.g., after the DASH "- test")void
handleComment(String c, boolean insideScalar)
Handle YAML comment process differently based on if this is inside a current TextUnitvoid
handleDocumentEnd(String end)
Document end token.void
handleDocumentStart(String start)
Document start token.void
handleEnd()
Called once at the end of a document.void
handleKey(Key key)
Handle YAML keys, used in resnamevoid
handleMapEnd(boolean flow)
void
handleMappingElementEnd()
Called after flow or mapping element is donevoid
handleMapStart(boolean flow)
Handle Yaml Maps (BLOCK and FLOW) For contextual information.void
handleMarker(String marker)
Handle separator, i.e., "," or "-"void
handleOther(String other)
Other tokens like ANCHOR, TAG, ALIASvoid
handleScalar(Scalar scalar)
Handle YAML valuevoid
handleSequenceEnd(boolean flow)
void
handleSequenceStart(boolean flow)
Handle YAML sequences (BLOCK and FLOW) For contextual information.void
handleStart()
Called once at the beginning of a new document.void
handleWhitespace(String whitespace, boolean isInsideScalar)
Handle YAML whitespace process differently based on if this is inside a current TextUnitboolean
hasNext()
Indicates if there is an event to process.protected boolean
isUtf8Bom()
Does the input have a UTF-8 Byte Order Mark?protected boolean
isUtf8Encoding()
Is the input encoded as UTF-8?Event
next()
Gets the next event available.void
open(RawDocument input)
Opens the input document described in a give RawDocument object.void
open(RawDocument input, boolean generateSkeleton)
Opens the input document described in a give RawDocument object, and optionally creates skeleton information.void
setParameters(IParameters params)
Sets new parameters for this filter.-
Methods inherited from class net.sf.okapi.common.filters.AbstractFilter
addConfiguration, addConfiguration, addConfiguration, addConfigurations, cancel, createEndFilterEvent, createFilterWriter, createStartFilterEvent, findConfiguration, getConfiguration, getConfigurations, getDisplayName, getDocumentId, getDocumentName, getEncoding, getFilterConfigurationMapper, getMimeType, getName, getNewlineType, getParameters, getParametersClassName, getParentId, getSrcLoc, getTrgLoc, isCanceled, isGenerateSkeleton, isMultilingual, removeConfiguration, setDisplayName, setDocumentName, setEncoding, setFilterConfigurationMapper, setGenerateSkeleton, setMimeType, setMultilingual, setName, setNewlineType, setOptions, setParentId, setSrcLoc, setTrgLoc
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.util.Iterator
forEachRemaining, remove
-
-
-
-
Field Detail
-
YAML_SCALAR_TYPE_PROPERTY_NAME
public static final String YAML_SCALAR_TYPE_PROPERTY_NAME
- See Also:
- Constant Field Values
-
YAML_PARENT_INDENT_PROPERTY_NAME
public static final String YAML_PARENT_INDENT_PROPERTY_NAME
- See Also:
- Constant Field Values
-
YAML_SCALAR_FLOW_PROPERTY_NAME
public static final String YAML_SCALAR_FLOW_PROPERTY_NAME
- See Also:
- Constant Field Values
-
-
Method Detail
-
close
public void close()
Description copied from interface:IFilter
Closes the input document. Developers should call this method from within their code before sending the last event: This can allow writer objects to overwrite the input file when they receive the last event. This method must also be safe to call even if the input document is not opened.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceIFilter
- Overrides:
close
in classAbstractFilter
-
hasNext
public boolean hasNext()
Description copied from interface:IFilter
Indicates if there is an event to process.Implementer Note: The caller must be able to call this method several times without changing state.
-
next
public Event next()
Description copied from interface:IFilter
Gets the next event available. Calling this method can be done only once on each event.
-
open
public void open(RawDocument input)
Description copied from interface:IFilter
Opens the input document described in a give RawDocument object. Skeleton information is always created when you use this method.
-
open
public void open(RawDocument input, boolean generateSkeleton)
Description copied from interface:IFilter
Opens the input document described in a give RawDocument object, and optionally creates skeleton information.- Specified by:
open
in interfaceIFilter
- Overrides:
open
in classAbstractFilter
- Parameters:
input
- The RawDocument object to use to open the document.generateSkeleton
- true to generate the skeleton data, false otherwise.
-
getParameters
public Parameters getParameters()
Description copied from interface:IFilter
Gets the current parameters for this filter.- Specified by:
getParameters
in interfaceIFilter
- Overrides:
getParameters
in classAbstractFilter
- Returns:
- The current parameters for this filter, or
DefaultParameters
if this filter has no parameters.
-
setParameters
public void setParameters(IParameters params)
Description copied from interface:IFilter
Sets new parameters for this filter.- Specified by:
setParameters
in interfaceIFilter
- Overrides:
setParameters
in classAbstractFilter
- Parameters:
params
- The new parameters to use.
-
getEncoderManager
public EncoderManager getEncoderManager()
Description copied from interface:IFilter
Gets the EncoderManager object for this filter. This encoder manager should provided the mappings to the different MIME types used by the filter.- Specified by:
getEncoderManager
in interfaceIFilter
- Overrides:
getEncoderManager
in classAbstractFilter
- Returns:
- the EncoderManager for this filter.
-
createSkeletonWriter
public ISkeletonWriter createSkeletonWriter()
Description copied from class:AbstractFilter
Default case. Override if needed.- Specified by:
createSkeletonWriter
in interfaceIFilter
- Overrides:
createSkeletonWriter
in classAbstractFilter
- Returns:
- new instance of
GenericSkeletonWriter
-
isUtf8Encoding
protected boolean isUtf8Encoding()
Description copied from class:AbstractFilter
Is the input encoded as UTF-8?- Overrides:
isUtf8Encoding
in classAbstractFilter
- Returns:
- true if the document is in utf8 encoding.
-
isUtf8Bom
protected boolean isUtf8Bom()
Description copied from class:AbstractFilter
Does the input have a UTF-8 Byte Order Mark?- Overrides:
isUtf8Bom
in classAbstractFilter
- Returns:
- true if the document has a utf-8 byte order mark.
-
handleStart
public void handleStart()
Description copied from interface:IYamlHandler
Called once at the beginning of a new document.- Specified by:
handleStart
in interfaceIYamlHandler
-
handleEnd
public void handleEnd()
Description copied from interface:IYamlHandler
Called once at the end of a document.- Specified by:
handleEnd
in interfaceIYamlHandler
-
handleComment
public void handleComment(String c, boolean insideScalar)
Description copied from interface:IYamlHandler
Handle YAML comment process differently based on if this is inside a current TextUnit- Specified by:
handleComment
in interfaceIYamlHandler
-
handleKey
public void handleKey(Key key)
Description copied from interface:IYamlHandler
Handle YAML keys, used in resname- Specified by:
handleKey
in interfaceIYamlHandler
-
handleWhitespace
public void handleWhitespace(String whitespace, boolean isInsideScalar)
Description copied from interface:IYamlHandler
Handle YAML whitespace process differently based on if this is inside a current TextUnit- Specified by:
handleWhitespace
in interfaceIYamlHandler
-
handleScalar
public void handleScalar(Scalar scalar)
Description copied from interface:IYamlHandler
Handle YAML value- Specified by:
handleScalar
in interfaceIYamlHandler
-
handleMapStart
public void handleMapStart(boolean flow)
Description copied from interface:IYamlHandler
Handle Yaml Maps (BLOCK and FLOW) For contextual information.- Specified by:
handleMapStart
in interfaceIYamlHandler
-
handleMapEnd
public void handleMapEnd(boolean flow)
- Specified by:
handleMapEnd
in interfaceIYamlHandler
-
handleSequenceStart
public void handleSequenceStart(boolean flow)
Description copied from interface:IYamlHandler
Handle YAML sequences (BLOCK and FLOW) For contextual information.- Specified by:
handleSequenceStart
in interfaceIYamlHandler
-
handleSequenceEnd
public void handleSequenceEnd(boolean flow)
- Specified by:
handleSequenceEnd
in interfaceIYamlHandler
-
handleMarker
public void handleMarker(String marker)
Description copied from interface:IYamlHandler
Handle separator, i.e., "," or "-"- Specified by:
handleMarker
in interfaceIYamlHandler
-
handleOther
public void handleOther(String other)
Description copied from interface:IYamlHandler
Other tokens like ANCHOR, TAG, ALIAS- Specified by:
handleOther
in interfaceIYamlHandler
-
handleDocumentStart
public void handleDocumentStart(String start)
Description copied from interface:IYamlHandler
Document start token. If non-null then start clean (clear stacks, finish TextUnits etc..)- Specified by:
handleDocumentStart
in interfaceIYamlHandler
-
handleDocumentEnd
public void handleDocumentEnd(String end)
Description copied from interface:IYamlHandler
Document end token. If non-null then clean up (clear stacks, finish TextUnits etc..)- Specified by:
handleDocumentEnd
in interfaceIYamlHandler
-
handleMappingElementEnd
public void handleMappingElementEnd()
Description copied from interface:IYamlHandler
Called after flow or mapping element is done- Specified by:
handleMappingElementEnd
in interfaceIYamlHandler
-
handleBlockSequenceNodeStart
public void handleBlockSequenceNodeStart(String dash, int indent)
Description copied from interface:IYamlHandler
Called at the start of a block sequence element (e.g., after the DASH "- test")- Specified by:
handleBlockSequenceNodeStart
in interfaceIYamlHandler
-
-