View Javadoc

1   package org.apache.maven.plugin.issues;
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 org.apache.maven.doxia.sink.Sink;
23  import org.apache.maven.doxia.sink.SinkEventAttributeSet;
24  import org.apache.maven.doxia.sink.SinkEventAttributes;
25  import org.apache.maven.doxia.util.HtmlTools;
26  import org.codehaus.plexus.util.StringUtils;
27  
28  import java.util.ResourceBundle;
29  
30  /**
31   * An abstract super class that helps when generating a report on issues.
32   *
33   * @author Dennis Lundberg
34   * @version $Id: AbstractIssuesReportGenerator.java 1103352 2011-05-15 12:44:39Z dennisl $
35   * @since 2.4
36   */
37  public abstract class AbstractIssuesReportGenerator
38  {
39      protected String author;
40  
41      protected String title;
42  
43      public AbstractIssuesReportGenerator()
44      {
45      }
46  
47      public String getAuthor()
48      {
49          return author;
50      }
51  
52      public void setAuthor( String author )
53      {
54          this.author = author;
55      }
56  
57      public String getTitle()
58      {
59          return title;
60      }
61  
62      public void setTitle( String title )
63      {
64          this.title = title;
65      }
66  
67      protected void sinkBeginReport( Sink sink, ResourceBundle bundle )
68      {
69          sink.head();
70  
71          String title = null;
72          if ( this.title != null )
73          {
74              title = this.title;
75          }
76          else
77          {
78              title = bundle.getString( "report.issues.header" );
79          }
80          sink.title();
81          sink.text( title );
82          sink.title_();
83  
84          if ( StringUtils.isNotEmpty( author ) )
85          {
86              sink.author();
87              sink.text( author );
88              sink.author_();
89          }
90  
91          sink.head_();
92  
93          sink.body();
94  
95          sink.section1();
96  
97          sinkSectionTitle1Anchor( sink, title, title );
98      }
99  
100     protected void sinkCell( Sink sink, String text )
101     {
102         sink.tableCell();
103 
104         if ( text != null )
105         {
106             sink.text( text );
107         }
108         else
109         {
110             sink.nonBreakingSpace();
111         }
112 
113         sink.tableCell_();
114     }
115 
116     protected void sinkCellLink( Sink sink, String text, String link )
117     {
118         sink.tableCell();
119 
120         sinkLink( sink, text, link );
121 
122         sink.tableCell_();
123     }
124 
125     protected void sinkEndReport( Sink sink )
126     {
127         sink.section1_();
128 
129         sink.body_();
130 
131         sink.flush();
132 
133         sink.close();
134     }
135 
136     protected void sinkFigure( Sink sink, String image, String altText )
137     {
138         SinkEventAttributes attributes = new SinkEventAttributeSet();
139         attributes.addAttribute( "alt", altText );
140         attributes.addAttribute( "title", altText );
141 
142         sink.figure( null );
143 
144         sink.figureGraphics( image, attributes );
145 
146         sink.figure_();
147     }
148 
149     protected void sinkHeader( Sink sink, String header )
150     {
151         sink.tableHeaderCell();
152 
153         sink.text( header );
154 
155         sink.tableHeaderCell_();
156     }
157 
158     protected void sinkLink( Sink sink, String text, String link )
159     {
160         sink.link( link );
161 
162         sink.text( text );
163 
164         sink.link_();
165     }
166 
167     protected void sinkSectionTitle1Anchor( Sink sink, String text, String anchor )
168     {
169         sink.sectionTitle1();
170 
171         sink.text( text );
172 
173         sink.sectionTitle1_();
174 
175         sink.anchor( HtmlTools.encodeId( anchor ) );
176         sink.anchor_();
177     }
178 
179     protected void sinkSectionTitle2Anchor( Sink sink, String text, String anchor )
180     {
181         sink.sectionTitle2();
182         sink.text( text );
183         sink.sectionTitle2_();
184 
185         sink.anchor( HtmlTools.encodeId( anchor ) );
186         sink.anchor_();
187     }
188 
189     protected void sinkShowTypeIcon( Sink sink, String type )
190     {
191         String image = "";
192         String altText = "";
193 
194         if ( type == null )
195         {
196             image = "images/icon_help_sml.gif";
197             altText = "?";
198         }
199         else if ( type.equals( "fix" ) )
200         {
201             image = "images/fix.gif";
202             altText = "fix";
203         }
204         else if ( type.equals( "update" ) )
205         {
206             image = "images/update.gif";
207             altText = "update";
208         }
209         else if ( type.equals( "add" ) )
210         {
211             image = "images/add.gif";
212             altText = "add";
213         }
214         else if ( type.equals( "remove" ) )
215         {
216             image = "images/remove.gif";
217             altText = "remove";
218         }
219 
220         sink.tableCell();
221 
222         sinkFigure( sink, image, altText );
223 
224         sink.tableCell_();
225     }
226 }