1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package net.sf.exorcist.xml;
17
18 import java.io.IOException;
19 import java.io.InputStream;
20
21 import org.apache.commons.io.IOUtils;
22
23 import net.sf.exorcist.api.ContentException;
24 import net.sf.exorcist.api.ContentExporter;
25 import net.sf.exorcist.api.ContentState;
26
27 /***
28 * Content exporter that exports the content XML document from
29 * a given input stream.
30 */
31 public class XmlExporter implements ContentExporter {
32
33 /*** The XML document stream. */
34 private InputStream content;
35
36 /***
37 * Sets the XML document stream to be exported.
38 *
39 * @param content XML document stream
40 */
41 public void setContent(InputStream content) {
42 this.content = content;
43 }
44
45 /***
46 * Copies the XML document from the configured content stream into
47 * the given content state.
48 * <p>
49 * Note that at the moment this method <em>does not</em> parse or
50 * validate the XML document stream.
51 *
52 * @param state the content state
53 * @throws ContentException if the content stream can not be read
54 * @see ContentExporter#exportContent(ContentState)
55 */
56 public void exportContent(ContentState state) throws ContentException {
57 try {
58 state.setContent(content);
59 } catch (IOException e) {
60 throw new ContentException(e);
61 } finally {
62 IOUtils.closeQuietly(content);
63 }
64 }
65
66 }