Revision: 1676 http://svn.sourceforge.net/vexi/?rev=1676&view=rev Author: mkpg2 Date: 2007-02-14 07:34:35 -0800 (Wed, 14 Feb 2007)
Log Message: ----------- Some refactoring, removing hardcoding. Modified Paths: -------------- tools/trunk/org.vexi.widgetdoc/src/org/vexi/widgetdoc/Main.java tools/trunk/org.vexi.widgetdoc/src/org/vexi/widgetdoc/util/Util.java Removed Paths: ------------- tools/trunk/org.vexi.widgetdoc/src/org/vexi/widgetdoc/FreemarkerGenerator.java Deleted: tools/trunk/org.vexi.widgetdoc/src/org/vexi/widgetdoc/FreemarkerGenerator.java =================================================================== --- tools/trunk/org.vexi.widgetdoc/src/org/vexi/widgetdoc/FreemarkerGenerator.java 2007-02-14 14:39:12 UTC (rev 1675) +++ tools/trunk/org.vexi.widgetdoc/src/org/vexi/widgetdoc/FreemarkerGenerator.java 2007-02-14 15:34:35 UTC (rev 1676) @@ -1,50 +0,0 @@ -package org.vexi.widgetdoc; - -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.OutputStreamWriter; -import java.io.Writer; -import java.util.Map; - -import freemarker.template.Configuration; -import freemarker.template.DefaultObjectWrapper; -import freemarker.template.Template; -import freemarker.template.TemplateException; - -public class FreemarkerGenerator { - - static final String OUTPUT_DIR = "generated"; - - // Singleton - static Configuration cfg; - - static public Configuration getConfiguration() { - if (cfg == null) { - cfg = new Configuration(); - // Specify the data source where the template files come from. - // Here I set a file directory for it: - cfg.setClassForTemplateLoading( org.vexi.autodoc.templates.Resource.class, ""); - - // Specify how templates will see the data model. This is an - // advanced topic... - // but just use this: - cfg.setObjectWrapper(new DefaultObjectWrapper()); - } - return cfg; - } - - static void generateSimple(String templateName, String outputName, Map root) throws IOException, TemplateException{ - System.out.println("++++ Generating " + outputName); - Template temp = getConfiguration().getTemplate(templateName); - File outputDir = new File(OUTPUT_DIR); - // replace .t with .html - File outputFile = new File(outputDir,outputName); - outputFile.getParentFile().mkdirs(); - Writer out = new OutputStreamWriter(new FileOutputStream(outputFile)); - //Writer out = new OutputStreamWriter(System.out); - temp.process(root, out); - out.flush(); - } - -} Modified: tools/trunk/org.vexi.widgetdoc/src/org/vexi/widgetdoc/Main.java =================================================================== --- tools/trunk/org.vexi.widgetdoc/src/org/vexi/widgetdoc/Main.java 2007-02-14 14:39:12 UTC (rev 1675) +++ tools/trunk/org.vexi.widgetdoc/src/org/vexi/widgetdoc/Main.java 2007-02-14 15:34:35 UTC (rev 1676) @@ -14,22 +14,27 @@ import org.vexi.widgetdoc.model.TFileModel; import org.vexi.widgetdoc.util.Util; +import freemarker.template.TemplateException; + public class Main { + static final String SUMMARY_TEMPLATE = "summary.ftl"; static final String PINDEX_TEMPLATE = "packageindex.ftl"; static final String TINDEX_TEMPLATE = "index.ftl"; private static final String TEMPLATE_TEMPLATE = "template.ftl"; static String rootPath; + static String outputDir; + /** * @param args * @throws Exception */ public static void main(String[] args) throws Exception { - //rootPath = "test"; - rootPath = "../org.vexi.widgets/src"; + outputDir = (args.length>0)?args[0]:"generated"; + rootPath = (args.length>1)?args[1]:"../org.vexi.widgets/src"; traverse(rootPath,"vexi.widget"); traverse(rootPath,"vexi.util"); @@ -45,7 +50,7 @@ // Generate ui:box - FreemarkerGenerator.generateSimple(TEMPLATE_TEMPLATE, "templates/_ui_box.html", BoxModel.getFTLModel()); + generate(TEMPLATE_TEMPLATE, "templates/_ui_box.html", BoxModel.getFTLModel()); // Generate templates Map traversed = TFileTraverser.traversed; @@ -54,23 +59,23 @@ String name = (String)I.next(); TFile tf = (TFile)traversed.get(name); String outputName = templateFilename(tf.getName()); - FreemarkerGenerator.generateSimple(TEMPLATE_TEMPLATE, "templates/"+outputName, TFileModel.getFTLModel(tf)); + generate(TEMPLATE_TEMPLATE, "templates/"+outputName, TFileModel.getFTLModel(tf)); } Map<String, Object> summaryModel = new HashMap<String, Object>(); summaryModel.put("version", "?"); summaryModel.put("generation_date",new Date(System.currentTimeMillis())); - FreemarkerGenerator.generateSimple(SUMMARY_TEMPLATE, "summary.html", summaryModel); + generate(SUMMARY_TEMPLATE, "summary.html", summaryModel); - FreemarkerGenerator.generateSimple(PINDEX_TEMPLATE, "packageindex.html", Package.packageIndexModel()); + generate(PINDEX_TEMPLATE, "packageindex.html", Package.packageIndexModel()); // Index of all templates - FreemarkerGenerator.generateSimple(TINDEX_TEMPLATE, "indices/_alltemplates.html", Package.allPackagesModel()); + generate(TINDEX_TEMPLATE, "indices/_alltemplates.html", Package.allPackagesModel()); Iterator<Package> I2 = Package.packages(); while(I2.hasNext()){ Package p = I2.next(); - FreemarkerGenerator.generateSimple(TINDEX_TEMPLATE, "indices/" + p.name + ".html", p.packageModel()); + generate(TINDEX_TEMPLATE, "indices/" + p.name + ".html", p.packageModel()); } @@ -86,7 +91,7 @@ System.out.println("++++ Copying " + name); InputStream is = org.vexi.autodoc.staticfiles.Resource.class.getResourceAsStream(name); - File out = new File(FreemarkerGenerator.OUTPUT_DIR + "/"+name); + File out = new File(outputDir + "/"+name); Util.copy(is, out); } @@ -125,7 +130,10 @@ f.isDirectory(); } - + static private void generate(String templateName, String outputName, Map root) throws IOException, TemplateException{ + Util.generateSimple(templateName, outputDir, outputName, root); + } + static public String templateFilename(String templateName){ return templateName + ".html"; } Modified: tools/trunk/org.vexi.widgetdoc/src/org/vexi/widgetdoc/util/Util.java =================================================================== --- tools/trunk/org.vexi.widgetdoc/src/org/vexi/widgetdoc/util/Util.java 2007-02-14 14:39:12 UTC (rev 1675) +++ tools/trunk/org.vexi.widgetdoc/src/org/vexi/widgetdoc/util/Util.java 2007-02-14 15:34:35 UTC (rev 1676) @@ -8,14 +8,23 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.io.OutputStreamWriter; import java.io.Reader; import java.io.StringWriter; +import java.io.Writer; import java.nio.MappedByteBuffer; import java.nio.channels.FileChannel; import java.util.ArrayList; +import java.util.Map; +import org.vexi.widgetdoc.Main; + +import freemarker.template.Configuration; +import freemarker.template.DefaultObjectWrapper; import freemarker.template.SimpleCollection; +import freemarker.template.Template; import freemarker.template.TemplateCollectionModel; +import freemarker.template.TemplateException; public class Util { @@ -116,5 +125,41 @@ } return bytesCopied; } + + ///////////// + // FREEMARKER + ////////// + + // Singleton + static Configuration cfg; + + static private Configuration getConfiguration() { + if (cfg == null) { + cfg = new Configuration(); + // Specify the data source where the template files come from. + // Here I set a file directory for it: + cfg.setClassForTemplateLoading( org.vexi.autodoc.templates.Resource.class, ""); + + // Specify how templates will see the data model. This is an + // advanced topic... + // but just use this: + cfg.setObjectWrapper(new DefaultObjectWrapper()); + } + return cfg; + } + + static public void generateSimple(String templateName, String outputDirName, String outputName, Map root) throws IOException, TemplateException{ + System.out.println("++++ Generating " + outputName); + Template temp = getConfiguration().getTemplate(templateName); + File outputDir = new File(outputDirName); + // replace .t with .html + File outputFile = new File(outputDir,outputName); + outputFile.getParentFile().mkdirs(); + Writer out = new OutputStreamWriter(new FileOutputStream(outputFile)); + //Writer out = new OutputStreamWriter(System.out); + temp.process(root, out); + out.flush(); + } + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys-and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV _______________________________________________ Vexi-svn mailing list Vexi-svn@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/vexi-svn