View Javadoc

1   /*
2    * Copyright 2010-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.testdoc.maven.export.sink;
17  
18  import org.apache.maven.doxia.sink.Sink;
19  import org.codehaus.plexus.util.StringUtils;
20  
21  import de.smartics.maven.util.report.MessageHelper;
22  
23  /**
24   * Base implementation of page renderers.
25   *
26   * @author <a href="mailto:robert.reiner@smartics.de">Robert Reiner</a>
27   * @version $Revision:591 $
28   */
29  public abstract class AbstractPageRenderer
30  {
31    // ********************************* Fields *********************************
32  
33    // --- constants ------------------------------------------------------------
34  
35    // --- members --------------------------------------------------------------
36  
37    protected final String reportName;
38  
39    /**
40     * The resource bundles with messages to display as labels in the generated
41     * report.
42     */
43    protected final MessageHelper messages;
44  
45    /**
46     * The output medium to write to.
47     */
48    protected final Sink sink;
49  
50    // ****************************** Initializer *******************************
51  
52    // ****************************** Constructors ******************************
53  
54    /**
55     * Default constructor.
56     *
57     * @param messages the resource bundles with messages to display as labels in
58     *          the generated report.
59     * @param exporter the exporter that knows the format of the file to be
60     *          written.
61     */
62    AbstractPageRenderer(final String reportName, final MessageHelper messages,
63        final Sink sink)
64    {
65      this.reportName = reportName;
66      this.messages = messages;
67      this.sink = sink;
68    }
69  
70    // ****************************** Inner Classes *****************************
71  
72    // ********************************* Methods ********************************
73  
74    // --- init -----------------------------------------------------------------
75  
76    // --- get&set --------------------------------------------------------------
77  
78    // --- business -------------------------------------------------------------
79  
80    protected void renderPageEndAndFinalize()
81    {
82      sink.body_();
83      sink.flush();
84      sink.close();
85    }
86  
87    protected void renderPageStart()
88    {
89      sink.head();
90      sink.title();
91      sink.text(messages.getLabel(messages.getReportTitleId()));
92      sink.title_();
93      sink.head_();
94  
95      sink.body();
96    }
97  
98    protected void renderBodyStart()
99    {
100     sink.section1();
101 
102     sink.sectionTitle1();
103     sink.text(messages.getLabel(messages.getReportTitleId()));
104     sink.sectionTitle1_();
105 
106     sink.paragraph();
107     sink.text(messages.getLabel(messages.getReportDescriptionId()));
108     sink.paragraph_();
109   }
110 
111   protected void renderBodyEnd()
112   {
113     renderFooter();
114     sink.section1_();
115   }
116 
117   /**
118    * Renders the footer text.
119    */
120   protected void renderFooter()
121   {
122     final String footerText = messages.getLabel("report.footer");
123     if (StringUtils.isNotBlank(footerText))
124     {
125       sink.rawText(footerText);
126     }
127   }
128 
129   // --- object basics --------------------------------------------------------
130 
131 }