1 package jimm.datavision.source; 2 import jimm.datavision.source.Column; 3 import org.xml.sax.*; 4 import org.xml.sax.helpers.DefaultHandler ; 5 6 import javax.xml.parsers.SAXParserFactory ; 7 8 14 class MetadataReader extends DefaultHandler { 15 16 protected DataSource source; 17 18 MetadataReader(DataSource source) { 19 this.source = source; 20 } 21 22 public void read(InputSource inputSource) throws Exception { 23 SAXParserFactory.newInstance().newSAXParser().parse(inputSource, this); 24 } 25 26 public void startElement(final String namespaceURI, final String localName, 27 final String qName, final Attributes attributes) 28 throws SAXException 29 { 30 String tagName = localName; 31 if (tagName == null || tagName.length() == 0) 32 tagName = qName; 33 34 if ("column".equals(tagName)) { 35 String colName = attributes.getValue("name"); 36 int type = Column.typeFromString(attributes.getValue("type")); 37 Column col = new Column(colName, colName, type); 38 col.setDateParseFormat(attributes.getValue("date-format")); 39 40 source.addColumn(col); 41 } 42 } 43 44 } 45 | Popular Tags |