View Javadoc
1   package org.codehaus.mojo.javancss;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.text.MessageFormat;
23  import java.util.ResourceBundle;
24  
25  import org.apache.maven.doxia.sink.Sink;
26  import org.apache.maven.plugin.logging.Log;
27  
28  /**
29   * Base abstract class for NCSSReport classes.<br>
30   * It holds essentially helper methods on top of the Sink Doxia object.
31   *
32   * @author <a href="jeanlaurent@NOSPAMgmail.com>Jean-Laurent de Morlhon</a>
33   * @version $Id$
34   */
35  public abstract class AbstractNcssReportGenerator
36  {
37      private ResourceBundle bundle;
38  
39      private Sink sink;
40  
41      private Log log;
42  
43      /**
44       * build a new NcssReportGenerator.
45       *
46       * @param sink the sink that will be used for reporting.
47       * @param bundle the correct RessourceBundle to be used for reporting.
48       * @param log the log object enabling logging within maven plugins.
49       */
50      protected AbstractNcssReportGenerator( Sink sink, ResourceBundle bundle, Log log )
51      {
52          this.bundle = bundle;
53          this.sink = sink;
54          this.log = log;
55      }
56  
57      /**
58       * Getter for the Log instance.
59       *
60       * @return the current log instance associated with this report generator.
61       */
62      public Log getLog()
63      {
64          return this.log;
65      }
66  
67      /**
68       * Getter for the Sink instance.
69       *
70       * @return the current instance of Sink associated with this report generator.
71       */
72      public Sink getSink()
73      {
74          return this.sink;
75      }
76  
77      /**
78       * Getter for the RessourceBundle.
79       *
80       * @return the current ResourceBundle associated with this report generator.
81       */
82      public ResourceBundle getResourceBundle()
83      {
84          return this.bundle;
85      }
86  
87      /**
88       * sink helper to write a "code" itemList.
89       *
90       * @param text the text to write within the code tags.
91       */
92      protected void codeItemListHelper( String text )
93      {
94          sink.listItem();
95          sink.monospaced();
96          sink.text( text );
97          sink.monospaced_();
98          sink.listItem_();
99      }
100 
101     /**
102      * sink helper to write a paragraph
103      *
104      * @param text the text to write within the paragraph.
105      */
106     protected void paragraphHelper( String text )
107     {
108         sink.paragraph();
109         sink.text( text );
110         sink.paragraph_();
111     }
112 
113     /**
114      * sink helper to write a subtitle
115      *
116      * @param text the text to write as a subtitle.
117      */
118     protected void subtitleHelper( String text )
119     {
120         sink.paragraph();
121         sink.bold();
122         sink.text( text );
123         sink.bold_();
124         sink.paragraph_();
125     }
126 
127     /**
128      * sink helper to write cell containing code.
129      *
130      * @param text the text to write within a cell and within code tags.
131      */
132     protected void codeCellHelper( String text )
133     {
134         sink.tableCell();
135         sink.monospaced();
136         sink.text( text );
137         sink.monospaced_();
138         sink.tableCell_();
139     }
140 
141     /**
142      * sink helper to write a simple table header cell.
143      *
144      * @param text the text to write within a table header cell.
145      */
146     protected void headerCellHelper( String text )
147     {
148         sink.tableHeaderCell();
149         sink.text( text );
150         sink.tableHeaderCell_();
151     }
152 
153     /**
154      * sink helper to write a simple table cell.
155      *
156      * @param text the text to write within a table cell.
157      */
158     protected void tableCellHelper( String text )
159     {
160         sink.tableCell();
161         sink.text( text );
162         sink.tableCell_();
163     }
164 
165     /**
166      * sink helper to start a section.
167      *
168      * @param link the anchor link.
169      * @param title the title of the anchor link.
170      */
171     protected void startSection( String link, String title )
172     {
173         sink.section1();
174         sink.sectionTitle1();
175         sink.text( bundle.getString( title ) );
176         sink.sectionTitle1_();
177 
178         sink.anchor( bundle.getString( link ) );
179         sink.text( bundle.getString( title ) );
180         sink.anchor_();
181     }
182 
183     /**
184      * sink helper to end a section
185      */
186     protected void endSection()
187     {
188         sink.section1_();
189     }
190 
191     /**
192      * resource bundle helper to get a value.
193      *
194      * @param key the key for the desired string.
195      * @return the string for the given key.
196      */
197     protected String getString( String key )
198     {
199         return bundle.getString( key );
200     }
201 
202     /**
203      * Output the report introduction.
204      *
205      * @param withNavigationBar a boolean stating whether or not the navigationBar should be displayed.
206      */
207     protected void doIntro( boolean withNavigationBar )
208     {
209         getSink().section1();
210         getSink().sectionTitle1();
211         getSink().text( getString( "report.javancss.main.title" ) );
212         getSink().sectionTitle1_();
213         if ( withNavigationBar )
214         {
215             navigationBar();
216         }
217         getSink().paragraph();
218         String version = NcssExecuter.getJavaNCSSVersion();
219         getSink().text( MessageFormat.format( getString( "report.javancss.main.text" ), version ) );
220         getSink().lineBreak();
221         getSink().link( "http://javancss.codehaus.org/" );
222         getSink().text( "JavaNCSS web site." );
223         getSink().link_();
224         getSink().paragraph_();
225         getSink().section1_();
226     }
227 
228     // print out the navigation bar
229     protected void navigationBar()
230     {
231         getSink().paragraph();
232         getSink().text( "[ " );
233         getSink().link( "#" + getString( "report.javancss.package.link" ) );
234         getSink().text( getString( "report.javancss.package.link" ) );
235         getSink().link_();
236         getSink().text( " ] [ " );
237         getSink().link( "#" + getString( "report.javancss.object.link" ) );
238         getSink().text( getString( "report.javancss.object.link" ) );
239         getSink().link_();
240         getSink().text( " ] [ " );
241         getSink().link( "#" + getString( "report.javancss.function.link" ) );
242         getSink().text( getString( "report.javancss.function.link" ) );
243         getSink().link_();
244         getSink().text( " ] [ " );
245         getSink().link( "#" + getString( "report.javancss.explanation.link" ) );
246         getSink().text( getString( "report.javancss.explanation.link" ) );
247         getSink().link_();
248         getSink().text( " ]" );
249         getSink().paragraph_();
250     }
251 }