Package org.apache.tika.parser.external2
Class ExternalParser
- java.lang.Object
-
- org.apache.tika.parser.external2.ExternalParser
-
- All Implemented Interfaces:
Serializable
,Initializable
,Parser
public class ExternalParser extends Object implements Parser, Initializable
This is a next generation external parser that uses some of the more recent additions to Tika. This is an experimental alternative to theExternalParser
. Specifically, it relies more on configuration than the SPI model. Further, users can specify a parser to handle the output of the external process.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static long
DEFAULT_TIMEOUT_MS
static String
INPUT_FILE_TOKEN
static String
OUTPUT_FILE_TOKEN
-
Constructor Summary
Constructors Constructor Description ExternalParser()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
checkInitialization(InitializableProblemHandler problemHandler)
Parser
getOutputParser()
Set<MediaType>
getSupportedTypes(ParseContext context)
Returns the set of media types supported by this parser when used with the given parse context.void
initialize(Map<String,Param> params)
void
parse(InputStream stream, ContentHandler handler, Metadata metadata, ParseContext context)
Parses a document stream into a sequence of XHTML SAX events.void
setCommandLine(List<String> commandLine)
Use this to specify the full commandLine.void
setMaxStdErr(int maxStdErr)
void
setMaxStdOut(int maxStdOut)
void
setOutputParser(Parser parser)
This parser is called on the output of the process.void
setReturnStderr(boolean returnStderr)
If set to true, this will return the stderr in the metadata viaExternalProcess.STD_ERR
.void
setReturnStdout(boolean returnStdout)
If set to true, this will return the stdout in the metadata viaExternalProcess.STD_OUT
.void
setSupportedTypes(List<String> supportedTypes)
This is set during initialization from a tika-config.void
setTimeoutMs(long timeoutMs)
-
-
-
Field Detail
-
DEFAULT_TIMEOUT_MS
public static final long DEFAULT_TIMEOUT_MS
- See Also:
- Constant Field Values
-
INPUT_FILE_TOKEN
public static final String INPUT_FILE_TOKEN
- See Also:
- Constant Field Values
-
OUTPUT_FILE_TOKEN
public static final String OUTPUT_FILE_TOKEN
- See Also:
- Constant Field Values
-
-
Method Detail
-
getSupportedTypes
public Set<MediaType> getSupportedTypes(ParseContext context)
Description copied from interface:Parser
Returns the set of media types supported by this parser when used with the given parse context.- Specified by:
getSupportedTypes
in interfaceParser
- Parameters:
context
- parse context- Returns:
- immutable set of media types
-
parse
public void parse(InputStream stream, ContentHandler handler, Metadata metadata, ParseContext context) throws IOException, SAXException, TikaException
Description copied from interface:Parser
Parses a document stream into a sequence of XHTML SAX events. Fills in related document metadata in the given metadata object.The given document stream is consumed but not closed by this method. The responsibility to close the stream remains on the caller.
Information about the parsing context can be passed in the context parameter. See the parser implementations for the kinds of context information they expect.
- Specified by:
parse
in interfaceParser
- Parameters:
stream
- the document stream (input)handler
- handler for the XHTML SAX events (output)metadata
- document metadata (input and output)context
- parse context- Throws:
IOException
- if the document stream could not be readSAXException
- if the SAX events could not be processedTikaException
- if the document could not be parsed
-
setSupportedTypes
@Field public void setSupportedTypes(List<String> supportedTypes)
This is set during initialization from a tika-config. Any calls after initialization will result in aIllegalStateException
.- Parameters:
supportedTypes
-
-
setTimeoutMs
@Field public void setTimeoutMs(long timeoutMs)
-
setMaxStdErr
@Field public void setMaxStdErr(int maxStdErr)
-
setMaxStdOut
@Field public void setMaxStdOut(int maxStdOut)
-
setCommandLine
@Field public void setCommandLine(List<String> commandLine)
Use this to specify the full commandLine. The commandline must include at leastINPUT_FILE_TOKEN
. If the external process writes to an output file, specifyOUTPUT_FILE_TOKEN
.- Parameters:
commandLine
-
-
setReturnStdout
@Field public void setReturnStdout(boolean returnStdout)
If set to true, this will return the stdout in the metadata viaExternalProcess.STD_OUT
. Default isfalse
because this should normally be handled by the outputParser- Parameters:
returnStdout
-
-
setReturnStderr
@Field public void setReturnStderr(boolean returnStderr)
If set to true, this will return the stderr in the metadata viaExternalProcess.STD_ERR
. Default istrue
- Parameters:
returnStderr
-
-
setOutputParser
@Field public void setOutputParser(Parser parser)
This parser is called on the output of the process. If the process writes to an output file, specified byOUTPUT_FILE_TOKEN
, this parser will parse that file, otherwise it will parse the UTF-8 encoded bytes from the process' STD_OUT.- Parameters:
parser
-
-
getOutputParser
public Parser getOutputParser()
-
initialize
public void initialize(Map<String,Param> params) throws TikaConfigException
- Specified by:
initialize
in interfaceInitializable
- Parameters:
params
- params to use for initialization- Throws:
TikaConfigException
-
checkInitialization
public void checkInitialization(InitializableProblemHandler problemHandler) throws TikaConfigException
- Specified by:
checkInitialization
in interfaceInitializable
- Parameters:
problemHandler
- if there is a problem and no custom initializableProblemHandler has been configured via Initializable parameters, this is called to respond.- Throws:
TikaConfigException
-
-