1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package de.fu_berlin.ties;
23
24 import java.io.IOException;
25 import java.io.Writer;
26
27 import org.dom4j.Document;
28
29 import de.fu_berlin.ties.io.IOUtils;
30 import de.fu_berlin.ties.xml.dom.DOMUtils;
31
32 /***
33 * Abstract base class for a {@link de.fu_berlin.ties.Processor} that operates
34 * on {@linkplain org.dom4j.Document XML documents}.
35 *
36 * @author Christian Siefkes
37 * @version $Revision: 1.5 $, $Date: 2004/08/30 15:40:21 $, $Author: siefkes $
38 */
39 public abstract class DocumentProcessor extends DocumentReader {
40
41 /***
42 * Creates a new instance.
43 *
44 * @param outExt the extension to use for output files.
45 * @param conf used to configure this instance; if <code>null</code>,
46 * the {@linkplain TiesConfiguration#CONF standard configuration} is used
47 */
48 public DocumentProcessor(final String outExt,
49 final TiesConfiguration conf) {
50 super(outExt, conf);
51 }
52
53 /***
54 * Processes an XML document.
55 *
56 * @param document the document to process
57 * @param context a map of objects that are made available for processing
58 * @throws IOException if an I/O error occurs
59 * @throws ProcessingException if an error occurs during processing
60 */
61 public abstract void process(final Document document,
62 final ContextMap context) throws IOException, ProcessingException;
63
64 /***
65 * Processes an XML document, writing a modified version to a writer.
66 * This implementation delegates to {@link #process(Document, ContextMap)}.
67 *
68 * @param document the document to process
69 * @param writer the writer to write the processed text to; flushed
70 * but not closed by this method
71 * @param context a map of objects that are made available for processing;
72 * <strong>must</strong> contain a mapping from
73 * {@link IOUtils#KEY_LOCAL_CHARSET} to the character set of the
74 * <code>writer</code>
75 * @throws IOException if an I/O error occurs
76 * @throws ProcessingException if an error occurs during processing
77 */
78 public final void process(final Document document, final Writer writer,
79 final ContextMap context) throws IOException, ProcessingException {
80
81 process(document, context);
82 DOMUtils.writeDocument(document, writer,
83 (String) context.get(IOUtils.KEY_LOCAL_CHARSET));
84 }
85
86 }