1 16 package org.apache.axis.message; 17 18 import org.apache.axis.components.logger.LogFactory; 19 import org.apache.axis.encoding.SerializationContext; 20 import org.apache.axis.utils.XMLUtils; 21 import org.apache.commons.logging.Log; 22 import org.xml.sax.Attributes ; 23 import org.xml.sax.SAXException ; 24 import org.xml.sax.ext.LexicalHandler ; 25 import org.xml.sax.helpers.DefaultHandler ; 26 27 import javax.xml.namespace.QName ; 28 import java.io.IOException ; 29 30 public class SAXOutputter extends DefaultHandler implements LexicalHandler 31 { 32 protected static Log log = 33 LogFactory.getLog(SAXOutputter.class.getName()); 34 35 SerializationContext context; 36 boolean isCDATA = false; 37 38 public SAXOutputter(SerializationContext context) 39 { 40 this.context = context; 41 } 42 43 public void startDocument() throws SAXException { 44 context.setSendDecl(true); 45 } 46 47 public void endDocument() throws SAXException { 48 if (log.isDebugEnabled()) { 49 log.debug("SAXOutputter.endDocument"); 50 } 51 } 52 53 public void startPrefixMapping(String p1, String p2) throws SAXException { 54 context.registerPrefixForURI(p1,p2); 55 } 56 57 public void endPrefixMapping(String p1) throws SAXException { 58 } 60 61 public void characters(char[] p1, int p2, int p3) throws SAXException { 62 if (log.isDebugEnabled()) { 63 log.debug("SAXOutputter.characters ['" + new String (p1, p2, p3) + "']"); 64 } 65 try { 66 if(!isCDATA) { 67 context.writeChars(p1, p2, p3); 68 } else { 69 context.writeString(new String (p1, p2, p3)); 70 } 71 } catch (IOException e) { 72 throw new SAXException (e); 73 } 74 } 75 76 public void ignorableWhitespace(char[] p1, int p2, int p3) 77 throws SAXException 78 { 79 try { 80 context.writeChars(p1, p2, p3); 81 } catch (IOException e) { 82 throw new SAXException (e); 83 } 84 } 85 86 public void skippedEntity(String p1) throws SAXException { 87 } 88 89 public void startElement(String namespace, String localName, 90 String qName, Attributes attributes) 91 throws SAXException 92 { 93 if (log.isDebugEnabled()) { 94 log.debug("SAXOutputter.startElement ['" + namespace + "' " + 95 localName + "]"); 96 } 97 98 try { 99 context.startElement(new QName (namespace,localName), attributes); 100 } catch (IOException e) { 101 throw new SAXException (e); 102 } 103 } 104 105 public void endElement(String namespace, String localName, String qName) 106 throws SAXException 107 { 108 if (log.isDebugEnabled()) { 109 log.debug("SAXOutputter.endElement ['" + namespace + "' " + 110 localName + "]"); 111 } 112 113 try { 114 context.endElement(); 115 } catch (IOException e) { 116 throw new SAXException (e); 117 } 118 } 119 120 public void startDTD(java.lang.String name, 121 java.lang.String publicId, 122 java.lang.String systemId) 123 throws SAXException 124 { 125 } 126 127 public void endDTD() 128 throws SAXException 129 { 130 } 131 132 public void startEntity(java.lang.String name) 133 throws SAXException 134 { 135 } 136 137 public void endEntity(java.lang.String name) 138 throws SAXException 139 { 140 } 141 142 public void startCDATA() 143 throws SAXException 144 { 145 try { 146 isCDATA = true; 147 context.writeString("<![CDATA["); 148 } catch (IOException e) { 149 throw new SAXException (e); 150 } 151 } 152 153 public void endCDATA() 154 throws SAXException 155 { 156 try { 157 isCDATA = false; 158 context.writeString("]]>"); 159 } catch (IOException e) { 160 throw new SAXException (e); 161 } 162 } 163 164 public void comment(char[] ch, 165 int start, 166 int length) 167 throws SAXException 168 { 169 if (log.isDebugEnabled()) { 170 log.debug("SAXOutputter.comment ['" + new String (ch, start, length) + "']"); 171 } 172 try { 173 context.writeString("<!--"); 174 context.writeChars(ch, start, length); 175 context.writeString("-->"); 176 } catch (IOException e) { 177 throw new SAXException (e); 178 } 179 } 180 } 181 | Popular Tags |