1 42 43 package org.jfree.data.xml; 44 45 import org.xml.sax.Attributes ; 46 import org.xml.sax.SAXException ; 47 import org.xml.sax.helpers.DefaultHandler ; 48 49 52 public class ValueHandler extends DefaultHandler implements DatasetTags { 53 54 55 private RootHandler rootHandler; 56 57 58 private ItemHandler itemHandler; 59 60 61 private StringBuffer currentText; 62 63 69 public ValueHandler(RootHandler rootHandler, ItemHandler itemHandler) { 70 this.rootHandler = rootHandler; 71 this.itemHandler = itemHandler; 72 this.currentText = new StringBuffer (); 73 } 74 75 85 public void startElement(String namespaceURI, 86 String localName, 87 String qName, 88 Attributes atts) throws SAXException { 89 90 if (qName.equals(VALUE_TAG)) { 91 clearCurrentText(); 93 } 94 else { 95 throw new SAXException ("Expecting <Value> but found " + qName); 96 } 97 98 } 99 100 109 public void endElement(String namespaceURI, 110 String localName, 111 String qName) throws SAXException { 112 113 if (qName.equals(VALUE_TAG)) { 114 Number value; 115 try { 116 value = Double.valueOf(this.currentText.toString()); 117 if (((Double ) value).isNaN()) { 118 value = null; 119 } 120 } 121 catch (NumberFormatException e1) { 122 value = null; 123 } 124 this.itemHandler.setValue(value); 125 this.rootHandler.popSubHandler(); 126 } 127 else { 128 throw new SAXException ("Expecting </Value> but found " + qName); 129 } 130 131 } 132 133 140 public void characters(char[] ch, int start, int length) { 141 if (this.currentText != null) { 142 this.currentText.append(String.copyValueOf(ch, start, length)); 143 } 144 } 145 146 151 protected String getCurrentText() { 152 return this.currentText.toString(); 153 } 154 155 158 protected void clearCurrentText() { 159 this.currentText.delete(0, this.currentText.length()); 160 } 161 162 } 163 | Popular Tags |