View Javadoc

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