From: <dr...@us...> - 2003-06-12 00:48:21
|
Update of /cvsroot/webmacro/webmacro/src/org/webmacro/tools In directory sc8-pr-cvs1:/tmp/cvs-serv6675/src/org/webmacro/tools Modified Files: CheckTemplates.java EvalTemplates.java TemplateEvalAntTask.java WMTemplateAntTask.java Log Message: If this doesn't drive our SF "activity" stats through the roof, I don't know what will. Mass re-formatting of all code, following (to the best of my interpertation) the Sun (w/ jakarta tweaks) coding style guidelines defined here: http://java.sun.com/docs/codeconv/html/CodeConvTOC.doc.html and here: http://jakarta.apache.org/turbine/common/code-standards.html I did this reformatting with IDEA 3.0.5, and I am going to commit the style configuration for IDEA (if I can find it). Index: CheckTemplates.java =================================================================== RCS file: /cvsroot/webmacro/webmacro/src/org/webmacro/tools/CheckTemplates.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** CheckTemplates.java 12 Jun 2002 17:17:28 -0000 1.6 --- CheckTemplates.java 12 Jun 2003 00:47:48 -0000 1.7 *************** *** 1,13 **** package org.webmacro.tools; - import java.io.*; - import org.webmacro.Broker; import org.webmacro.WM; - import org.webmacro.engine.Block; import org.webmacro.engine.BuildContext; import org.webmacro.engine.Builder; import org.webmacro.engine.Parser; /** * CheckTemplates --- 1,14 ---- package org.webmacro.tools; import org.webmacro.Broker; import org.webmacro.WM; import org.webmacro.engine.BuildContext; import org.webmacro.engine.Builder; import org.webmacro.engine.Parser; + import java.io.FileReader; + import java.io.InputStreamReader; + import java.io.Reader; + /** * CheckTemplates *************** *** 18,51 **** */ ! public class CheckTemplates { ! private static Parser parser; ! private static Broker broker; ! public static void parseTemplate(String name, Reader in) { ! try { ! Builder bb = parser.parseBlock(name, in); ! bb.build(new BuildContext(broker)); ! } ! catch (Exception e) { ! System.err.println("Exception parsing template " + name + "\n" + e); ! } ! } ! public static void main(String[] args) throws Exception { ! if (!System.getProperties().containsKey("org.webmacro.LogLevel")) ! System.getProperties().setProperty("org.webmacro.LogLevel", "ERROR"); ! WM wm = new WM(); ! broker = wm.getBroker(); ! parser = (Parser) broker.get("parser", "wm"); ! if (args.length == 0) ! parseTemplate("Standard in", new InputStreamReader(System.in)); ! else { ! for (int i = 0; i < args.length; i++) ! parseTemplate(args[i], new FileReader(args[i])); ! } ! ; ! } } --- 19,58 ---- */ ! public class CheckTemplates ! { ! private static Parser parser; ! private static Broker broker; ! public static void parseTemplate (String name, Reader in) ! { ! try ! { ! Builder bb = parser.parseBlock(name, in); ! bb.build(new BuildContext(broker)); ! } ! catch (Exception e) ! { ! System.err.println("Exception parsing template " + name + "\n" + e); ! } ! } ! public static void main (String[] args) throws Exception ! { ! if (!System.getProperties().containsKey("org.webmacro.LogLevel")) ! System.getProperties().setProperty("org.webmacro.LogLevel", "ERROR"); ! WM wm = new WM(); ! broker = wm.getBroker(); ! parser = (Parser) broker.get("parser", "wm"); ! if (args.length == 0) ! parseTemplate("Standard in", new InputStreamReader(System.in)); ! else ! { ! for (int i = 0; i < args.length; i++) ! parseTemplate(args[i], new FileReader(args[i])); ! } ! ; ! } } Index: EvalTemplates.java =================================================================== RCS file: /cvsroot/webmacro/webmacro/src/org/webmacro/tools/EvalTemplates.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** EvalTemplates.java 21 Jul 2002 00:02:10 -0000 1.4 --- EvalTemplates.java 12 Jun 2003 00:47:48 -0000 1.5 *************** *** 1,3 **** --- 1,4 ---- package org.webmacro.tools; + import org.webmacro.Context; import org.webmacro.util.WMEval; *************** *** 17,85 **** */ ! public class EvalTemplates { ! ! private WMEval wm = new WMEval(); // constructs an encapsulation of WM ! /** ! * Evaluates a single template file argument. ! * Exceptions are reported to standard error, not thrown. ! */ ! public void run(String inputTemplate) { ! System.out.println("Template File=" + inputTemplate); ! try { ! wm.eval(wm.getNewContext(), inputTemplate, null, false, null); ! } ! catch (Exception e) { ! System.err.println("Unable to evaluate input."); ! e.printStackTrace(); ! } ! } ! /** ! * Evaluates a single template file argument. ! * Exceptions are reported to standard error, not thrown. ! * <p>This method provides programmer control ! * over the evaluation options. ! * @param inputTemplate A template in the resource path. ! * @param outFile An output file for the template output. If ! * null, the template must set the output. ! * @param append If true, output will be appended to existing file. ! * @param encoding The encoding to use on the output file, null allowed. ! */ ! public Context run(String inputTemplate, String outFile, boolean append, ! String encoding) { ! try { ! wm.eval(wm.getNewContext(), inputTemplate, outFile, append, encoding); ! return wm.getCurrentContext(); } ! catch (Exception e) { ! System.err.println("Unable to evaluate input."); ! e.printStackTrace(); ! return null; } - } ! /** ! * After a template has been run, this method ! * will return an object in the context by name. ! */ ! public Object getContextElement(String key) { ! Context context = wm.getCurrentContext(); ! return context.get(key); ! } ! /** ! * Normally this main is invoked from an ant task but it can ! * be invoked from any main launcher including ! * a command line. ! * @param args One or more file references to an input template file name. ! */ ! public static void main(String[] args) throws Exception { ! if (args == null) return; ! EvalTemplates ev = new EvalTemplates(); ! for (int i = 0; i < args.length; i++) { ! ev.run(args[i]); ! } ! } } --- 18,96 ---- */ ! public class EvalTemplates ! { ! private WMEval wm = new WMEval(); // constructs an encapsulation of WM ! /** ! * Evaluates a single template file argument. ! * Exceptions are reported to standard error, not thrown. ! */ ! public void run (String inputTemplate) ! { ! System.out.println("Template File=" + inputTemplate); ! try ! { ! wm.eval(wm.getNewContext(), inputTemplate, null, false, null); ! } ! catch (Exception e) ! { ! System.err.println("Unable to evaluate input."); ! e.printStackTrace(); ! } } ! ! /** ! * Evaluates a single template file argument. ! * Exceptions are reported to standard error, not thrown. ! * <p>This method provides programmer control ! * over the evaluation options. ! * @param inputTemplate A template in the resource path. ! * @param outFile An output file for the template output. If ! * null, the template must set the output. ! * @param append If true, output will be appended to existing file. ! * @param encoding The encoding to use on the output file, null allowed. ! */ ! public Context run (String inputTemplate, String outFile, boolean append, ! String encoding) ! { ! try ! { ! wm.eval(wm.getNewContext(), inputTemplate, outFile, append, encoding); ! return wm.getCurrentContext(); ! } ! catch (Exception e) ! { ! System.err.println("Unable to evaluate input."); ! e.printStackTrace(); ! return null; ! } } ! /** ! * After a template has been run, this method ! * will return an object in the context by name. ! */ ! public Object getContextElement (String key) ! { ! Context context = wm.getCurrentContext(); ! return context.get(key); ! } ! /** ! * Normally this main is invoked from an ant task but it can ! * be invoked from any main launcher including ! * a command line. ! * @param args One or more file references to an input template file name. ! */ ! public static void main (String[] args) throws Exception ! { ! if (args == null) return; ! EvalTemplates ev = new EvalTemplates(); ! for (int i = 0; i < args.length; i++) ! { ! ev.run(args[i]); ! } ! } } Index: TemplateEvalAntTask.java =================================================================== RCS file: /cvsroot/webmacro/webmacro/src/org/webmacro/tools/TemplateEvalAntTask.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** TemplateEvalAntTask.java 11 Jun 2002 17:43:23 -0000 1.2 --- TemplateEvalAntTask.java 12 Jun 2003 00:47:48 -0000 1.3 *************** *** 1,13 **** package org.webmacro.tools; ! public class TemplateEvalAntTask extends WMTemplateAntTask { ! public TemplateEvalAntTask() { ! super(); ! } ! protected String getMainClass() { ! return "org.webmacro.tools.EvalTemplates"; ! } } --- 1,16 ---- package org.webmacro.tools; ! public class TemplateEvalAntTask extends WMTemplateAntTask ! { ! public TemplateEvalAntTask () ! { ! super(); ! } ! protected String getMainClass () ! { ! return "org.webmacro.tools.EvalTemplates"; ! } } Index: WMTemplateAntTask.java =================================================================== RCS file: /cvsroot/webmacro/webmacro/src/org/webmacro/tools/WMTemplateAntTask.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** WMTemplateAntTask.java 11 Jun 2002 17:43:23 -0000 1.4 --- WMTemplateAntTask.java 12 Jun 2003 00:47:48 -0000 1.5 *************** *** 1,10 **** package org.webmacro.tools; ! import java.io.*; ! import java.util.*; ! import org.apache.tools.ant.*; ! import org.apache.tools.ant.taskdefs.*; ! import org.apache.tools.ant.types.*; /** --- 1,15 ---- package org.webmacro.tools; ! import org.apache.tools.ant.BuildException; ! import org.apache.tools.ant.DirectoryScanner; ! import org.apache.tools.ant.Task; ! import org.apache.tools.ant.taskdefs.Execute; ! import org.apache.tools.ant.types.CommandlineJava; ! import org.apache.tools.ant.types.FileSet; ! import org.apache.tools.ant.types.Path; ! import org.apache.tools.ant.types.Reference; ! import java.io.File; ! import java.util.Vector; /** *************** *** 14,86 **** */ ! public class WMTemplateAntTask extends Task { ! protected Vector filesets = new Vector(); ! private CommandlineJava cmdl = new CommandlineJava(); ! private Path compileClasspath; ! public void addFileset(FileSet set) { ! filesets.addElement(set); ! } ! public void setClasspath(Path classpath) { ! if (compileClasspath == null) { ! compileClasspath = classpath; ! } ! else { ! compileClasspath.append(classpath); ! } ! } ! public Path getClasspath() { ! return compileClasspath; ! } ! public Path createClasspath() { ! if (compileClasspath == null) { ! compileClasspath = new Path(project); ! } ! return compileClasspath.createPath(); ! } ! public void setClasspathRef(Reference r) { ! createClasspath().setRefid(r); ! } ! /** ! * Subclasses should override this ! * to supply their own template execution ! * vehicle. ! */ ! protected String getMainClass() { ! return "org.webmacro.tools.CheckTemplates"; ! } ! public WMTemplateAntTask() { ! cmdl.setVm("java"); ! cmdl.setClassname(getMainClass()); ! } ! public void execute() throws BuildException { ! for (int i = 0; i < filesets.size(); i++) { ! FileSet fs = (FileSet) filesets.elementAt(i); ! File fromDir = fs.getDir(project); ! DirectoryScanner ds = fs.getDirectoryScanner(project); ! String[] srcFiles = ds.getIncludedFiles(); ! for (int j = 0; j < srcFiles.length; j++) ! cmdl.createArgument() ! .setValue(new File(fromDir.getAbsolutePath(), srcFiles[j]) ! .getAbsolutePath()); ! } ! Path classpath = cmdl.createClasspath(project); ! classpath.append(getClasspath()); ! Execute.runCommand(this, cmdl.getCommandline()); ! } } --- 19,104 ---- */ ! public class WMTemplateAntTask extends Task ! { ! protected Vector filesets = new Vector(); ! private CommandlineJava cmdl = new CommandlineJava(); ! private Path compileClasspath; ! public void addFileset (FileSet set) ! { ! filesets.addElement(set); ! } ! public void setClasspath (Path classpath) ! { ! if (compileClasspath == null) ! { ! compileClasspath = classpath; ! } ! else ! { ! compileClasspath.append(classpath); ! } ! } ! public Path getClasspath () ! { ! return compileClasspath; ! } ! public Path createClasspath () ! { ! if (compileClasspath == null) ! { ! compileClasspath = new Path(project); ! } ! return compileClasspath.createPath(); ! } ! public void setClasspathRef (Reference r) ! { ! createClasspath().setRefid(r); ! } ! /** ! * Subclasses should override this ! * to supply their own template execution ! * vehicle. ! */ ! protected String getMainClass () ! { ! return "org.webmacro.tools.CheckTemplates"; ! } ! public WMTemplateAntTask () ! { ! cmdl.setVm("java"); ! cmdl.setClassname(getMainClass()); ! } ! public void execute () throws BuildException ! { ! for (int i = 0; i < filesets.size(); i++) ! { ! FileSet fs = (FileSet) filesets.elementAt(i); ! File fromDir = fs.getDir(project); ! DirectoryScanner ds = fs.getDirectoryScanner(project); ! String[] srcFiles = ds.getIncludedFiles(); ! for (int j = 0; j < srcFiles.length; j++) ! cmdl.createArgument() ! .setValue(new File(fromDir.getAbsolutePath(), srcFiles[j]) ! .getAbsolutePath()); ! } ! Path classpath = cmdl.createClasspath(project); ! classpath.append(getClasspath()); ! Execute.runCommand(this, cmdl.getCommandline()); ! } } |