ILIAS  Release_3_10_x_branch Revision 61812
 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  }
52 
60  public function setHandlers($a_xml_parser)
61  {
62  xml_set_object($a_xml_parser,$this);
63  xml_set_element_handler($a_xml_parser,'handlerBeginTag','handlerEndTag');
64  xml_set_character_data_handler($a_xml_parser,'handlerCharacterData');
65  return;
66  }
67 
75  public function setDefaultElementHandler(ilSaxSubsetParser $a_default_parser)
76  {
77  $this->default_handler = $a_default_parser;
78  }
79 
88  public function setElementHandler(ilSaxSubsetParser $a_parser,$a_element)
89  {
90  $this->element_handlers[$a_element] = $a_parser;
91  $this->handlers_in_use[$a_element] = false;
92  }
93 
112  public function handlerBeginTag($a_xml_parser,$a_name,$a_attribs)
113  {
114  if(isset($this->element_handlers[$a_name]) or $this->handler_in_use)
115  {
116  if(!$this->handler_in_use)
117  {
118  $this->handler_in_use = $this->element_handlers[$a_name];
119  }
120  // Forward to handler
121  $this->current_handler = $this->handler_in_use;
122  return $this->current_handler->handlerBeginTag($a_xml_parser,$a_name,$a_attribs);
123  }
124  // Call default handler
125  $this->handler_in_use = false;
126  $this->current_handler = $this->default_handler;
127  return $this->default_handler->handlerBeginTag($a_xml_parser,$a_name,$a_attribs);
128  }
129 
136  function handlerEndTag($a_xml_parser,$a_name)
137  {
138  if(isset($this->element_handlers[$a_name]))
139  {
140  $this->handler_in_use = false;
141  $this->current_handler = $this->element_handlers[$a_name];
142  return $this->element_handlers[$a_name]->handlerEndTag($a_xml_parser,$a_name);
143  }
144  elseif($this->handler_in_use)
145  {
146  $this->current_handler = $this->handler_in_use;
147  return $this->current_handler->handlerEndTag($a_xml_parser,$a_name);
148  }
149  $this->handler_in_use = false;
150  $this->current_handler = $this->default_handler;
151  return $this->default_handler->handlerEndTag($a_xml_parser,$a_name);
152  }
153 
160  function handlerCharacterData($a_xml_parser,$a_data)
161  {
162  return $this->current_handler->handlerCharacterData(a_xml_parser,$a_data);
163  }
164 
165 }
166 ?>