ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
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  {
115  if(!$this->handler_in_use)
116  {
117  $this->handler_in_use = $this->element_handlers[$a_name];
118  }
119  // Forward to handler
120  $this->current_handler = $this->handler_in_use;
121  return $this->current_handler->handlerBeginTag($a_xml_parser,$a_name,$a_attribs);
122  }
123  // Call default handler
124  $this->handler_in_use = false;
125  $this->current_handler = $this->default_handler;
126  return $this->default_handler->handlerBeginTag($a_xml_parser,$a_name,$a_attribs);
127  }
128 
135  function handlerEndTag($a_xml_parser,$a_name)
136  {
137  if(isset($this->element_handlers[$a_name]))
138  {
139  $this->handler_in_use = false;
140  $this->current_handler = $this->element_handlers[$a_name];
141  return $this->element_handlers[$a_name]->handlerEndTag($a_xml_parser,$a_name);
142  }
143  elseif($this->handler_in_use)
144  {
145  $this->current_handler = $this->handler_in_use;
146  return $this->current_handler->handlerEndTag($a_xml_parser,$a_name);
147  }
148  $this->handler_in_use = false;
149  $this->current_handler = $this->default_handler;
150  return $this->default_handler->handlerEndTag($a_xml_parser,$a_name);
151  }
152 
159  function handlerCharacterData($a_xml_parser,$a_data)
160  {
161  return $this->current_handler->handlerCharacterData(a_xml_parser,$a_data);
162  }
163 
164 }
165 ?>