View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.plugins.site.render;
20  
21  import java.io.FileNotFoundException;
22  import java.io.Writer;
23  import java.util.Collections;
24  import java.util.List;
25  import java.util.Locale;
26  
27  import org.apache.maven.doxia.sink.Sink;
28  import org.apache.maven.doxia.siterenderer.DocumentRenderer;
29  import org.apache.maven.doxia.siterenderer.Renderer;
30  import org.apache.maven.doxia.siterenderer.RendererException;
31  import org.apache.maven.doxia.siterenderer.RenderingContext;
32  import org.apache.maven.doxia.siterenderer.SiteRenderingContext;
33  import org.apache.maven.doxia.siterenderer.sink.SiteRendererSink;
34  import org.apache.maven.plugin.logging.Log;
35  import org.apache.maven.reporting.MavenReport;
36  import org.codehaus.plexus.i18n.I18N;
37  
38  /**
39   * Renders a Maven report.
40   *
41   * @author <a href="mailto:brett@apache.org">Brett Porter</a>
42   */
43  public class CategorySummaryDocumentRenderer implements DocumentRenderer {
44      private RenderingContext docRenderingContext;
45  
46      private String title;
47  
48      private String desc1;
49  
50      private String desc2;
51  
52      private I18N i18n;
53  
54      private List<MavenReport> categoryReports;
55  
56      private final Log log;
57  
58      public CategorySummaryDocumentRenderer(
59              RenderingContext docRenderingContext,
60              String title,
61              String desc1,
62              String desc2,
63              I18N i18n,
64              List<MavenReport> categoryReports) {
65          this(docRenderingContext, title, desc1, desc2, i18n, categoryReports, null);
66      }
67  
68      public CategorySummaryDocumentRenderer(
69              RenderingContext docRenderingContext,
70              String title,
71              String desc1,
72              String desc2,
73              I18N i18n,
74              List<MavenReport> categoryReports,
75              Log log) {
76          this.docRenderingContext = docRenderingContext;
77          this.title = title;
78          this.desc1 = desc1;
79          this.desc2 = desc2;
80          this.i18n = i18n;
81          this.categoryReports = Collections.unmodifiableList(categoryReports);
82          this.log = log;
83      }
84  
85      public void renderDocument(Writer writer, Renderer siteRenderer, SiteRenderingContext siteRenderingContext)
86              throws RendererException, FileNotFoundException {
87          SiteRendererSink sink = new SiteRendererSink(docRenderingContext);
88  
89          sink.head();
90  
91          sink.title();
92  
93          sink.text(title);
94  
95          sink.title_();
96  
97          sink.head_();
98  
99          sink.body();
100 
101         sink.section1();
102         sink.sectionTitle1();
103         sink.text(title);
104         sink.sectionTitle1_();
105 
106         sink.paragraph();
107         sink.text(desc1 + " ");
108         sink.link("http://maven.apache.org");
109         sink.text("Maven");
110         sink.link_();
111         sink.text(" " + desc2);
112         sink.paragraph_();
113 
114         sink.section2();
115         sink.sectionTitle2();
116         Locale locale = siteRenderingContext.getLocale();
117         sink.text(i18n.getString("site-plugin", locale, "report.category.sectionTitle"));
118         sink.sectionTitle2_();
119 
120         sink.table();
121 
122         sink.tableRows(new int[] {Sink.JUSTIFY_LEFT, Sink.JUSTIFY_LEFT}, false);
123 
124         String name = i18n.getString("site-plugin", locale, "report.category.column.document");
125         String description = i18n.getString("site-plugin", locale, "report.category.column.description");
126 
127         sink.tableRow();
128 
129         sink.tableHeaderCell();
130 
131         sink.text(name);
132 
133         sink.tableHeaderCell_();
134 
135         sink.tableHeaderCell();
136 
137         sink.text(description);
138 
139         sink.tableHeaderCell_();
140 
141         sink.tableRow_();
142 
143         if (categoryReports != null) {
144             for (MavenReport report : categoryReports) {
145                 sink.tableRow();
146                 sink.tableCell();
147                 sink.link(report.getOutputName() + ".html");
148                 sink.text(report.getName(locale));
149                 sink.link_();
150                 sink.tableCell_();
151                 sink.tableCell();
152                 sink.text(report.getDescription(locale));
153                 sink.tableCell_();
154                 sink.tableRow_();
155             }
156         }
157 
158         sink.tableRows_();
159 
160         sink.table_();
161 
162         sink.section2_();
163 
164         sink.section1_();
165 
166         sink.body_();
167 
168         sink.flush();
169 
170         sink.close();
171 
172         siteRenderer.mergeDocumentIntoSite(writer, sink, siteRenderingContext);
173     }
174 
175     public String getOutputName() {
176         return docRenderingContext.getOutputName();
177     }
178 
179     public RenderingContext getRenderingContext() {
180         return docRenderingContext;
181     }
182 
183     public boolean isOverwrite() {
184         return true;
185     }
186 
187     public boolean isExternalReport() {
188         return false;
189     }
190 }