diff options
Diffstat (limited to '')
-rw-r--r-- | src/de/animux/android/andmal/api/MalListParser.java | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/de/animux/android/andmal/api/MalListParser.java b/src/de/animux/android/andmal/api/MalListParser.java new file mode 100644 index 0000000..014b718 --- /dev/null +++ b/src/de/animux/android/andmal/api/MalListParser.java @@ -0,0 +1,40 @@ +package de.animux.android.andmal.api; + +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; +import org.xml.sax.helpers.DefaultHandler; + +public abstract class MalListParser<T extends MalObject> extends DefaultHandler { + private StringBuffer currentValue; + + protected MalObjectStore<T> objectStore; + + public MalListParser(MalObjectStore<T> objectStore) { + super(); + + this.objectStore = objectStore; + currentValue = new StringBuffer(); + } + + @Override + public void characters(char[] ch, int start, int length) + throws SAXException { + currentValue.append(new String(ch).substring(start, length - start) + .replaceAll("&", "&")); + } + + @Override + public void endElement(String uri, String localName, String qName) + throws SAXException { + addElement(localName, currentValue.toString()); + currentValue.setLength(0); + } + + @Override + public void startElement(String uri, String localName, String qName, + Attributes attributes) throws SAXException { + currentValue.setLength(0); + } + + abstract public void addElement(String name, String value); +} |