Package net.sf.okapi.filters.json
Class JSONFilter
- java.lang.Object
-
- net.sf.okapi.common.filters.AbstractFilter
-
- net.sf.okapi.filters.json.JSONFilter
-
- All Implemented Interfaces:
AutoCloseable
,Iterator<Event>
,IFilter
,IJsonHandler
public class JSONFilter extends AbstractFilter implements IJsonHandler
Implements the IFilter interface for JSON files.
-
-
Field Summary
-
Fields inherited from interface net.sf.okapi.common.filters.IFilter
SUB_FILTER
-
-
Constructor Summary
Constructors Constructor Description JSONFilter()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Closes the input document.EncoderManager
getEncoderManager()
Gets the EncoderManager object for this filter.Parameters
getParameters()
Gets the current parameters for this filter.void
handleComment(String c)
Handle Json comment (illegal but found in partice)void
handleEnd()
Called once at the end of a document.void
handleKey(String key, JsonValueTypes valueType, JsonKeyTypes keyType)
Handle json key, used in resnamevoid
handleListEnd()
void
handleListStart()
Handle json List: i.e., [ "value1", "value2" ] For contextual information.void
handleObjectEnd()
void
handleObjectStart()
Handle json Object: i.e., { "key" : "value" } For contextual information.void
handleSeparator(String separator)
Handle separator, i.e., ":" or ","void
handleStart()
Called once at the beginning of a new document.void
handleValue(String value, JsonValueTypes valueType)
Handle json value, may be double, single quoted string, number, boolean symbol or nullvoid
handleWhitespace(String whitespace)
Handle json whitespaceboolean
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, createSkeletonWriter, 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
-
-
-
-
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.
-
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:IJsonHandler
Called once at the beginning of a new document.- Specified by:
handleStart
in interfaceIJsonHandler
-
handleEnd
public void handleEnd()
Description copied from interface:IJsonHandler
Called once at the end of a document.- Specified by:
handleEnd
in interfaceIJsonHandler
-
handleComment
public void handleComment(String c)
Description copied from interface:IJsonHandler
Handle Json comment (illegal but found in partice)- Specified by:
handleComment
in interfaceIJsonHandler
-
handleKey
public void handleKey(String key, JsonValueTypes valueType, JsonKeyTypes keyType)
Description copied from interface:IJsonHandler
Handle json key, used in resname- Specified by:
handleKey
in interfaceIJsonHandler
-
handleWhitespace
public void handleWhitespace(String whitespace)
Description copied from interface:IJsonHandler
Handle json whitespace- Specified by:
handleWhitespace
in interfaceIJsonHandler
-
handleValue
public void handleValue(String value, JsonValueTypes valueType)
Description copied from interface:IJsonHandler
Handle json value, may be double, single quoted string, number, boolean symbol or null- Specified by:
handleValue
in interfaceIJsonHandler
-
handleObjectStart
public void handleObjectStart()
Description copied from interface:IJsonHandler
Handle json Object: i.e., { "key" : "value" } For contextual information.- Specified by:
handleObjectStart
in interfaceIJsonHandler
-
handleObjectEnd
public void handleObjectEnd()
- Specified by:
handleObjectEnd
in interfaceIJsonHandler
-
handleListStart
public void handleListStart()
Description copied from interface:IJsonHandler
Handle json List: i.e., [ "value1", "value2" ] For contextual information.- Specified by:
handleListStart
in interfaceIJsonHandler
-
handleListEnd
public void handleListEnd()
- Specified by:
handleListEnd
in interfaceIJsonHandler
-
handleSeparator
public void handleSeparator(String separator)
Description copied from interface:IJsonHandler
Handle separator, i.e., ":" or ","- Specified by:
handleSeparator
in interfaceIJsonHandler
-
-