|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectde.fu_berlin.ties.ConfigurableProcessor
de.fu_berlin.ties.TextProcessor
public abstract class TextProcessor
Abstract base class for a Processor
that operates
on text documents. Input is read from a file or URL or
Reader
, output is written to a file or
Writer
.
Field Summary | |
---|---|
static String |
CONFIG_POST
Configuration prefix for post-processors. |
static String |
KEY_DIRECTORY
Context key referring to the directory of the processed document, if it is a local file. |
static String |
KEY_LOCAL_NAME
Context key referring to the local name of the processed document. |
static String |
KEY_OUT_DIRECTORY
Context key referring output directory; if missing, the value of KEY_DIRECTORY is used instead. |
static String |
KEY_URL
Context key referring to the URL of the processed document, if loaded from an URL. |
Constructor Summary | |
---|---|
TextProcessor(String outExt,
TiesConfiguration conf)
Creates a new instance. |
Method Summary | |
---|---|
protected abstract void |
doProcess(Reader reader,
Writer writer,
ContextMap context)
Processes the contents of a reader, writing a modified version to a writer. |
String |
getOutFileExt()
Returns the extension used for output files. |
void |
process(File file,
Writer writer)
Processes the contents of a file, delegating to the process(File, Writer, ContextMap) method. |
void |
process(File file,
Writer writer,
ContextMap context)
Processes the contents of a file, delegating to the process(Reader, Writer, ContextMap) method. |
void |
process(Reader reader,
Writer writer,
ContextMap context)
Delegates to the abstract doProcess(Reader, Writer, ContextMap)
method and invokes a post-processor, if configured. |
void |
process(String inputName)
Processes a file or URL given as input argument, delegating to the appropriate process method. |
void |
process(URLConnection urlConn,
Writer writer)
Processes the contents of an URL connection, delegating to the process(URLConnection, Writer, ContextMap) method. |
void |
process(URLConnection urlConn,
Writer writer,
ContextMap context)
Processes the contents of an URL connection, delegating to the process(Reader, Writer, ContextMap) method. |
String |
toString()
Returns a string representation of this object. |
Methods inherited from class de.fu_berlin.ties.ConfigurableProcessor |
---|
getConfig |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final String CONFIG_POST
public static final String KEY_LOCAL_NAME
public static final String KEY_DIRECTORY
public static final String KEY_OUT_DIRECTORY
KEY_DIRECTORY
is used instead.
public static final String KEY_URL
Constructor Detail |
---|
public TextProcessor(String outExt, TiesConfiguration conf)
outExt
- the extension to use for output filesconf
- used to configure this instance; if null
,
the standard configuration is usedMethod Detail |
---|
protected abstract void doProcess(Reader reader, Writer writer, ContextMap context) throws IOException, ProcessingException
reader
- reader containing the text to process; should not be closed
by this methodwriter
- the writer to write the processed text to; might be flushed
but not closed by this method; if this method does not use the writer,
the underlying file will be deleted afterwardscontext
- a map of objects that are made available for processing;
when called from the implemented process
methods in this
class, it will contain mappings from IOUtils.KEY_LOCAL_CHARSET
to the character set of the output writer; from
ContentType.KEY_MIME_TYPE
to the document's MIME type; from
KEY_LOCAL_NAME
to the local name (String) and either from
KEY_DIRECTORY
to the directory (File
), in case of a
local file) or from KEY_URL
to the URL
(otherwise) of
the processed document
IOException
- if an I/O error occurs
ProcessingException
- if an error occurs during processingpublic String getOutFileExt()
public final void process(Reader reader, Writer writer, ContextMap context) throws IOException, ProcessingException
doProcess(Reader, Writer, ContextMap)
method and invokes a post-processor, if configured.
reader
- reader containing the text to process; should not be closed
by this methodwriter
- the writer to write the processed text to; might be flushed
but not closed by this method; if this method does not use the writer,
the underlying file will be deleted afterwardscontext
- a map of objects that are made available for processing;
when called from the implemented process
methods in this
class, it will contain mappings from IOUtils.KEY_LOCAL_CHARSET
to the character set of the output writer; from
ContentType.KEY_MIME_TYPE
to the document's MIME type; from
KEY_LOCAL_NAME
to the local name (String) and either from
KEY_DIRECTORY
to the directory (File
), in case of a
local file) or from KEY_URL
to the URL
(otherwise) of
the processed document
IOException
- if an I/O error occurs
ProcessingException
- if an error occurs during processingpublic final void process(File file, Writer writer) throws IOException, ProcessingException
process(File, Writer, ContextMap)
method.
file
- the file to processwriter
- the writer to write the processed text to; not closed by
this method
IOException
- if an I/O error occurs
ProcessingException
- if an error occurs during processingpublic final void process(File file, Writer writer, ContextMap context) throws IOException, ProcessingException
process(Reader, Writer, ContextMap)
method. Stores a mapping
from ContentType.KEY_MIME_TYPE
to the document's MIME type in the
context
.
file
- the file to processwriter
- the writer to write the processed text to; not closed by
this methodcontext
- a map of objects that are made available for processing;
should contain a mapping from IOUtils.KEY_LOCAL_CHARSET
to the
character set to use for local files
IOException
- if an I/O error occurs
ProcessingException
- if an error occurs during processingpublic final void process(String inputName) throws IOException, ProcessingException
process
method. A warning is logged if the input
is neither a readable file nor a readable URL. Stores a mapping
from IOUtils.KEY_LOCAL_CHARSET
to the character set of the
output writer in the created context
.
inputName
- the name of a readable file or URL to process
IOException
- if an I/O error occurs during processing
ProcessingException
- if an error occurs during processingpublic final void process(URLConnection urlConn, Writer writer) throws IOException, ProcessingException
process(URLConnection, Writer, ContextMap)
method.
Assumed the standard HTTP
character set ("ISO-8859-1") if no IOUtils.KEY_LOCAL_CHARSET
has been configured.
urlConn
- the URL connection to processwriter
- the writer to write the processed text to; not closed by
this method
IOException
- if an I/O error occurs
ProcessingException
- if an error occurs during processingpublic final void process(URLConnection urlConn, Writer writer, ContextMap context) throws IOException, ProcessingException
process(Reader, Writer, ContextMap)
method. Stores a mapping
from ContentType.KEY_MIME_TYPE
to the document's MIME type in the
context
.
urlConn
- the URL connection to processwriter
- the writer to write the processed text to; not closed by
this methodcontext
- a map of objects that are made available for processing;
must contain a mapping from IOUtils.KEY_LOCAL_CHARSET
to the
character set to use for local files
IOException
- if an I/O error occurs
ProcessingException
- if an error occurs during processingpublic String toString()
toString
in class Object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |