1 4 package org.znerd.xmlenc.sax; 5 6 import java.io.IOException ; 7 import java.io.UnsupportedEncodingException ; 8 import java.io.Writer ; 9 import org.xml.sax.Attributes ; 10 import org.xml.sax.ContentHandler ; 11 import org.xml.sax.Locator ; 12 import org.xml.sax.SAXException ; 13 import org.znerd.xmlenc.XMLEventListener; 14 15 24 public class SAXEventReceiver 25 extends Object 26 implements ContentHandler { 27 28 32 36 40 51 public SAXEventReceiver(XMLEventListener eventListener) 52 throws IllegalArgumentException { 53 if (eventListener == null) { 54 throw new IllegalArgumentException ("eventListener == null"); 55 } 56 57 _eventListener = eventListener; 58 } 59 60 61 65 68 private final XMLEventListener _eventListener; 69 70 71 75 public void setDocumentLocator(Locator locator) { 76 } 78 79 public void startDocument() throws SAXException { 80 } 82 83 public void endDocument() throws SAXException { 84 try { 85 _eventListener.endDocument(); 86 } catch (IOException ioException) { 87 throw new SAXException (ioException); 88 } 89 } 90 91 public void startPrefixMapping(String prefix, String uri) 92 throws SAXException { 93 } 95 96 public void endPrefixMapping(String prefix) 97 throws SAXException { 98 } 100 101 public void startElement(String uri, String localName, String qName, Attributes atts) 102 throws SAXException { 103 try { 104 _eventListener.startTag(qName); 105 int attributeCount = atts.getLength(); 106 for (int i = 0; i < attributeCount; i++) { 107 _eventListener.attribute(atts.getQName(i), atts.getValue(i)); 108 } 109 } catch (IOException ioException) { 110 throw new SAXException (ioException); 111 } 112 } 113 114 public void endElement(String uri, String localName, String qName) 115 throws SAXException { 116 try { 117 _eventListener.endTag(); 118 } catch (IOException ioException) { 119 throw new SAXException (ioException); 120 } 121 } 122 123 public void characters(char[] ch, int start, int length) 124 throws SAXException { 125 try { 126 _eventListener.pcdata(ch, start, length); 127 } catch (IOException ioException) { 128 throw new SAXException (ioException); 129 } 130 } 131 132 public void ignorableWhitespace(char[] ch, int start, int length) 133 throws SAXException { 134 try { 135 _eventListener.whitespace(ch, start, length); 136 } catch (IOException ioException) { 137 throw new SAXException (ioException); 138 } 139 } 140 141 public void processingInstruction(String target, String data) 142 throws SAXException { 143 try { 144 _eventListener.pi(target, data); 145 } catch (IOException ioException) { 146 throw new SAXException (ioException); 147 } 148 } 149 150 public void skippedEntity(String name) 151 throws SAXException { 152 } 154 } 155 | Popular Tags |