1 52 53 package freemarker.template.utility; 54 55 import freemarker.template.*; 56 import java.io.*; 57 58 61 62 public class ToCanonical { 63 64 static Configuration config = Configuration.getDefaultConfiguration(); 65 66 static public void main(String [] args) { 67 config.setWhitespaceStripping(false); 68 if (args.length == 0) { 69 usage(); 70 } 71 for (int i=0; i<args.length; i++) { 72 File f = new File(args[i]); 73 if (!f.exists()) { 74 System.err.println("File " + f + " doesn't exist."); 75 } 76 try { 77 convertFile(f); 78 } catch (Exception e) { 79 System.err.println("Error converting file: " + f); 80 e.printStackTrace(); 81 } 82 } 83 } 84 85 static void convertFile(File f) throws IOException { 86 File fullPath = f.getAbsoluteFile(); 87 File dir = fullPath.getParentFile(); 88 String filename = fullPath.getName(); 89 File convertedFile = new File(dir, filename + ".canonical"); 90 config.setDirectoryForTemplateLoading(dir); 91 Template template = config.getTemplate(filename); 92 FileWriter output = new FileWriter(convertedFile); 93 try { 94 template.dump(output); 95 } finally { 96 output.close(); 97 } 98 } 99 100 static void usage() { 101 System.err.println("Usage: java freemarker.template.utility.ToCanonical <filename(s)>"); 102 } 103 } 104 | Popular Tags |