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.FileNotFoundException;
027: import java.io.FileOutputStream;
028: import java.io.InputStream;
029: import java.util.Iterator;
030:
031: import org.hammurapi.render.dom.InspectorDescriptorRenderer;
032: import org.hammurapi.render.dom.InspectorSetRenderer;
033:
034: import com.pavelvlasov.config.ConfigurationException;
035: import com.pavelvlasov.logging.Logger;
036: import com.pavelvlasov.logging.ConsoleLogger;
037: import com.pavelvlasov.render.RenderRequest;
038: import com.pavelvlasov.render.RenderingException;
039: import com.pavelvlasov.render.dom.AbstractRenderer;
040:
041: /**
042: * @author Pavel Vlasov
043: * @version $Revision: 1.9 $
044: */
045: public class EmbeddedInspectorSetDocumenter {
046:
047: public static void main(String[] args) throws Exception {
048: System.out
049: .println("Usage: EmbeddedInspecgtorSetDocumenter <output dir> <yes|no>");
050:
051: InspectorSet inspectorSet = new InspectorSet(
052: new InspectorContextFactory() {
053: public InspectorContext newContext(
054: InspectorDescriptor descriptor,
055: Logger logger) {
056: return new InspectorContextImpl(descriptor,
057: logger, null, null, null);
058: }
059: }, new ConsoleLogger(ConsoleLogger.VERBOSE));
060:
061: InputStream inspectorStream = HammurapiTask.class
062: .getResourceAsStream("TaskBase.xml");
063: if (inspectorStream == null) {
064: throw new HammurapiException(
065: "Cannot load embedded inspectors");
066: }
067:
068: DomInspectorSource source = new DomInspectorSource(
069: inspectorStream, "Hammurapi.jar");
070: source.loadInspectors(inspectorSet);
071:
072: File outDir = new File(args[0]);
073:
074: boolean embedded = "yes".equals(args[1]);
075: render(
076: new InspectorSetRenderer(
077: new RenderRequest(inspectorSet)), new File(
078: outDir, "inspectors.html"), embedded);
079:
080: try {
081: Iterator inspectors = inspectorSet.getInspectors()
082: .iterator();
083: while (inspectors.hasNext()) {
084: InspectorDescriptor d = ((Inspector) inspectors.next())
085: .getContext().getDescriptor();
086: render(new InspectorDescriptorRenderer(
087: new RenderRequest(d)),
088: new File(outDir, "inspectors/inspector_"
089: + d.getName() + ".html"), embedded);
090: }
091: } catch (ConfigurationException e) {
092: throw new HammurapiException(
093: "Cannot render inspector descriptions.", e);
094: }
095:
096: }
097:
098: private static void render(AbstractRenderer renderer, File outFile,
099: boolean embedded) throws RenderingException,
100: FileNotFoundException, HammurapiException {
101: File outFileParent = outFile.getParentFile();
102: if (!outFileParent.exists()) {
103: if (!outFileParent.mkdirs()) {
104: throw new HammurapiException("Can't create "
105: + outFileParent.getAbsolutePath());
106: }
107: }
108:
109: renderer.setEmbeddedStyle(true);
110:
111: if (embedded) {
112: renderer.setParameter("embedded", "yes");
113: }
114:
115: renderer.render(new FileOutputStream(outFile));
116: }
117:
118: }
|