net.jangaroo.utils.CharacterRecordingHandler Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jangaroo-utils Show documentation
Show all versions of jangaroo-utils Show documentation
Contains several shared utils
package net.jangaroo.utils;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
/**
* A ContentHandler that records characters (CDATA). Recording can be started and is stopped when
* the characters are retrieved.
*/
public class CharacterRecordingHandler extends DefaultHandler {//stores all characters
private StringBuffer characterStack;
protected void startRecordingCharacters() {
//create new character Stack that will store all following CDATA sections
characterStack = new StringBuffer();
}
public void ignorableWhitespace(char ch[], int start, int length)
throws SAXException {
if (characterStack != null) {
String cdata = new String(ch, start, length);
characterStack.append(cdata);
}
}
public void characters(char[] ch, int start, int length) throws SAXException {
if (characterStack != null) {
String cdata = new String(ch, start, length);
characterStack.append(cdata);
}
}
protected String popRecordedCharacters() {
if (characterStack == null) {
return null;
}
String characters = characterStack.toString();
characterStack = null;
return characters;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy