Refactored simple SAX ElementHandler to be an interface.

This commit is contained in:
Sampo Niskanen 2012-02-19 08:42:53 +00:00
parent b211266f45
commit 02fbe90a32
2 changed files with 8 additions and 8 deletions

View File

@ -13,7 +13,7 @@ import org.xml.sax.helpers.DefaultHandler;
/** /**
* The actual SAX handler class. Contains the necessary methods for parsing the SAX source. * The actual SAX handler class. Contains the necessary methods for parsing the SAX source.
* Delegates the actual content parsing to {@link AbstractElementHandler} objects. * Delegates the actual content parsing to {@link ElementHandler} objects.
*/ */
class DelegatorHandler extends DefaultHandler { class DelegatorHandler extends DefaultHandler {
private final WarningSet warnings; private final WarningSet warnings;
@ -27,7 +27,7 @@ class DelegatorHandler extends DefaultHandler {
private int ignore = 0; private int ignore = 0;
public DelegatorHandler(AbstractElementHandler initialHandler, WarningSet warnings) { public DelegatorHandler(ElementHandler initialHandler, WarningSet warnings) {
this.warnings = warnings; this.warnings = warnings;
handlerStack.add(initialHandler); handlerStack.add(initialHandler);
elementData.add(new StringBuilder()); // Just in case elementData.add(new StringBuilder()); // Just in case

View File

@ -16,14 +16,14 @@ import org.xml.sax.helpers.XMLReaderFactory;
* both. This holds true for both the OpenRocket and RockSim design formats and the * both. This holds true for both the OpenRocket and RockSim design formats and the
* RockSim engine definition format. * RockSim engine definition format.
* <p> * <p>
* The actual handling is performed by subclasses of {@link AbstractElementHandler}. The * The actual handling is performed by subclasses of {@link ElementHandler}. The
* initial handler is provided to the {@link #readXML(InputSource, AbstractElementHandler, WarningSet)} * initial handler is provided to the {@link #readXML(InputSource, ElementHandler, WarningSet)}
* method. * method.
* *
* @author Sampo Niskanen <sampo.niskanen@iki.fi> * @author Sampo Niskanen <sampo.niskanen@iki.fi>
*/ */
public class SimpleSAX { public class SimpleSAX {
/** /**
* Read a simple XML file. * Read a simple XML file.
* *
@ -33,11 +33,11 @@ public class SimpleSAX {
* @throws IOException if an I/O exception occurs while reading. * @throws IOException if an I/O exception occurs while reading.
* @throws SAXException if e.g. malformed XML is encountered. * @throws SAXException if e.g. malformed XML is encountered.
*/ */
public static void readXML(InputSource source, AbstractElementHandler initialHandler, public static void readXML(InputSource source, ElementHandler initialHandler,
WarningSet warnings) throws IOException, SAXException { WarningSet warnings) throws IOException, SAXException {
DelegatorHandler xmlhandler = new DelegatorHandler(initialHandler, warnings); DelegatorHandler xmlhandler = new DelegatorHandler(initialHandler, warnings);
XMLReader reader = XMLReaderFactory.createXMLReader(); XMLReader reader = XMLReaderFactory.createXMLReader();
reader.setContentHandler(xmlhandler); reader.setContentHandler(xmlhandler);
reader.setErrorHandler(xmlhandler); reader.setErrorHandler(xmlhandler);