View Javadoc

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