1 16 package org.apache.commons.betwixt.io; 17 18 import org.apache.commons.logging.Log; 19 import org.apache.commons.logging.LogFactory; 20 import org.xml.sax.Attributes ; 21 import org.xml.sax.ContentHandler ; 22 import org.xml.sax.SAXException ; 23 24 27 33 public class SAXBeanWriter extends AbstractBeanWriter { 34 35 36 private ContentHandler contentHandler; 37 38 private Log log = LogFactory.getLog( SAXBeanWriter.class ); 39 40 private boolean callDocumentEvents = true; 41 42 47 public SAXBeanWriter(ContentHandler contentHandler) { 48 this.contentHandler = contentHandler; 49 } 50 51 58 public boolean getCallDocumentEvents() { 59 return callDocumentEvents; 60 } 61 62 68 public void setCallDocumentEvents(boolean callDocumentEvents) { 69 this.callDocumentEvents = callDocumentEvents; 70 } 71 72 77 public Log getLog() { 78 return log; 79 } 80 81 86 public void setLog(Log log) { 87 this.log = log; 88 } 89 90 91 94 96 99 100 110 protected void startElement( 111 WriteContext context, 112 String uri, 113 String localName, 114 String qName, 115 Attributes attributes) 116 throws 117 SAXException { 118 contentHandler.startElement( 119 uri, 120 localName, 121 qName, 122 attributes); 123 } 124 125 134 protected void endElement( 135 WriteContext context, 136 String uri, 137 String localName, 138 String qName) 139 throws 140 SAXException { 141 contentHandler.endElement( 142 uri, 143 localName, 144 qName); 145 } 146 147 153 protected void bodyText(WriteContext context, String text) throws SAXException { 154 char[] body = text.toCharArray(); 159 contentHandler.characters(body, 0, body.length); 160 } 161 162 168 public void start() throws SAXException { 169 if ( callDocumentEvents ) { 170 contentHandler.startDocument(); 171 } 172 } 173 174 180 public void end() throws SAXException { 181 if ( callDocumentEvents ) { 182 contentHandler.endDocument(); 183 } 184 } 185 } 186 | Popular Tags |