1 41 42 package org.jfree.data.xml; 43 44 import org.xml.sax.Attributes ; 45 import org.xml.sax.SAXException ; 46 import org.xml.sax.helpers.DefaultHandler ; 47 48 51 public class KeyHandler extends DefaultHandler implements DatasetTags { 52 53 54 private RootHandler rootHandler; 55 56 57 private ItemHandler itemHandler; 58 59 60 private StringBuffer currentText; 61 62 63 65 71 public KeyHandler(RootHandler rootHandler, ItemHandler itemHandler) { 72 this.rootHandler = rootHandler; 73 this.itemHandler = itemHandler; 74 this.currentText = new StringBuffer (); 75 } 77 78 88 public void startElement(String namespaceURI, 89 String localName, 90 String qName, 91 Attributes atts) throws SAXException { 92 93 if (qName.equals(KEY_TAG)) { 94 clearCurrentText(); 95 } 96 else { 97 throw new SAXException ("Expecting <Key> but found " + qName); 98 } 99 100 } 101 102 111 public void endElement(String namespaceURI, 112 String localName, 113 String qName) throws SAXException { 114 115 if (qName.equals(KEY_TAG)) { 116 this.itemHandler.setKey(getCurrentText()); 117 this.rootHandler.popSubHandler(); 118 this.rootHandler.pushSubHandler( 119 new ValueHandler(this.rootHandler, this.itemHandler) 120 ); 121 } 122 else { 123 throw new SAXException ("Expecting </Key> but found " + qName); 124 } 125 126 } 127 128 135 public void characters(char[] ch, int start, int length) { 136 if (this.currentText != null) { 137 this.currentText.append(String.copyValueOf(ch, start, length)); 138 } 139 } 140 141 146 protected String getCurrentText() { 147 return this.currentText.toString(); 148 } 149 150 153 protected void clearCurrentText() { 154 this.currentText.delete(0, this.currentText.length()); 155 } 156 157 } 158 | Popular Tags |