KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hammurapi > V4InspectorSetDocumenter


1 /*
2  * Hammurapi
3  * Automated Java code review system.
4  * Copyright (C) 2004 Hammurapi Group
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  *
20  * URL: http://www.hammurapi.org
21  * e-Mail: support@hammurapi.biz
22  */

23 package org.hammurapi;
24
25 import java.io.File JavaDoc;
26 import java.io.FileInputStream JavaDoc;
27 import java.io.FileNotFoundException JavaDoc;
28 import java.io.FileOutputStream JavaDoc;
29 import java.io.InputStream JavaDoc;
30 import java.util.Iterator JavaDoc;
31
32 import org.hammurapi.render.dom.InspectorDescriptorRenderer;
33 import org.hammurapi.render.dom.InspectorSetRenderer;
34
35 import com.pavelvlasov.config.ConfigurationException;
36 import com.pavelvlasov.logging.ConsoleLogger;
37 import com.pavelvlasov.logging.Logger;
38 import com.pavelvlasov.render.RenderRequest;
39 import com.pavelvlasov.render.RenderingException;
40 import com.pavelvlasov.render.dom.AbstractRenderer;
41
42 /**
43  * @author Pavel Vlasov
44  * @version $Revision: 1.8 $
45  */

46 public class V4InspectorSetDocumenter {
47
48     public static void main(String JavaDoc[] args) throws Exception JavaDoc {
49         System.out.println("Usage: EmbeddedInspecgtorSetDocumenter <output dir> <yes|no>");
50         
51         InspectorSet inspectorSet=new InspectorSet(
52             new InspectorContextFactory() {
53                 public InspectorContext newContext(InspectorDescriptor descriptor, Logger logger) {
54                     return new InspectorContextImpl(descriptor, logger, null, null, null);
55                 }
56             },
57             new ConsoleLogger(ConsoleLogger.VERBOSE));
58         
59         InputStream JavaDoc inspectorStream=new FileInputStream JavaDoc("inspectors.xml");
60         
61         DomInspectorSource source=new DomInspectorSource(inspectorStream, "inspectors.xml");
62         source.loadInspectors(inspectorSet);
63         
64         File JavaDoc outDir=new File JavaDoc(args[0]);
65         
66         boolean embedded = "yes".equals(args[1]);
67         render(new InspectorSetRenderer(new RenderRequest(inspectorSet)), new File JavaDoc(outDir, "inspectors.html"), embedded);
68
69         try {
70             Iterator JavaDoc inspectors=inspectorSet.getInspectors().iterator();
71             while (inspectors.hasNext()) {
72                 InspectorDescriptor d =((Inspector) inspectors.next()).getContext().getDescriptor();
73                 render(new InspectorDescriptorRenderer(new RenderRequest(d)), new File JavaDoc(outDir, "inspectors/inspector_" + d.getName() + ".html"), embedded);
74             }
75         } catch (ConfigurationException e) {
76             throw new HammurapiException("Cannot render inspector descriptions.", e);
77         }
78     }
79
80     private static void render(AbstractRenderer renderer, File JavaDoc outFile, boolean embedded) throws RenderingException, FileNotFoundException JavaDoc, HammurapiException {
81         File JavaDoc outFileParent=outFile.getParentFile();
82         if (!outFileParent.exists()) {
83             if (!outFileParent.mkdirs()) {
84                 throw new HammurapiException("Can't create "+outFileParent.getAbsolutePath());
85             }
86         }
87         
88         renderer.setEmbeddedStyle(true);
89         
90         if (embedded) {
91             renderer.setParameter("embedded", "yes");
92         }
93                 
94         renderer.render(new FileOutputStream JavaDoc(outFile));
95     }
96     
97
98 }
99
Popular Tags