1 package org.apache.maven.jxr;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 import org.apache.commons.logging.LogFactory;
21 import org.apache.commons.logging.Log;
22
23 import java.io.IOException;
24 import java.util.LinkedList;
25 import java.util.List;
26 import java.util.Locale;
27
28 /**
29 * Creates an html-based, cross referenced version of Java source code
30 * for a project.
31 *
32 * @author <a href="mailto:lucas@collab.net">Josh Lucas</a>
33 * @author <a href="mailto:jason@zenplex.com">Jason van Zyl</a>
34 * @author <a href="mailto:brian@brainslug.com">Brian Leonard</a>
35 * @version $Id: JxrBean.java 379214 2006-02-20 19:52:34Z ltheussl $
36 */
37 public class JxrBean
38 {
39 /** List of source directories to be cross-referenced. */
40 private List sourceDirs;
41
42 /** The destination directory for jxr output. */
43 private String destDir;
44
45 /** The locale. */
46 private Locale locale;
47
48 /** The inputEncoding. */
49 private String inputEncoding;
50
51 /** The outputEncoding. */
52 private String outputEncoding;
53
54 /** Used to cross-reference with javadoc pages. */
55 private String javadocDir;
56
57 /** Used by DirectoryIndexer. */
58 private String windowTitle;
59
60 /** Used by DirectoryIndexer. */
61 private String docTitle;
62
63 /** Used by DirectoryIndexer. */
64 private String bottom;
65
66 /** Where the navigation templates are located. */
67 private String templateDir;
68
69 /** Used for logging. */
70 private final Log log = LogFactory.getLog( JxrBean.class );
71
72 /**
73 * Default constructor
74 */
75 public JxrBean()
76 {
77 sourceDirs = new LinkedList();
78 }
79
80 /**
81 * Starts the cross-referencing and indexing.
82 * @throws JxrException JxrException
83 */
84 public void xref()
85 throws JxrException
86 {
87 org.apache.maven.jxr.log.Log logger = new org.apache.maven.jxr.log.Log()
88 {
89 public void info( String message )
90 {
91 log.info( message );
92 }
93
94 public void debug( String message )
95 {
96 log.debug( message );
97 }
98
99 public void warn( String message )
100 {
101 log.warn( message );
102 }
103
104 public void error( String message )
105 {
106 log.error( message );
107 }
108 };
109
110 JXR jxr = new JXR();
111 jxr.setDest( destDir );
112 jxr.setLocale( locale );
113 jxr.setInputEncoding( inputEncoding );
114 jxr.setOutputEncoding( outputEncoding );
115 jxr.setJavadocLinkDir( javadocDir );
116 jxr.setRevision( "HEAD" );
117 jxr.setLog( logger );
118
119 try
120 {
121 jxr.xref( sourceDirs, getTemplateDir(), getWindowTitle(), getDocTitle(), getBottom() );
122 }
123 catch ( IOException e )
124 {
125 throw new JxrException( "Error processing files", e );
126 }
127 }
128
129 /**
130 * Sets a list of source directories to be cross-referenced.
131 * @param newSourceDirs The list of source directories.
132 */
133 public void setSourceDirs( List newSourceDirs )
134 {
135 if ( !sourceDirs.isEmpty() )
136 {
137 sourceDirs.clear();
138 }
139 this.sourceDirs = newSourceDirs;
140 }
141
142 /**
143 * Sets a single source directory to be cross-referenced.
144 * @param sourceDir The source directory to be cross-referenced.
145 */
146 public void setSourceDir( String sourceDir )
147 {
148 if ( !sourceDirs.isEmpty() )
149 {
150 sourceDirs.clear();
151 }
152 addSourceDir( sourceDir );
153 }
154
155 /**
156 * Adds a directory to the list of those to be cross-referenced.
157 * @param sourceDir The source directory to be cross-referenced.
158 */
159 public void addSourceDir( String sourceDir )
160 {
161 sourceDirs.add( sourceDir );
162 }
163
164
165 /**
166 * DestDir is the directory in which jxr will write its output
167 * @param newDestDir the destination directory for jxr output
168 */
169 public void setDestDir( String newDestDir )
170 {
171 this.destDir = newDestDir;
172 }
173
174 /**
175 * see setDestDir(String)
176 * @return destDir
177 */
178 public String getDestDir()
179 {
180 return destDir;
181 }
182
183 /**
184 * Returns the locale.
185 * @return the locale.
186 */
187 public Locale getLocale()
188 {
189 return locale;
190 }
191
192 /**
193 *Sets the locale.
194 * @param newLocale the locale.
195 */
196 public void setLocale( Locale newLocale )
197 {
198 this.locale = newLocale;
199 }
200
201 /**
202 * InputEncoding is the encoding of source files.
203 * @param newInputEncoding encoding of source files
204 */
205 public void setInputEncoding( String newInputEncoding )
206 {
207 this.inputEncoding = newInputEncoding;
208 }
209
210 /**
211 * see setInputEncoding(String)
212 * @return inputEncoding
213 */
214 public String getInputEncoding()
215 {
216 return inputEncoding;
217 }
218
219
220 /**
221 * OutputEncoding is the encoding of output files.
222 * @param newOutputEncoding encoding of output files
223 */
224 public void setOutputEncoding( String newOutputEncoding )
225 {
226 this.outputEncoding = newOutputEncoding;
227 }
228
229 /**
230 * see setOutputEncoding(String)
231 * @return outputEncoding
232 */
233 public String getOutputEncoding()
234 {
235 return outputEncoding;
236 }
237
238
239 /**
240 * JavadocDir is used to cross-reference the source code with
241 * the appropriate javadoc pages.
242 *
243 * If <code>null</code>, no javadoc link will be added.
244 *
245 * @param newJavadocDir The root directory containing javadocs
246 */
247 public void setJavadocDir( String newJavadocDir )
248 {
249 this.javadocDir = newJavadocDir;
250 }
251
252 /**
253 * see setJavadocDir(String)
254 * @return javadocDir
255 */
256 public String getJavadocDir()
257 {
258 return javadocDir;
259 }
260
261 /**
262 * see DirectoryIndexer
263 * @param newWindowTitle used by DirectoryIndexer
264 * @see DirectoryIndexer#setWindowTitle(String) setWindowTitle(String)
265 */
266 public void setWindowTitle( String newWindowTitle )
267 {
268 this.windowTitle = newWindowTitle;
269 }
270
271 /**
272 * see DirectoryIndexer
273 * @return windowTitle
274 * @see DirectoryIndexer#setWindowTitle(String) setWindowTitle(String)
275 */
276 public String getWindowTitle()
277 {
278 return windowTitle;
279 }
280
281 /**
282 * see DirectoryIndexer
283 * @param newDocTitle used by DirectoryIndexer
284 * @see DirectoryIndexer#setDocTitle(String) setDocTitle(String)
285 */
286 public void setDocTitle( String newDocTitle )
287 {
288 this.docTitle = newDocTitle;
289 }
290
291 /**
292 * see DirectoryIndexer
293 * @return docTitle
294 * @see DirectoryIndexer#setDocTitle(String) setDocTitle(String)
295 */
296 public String getDocTitle()
297 {
298 return docTitle;
299 }
300
301 /**
302 * see DirectoryIndexer
303 * @param newBottom used by DirectoryIndexer
304 * @see DirectoryIndexer#setBottom(String) setBottom(String)
305 */
306 public void setBottom( String newBottom )
307 {
308 this.bottom = newBottom;
309 }
310
311 /**
312 * see DirectoryIndexer
313 * @return bottom
314 * @see DirectoryIndexer#setBottom(String) setBottom(String)
315 */
316 public String getBottom()
317 {
318 return bottom;
319 }
320
321 /**
322 * TemplateDir is where the navigation templates are located
323 * @param newTemplateDir the template directory
324 */
325 public void setTemplateDir( String newTemplateDir )
326 {
327 this.templateDir = newTemplateDir;
328 }
329
330 /**
331 * see setTemplateDir(String)
332 * @return templateDir
333 */
334 public String getTemplateDir()
335 {
336 return templateDir;
337 }
338
339 }
340