ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilSaxController.php
Go to the documentation of this file.
1<?php
2/*
3 +-----------------------------------------------------------------------------+
4 | ILIAS open source |
5 +-----------------------------------------------------------------------------+
6 | Copyright (c) 1998-2006 ILIAS open source, University of Cologne |
7 | |
8 | This program is free software; you can redistribute it and/or |
9 | modify it under the terms of the GNU General Public License |
10 | as published by the Free Software Foundation; either version 2 |
11 | of the License, or (at your option) any later version. |
12 | |
13 | This program is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | GNU General Public License for more details. |
17 | |
18 | You should have received a copy of the GNU General Public License |
19 | along with this program; if not, write to the Free Software |
20 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21 +-----------------------------------------------------------------------------+
22*/
23
36{
37 protected $default_handler = null;
38 protected $element_handlers = array();
39 protected $handlers_in_use = array();
40
48 public function __construct()
49 {
50 }
51
59 public function setHandlers($a_xml_parser)
60 {
61 xml_set_object($a_xml_parser, $this);
62 xml_set_element_handler($a_xml_parser, 'handlerBeginTag', 'handlerEndTag');
63 xml_set_character_data_handler($a_xml_parser, 'handlerCharacterData');
64 return;
65 }
66
74 public function setDefaultElementHandler(ilSaxSubsetParser $a_default_parser)
75 {
76 $this->default_handler = $a_default_parser;
77 }
78
87 public function setElementHandler(ilSaxSubsetParser $a_parser, $a_element)
88 {
89 $this->element_handlers[$a_element] = $a_parser;
90 $this->handlers_in_use[$a_element] = false;
91 }
92
111 public function handlerBeginTag($a_xml_parser, $a_name, $a_attribs)
112 {
113 if (isset($this->element_handlers[$a_name]) or $this->handler_in_use) {
114 if (!$this->handler_in_use) {
115 $this->handler_in_use = $this->element_handlers[$a_name];
116 }
117 // Forward to handler
118 $this->current_handler = $this->handler_in_use;
119 return $this->current_handler->handlerBeginTag($a_xml_parser, $a_name, $a_attribs);
120 }
121 // Call default handler
122 $this->handler_in_use = false;
123 $this->current_handler = $this->default_handler;
124 return $this->default_handler->handlerBeginTag($a_xml_parser, $a_name, $a_attribs);
125 }
126
133 public function handlerEndTag($a_xml_parser, $a_name)
134 {
135 if (isset($this->element_handlers[$a_name])) {
136 $this->handler_in_use = false;
137 $this->current_handler = $this->element_handlers[$a_name];
138 return $this->element_handlers[$a_name]->handlerEndTag($a_xml_parser, $a_name);
139 } elseif ($this->handler_in_use) {
140 $this->current_handler = $this->handler_in_use;
141 return $this->current_handler->handlerEndTag($a_xml_parser, $a_name);
142 }
143 $this->handler_in_use = false;
144 $this->current_handler = $this->default_handler;
145 return $this->default_handler->handlerEndTag($a_xml_parser, $a_name);
146 }
147
154 public function handlerCharacterData($a_xml_parser, $a_data)
155 {
156 return $this->current_handler->handlerCharacterData($a_xml_parser, $a_data);
157 }
158}
An exception for terminatinating execution or to throw for unit testing.
Controller class for sax element handlers.
handlerCharacterData($a_xml_parser, $a_data)
handler for character data
__construct()
Constructor.
setElementHandler(ilSaxSubsetParser $a_parser, $a_element)
Set element handler by element name.
setDefaultElementHandler(ilSaxSubsetParser $a_default_parser)
Set default element handler.
handlerEndTag($a_xml_parser, $a_name)
handler for end of element
setHandlers($a_xml_parser)
Set handlers.
handlerBeginTag($a_xml_parser, $a_name, $a_attribs)
Set default element handler.
Interface definition for sax subset parsers.