View Javadoc

1   /*
2    * Copyright 2008-2010 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  
17  package de.smartics.maven.issues.bugzilla;
18  
19  import java.util.List;
20  import java.util.ResourceBundle;
21  
22  import org.apache.commons.logging.Log;
23  import org.apache.commons.logging.LogFactory;
24  import org.apache.maven.doxia.sink.Sink;
25  import org.eclipse.mylyn.tasks.core.data.TaskData;
26  
27  import de.smartics.maven.issues.RendererConfig;
28  import de.smartics.maven.issues.bugzilla.Sections.Section;
29  import de.smartics.maven.issues.util.ReportReference;
30  
31  /**
32   * The renderer prints issue information in different sections. The sections are
33   * defines by the key {@link RendererConfig#getSectionType()} and are selected
34   * and ordered by {@link RendererConfig#getSections()}.
35   *
36   * @author <a href="mailto:robert.reiner@smartics.de">Robert Reiner</a>
37   */
38  public abstract class AbstractSectionReportRenderer extends
39      AbstractIssuesReportRenderer
40  {
41    // ********************************* Fields *********************************
42  
43    // --- constants ------------------------------------------------------------
44  
45    /**
46     * Reference to the logger for this class.
47     */
48    private static final Log LOG = LogFactory
49        .getLog(AbstractSectionReportRenderer.class);
50  
51    // --- members --------------------------------------------------------------
52  
53    // ****************************** Initializer *******************************
54  
55    // ****************************** Constructors ******************************
56  
57    /**
58     * Default constructor.
59     *
60     * @param config the configuration to control the rendering process.
61     * @param sink the sink to write to.
62     * @param issues the issue information to render in the report.
63     */
64    protected AbstractSectionReportRenderer(final RendererConfig config,
65        final Sink sink, final List<TaskData> issues)
66    {
67      super(config, sink, issues);
68    }
69  
70    // ****************************** Inner Classes *****************************
71  
72    // ********************************* Methods ********************************
73  
74    // --- init -----------------------------------------------------------------
75  
76    // --- get&set --------------------------------------------------------------
77  
78    // --- business -------------------------------------------------------------
79  
80    /**
81     * {@inheritDoc}
82     */
83    @Override
84    protected void renderBody()
85    {
86      sink.section1();
87      final boolean noResults = issues.isEmpty();
88      renderTitle(noResults);
89  
90      if (!noResults)
91      {
92        final SimpleSectioner sectioner = new SimpleSectioner(config, issues);
93        final Sections sections = sectioner.run();
94        renderSections(sections);
95      }
96  
97      renderPreviousReportReferences();
98  
99      renderFooter();
100     sink.section1_();
101   }
102 
103   /**
104    * Renders references to previous release reports.
105    */
106   protected void renderPreviousReportReferences()
107   {
108     final List<ReportReference> refs = config.getReportReferences();
109     if (refs != null && !refs.isEmpty())
110     {
111       sink.section2();
112       renderSectionHeader("previousReleases");
113       sink.list();
114       for (ReportReference ref : refs)
115       {
116         sink.listItem();
117         ReportHelper.renderLink(sink, ref.getUrl(), ref.getLabel());
118         sink.listItem_();
119       }
120       sink.list_();
121       sink.section2_();
122     }
123   }
124 
125   /**
126    * Renders the sections.
127    *
128    * @param sections the sections to be rendered.
129    */
130   protected void renderSections(final Sections sections)
131   {
132     for (Section section : sections)
133     {
134       final String sectionId = section.getSectionName();
135       final List<TaskData> sectionIssues = section.getTasks();
136       if (!sectionIssues.isEmpty())
137       {
138         renderSectionSectionStart();
139         renderSectionHeader(sectionId);
140         sink.table();
141         renderTableHeader();
142         for (TaskData issue : sectionIssues)
143         {
144           renderTableRow(issue);
145         }
146         sink.table_();
147         renderSectionSectionEnd();
148       }
149       else
150       {
151         if (LOG.isDebugEnabled())
152         {
153           LOG.debug("No issues for section '" + sectionId + "' found.");
154         }
155       }
156     }
157   }
158 
159   /**
160    * Renders the section header.
161    *
162    * @param sectionId the identifier (an attribute key of the issue management
163    *          system) of the section.
164    */
165   protected void renderSectionHeader(final String sectionId)
166   {
167     final ResourceBundle bundle = config.getBundle();
168     final String sectionLabel =
169         ReportHelper.getLabel(bundle, "section", sectionId);
170     renderSectionTitleStart();
171     sink.text(sectionLabel);
172     renderSectionTitleEnd();
173 
174     final String sectionText = getSectionText(bundle, sectionId);
175     sink.paragraph();
176     sink.text(sectionText);
177     sink.paragraph_();
178   }
179 
180   /**
181    * Returns the introduction text after the section title.
182    *
183    * @param bundle the resource bundle to use.
184    * @param sectionId the identifier (an attribute key of the issue management
185    *          system) of the section.
186    * @return the localized text to render.
187    */
188   protected String getSectionText(final ResourceBundle bundle,
189       final String sectionId)
190   {
191     return ReportHelper.getLabel(bundle, "section.text.unversioned", sectionId);
192   }
193 
194   /**
195    * Renders the start of a section.
196    *
197    * @impl Subclasses should override this if the default level 2 is not
198    *       adequate for the report.
199    */
200   protected void renderSectionSectionStart()
201   {
202     sink.section2();
203   }
204 
205   /**
206    * Renders the end of a section.
207    *
208    * @impl Subclasses should override this if the default level 2 is not
209    *       adequate for the report.
210    */
211   protected void renderSectionSectionEnd()
212   {
213     sink.section2_();
214   }
215 
216   /**
217    * Renders the start of a section title.
218    *
219    * @impl Subclasses should override this if the default level 2 is not
220    *       adequate for the report.
221    */
222   protected void renderSectionTitleStart()
223   {
224     sink.sectionTitle2();
225   }
226 
227   /**
228    * Renders the end of a section title.
229    *
230    * @impl Subclasses should override this if the default level 2 is not
231    *       adequate for the report.
232    */
233   protected void renderSectionTitleEnd()
234   {
235     sink.sectionTitle2_();
236   }
237 
238   // --- object basics --------------------------------------------------------
239 
240 }