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