PageRenderTime 32ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/install/phing/classes/phing/parser/AbstractSAXParser.php

https://github.com/chregu/fluxcms
PHP | 140 lines | 37 code | 9 blank | 94 comment | 0 complexity | f7275810bc91546d6b60a822f26b0b9e MD5 | raw file
Possible License(s): GPL-2.0, BSD-3-Clause, Apache-2.0, LGPL-2.1
  1. <?php
  2. /*
  3. * $Id$
  4. *
  5. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  6. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  7. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  8. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  9. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  10. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  11. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  12. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  13. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  14. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  15. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  16. *
  17. * This software consists of voluntary contributions made by many individuals
  18. * and is licensed under the LGPL. For more information please see
  19. * <http://phing.info>.
  20. */
  21. /**
  22. * The abstract SAX parser class.
  23. *
  24. * This class represents a SAX parser. It is a abstract calss that must be
  25. * implemented by the real parser that must extend this class
  26. *
  27. * @author Andreas Aderhold <andi@binarycloud.com>
  28. * @author Hans Lellelid <hans@xmpl.org>
  29. * @copyright © 2001,2002 THYRELL. All rights reserved
  30. * @version $Revision: 1.13 $
  31. * @package phing.parser
  32. */
  33. abstract class AbstractSAXParser {
  34. /** The AbstractHandler object. */
  35. protected $handler;
  36. /**
  37. * Constructs a SAX parser
  38. */
  39. function __construct() {}
  40. /**
  41. * Sets options for PHP interal parser. Must be implemented by the parser
  42. * class if it should be used.
  43. */
  44. abstract function parserSetOption($opt, $val);
  45. /**
  46. * Sets the current element handler object for this parser. Usually this
  47. * is an object using extending "AbstractHandler".
  48. *
  49. * @param AbstractHandler $obj The handler object.
  50. */
  51. function setHandler( $obj) {
  52. $this->handler = $obj;
  53. }
  54. /**
  55. * Method that gets invoked when the parser runs over a XML start element.
  56. *
  57. * This method is called by PHP's internal parser funcitons and registered
  58. * in the actual parser implementation.
  59. * It gives control to the current active handler object by calling the
  60. * <code>startElement()</code> method.
  61. *
  62. * BECAUSE OF PROBLEMS WITH EXCEPTIONS BUBBLING UP THROUGH xml_parse() THIS
  63. * METHOD WILL CALL Phing::halt(-1) ON EXCEPTION.
  64. *
  65. * @param object the php's internal parser handle
  66. * @param string the open tag name
  67. * @param array the tag's attributes if any
  68. */
  69. function startElement($parser, $name, $attribs) {
  70. try {
  71. $this->handler->startElement($name, $attribs);
  72. } catch (Exception $e) {
  73. print "[Exception in XML parsing]\n";
  74. print $e;
  75. Phing::halt(-1);
  76. }
  77. }
  78. /**
  79. * Method that gets invoked when the parser runs over a XML close element.
  80. *
  81. * This method is called by PHP's internal parser funcitons and registered
  82. * in the actual parser implementation.
  83. *
  84. * It gives control to the current active handler object by calling the
  85. * <code>endElement()</code> method.
  86. *
  87. * BECAUSE OF PROBLEMS WITH EXCEPTIONS BUBBLING UP THROUGH xml_parse() THIS
  88. * METHOD WILL CALL Phing::halt(-1) ON EXCEPTION.
  89. *
  90. * @param object the php's internal parser handle
  91. * @param string the closing tag name
  92. */
  93. function endElement($parser, $name) {
  94. try {
  95. $this->handler->endElement($name);
  96. } catch (Exception $e) {
  97. print "[Exception in XML parsing]\n";
  98. print $e;
  99. Phing::halt(-1);
  100. }
  101. }
  102. /**
  103. * Method that gets invoked when the parser runs over CDATA.
  104. *
  105. * This method is called by PHP's internal parser functions and registered
  106. * in the actual parser implementation.
  107. *
  108. * It gives control to the current active handler object by calling the
  109. * <code>characters()</code> method. That processes the given CDATA.
  110. *
  111. * BECAUSE OF PROBLEMS WITH EXCEPTIONS BUBBLING UP THROUGH xml_parse() THIS
  112. * METHOD WILL CALL Phing::halt(-1) ON EXCEPTION.
  113. *
  114. * @param resource $parser php's internal parser handle.
  115. * @param string $data the CDATA
  116. */
  117. function characters($parser, $data) {
  118. try {
  119. $this->handler->characters($data);
  120. } catch (Exception $e) {
  121. print "[Exception in XML parsing]\n";
  122. print $e;
  123. Phing::halt(-1);
  124. }
  125. }
  126. /**
  127. * Entrypoint for parser. This method needs to be implemented by the
  128. * child classt that utilizes the concrete parser
  129. */
  130. abstract function parse();
  131. }