| 1 |
lars |
1 |
<?php
|
|
|
2 |
/*
|
|
|
3 |
* $Id: AbstractSAXParser.php 322 2007-12-20 03:00:35Z hans $
|
|
|
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 |
/**
|
|
|
23 |
* The abstract SAX parser class.
|
|
|
24 |
*
|
|
|
25 |
* This class represents a SAX parser. It is a abstract calss that must be
|
|
|
26 |
* implemented by the real parser that must extend this class
|
|
|
27 |
*
|
|
|
28 |
* @author Andreas Aderhold <andi@binarycloud.com>
|
|
|
29 |
* @author Hans Lellelid <hans@xmpl.org>
|
|
|
30 |
* @copyright � 2001,2002 THYRELL. All rights reserved
|
|
|
31 |
* @version $Revision: 1.13 $
|
|
|
32 |
* @package phing.parser
|
|
|
33 |
*/
|
|
|
34 |
abstract class AbstractSAXParser {
|
|
|
35 |
|
|
|
36 |
/** The AbstractHandler object. */
|
|
|
37 |
protected $handler;
|
|
|
38 |
|
|
|
39 |
/**
|
|
|
40 |
* Constructs a SAX parser
|
|
|
41 |
*/
|
|
|
42 |
function __construct() {}
|
|
|
43 |
|
|
|
44 |
/**
|
|
|
45 |
* Sets options for PHP interal parser. Must be implemented by the parser
|
|
|
46 |
* class if it should be used.
|
|
|
47 |
*/
|
|
|
48 |
abstract function parserSetOption($opt, $val);
|
|
|
49 |
|
|
|
50 |
/**
|
|
|
51 |
* Sets the current element handler object for this parser. Usually this
|
|
|
52 |
* is an object using extending "AbstractHandler".
|
|
|
53 |
*
|
|
|
54 |
* @param AbstractHandler $obj The handler object.
|
|
|
55 |
*/
|
|
|
56 |
function setHandler( $obj) {
|
|
|
57 |
$this->handler = $obj;
|
|
|
58 |
}
|
|
|
59 |
|
|
|
60 |
/**
|
|
|
61 |
* Method that gets invoked when the parser runs over a XML start element.
|
|
|
62 |
*
|
|
|
63 |
* This method is called by PHP's internal parser functions and registered
|
|
|
64 |
* in the actual parser implementation.
|
|
|
65 |
* It gives control to the current active handler object by calling the
|
|
|
66 |
* <code>startElement()</code> method.
|
|
|
67 |
*
|
|
|
68 |
* @param object the php's internal parser handle
|
|
|
69 |
* @param string the open tag name
|
|
|
70 |
* @param array the tag's attributes if any
|
|
|
71 |
* @throws Exception - Exceptions may be thrown by the Handler
|
|
|
72 |
*/
|
|
|
73 |
function startElement($parser, $name, $attribs) {
|
|
|
74 |
$this->handler->startElement($name, $attribs);
|
|
|
75 |
}
|
|
|
76 |
|
|
|
77 |
/**
|
|
|
78 |
* Method that gets invoked when the parser runs over a XML close element.
|
|
|
79 |
*
|
|
|
80 |
* This method is called by PHP's internal parser funcitons and registered
|
|
|
81 |
* in the actual parser implementation.
|
|
|
82 |
*
|
|
|
83 |
* It gives control to the current active handler object by calling the
|
|
|
84 |
* <code>endElement()</code> method.
|
|
|
85 |
*
|
|
|
86 |
* @param object the php's internal parser handle
|
|
|
87 |
* @param string the closing tag name
|
|
|
88 |
* @throws Exception - Exceptions may be thrown by the Handler
|
|
|
89 |
*/
|
|
|
90 |
function endElement($parser, $name) {
|
|
|
91 |
$this->handler->endElement($name);
|
|
|
92 |
}
|
|
|
93 |
|
|
|
94 |
/**
|
|
|
95 |
* Method that gets invoked when the parser runs over CDATA.
|
|
|
96 |
*
|
|
|
97 |
* This method is called by PHP's internal parser functions and registered
|
|
|
98 |
* in the actual parser implementation.
|
|
|
99 |
*
|
|
|
100 |
* It gives control to the current active handler object by calling the
|
|
|
101 |
* <code>characters()</code> method. That processes the given CDATA.
|
|
|
102 |
*
|
|
|
103 |
* @param resource $parser php's internal parser handle.
|
|
|
104 |
* @param string $data the CDATA
|
|
|
105 |
* @throws Exception - Exceptions may be thrown by the Handler
|
|
|
106 |
*/
|
|
|
107 |
function characters($parser, $data) {
|
|
|
108 |
$this->handler->characters($data);
|
|
|
109 |
}
|
|
|
110 |
|
|
|
111 |
/**
|
|
|
112 |
* Entrypoint for parser. This method needs to be implemented by the
|
|
|
113 |
* child classt that utilizes the concrete parser
|
|
|
114 |
*/
|
|
|
115 |
abstract function parse();
|
|
|
116 |
}
|