package net.jaekl.qd.xml;
+import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
}
}
- public abstract void endContents(String uri, String localName, String qName, String chars, Attributes attr) throws XmlParseException;
+ public abstract void endContents(String uri, String localName, String qName, String chars) throws XmlParseException;
public abstract void endExternal(String uri, String localName, String qName) throws XmlParseException;
+
+ // Called once for this tag itself
+ public void handleMainAttributes(Attributes attr) throws MissingAttributeException {
+ // Default action is to do nothing.
+ // Override this if you want to process tag attributes.
+ }
+
+ // Called once for each internally-handled subtag
+ public void handleInternalAttributes(String tagName, Attributes attr) throws MissingAttributeException {
+ // Default action is to do nothing.
+ // Override this if you want to process tag attributes.
+ }
public String getTagName() { return m_tagName; }
- public boolean haveSeenMyTag() { return m_haveSeenMyTag; }
public void characters(char[] ch, int start, int length) throws XmlParseException
{
m_chars.append(ch, start, length);
}
+ // Dump human-readable text describing this tag and its children.
+ // Default implemenation: print the tag name (only)
+ public void dump(PrintWriter pw, int indent) {
+ String margin = String.format("%"+indent+"s", "");
+ pw.println(margin + getTagName());
+ }
+
protected ParseResult[] collectParsedChildren(Class<? extends ParseResult> cls) {
ArrayList<ParseResult> collection = new ArrayList<ParseResult>();
Iterator<ParseResult> iter = m_childParsers.iterator();
}
// returns true if this ParseResult's context has ended with this endElement() call
- public boolean endElement(String uri, String localName, String qName) throws XmlParseException
+ protected boolean endElement(String uri, String localName, String qName) throws XmlParseException
{
assert (null != localName);
}
String chars = m_chars.toString();
- endContents(uri, localName, qName, chars, info.getAttributes());
+ endContents(uri, localName, qName, chars);
return false;
}
// returns either itself, or a new ParseResult-derived object, whichever should handle parsing the inside of this element
- public ParseResult startElement(String uri, String localName, String qName, Attributes attributes)
+ public ParseResult startElement(String uri, String localName, String qName, Attributes attrs)
throws XmlParseException
{
assert (null != localName);
if (m_tagName.equals(localName)) {
m_haveSeenMyTag = true;
+ handleMainAttributes(attrs);
return this;
}
else {
}
if (m_internal.contains(localName)) {
- CurrentInfo info = new CurrentInfo(localName, attributes);
+ handleInternalAttributes(localName, attrs);
+ CurrentInfo info = new CurrentInfo(localName, attrs);
m_current.push(info);
return this;
}
try {
ParseResult childParser = (ParseResult) parserClass.newInstance();
m_childParsers.add(childParser);
- return childParser.startElement(uri, localName, qName, attributes);
+ return childParser.startElement(uri, localName, qName, attrs);
}
catch (IllegalAccessException iae) {
throw new XmlParseException(iae);
}
return value;
}
+
}