1 23 package org.hammurapi; 24 25 import java.io.File ; 26 import java.io.FileInputStream ; 27 import java.io.FileNotFoundException ; 28 import java.io.FileOutputStream ; 29 import java.io.InputStream ; 30 import java.util.Iterator ; 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 46 public class V4InspectorSetDocumenter { 47 48 public static void main(String [] args) throws Exception { 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 inspectorStream=new FileInputStream ("inspectors.xml"); 60 61 DomInspectorSource source=new DomInspectorSource(inspectorStream, "inspectors.xml"); 62 source.loadInspectors(inspectorSet); 63 64 File outDir=new File (args[0]); 65 66 boolean embedded = "yes".equals(args[1]); 67 render(new InspectorSetRenderer(new RenderRequest(inspectorSet)), new File (outDir, "inspectors.html"), embedded); 68 69 try { 70 Iterator 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 (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 outFile, boolean embedded) throws RenderingException, FileNotFoundException , HammurapiException { 81 File 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 (outFile)); 95 } 96 97 98 } 99 | Popular Tags |