View Javadoc

1   /*
2    * Copyright 2007-2013 smartics, Kronseder & Reiner GmbH
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 de.smartics.exceptions.report.generator;
17  
18  import java.io.Writer;
19  
20  import javax.xml.stream.XMLOutputFactory;
21  import javax.xml.stream.XMLStreamException;
22  import javax.xml.stream.XMLStreamWriter;
23  
24  import de.smartics.exceptions.report.app.ReportException;
25  import de.smartics.exceptions.report.data.ProjectConfiguration;
26  import de.smartics.exceptions.report.data.StoredExceptionCodesReport;
27  import de.smartics.exceptions.report.renderer.JavadocRenderer;
28  
29  /**
30   * Simple generator that generates a HTML file.
31   */
32  public abstract class AbstractXmlReportGenerator extends
33      AbstractOutputReportGenerator<XMLStreamWriter>
34  {
35    // ********************************* Fields *********************************
36  
37    // --- constants ------------------------------------------------------------
38  
39    // --- members --------------------------------------------------------------
40  
41    // ****************************** Initializer *******************************
42  
43    // ****************************** Constructors ******************************
44  
45    /**
46     * Default constructor.
47     *
48     * @param renderer the renderer used to map Javadoc comments to the report's
49     *          output format.
50     */
51    protected AbstractXmlReportGenerator(final JavadocRenderer renderer)
52    {
53      super(renderer);
54    }
55  
56    // ****************************** Inner Classes *****************************
57  
58    // ********************************* Methods ********************************
59  
60    // --- init -----------------------------------------------------------------
61  
62    // --- get&set --------------------------------------------------------------
63  
64    // --- business -------------------------------------------------------------
65  
66    /**
67     * Creates an output instance from a writer to use subclasses of this report
68     * generator implementation.
69     *
70     * @param writer the basic writer to use for XML writing.
71     * @return the output instance to use.
72     * @throws XMLStreamException on any problem generating the XML writer.
73     */
74    public static XMLStreamWriter createOutput(final Writer writer)
75        throws XMLStreamException
76    {
77      final XMLOutputFactory factory = XMLOutputFactory.newInstance();
78      final XMLStreamWriter xmlWriter = factory.createXMLStreamWriter(writer);
79      return xmlWriter;
80    }
81  
82    // --- object basics --------------------------------------------------------
83  
84    /**
85     * {@inheritDoc}
86     */
87    @Override
88    public void writeReport(
89        final ProjectConfiguration<XMLStreamWriter> config,
90        final StoredExceptionCodesReport report) throws ReportException
91    {
92      try
93      {
94        output.writeStartDocument(encoding, "1.0");
95        writeContent(output, config, report);
96        output.writeEndDocument();
97      }
98      catch (final ReportException e) // NOPMD
99      {
100       throw e;
101     }
102     catch (final Exception e)
103     {
104       throw new ReportException(e);
105     }
106   }
107 
108   // --- object basics --------------------------------------------------------
109 
110 }