1 21 22 package nu.xom.samples; 23 24 import java.io.FileInputStream ; 25 import java.io.FileOutputStream ; 26 import java.io.IOException ; 27 import java.io.InputStream ; 28 import java.io.OutputStream ; 29 import java.util.Iterator ; 30 import java.util.List ; 31 import java.util.Map ; 32 33 import nu.xom.Document; 34 import nu.xom.Serializer; 35 36 37 52 public class HierarchicalXMLBudget { 53 54 public static void convert(List budgetData, String year, 55 OutputStream out) throws IOException { 56 57 Budget budget = new Budget(year); 58 Iterator records = budgetData.iterator(); 59 while (records.hasNext()) { 60 Map lineItem = (Map ) records.next(); 61 budget.add(lineItem); 62 } 63 64 Document doc = new Document(budget.getXML()); 65 Serializer sout = new Serializer(out, "UTF-8"); 66 sout.write(doc); 67 sout.flush(); 68 69 } 70 71 public static void main(String [] args) { 72 73 try { 74 75 if (args.length < 2) { 76 System.out.println( 77 "Usage: nu.xom.samples.HierarchicalXMLBudget year infile outfile"); 78 return; 79 } 80 81 try { 83 if (!args[0].equals("TransitionalQuarter")) { 84 Integer.parseInt(args[0]); 85 } 86 } 87 catch (NumberFormatException ex) { 88 System.out.println( 89 "Usage: HierarchicalXMLBudget year infile outfile"); 90 return; 91 } 92 93 InputStream in = new FileInputStream (args[1]); 94 OutputStream out; 95 if (args.length < 3) { 96 out = System.out; 97 } 98 else { 99 out = new FileOutputStream (args[2]); 100 } 101 102 List results = BudgetData.parse(in); 103 convert(results, args[0], out); 104 } 105 catch (IOException e) { 106 System.err.println(e); 107 } 108 109 } 110 111 } | Popular Tags |