1 16 19 20 package org.apache.xml.serializer; 21 22 import java.io.IOException ; 23 import java.io.OutputStream ; 24 import java.io.Writer ; 25 import java.util.Properties ; 26 27 import javax.xml.transform.Result ; 28 29 import org.w3c.dom.Node ; 30 import org.xml.sax.Attributes ; 31 import org.xml.sax.ContentHandler ; 32 import org.xml.sax.Locator ; 33 import org.xml.sax.SAXException ; 34 import org.xml.sax.ext.LexicalHandler ; 35 36 43 public class ToHTMLSAXHandler extends ToSAXHandler 44 { 45 46 49 protected boolean m_escapeSetting = false; 50 51 56 public Properties getOutputFormat() 57 { 58 return null; 59 } 60 61 66 public OutputStream getOutputStream() 67 { 68 return null; 69 } 70 71 76 public Writer getWriter() 77 { 78 return null; 79 } 80 81 85 public void indent(int n) throws SAXException 86 { 87 } 88 89 93 public void serialize(Node node) throws IOException 94 { 95 return; 96 } 97 98 106 public boolean setEscaping(boolean escape) throws SAXException 107 { 108 boolean oldEscapeSetting = m_escapeSetting; 109 m_escapeSetting = escape; 110 111 if (escape) { 112 processingInstruction(Result.PI_ENABLE_OUTPUT_ESCAPING, ""); 113 } else { 114 processingInstruction(Result.PI_DISABLE_OUTPUT_ESCAPING, ""); 115 } 116 117 return oldEscapeSetting; 118 } 119 120 126 public void setIndent(boolean indent) 127 { 128 } 129 130 135 public void setOutputFormat(Properties format) 136 { 137 } 138 139 144 public void setOutputStream(OutputStream output) 145 { 146 } 147 148 149 154 public void setWriter(Writer writer) 155 { 156 } 157 158 161 171 public void attributeDecl( 172 String eName, 173 String aName, 174 String type, 175 String valueDefault, 176 String value) 177 throws SAXException 178 { 179 } 180 181 182 186 public void elementDecl(String name, String model) throws SAXException 187 { 188 return; 189 } 190 191 194 public void externalEntityDecl(String arg0, String arg1, String arg2) 195 throws SAXException 196 { 197 } 198 199 204 public void internalEntityDecl(String name, String value) 205 throws SAXException 206 { 207 } 208 209 234 public void endElement(String uri, String localName, String qName) 235 throws SAXException 236 { 237 flushPending(); 238 m_saxHandler.endElement(uri, localName, qName); 239 240 if (m_tracer != null) 242 super.fireEndElem(qName); 243 } 244 245 248 public void endPrefixMapping(String prefix) throws SAXException 249 { 250 } 251 252 256 public void ignorableWhitespace(char[] ch, int start, int length) 257 throws SAXException 258 { 259 } 260 261 281 public void processingInstruction(String arg0, String arg1) 282 throws SAXException 283 { 284 flushPending(); 285 m_saxHandler.processingInstruction(arg0,arg1); 286 287 289 if (m_tracer != null) 290 super.fireEscapingEvent(arg0,arg1); 291 } 292 293 297 public void setDocumentLocator(Locator arg0) 298 { 299 } 301 302 306 public void skippedEntity(String arg0) throws SAXException 307 { 308 } 309 310 334 public void startElement( 335 String namespaceURI, 336 String localName, 337 String qName, 338 Attributes atts) 339 throws SAXException 340 { 341 flushPending(); 342 super.startElement(namespaceURI, localName, qName, atts); 343 m_saxHandler.startElement(namespaceURI, localName, qName, atts); 344 m_elemContext.m_startTagOpen = false; 345 } 346 347 357 public void comment(char[] ch, int start, int length) throws SAXException 358 { 359 flushPending(); 360 m_lexHandler.comment(ch, start, length); 361 362 if (m_tracer != null) 364 super.fireCommentEvent(ch, start, length); 365 return; 366 } 367 368 372 public void endCDATA() throws SAXException 373 { 374 return; 375 } 376 377 381 public void endDTD() throws SAXException 382 { 383 } 384 385 389 public void startCDATA() throws SAXException 390 { 391 } 392 393 397 public void startEntity(String arg0) throws SAXException 398 { 399 } 400 401 417 public void endDocument() throws SAXException 418 { 419 flushPending(); 420 421 m_saxHandler.endDocument(); 423 424 if (m_tracer != null) 425 super.fireEndDoc(); 426 } 427 428 432 protected void closeStartTag() throws SAXException 433 { 434 435 m_elemContext.m_startTagOpen = false; 436 437 m_saxHandler.startElement( 439 EMPTYSTRING, 440 m_elemContext.m_elementName, 441 m_elemContext.m_elementName, 442 m_attributes); 443 m_attributes.clear(); 444 445 } 446 447 451 public void close() 452 { 453 return; 454 } 455 456 465 public void characters(final String chars) throws SAXException 466 { 467 final int length = chars.length(); 468 if (length > m_charsBuff.length) 469 { 470 m_charsBuff = new char[length * 2 + 1]; 471 } 472 chars.getChars(0, length, m_charsBuff, 0); 473 this.characters(m_charsBuff, 0, length); 474 } 475 476 477 482 public ToHTMLSAXHandler(ContentHandler handler, String encoding) 483 { 484 super(handler,encoding); 485 } 486 492 public ToHTMLSAXHandler( 493 ContentHandler handler, 494 LexicalHandler lex, 495 String encoding) 496 { 497 super(handler,lex,encoding); 498 } 499 500 511 public void startElement( 512 String elementNamespaceURI, 513 String elementLocalName, 514 String elementName) throws SAXException 515 { 516 517 super.startElement(elementNamespaceURI, elementLocalName, elementName); 518 519 flushPending(); 520 521 if (m_lexHandler != null) 523 { 524 String doctypeSystem = getDoctypeSystem(); 525 String doctypePublic = getDoctypePublic(); 526 if ((doctypeSystem != null) || (doctypePublic != null)) 527 m_lexHandler.startDTD( 528 elementName, 529 doctypePublic, 530 doctypeSystem); 531 m_lexHandler = null; 532 } 533 m_elemContext = m_elemContext.push(elementNamespaceURI, elementLocalName, elementName); 534 } 535 542 public void startElement(String elementName) throws SAXException 543 { 544 this.startElement(null,null, elementName); 545 } 546 547 555 public void endElement(String elementName) throws SAXException 556 { 557 flushPending(); 558 m_saxHandler.endElement(EMPTYSTRING, elementName, elementName); 559 560 if (m_tracer != null) 562 super.fireEndElem(elementName); 563 } 564 565 594 public void characters(char[] ch, int off, int len) throws SAXException 595 { 596 597 flushPending(); 598 m_saxHandler.characters(ch, off, len); 599 600 if (m_tracer != null) 602 super.fireCharEvent(ch, off, len); 603 } 604 605 609 public void flushPending() throws SAXException 610 { 611 if (m_needToCallStartDocument) 612 { 613 startDocumentInternal(); 614 m_needToCallStartDocument = false; 615 } 616 if (m_elemContext.m_startTagOpen) 618 { 619 closeStartTag(); 620 m_elemContext.m_startTagOpen = false; 621 } 622 } 623 642 public boolean startPrefixMapping( 643 String prefix, 644 String uri, 645 boolean shouldFlush) 646 throws SAXException 647 { 648 if (shouldFlush) 650 flushPending(); 651 m_saxHandler.startPrefixMapping(prefix,uri); 652 return false; 653 } 654 655 670 public void startPrefixMapping(String prefix, String uri) 671 throws org.xml.sax.SAXException 672 { 673 startPrefixMapping(prefix,uri,true); 674 } 675 676 687 public void namespaceAfterStartElement( 688 final String prefix, 689 final String uri) 690 throws SAXException 691 { 692 if (m_elemContext.m_elementURI == null) 694 { 695 String prefix1 = getPrefixPart(m_elemContext.m_elementName); 696 if (prefix1 == null && EMPTYSTRING.equals(prefix)) 697 { 698 m_elemContext.m_elementURI = uri; 703 } 704 } 705 startPrefixMapping(prefix,uri,false); 706 } 707 708 716 public boolean reset() 717 { 718 boolean wasReset = false; 719 if (super.reset()) 720 { 721 resetToHTMLSAXHandler(); 722 wasReset = true; 723 } 724 return wasReset; 725 } 726 727 731 private void resetToHTMLSAXHandler() 732 { 733 this.m_escapeSetting = false; 734 } 735 } 736 | Popular Tags |