1 55 package org.jboss.axis.message; 56 57 import org.jboss.axis.encoding.SerializationContext; 58 import org.jboss.logging.Logger; 59 import org.xml.sax.Attributes ; 60 import org.xml.sax.SAXException ; 61 import org.xml.sax.ext.LexicalHandler ; 62 import org.xml.sax.helpers.DefaultHandler ; 63 64 import javax.xml.namespace.QName ; 65 import java.io.IOException ; 66 67 public class SAXOutputter extends DefaultHandler implements LexicalHandler 68 { 69 private static Logger log = Logger.getLogger(SAXOutputter.class.getName()); 70 71 SerializationContext context; 72 boolean isCDATA = false; 73 74 public SAXOutputter(SerializationContext context) 75 { 76 this.context = context; 77 } 78 79 public void startDocument() throws SAXException 80 { 81 if (log.isDebugEnabled()) 82 { 83 log.debug("SAXOutputter.startDocument"); 84 } 85 86 try 87 { 88 context.startDocument(); 89 } 90 catch (IOException e) 91 { 92 throw new SAXException (e); 93 } 94 } 95 96 public void endDocument() throws SAXException 97 { 98 if (log.isDebugEnabled()) 99 { 100 log.debug("SAXOutputter.endDocument"); 101 } 102 } 103 104 public void startPrefixMapping(String p1, String p2) throws SAXException 105 { 106 context.registerPrefixForURI(p1, p2); 107 } 108 109 public void endPrefixMapping(String p1) throws SAXException 110 { 111 } 113 114 public void characters(char[] p1, int p2, int p3) throws SAXException 115 { 116 if (log.isDebugEnabled()) 117 { 118 log.debug("SAXOutputter.characters ['" + new String (p1, p2, p3) + "']"); 119 } 120 try 121 { 122 if (!isCDATA) 123 { 124 context.writeChars(p1, p2, p3); 125 } 126 else 127 { 128 context.writeString(new String (p1, p2, p3)); 129 } 130 } 131 catch (IOException e) 132 { 133 throw new SAXException (e); 134 } 135 } 136 137 public void ignorableWhitespace(char[] p1, int p2, int p3) 138 throws SAXException 139 { 140 try 141 { 142 context.writeChars(p1, p2, p3); 143 } 144 catch (IOException e) 145 { 146 throw new SAXException (e); 147 } 148 } 149 150 public void skippedEntity(String p1) throws SAXException 151 { 152 } 153 154 public void startElement(String namespace, String localName, 155 String qName, Attributes attributes) 156 throws SAXException 157 { 158 if (log.isDebugEnabled()) 159 { 160 log.debug("SAXOutputter.startElement ['" + namespace + "' " + 161 localName + "]"); 162 } 163 164 try 165 { 166 context.startElement(new QName (namespace, localName), attributes); 167 } 168 catch (IOException e) 169 { 170 throw new SAXException (e); 171 } 172 } 173 174 public void endElement(String namespace, String localName, String qName) 175 throws SAXException 176 { 177 if (log.isDebugEnabled()) 178 { 179 log.debug("SAXOutputter.endElement ['" + namespace + "' " + 180 localName + "]"); 181 } 182 183 try 184 { 185 context.endElement(); 186 } 187 catch (IOException e) 188 { 189 throw new SAXException (e); 190 } 191 } 192 193 public void startDTD(java.lang.String name, 194 java.lang.String publicId, 195 java.lang.String systemId) 196 throws SAXException 197 { 198 } 199 200 public void endDTD() 201 throws SAXException 202 { 203 } 204 205 public void startEntity(java.lang.String name) 206 throws SAXException 207 { 208 } 209 210 public void endEntity(java.lang.String name) 211 throws SAXException 212 { 213 } 214 215 public void startCDATA() 216 throws SAXException 217 { 218 try 219 { 220 isCDATA = true; 221 context.writeString("<![CDATA["); 222 } 223 catch (IOException e) 224 { 225 throw new SAXException (e); 226 } 227 } 228 229 public void endCDATA() 230 throws SAXException 231 { 232 try 233 { 234 isCDATA = false; 235 context.writeString("]]>"); 236 } 237 catch (IOException e) 238 { 239 throw new SAXException (e); 240 } 241 } 242 243 public void comment(char[] ch, 244 int start, 245 int length) 246 throws SAXException 247 { 248 if (log.isDebugEnabled()) 249 { 250 log.debug("SAXOutputter.comment ['" + new String (ch, start, length) + "']"); 251 } 252 try 253 { 254 context.writeString("<!--"); 255 context.writeChars(ch, start, length); 256 context.writeString("-->"); 257 } 258 catch (IOException e) 259 { 260 throw new SAXException (e); 261 } 262 } 263 } 264 | Popular Tags |