AbstractSAXParser.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <?php
  2. /*
  3. * $Id: AbstractSAXParser.php 905 2010-10-05 16:28:03Z mrook $
  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: 905 $
  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 functions 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. * @param object the php's internal parser handle
  63. * @param string the open tag name
  64. * @param array the tag's attributes if any
  65. * @throws Exception - Exceptions may be thrown by the Handler
  66. */
  67. function startElement($parser, $name, $attribs) {
  68. $this->handler->startElement($name, $attribs);
  69. }
  70. /**
  71. * Method that gets invoked when the parser runs over a XML close element.
  72. *
  73. * This method is called by PHP's internal parser funcitons and registered
  74. * in the actual parser implementation.
  75. *
  76. * It gives control to the current active handler object by calling the
  77. * <code>endElement()</code> method.
  78. *
  79. * @param object the php's internal parser handle
  80. * @param string the closing tag name
  81. * @throws Exception - Exceptions may be thrown by the Handler
  82. */
  83. function endElement($parser, $name) {
  84. $this->handler->endElement($name);
  85. }
  86. /**
  87. * Method that gets invoked when the parser runs over CDATA.
  88. *
  89. * This method is called by PHP's internal parser functions and registered
  90. * in the actual parser implementation.
  91. *
  92. * It gives control to the current active handler object by calling the
  93. * <code>characters()</code> method. That processes the given CDATA.
  94. *
  95. * @param resource $parser php's internal parser handle.
  96. * @param string $data the CDATA
  97. * @throws Exception - Exceptions may be thrown by the Handler
  98. */
  99. function characters($parser, $data) {
  100. $this->handler->characters($data);
  101. }
  102. /**
  103. * Entrypoint for parser. This method needs to be implemented by the
  104. * child classt that utilizes the concrete parser
  105. */
  106. abstract function parse();
  107. }