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 StringYAML_PARENT_INDENT_PROPERTY_NAMEstatic StringYAML_SCALAR_FLOW_PROPERTY_NAMEstatic StringYAML_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 voidclose()Closes the input document.ISkeletonWritercreateSkeletonWriter()Default case.EncoderManagergetEncoderManager()Gets the EncoderManager object for this filter.ParametersgetParameters()Gets the current parameters for this filter.voidhandleBlockSequenceNodeStart(String dash, int indent)Called at the start of a block sequence element (e.g., after the DASH "- test")voidhandleComment(String c, boolean insideScalar)Handle YAML comment process differently based on if this is inside a current TextUnitvoidhandleDocumentEnd(String end)Document end token.voidhandleDocumentStart(String start)Document start token.voidhandleEnd()Called once at the end of a document.voidhandleKey(Key key)Handle YAML keys, used in resnamevoidhandleMapEnd(boolean flow)voidhandleMappingElementEnd()Called after flow or mapping element is donevoidhandleMapStart(boolean flow)Handle Yaml Maps (BLOCK and FLOW) For contextual information.voidhandleMarker(String marker)Handle separator, i.e., "," or "-"voidhandleOther(String other)Other tokens like ANCHOR, TAG, ALIASvoidhandleScalar(Scalar scalar)Handle YAML valuevoidhandleSequenceEnd(boolean flow)voidhandleSequenceStart(boolean flow)Handle YAML sequences (BLOCK and FLOW) For contextual information.voidhandleStart()Called once at the beginning of a new document.voidhandleWhitespace(String whitespace, boolean isInsideScalar)Handle YAML whitespace process differently based on if this is inside a current TextUnitbooleanhasNext()Indicates if there is an event to process.protected booleanisUtf8Bom()Does the input have a UTF-8 Byte Order Mark?protected booleanisUtf8Encoding()Is the input encoded as UTF-8?Eventnext()Gets the next event available.voidopen(RawDocument input)Opens the input document described in a give RawDocument object.voidopen(RawDocument input, boolean generateSkeleton)Opens the input document described in a give RawDocument object, and optionally creates skeleton information.voidsetParameters(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:IFilterCloses 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:
closein interfaceAutoCloseable- Specified by:
closein interfaceIFilter- Overrides:
closein classAbstractFilter
-
hasNext
public boolean hasNext()
Description copied from interface:IFilterIndicates 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:IFilterGets 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:IFilterOpens 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:IFilterOpens the input document described in a give RawDocument object, and optionally creates skeleton information.- Specified by:
openin interfaceIFilter- Overrides:
openin 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:IFilterGets the current parameters for this filter.- Specified by:
getParametersin interfaceIFilter- Overrides:
getParametersin classAbstractFilter- Returns:
- The current parameters for this filter, or
DefaultParametersif this filter has no parameters.
-
setParameters
public void setParameters(IParameters params)
Description copied from interface:IFilterSets new parameters for this filter.- Specified by:
setParametersin interfaceIFilter- Overrides:
setParametersin classAbstractFilter- Parameters:
params- The new parameters to use.
-
getEncoderManager
public EncoderManager getEncoderManager()
Description copied from interface:IFilterGets the EncoderManager object for this filter. This encoder manager should provided the mappings to the different MIME types used by the filter.- Specified by:
getEncoderManagerin interfaceIFilter- Overrides:
getEncoderManagerin classAbstractFilter- Returns:
- the EncoderManager for this filter.
-
createSkeletonWriter
public ISkeletonWriter createSkeletonWriter()
Description copied from class:AbstractFilterDefault case. Override if needed.- Specified by:
createSkeletonWriterin interfaceIFilter- Overrides:
createSkeletonWriterin classAbstractFilter- Returns:
- new instance of
GenericSkeletonWriter
-
isUtf8Encoding
protected boolean isUtf8Encoding()
Description copied from class:AbstractFilterIs the input encoded as UTF-8?- Overrides:
isUtf8Encodingin classAbstractFilter- Returns:
- true if the document is in utf8 encoding.
-
isUtf8Bom
protected boolean isUtf8Bom()
Description copied from class:AbstractFilterDoes the input have a UTF-8 Byte Order Mark?- Overrides:
isUtf8Bomin classAbstractFilter- Returns:
- true if the document has a utf-8 byte order mark.
-
handleStart
public void handleStart()
Description copied from interface:IYamlHandlerCalled once at the beginning of a new document.- Specified by:
handleStartin interfaceIYamlHandler
-
handleEnd
public void handleEnd()
Description copied from interface:IYamlHandlerCalled once at the end of a document.- Specified by:
handleEndin interfaceIYamlHandler
-
handleComment
public void handleComment(String c, boolean insideScalar)
Description copied from interface:IYamlHandlerHandle YAML comment process differently based on if this is inside a current TextUnit- Specified by:
handleCommentin interfaceIYamlHandler
-
handleKey
public void handleKey(Key key)
Description copied from interface:IYamlHandlerHandle YAML keys, used in resname- Specified by:
handleKeyin interfaceIYamlHandler
-
handleWhitespace
public void handleWhitespace(String whitespace, boolean isInsideScalar)
Description copied from interface:IYamlHandlerHandle YAML whitespace process differently based on if this is inside a current TextUnit- Specified by:
handleWhitespacein interfaceIYamlHandler
-
handleScalar
public void handleScalar(Scalar scalar)
Description copied from interface:IYamlHandlerHandle YAML value- Specified by:
handleScalarin interfaceIYamlHandler
-
handleMapStart
public void handleMapStart(boolean flow)
Description copied from interface:IYamlHandlerHandle Yaml Maps (BLOCK and FLOW) For contextual information.- Specified by:
handleMapStartin interfaceIYamlHandler
-
handleMapEnd
public void handleMapEnd(boolean flow)
- Specified by:
handleMapEndin interfaceIYamlHandler
-
handleSequenceStart
public void handleSequenceStart(boolean flow)
Description copied from interface:IYamlHandlerHandle YAML sequences (BLOCK and FLOW) For contextual information.- Specified by:
handleSequenceStartin interfaceIYamlHandler
-
handleSequenceEnd
public void handleSequenceEnd(boolean flow)
- Specified by:
handleSequenceEndin interfaceIYamlHandler
-
handleMarker
public void handleMarker(String marker)
Description copied from interface:IYamlHandlerHandle separator, i.e., "," or "-"- Specified by:
handleMarkerin interfaceIYamlHandler
-
handleOther
public void handleOther(String other)
Description copied from interface:IYamlHandlerOther tokens like ANCHOR, TAG, ALIAS- Specified by:
handleOtherin interfaceIYamlHandler
-
handleDocumentStart
public void handleDocumentStart(String start)
Description copied from interface:IYamlHandlerDocument start token. If non-null then start clean (clear stacks, finish TextUnits etc..)- Specified by:
handleDocumentStartin interfaceIYamlHandler
-
handleDocumentEnd
public void handleDocumentEnd(String end)
Description copied from interface:IYamlHandlerDocument end token. If non-null then clean up (clear stacks, finish TextUnits etc..)- Specified by:
handleDocumentEndin interfaceIYamlHandler
-
handleMappingElementEnd
public void handleMappingElementEnd()
Description copied from interface:IYamlHandlerCalled after flow or mapping element is done- Specified by:
handleMappingElementEndin interfaceIYamlHandler
-
handleBlockSequenceNodeStart
public void handleBlockSequenceNodeStart(String dash, int indent)
Description copied from interface:IYamlHandlerCalled at the start of a block sequence element (e.g., after the DASH "- test")- Specified by:
handleBlockSequenceNodeStartin interfaceIYamlHandler
-
-