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.File; |
23 | |
import java.io.IOException; |
24 | |
|
25 | |
import java.util.Iterator; |
26 | |
import java.util.List; |
27 | |
import java.util.Locale; |
28 | |
|
29 | |
import org.apache.maven.doxia.module.xdoc.XdocSinkFactory; |
30 | |
import org.apache.maven.doxia.sink.Sink; |
31 | |
import org.apache.maven.doxia.site.decoration.DecorationModel; |
32 | |
import org.apache.maven.doxia.site.decoration.Menu; |
33 | |
import org.apache.maven.doxia.site.decoration.MenuItem; |
34 | |
|
35 | |
import org.codehaus.plexus.i18n.I18N; |
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
public class SiteMap |
45 | |
{ |
46 | |
|
47 | |
private String encoding; |
48 | |
private I18N i18n; |
49 | |
|
50 | |
public SiteMap( String encoding, I18N i18n ) |
51 | 0 | { |
52 | 0 | this.encoding = encoding; |
53 | 0 | this.i18n = i18n; |
54 | 0 | } |
55 | |
|
56 | |
|
57 | |
|
58 | |
|
59 | |
|
60 | |
|
61 | |
public I18N getI18n() |
62 | |
{ |
63 | 0 | return i18n; |
64 | |
} |
65 | |
|
66 | |
|
67 | |
|
68 | |
|
69 | |
|
70 | |
|
71 | |
public void setI18n( I18N i18n ) |
72 | |
{ |
73 | 0 | this.i18n = i18n; |
74 | 0 | } |
75 | |
|
76 | |
|
77 | |
|
78 | |
|
79 | |
|
80 | |
|
81 | |
public String getEncoding() |
82 | |
{ |
83 | 0 | return encoding; |
84 | |
} |
85 | |
|
86 | |
|
87 | |
|
88 | |
|
89 | |
|
90 | |
|
91 | |
public void setEncoding( String enc ) |
92 | |
{ |
93 | 0 | this.encoding = enc; |
94 | 0 | } |
95 | |
|
96 | |
|
97 | |
|
98 | |
|
99 | |
|
100 | |
|
101 | |
|
102 | |
|
103 | |
|
104 | |
|
105 | |
|
106 | |
|
107 | |
public void generate( DecorationModel model, File targetDir, Locale locale ) |
108 | |
throws IOException |
109 | |
{ |
110 | 0 | File outputDir = new File( targetDir, "xdoc" ); |
111 | 0 | Sink sink = new XdocSinkFactory().createSink( outputDir, "sitemap.xml", encoding ); |
112 | |
|
113 | |
try |
114 | |
{ |
115 | 0 | extract( model, sink, locale ); |
116 | |
} |
117 | |
finally |
118 | |
{ |
119 | 0 | sink.close(); |
120 | 0 | } |
121 | 0 | } |
122 | |
|
123 | |
private void extract( DecorationModel decoration, Sink sink, Locale locale ) |
124 | |
{ |
125 | 0 | sink.head(); |
126 | 0 | sink.title(); |
127 | 0 | sink.text( i18n.getString( "site-plugin", locale, "site.sitemap.title" ) ); |
128 | 0 | sink.title_(); |
129 | 0 | sink.head_(); |
130 | 0 | sink.body(); |
131 | |
|
132 | 0 | sink.section1(); |
133 | 0 | sink.sectionTitle1(); |
134 | 0 | sink.text( i18n.getString( "site-plugin", locale, "site.sitemap.section.title" ) ); |
135 | 0 | sink.sectionTitle1_(); |
136 | |
|
137 | 0 | sink.paragraph(); |
138 | 0 | sink.text( i18n.getString( "site-plugin", locale, "site.sitemap.description" ) ); |
139 | 0 | sink.paragraph_(); |
140 | |
|
141 | 0 | for ( Iterator<Menu> it = decoration.getMenus().iterator(); it.hasNext(); ) |
142 | |
{ |
143 | 0 | Menu menu = it.next(); |
144 | |
|
145 | 0 | sink.section3(); |
146 | 0 | sink.sectionTitle3(); |
147 | 0 | sink.text( menu.getName() ); |
148 | 0 | sink.sectionTitle3_(); |
149 | 0 | sink.horizontalRule(); |
150 | |
|
151 | 0 | extractItems( menu.getItems(), sink ); |
152 | |
|
153 | 0 | sink.section3_(); |
154 | 0 | } |
155 | |
|
156 | 0 | sink.section1_(); |
157 | 0 | sink.body_(); |
158 | 0 | } |
159 | |
|
160 | |
private void extractItems( List<MenuItem> items, Sink sink ) |
161 | |
{ |
162 | 0 | if ( items == null || items.isEmpty() ) |
163 | |
{ |
164 | 0 | return; |
165 | |
} |
166 | |
|
167 | 0 | sink.list(); |
168 | |
|
169 | 0 | for ( MenuItem item : items ) |
170 | |
{ |
171 | 0 | sink.listItem(); |
172 | 0 | sink.link( item.getHref() ); |
173 | 0 | sink.text( item.getName() ); |
174 | 0 | sink.link_(); |
175 | 0 | sink.listItem_(); |
176 | |
|
177 | 0 | extractItems( item.getItems(), sink ); |
178 | |
} |
179 | |
|
180 | 0 | sink.list_(); |
181 | 0 | } |
182 | |
} |