1 package org.apache.maven.plugins.site;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
44
45
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 }