View Javadoc

1   /*
2    * Copyright 2012-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.properties.reports;
17  
18  import java.io.IOException;
19  import java.io.OutputStream;
20  
21  import javax.annotation.concurrent.NotThreadSafe;
22  
23  import org.jdom.Document;
24  
25  import de.smartics.properties.api.core.domain.DocumentMetaData;
26  import de.smartics.properties.report.data.PropertyReportSet;
27  import de.smartics.properties.utils.HtmlUtils;
28  
29  /**
30   * Helper to construct a projectdoc property set document.
31   */
32  @NotThreadSafe
33  class XmlPropertySetReporter extends AbstractReporter
34  {
35    // ********************************* Fields *********************************
36  
37    // --- constants ------------------------------------------------------------
38  
39    /**
40     * The namespace of the document that is created.
41     */
42    private static final String NAMESPACE =
43        "http://www.smartics.de/schema/projectdoc/doctype/property-set/1";
44  
45    // --- members --------------------------------------------------------------
46  
47    /**
48     * The information to be set to the report.
49     */
50    private final PropertyReportSet reportSet;
51  
52    /**
53     * The helper to cleanup HTML fragments.
54     */
55    private final HtmlUtils htmlUtils;
56  
57    // ****************************** Initializer *******************************
58  
59    // ****************************** Constructors ******************************
60  
61    XmlPropertySetReporter(final String encoding, final PropertyReportSet reportSet)
62    {
63      super(NAMESPACE);
64      this.reportSet = reportSet;
65      this.htmlUtils = new HtmlUtils(encoding);
66    }
67  
68    // ****************************** Inner Classes *****************************
69  
70    // ********************************* Methods ********************************
71  
72    // --- init -----------------------------------------------------------------
73  
74    // --- get&set --------------------------------------------------------------
75  
76    // --- business -------------------------------------------------------------
77  
78    void write(final OutputStream out) throws IOException
79    {
80      final Document document = buildDocument("property-set");
81      final String comment = htmlUtils.clean(getComment());
82      writeSpecification(comment);
83      writeXml(out, document);
84    }
85  
86    @Override
87    protected DocumentMetaData getMetaData()
88    {
89      return reportSet.getMetaData();
90    }
91  
92    @Override
93    protected String getComment()
94    {
95      final String comment = reportSet.getComment();
96      final String cleanComment = htmlUtils.clean(comment);
97      return cleanComment;
98    }
99  
100   @Override
101   protected String getName()
102   {
103     return reportSet.getName();
104   }
105 
106   @Override
107   protected String getSpace()
108   {
109     return reportSet.getSpace();
110   }
111 
112   @Override
113   protected String getTitle()
114   {
115     return reportSet.getTitle();
116   }
117 
118   // --- object basics --------------------------------------------------------
119 
120 }