1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package net.sf.exorcist.multi;
17
18 import java.io.IOException;
19 import java.util.Iterator;
20 import java.util.List;
21
22 import javax.xml.parsers.ParserConfigurationException;
23
24 import net.sf.exorcist.api.ContentException;
25 import net.sf.exorcist.api.ContentExporter;
26 import net.sf.exorcist.api.ContentState;
27
28 import org.xml.sax.SAXException;
29
30 /***
31 * Exporter plugin that combines the output of multiple exporters
32 * into a combined content state export.
33 */
34 public class MultiExporter implements ContentExporter {
35
36 /*** List of exporter components. */
37 private List exporters;
38
39 /***
40 * Sets the list of exporter components.
41 *
42 * @param exporters exporter components
43 */
44 public void setExporters(List exporters) {
45 this.exporters = exporters;
46 }
47
48 /***
49 * Runs each of the configured exporter components and combines their
50 * output into the given content state instance.
51 *
52 * @param state content state
53 * @throws ContentException if some exporter component fails
54 * @see ContentExporter#exportContent(ContentState)
55 */
56 public void exportContent(ContentState state) throws ContentException {
57 try {
58 MultiState multi = new MultiState(state);
59 multi.startCollection();
60 Iterator iterator = exporters.iterator();
61 while (iterator.hasNext()) {
62 ContentExporter exporter = (ContentExporter) iterator.next();
63 exporter.exportContent(multi);
64 }
65 multi.endCollection();
66 } catch (IOException e) {
67 throw new ContentException(e);
68 } catch (SAXException e) {
69 throw new ContentException(e);
70 } catch (ParserConfigurationException e) {
71 throw new ContentException(e);
72 }
73 }
74
75 }