KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hammurapi > EmbeddedInspectorSetDocumenter


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.FileNotFoundException JavaDoc;
27 import java.io.FileOutputStream JavaDoc;
28 import java.io.InputStream JavaDoc;
29 import java.util.Iterator JavaDoc;
30
31 import org.hammurapi.render.dom.InspectorDescriptorRenderer;
32 import org.hammurapi.render.dom.InspectorSetRenderer;
33
34 import com.pavelvlasov.config.ConfigurationException;
35 import com.pavelvlasov.logging.Logger;
36 import com.pavelvlasov.logging.ConsoleLogger;
37 import com.pavelvlasov.render.RenderRequest;
38 import com.pavelvlasov.render.RenderingException;
39 import com.pavelvlasov.render.dom.AbstractRenderer;
40
41 /**
42  * @author Pavel Vlasov
43  * @version $Revision: 1.9 $
44  */

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