001: /*
002: * Hammurapi
003: * Automated Java code review system.
004: * Copyright (C) 2004 Hammurapi Group
005: *
006: * This program is free software; you can redistribute it and/or modify
007: * it under the terms of the GNU General Public License as published by
008: * the Free Software Foundation; either version 2 of the License, or
009: * (at your option) any later version.
010: *
011: * This program is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: * GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
019: *
020: * URL: http://www.hammurapi.org
021: * e-Mail: support@hammurapi.biz
022: */
023: package org.hammurapi;
024:
025: import java.io.File;
026: import java.io.FileInputStream;
027: import java.io.FileNotFoundException;
028: import java.io.FileOutputStream;
029: import java.io.InputStream;
030: import java.util.Iterator;
031:
032: import org.hammurapi.render.dom.InspectorDescriptorRenderer;
033: import org.hammurapi.render.dom.InspectorSetRenderer;
034:
035: import com.pavelvlasov.config.ConfigurationException;
036: import com.pavelvlasov.logging.ConsoleLogger;
037: import com.pavelvlasov.logging.Logger;
038: import com.pavelvlasov.render.RenderRequest;
039: import com.pavelvlasov.render.RenderingException;
040: import com.pavelvlasov.render.dom.AbstractRenderer;
041:
042: /**
043: * @author Pavel Vlasov
044: * @version $Revision: 1.8 $
045: */
046: public class V4InspectorSetDocumenter {
047:
048: public static void main(String[] args) throws Exception {
049: System.out
050: .println("Usage: EmbeddedInspecgtorSetDocumenter <output dir> <yes|no>");
051:
052: InspectorSet inspectorSet = new InspectorSet(
053: new InspectorContextFactory() {
054: public InspectorContext newContext(
055: InspectorDescriptor descriptor,
056: Logger logger) {
057: return new InspectorContextImpl(descriptor,
058: logger, null, null, null);
059: }
060: }, new ConsoleLogger(ConsoleLogger.VERBOSE));
061:
062: InputStream inspectorStream = new FileInputStream(
063: "inspectors.xml");
064:
065: DomInspectorSource source = new DomInspectorSource(
066: inspectorStream, "inspectors.xml");
067: source.loadInspectors(inspectorSet);
068:
069: File outDir = new File(args[0]);
070:
071: boolean embedded = "yes".equals(args[1]);
072: render(
073: new InspectorSetRenderer(
074: new RenderRequest(inspectorSet)), new File(
075: outDir, "inspectors.html"), embedded);
076:
077: try {
078: Iterator inspectors = inspectorSet.getInspectors()
079: .iterator();
080: while (inspectors.hasNext()) {
081: InspectorDescriptor d = ((Inspector) inspectors.next())
082: .getContext().getDescriptor();
083: render(new InspectorDescriptorRenderer(
084: new RenderRequest(d)),
085: new File(outDir, "inspectors/inspector_"
086: + d.getName() + ".html"), embedded);
087: }
088: } catch (ConfigurationException e) {
089: throw new HammurapiException(
090: "Cannot render inspector descriptions.", e);
091: }
092: }
093:
094: private static void render(AbstractRenderer renderer, File outFile,
095: boolean embedded) throws RenderingException,
096: FileNotFoundException, HammurapiException {
097: File outFileParent = outFile.getParentFile();
098: if (!outFileParent.exists()) {
099: if (!outFileParent.mkdirs()) {
100: throw new HammurapiException("Can't create "
101: + outFileParent.getAbsolutePath());
102: }
103: }
104:
105: renderer.setEmbeddedStyle(true);
106:
107: if (embedded) {
108: renderer.setParameter("embedded", "yes");
109: }
110:
111: renderer.render(new FileOutputStream(outFile));
112: }
113:
114: }
|