1 package org.sapia.util.xml.parser; 2 3 4 import org.xml.sax.Attributes ; 7 import org.xml.sax.InputSource ; 8 import org.xml.sax.Locator ; 9 import org.xml.sax.SAXException ; 10 import org.xml.sax.SAXParseException ; 11 import org.xml.sax.helpers.DefaultHandler ; 12 13 14 18 34 public class StatefullSAXHandler extends DefaultHandler { 35 39 40 41 46 47 private HandlerContextIF _theContext; 48 49 50 private Locator _theLocator; 51 52 56 61 public StatefullSAXHandler(HandlerContextIF aHandlerContext) { 62 _theContext = aHandlerContext; 63 } 64 65 69 75 public String getDocumentPosition() { 76 StringBuffer aBuffer = new StringBuffer (); 77 aBuffer.append("Document position: line number=") 78 .append(_theLocator.getLineNumber()).append(" column number=") 79 .append(_theLocator.getColumnNumber()); 80 81 return aBuffer.toString(); 82 } 83 84 88 95 public InputSource resolveEntity(String aPublicID, String aSystemID) 96 throws SAXException { 97 99 105 return null; 106 } 107 108 116 public void notationDecl(String aName, String aPublicID, String aSystemID) 117 throws SAXException { 118 120 127 } 128 129 138 public void unparsedEntityDecl(String aName, String aPublicID, 139 String aSystemID, String aNotationName) throws SAXException { 140 142 150 } 151 152 159 public void setDocumentLocator(Locator aLocator) { 160 _theLocator = aLocator; 161 } 162 163 171 public void startDocument() throws SAXException { 172 174 177 } 178 179 187 public void endDocument() throws SAXException { 188 190 193 } 194 195 203 public void startPrefixMapping(String aPrefix, String anUri) 204 throws SAXException { 205 207 211 try { 212 _theContext.startPrefixMapping(aPrefix, anUri); 213 } catch (RuntimeException re) { 214 final String aMessage = "RuntimeException caugh in method startPrefixMapping()."; 215 216 throw new SAXException (aMessage, re); 218 } 219 } 220 221 229 public void endPrefixMapping(String aPrefix) throws SAXException { 230 232 235 try { 236 _theContext.endPrefixMapping(aPrefix); 237 } catch (RuntimeException re) { 238 final String aMessage = "RuntimeException caugh in method endPrefixMapping()."; 239 240 throw new SAXException (aMessage, re); 242 } 243 } 244 245 257 public void startElement(String anUri, String aLocalName, 258 String aQualifiedName, Attributes someAttributes) throws SAXException { 259 try { 260 _theContext.getCurrentState().startElement(_theContext, anUri, 261 aLocalName, aQualifiedName, someAttributes); 262 } catch (RuntimeException re) { 263 final String aMessage = "RuntimeException caugh in method startElement()."; 264 265 throw new SAXException (aMessage, re); 267 } 268 } 269 270 282 public void endElement(String anUri, String aLocalName, String aQualifiedName) 283 throws SAXException { 284 try { 285 _theContext.getCurrentState().endElement(_theContext, anUri, aLocalName, 286 aQualifiedName); 287 } catch (RuntimeException re) { 288 final String aMessage = "RuntimeException caugh in method endElement()."; 289 290 throw new SAXException (aMessage, re); 292 } 293 } 294 295 306 public void characters(char[] someChars, int anOffset, int aLength) 307 throws SAXException { 308 try { 309 _theContext.getCurrentState().characters(_theContext, someChars, 310 anOffset, aLength); 311 } catch (RuntimeException re) { 312 final String aMessage = "RuntimeException caugh in method character()."; 313 314 throw new SAXException (aMessage, re); 316 } 317 } 318 319 330 public void ignorableWhitespace(char[] someChars, int anOffset, int aLength) 331 throws SAXException { 332 try { 333 _theContext.getCurrentState().ignorableWhitespace(_theContext, someChars, 334 anOffset, aLength); 335 } catch (RuntimeException re) { 336 final String aMessage = "RuntimeException caugh in method ignorableWhitespace()."; 337 338 throw new SAXException (aMessage, re); 340 } 341 } 342 343 351 public void warning(SAXParseException aWarning) throws SAXException { 352 } 354 355 364 public void error(SAXParseException anError) throws SAXException { 365 } 367 368 377 public void fatalError(SAXParseException aFatalError) 378 throws SAXException { 379 throw aFatalError; 381 } 382 } 383 | Popular Tags |