1 41 42 package org.jfree.data.xml; 43 44 import java.io.File ; 45 import java.io.FileInputStream ; 46 import java.io.IOException ; 47 import java.io.InputStream ; 48 49 import javax.xml.parsers.ParserConfigurationException ; 50 import javax.xml.parsers.SAXParser ; 51 import javax.xml.parsers.SAXParserFactory ; 52 53 import org.jfree.data.category.CategoryDataset; 54 import org.jfree.data.general.PieDataset; 55 import org.xml.sax.SAXException ; 56 57 60 public class DatasetReader { 61 62 71 public static PieDataset readPieDatasetFromXML(File file) 72 throws IOException { 73 InputStream in = new FileInputStream (file); 74 return readPieDatasetFromXML(in); 75 } 76 77 86 public static PieDataset readPieDatasetFromXML(InputStream in) 87 throws IOException { 88 89 PieDataset result = null; 90 SAXParserFactory factory = SAXParserFactory.newInstance(); 91 try { 92 SAXParser parser = factory.newSAXParser(); 93 PieDatasetHandler handler = new PieDatasetHandler(); 94 parser.parse(in, handler); 95 result = handler.getDataset(); 96 } 97 catch (SAXException e) { 98 System.out.println(e.getMessage()); 99 } 100 catch (ParserConfigurationException e2) { 101 System.out.println(e2.getMessage()); 102 } 103 return result; 104 105 } 106 107 116 public static CategoryDataset readCategoryDatasetFromXML(File file) 117 throws IOException { 118 InputStream in = new FileInputStream (file); 119 return readCategoryDatasetFromXML(in); 120 } 121 122 131 public static CategoryDataset readCategoryDatasetFromXML(InputStream in) 132 throws IOException { 133 134 CategoryDataset result = null; 135 136 SAXParserFactory factory = SAXParserFactory.newInstance(); 137 try { 138 SAXParser parser = factory.newSAXParser(); 139 CategoryDatasetHandler handler = new CategoryDatasetHandler(); 140 parser.parse(in, handler); 141 result = handler.getDataset(); 142 } 143 catch (SAXException e) { 144 System.out.println(e.getMessage()); 145 } 146 catch (ParserConfigurationException e2) { 147 System.out.println(e2.getMessage()); 148 } 149 return result; 150 151 } 152 153 } 154 | Popular Tags |