Package net.sf.okapi.lib.xliff2.reader
Class XLIFFReader
- java.lang.Object
-
- net.sf.okapi.lib.xliff2.reader.XLIFFReader
-
- All Implemented Interfaces:
Closeable,AutoCloseable
public class XLIFFReader extends Object implements Closeable
Implements a stream-based and event-driven XLIFF reader.
-
-
Field Summary
Fields Modifier and Type Field Description static intVALIDATION_INCLUDE_FRAGIDPREFIXIncludes validation of the fragment identification values.static intVALIDATION_INCLUDE_SCHEMASIncludes schemas-based validation.static intVALIDATION_MAXIMALPerforms as much validation as possible with the reader (which may not be a full validation for the modules, depending on the modules supported).static intVALIDATION_MINIMALPerforms as little validation as possible.
-
Constructor Summary
Constructors Constructor Description XLIFFReader()Creates a new XLIFFReader object with full validation.XLIFFReader(int validation)Creates a new XLIFFReader object.XLIFFReader(int validation, URIParser uriParserToUse)Creates a new XLIFFReader object.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Closes the document.intgetWarningCount()Gets the number of warnings.booleanhasNext()Indicates if there is another event.Eventnext()Gets the next filter event.voidopen(File file)Opens an XLIFF document by its File object.voidopen(InputStream inputStream)Opens an XLIFF document by its stream.voidopen(String input)Opens an XLIFF document passed as a string.voidopen(URI inputURI)Opens an XLIFF document by its URI.protected voidprocessMatches()voidsetDiscardInvalidTargets(boolean discardInvalidTargets)If set, discard invalid target data and report it as a warning, rather than an error.voidsetForceUniqueIds(boolean forceUniqueIds)If set, include the segment id in the tag id to enforce uniqueness.voidsetIgnoreTagTypeMatch(boolean ignoreTagTypeMatch)If set, force tag types in the target to match their corresponding tag type in source.voidsetReportUnsingnificantParts(boolean reportUnsingnificantParts)Sets the flag to report or not parts of the documents that are not significant.static voidvalidate(File file)Validates an XLIFF document passed as a File object.static voidvalidate(File file, URIParser uriParser)Validates an XLIFF document passed as a File object.static voidvalidate(InputStream inputStream, URIParser uriParser)Validates an XLIFF document passed as a stream.static voidvalidate(String input, URIParser uriParser)Validates an XLIFF document passed as a string.static voidvalidate(URI inputURI, URIParser uriParser)Validates an XLIFF document passed as a URI.
-
-
-
Field Detail
-
VALIDATION_MINIMAL
public static final int VALIDATION_MINIMAL
Performs as little validation as possible.- See Also:
- Constant Field Values
-
VALIDATION_MAXIMAL
public static final int VALIDATION_MAXIMAL
Performs as much validation as possible with the reader (which may not be a full validation for the modules, depending on the modules supported).- See Also:
- Constant Field Values
-
VALIDATION_INCLUDE_SCHEMAS
public static final int VALIDATION_INCLUDE_SCHEMAS
Includes schemas-based validation.- See Also:
- Constant Field Values
-
VALIDATION_INCLUDE_FRAGIDPREFIX
public static final int VALIDATION_INCLUDE_FRAGIDPREFIX
Includes validation of the fragment identification values.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
XLIFFReader
public XLIFFReader()
Creates a new XLIFFReader object with full validation.
-
XLIFFReader
public XLIFFReader(int validation)
Creates a new XLIFFReader object. You can choose the type of validation to perform.- Parameters:
validation- one of the VALIDATION_* constants or a ORed combination.
-
XLIFFReader
public XLIFFReader(int validation, URIParser uriParserToUse)Creates a new XLIFFReader object.- Parameters:
validation- one of the VALIDATION_* constants or a ORed combination.uriParserToUse- URI parser to use when processing references (e.g. value of ref in an <mrk> element). If it is set to null, a URIParser object that handles default prefixes will be used.
-
-
Method Detail
-
validate
public static void validate(File file)
Validates an XLIFF document passed as a File object.- Parameters:
file- the XLIFF document to validate.
-
validate
public static void validate(File file, URIParser uriParser)
Validates an XLIFF document passed as a File object.- Parameters:
file- the XLIFF document to validate.uriParser- the URI parser to use when processing references (can be null).
-
validate
public static void validate(URI inputURI, URIParser uriParser)
Validates an XLIFF document passed as a URI.- Parameters:
inputURI- the URI to process.uriParser- the URI parser to use when processing references (can be null).
-
validate
public static void validate(String input, URIParser uriParser)
Validates an XLIFF document passed as a string.- Parameters:
input- the content to process.uriParser- the URI parser to use when processing references (can be null).
-
validate
public static void validate(InputStream inputStream, URIParser uriParser)
Validates an XLIFF document passed as a stream.- Parameters:
inputStream- the stream to process.uriParser- the URI parser to use when processing references (can be null).
-
open
public void open(File file)
Opens an XLIFF document by its File object.- Parameters:
file- the file to process.
-
open
public void open(URI inputURI)
Opens an XLIFF document by its URI.- Parameters:
inputURI- the URI to process.
-
open
public void open(String input)
Opens an XLIFF document passed as a string.- Parameters:
input- the string containing the document to process.
-
open
public void open(InputStream inputStream)
Opens an XLIFF document by its stream. Note that if a schema validation is done, this call will create a temporary copy of the content. If you can useopen(File),open(URI)oropen(String).- Parameters:
inputStream- the input stream to process.
-
close
public void close()
Closes the document.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-
hasNext
public boolean hasNext()
Indicates if there is another event.- Returns:
- true if there is another event, false otherwise.
-
next
public Event next()
Gets the next filter event.- Returns:
- the next filter event.
-
setReportUnsingnificantParts
public void setReportUnsingnificantParts(boolean reportUnsingnificantParts)
Sets the flag to report or not parts of the documents that are not significant. For example white space between structural elements.By default those parts are not reported.
- Parameters:
reportUnsingnificantParts- true to report those parts, false to not report them.
-
setForceUniqueIds
public void setForceUniqueIds(boolean forceUniqueIds)
If set, include the segment id in the tag id to enforce uniqueness.
-
setDiscardInvalidTargets
public void setDiscardInvalidTargets(boolean discardInvalidTargets)
If set, discard invalid target data and report it as a warning, rather than an error.
-
setIgnoreTagTypeMatch
public void setIgnoreTagTypeMatch(boolean ignoreTagTypeMatch)
If set, force tag types in the target to match their corresponding tag type in source.
-
getWarningCount
public int getWarningCount()
Gets the number of warnings.- Returns:
- the number of warnings.
-
processMatches
protected void processMatches() throws XMLStreamException- Throws:
XMLStreamException
-
-