1 19 package org.java.plugin.registry.xml; 20 21 import java.io.IOException ; 22 import java.util.LinkedList ; 23 24 import org.apache.commons.logging.Log; 25 import org.apache.commons.logging.LogFactory; 26 import org.xml.sax.EntityResolver ; 27 import org.xml.sax.InputSource ; 28 import org.xml.sax.SAXException ; 29 import org.xml.sax.SAXParseException ; 30 import org.xml.sax.helpers.DefaultHandler ; 31 32 36 abstract class BaseHandler extends DefaultHandler { 37 protected final Log log = LogFactory.getLog(getClass()); 38 protected final EntityResolver entityResolver; 39 40 BaseHandler(final EntityResolver anEntityResolver) { 41 entityResolver = anEntityResolver; 42 } 43 44 48 public InputSource resolveEntity(final String publicId, 49 final String systemId) throws SAXException { 50 if (entityResolver != null) { 51 try { 52 return entityResolver.resolveEntity(publicId, systemId); 53 } catch (SAXException se) { 54 throw se; 55 } catch (IOException ioe) { 56 throw new SAXException ("I/O error has occurred - " + ioe, ioe); } 58 } 59 log.warn("ignoring publicId=" + publicId + " and systemId=" + systemId); return null; 62 } 63 64 67 public void warning(final SAXParseException e) { 68 log.warn("non-fatal error while parsing XML document", e); } 70 71 74 public void error(final SAXParseException e) throws SAXException { 75 if (entityResolver != null) { 76 log.error("failed parsing XML resource in validating mode", e); throw e; 79 } 80 log.warn("ignoring parse error", e); } 82 83 86 public void fatalError(final SAXParseException e) throws SAXException { 87 log.fatal("failed parsing XML resource", e); throw e; 89 } 90 } 91 92 class SimpleStack { 93 private LinkedList data; 94 95 SimpleStack() { 96 data = new LinkedList (); 97 } 98 99 Object pop() { 100 return data.isEmpty() ? null : data.removeLast(); 101 } 102 103 void push(final Object obj) { 104 data.addLast(obj); 105 } 106 107 int size() { 108 return data.size(); 109 } 110 } 111 | Popular Tags |