1 23 package org.hammurapi; 24 25 import java.io.File ; 26 import java.io.FileNotFoundException ; 27 import java.io.FileOutputStream ; 28 import java.io.InputStream ; 29 import java.util.Iterator ; 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 45 public class EmbeddedInspectorSetDocumenter { 46 47 public static void main(String [] args) throws Exception { 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 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 outDir=new File (args[0]); 67 68 boolean embedded = "yes".equals(args[1]); 69 render(new InspectorSetRenderer(new RenderRequest(inspectorSet)), new File (outDir, "inspectors.html"), embedded); 70 71 try { 72 Iterator 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 (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 outFile, boolean embedded) throws RenderingException, FileNotFoundException , HammurapiException { 84 File 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 (outFile)); 98 } 99 100 101 } 102 | Popular Tags |