View Javadoc

1   /*
2    * Copyright 2005 Jukka Zitting <jz@yukatan.fi>
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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  }