View Javadoc
1   package org.apache.maven.plugins.site.render;
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.io.FileNotFoundException;
23  import java.io.Writer;
24  import java.util.Collections;
25  import java.util.List;
26  import java.util.Locale;
27  
28  import org.apache.maven.doxia.sink.Sink;
29  import org.apache.maven.doxia.siterenderer.DocumentRenderer;
30  import org.apache.maven.doxia.siterenderer.Renderer;
31  import org.apache.maven.doxia.siterenderer.RendererException;
32  import org.apache.maven.doxia.siterenderer.RenderingContext;
33  import org.apache.maven.doxia.siterenderer.SiteRenderingContext;
34  import org.apache.maven.doxia.siterenderer.sink.SiteRendererSink;
35  import org.apache.maven.doxia.tools.MojoLogWrapper;
36  import org.apache.maven.plugin.logging.Log;
37  import org.apache.maven.reporting.MavenReport;
38  import org.codehaus.plexus.i18n.I18N;
39  
40  /**
41   * Renders a Maven report.
42   *
43   * @author <a href="mailto:brett@apache.org">Brett Porter</a>
44   */
45  public class CategorySummaryDocumentRenderer
46      implements DocumentRenderer
47  {
48      private RenderingContext renderingContext;
49  
50      private String title;
51  
52      private String desc1;
53  
54      private String desc2;
55  
56      private I18N i18n;
57  
58      private List<MavenReport> categoryReports;
59  
60      private final Log log;
61  
62      public CategorySummaryDocumentRenderer( RenderingContext renderingContext, String title, String desc1, String desc2,
63                                              I18N i18n, List<MavenReport> categoryReports )
64      {
65          this( renderingContext, title, desc1, desc2, i18n, categoryReports, null );
66      }
67  
68      public CategorySummaryDocumentRenderer( RenderingContext renderingContext, String title, String desc1, String desc2,
69                                              I18N i18n, List<MavenReport> categoryReports, Log log )
70      {
71          this.renderingContext = renderingContext;
72          this.title = title;
73          this.desc1 = desc1;
74          this.desc2 = desc2;
75          this.i18n = i18n;
76          this.categoryReports = Collections.unmodifiableList( categoryReports );
77          this.log = log;
78      }
79  
80      public void renderDocument( Writer writer, Renderer renderer, SiteRenderingContext siteRenderingContext )
81          throws RendererException, FileNotFoundException
82      {
83          SiteRendererSink sink = new SiteRendererSink( renderingContext );
84  
85          if ( log != null )
86          {
87              sink.enableLogging( new MojoLogWrapper( log ) );
88          }
89  
90          sink.head();
91  
92          sink.title();
93  
94          sink.text( title );
95  
96          sink.title_();
97  
98          sink.head_();
99  
100         sink.body();
101 
102         sink.section1();
103         sink.sectionTitle1();
104         sink.text( title );
105         sink.sectionTitle1_();
106 
107         sink.paragraph();
108         sink.text( desc1 + " " );
109         sink.link( "http://maven.apache.org" );
110         sink.text( "Maven" );
111         sink.link_();
112         sink.text( " " + desc2 );
113         sink.paragraph_();
114 
115         sink.section2();
116         sink.sectionTitle2();
117         Locale locale = siteRenderingContext.getLocale();
118         sink.text( i18n.getString( "site-plugin", locale, "report.category.sectionTitle" ) );
119         sink.sectionTitle2_();
120 
121         sink.table();
122 
123         sink.tableRows( new int[] {Sink.JUSTIFY_LEFT, Sink.JUSTIFY_LEFT}, false );
124 
125         String name = i18n.getString( "site-plugin", locale, "report.category.column.document" );
126         String description = i18n.getString( "site-plugin", locale, "report.category.column.description" );
127 
128         sink.tableRow();
129 
130         sink.tableHeaderCell();
131 
132         sink.text( name );
133 
134         sink.tableHeaderCell_();
135 
136         sink.tableHeaderCell();
137 
138         sink.text( description );
139 
140         sink.tableHeaderCell_();
141 
142         sink.tableRow_();
143 
144         if ( categoryReports != null )
145         {
146             for ( MavenReport report : categoryReports )
147             {
148                 sink.tableRow();
149                 sink.tableCell();
150                 sink.link( report.getOutputName() + ".html" );
151                 sink.text( report.getName( locale ) );
152                 sink.link_();
153                 sink.tableCell_();
154                 sink.tableCell();
155                 sink.text( report.getDescription( locale ) );
156                 sink.tableCell_();
157                 sink.tableRow_();
158             }
159         }
160 
161         sink.tableRows_();
162 
163         sink.table_();
164 
165         sink.section2_();
166 
167         sink.section1_();
168 
169         sink.body_();
170 
171         sink.flush();
172 
173         sink.close();
174 
175         renderer.generateDocument( writer, sink, siteRenderingContext );
176     }
177 
178     public String getOutputName()
179     {
180         return renderingContext.getOutputName();
181     }
182 
183     public RenderingContext getRenderingContext()
184     {
185         return renderingContext;
186     }
187 
188     public boolean isOverwrite()
189     {
190         return true;
191     }
192     
193     public boolean isExternalReport()
194     {
195         return false;
196     }
197 }