ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilObjectXMLParser.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2001 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 
24 
34 include_once './Services/Xml/classes/class.ilSaxParser.php';
35 include_once('./webservice/soap/classes/class.ilObjectXMLException.php');
36 
38 {
39  public $object_data = array();
40 
41  private $ref_id;
42  private $parent_id;
43 
53  public function __construct($a_xml_data = '', $throwException = false)
54  {
55  parent::__construct('', $throwException);
56  $this->setXMLContent($a_xml_data);
57  }
58 
59  public function getObjectData()
60  {
61  return $this->object_data ? $this->object_data : array();
62  }
63 
71  public function parse($a_xml_parser, $a_fp = null)
72  {
73  parent::parse($a_xml_parser, $a_fp);
74  }
75 
76 
83  public function setHandlers($a_xml_parser)
84  {
85  xml_set_object($a_xml_parser, $this);
86  xml_set_element_handler($a_xml_parser, 'handlerBeginTag', 'handlerEndTag');
87  xml_set_character_data_handler($a_xml_parser, 'handlerCharacterData');
88  }
89 
90 
91 
92 
100  public function handlerBeginTag($a_xml_parser, $a_name, $a_attribs)
101  {
102  switch ($a_name) {
103  case 'Objects':
104  $this->curr_obj = -1;
105  break;
106 
107  case 'Object':
108  ++$this->curr_obj;
109 
110  $this->__addProperty('type', $a_attribs['type']);
111  $this->__addProperty('obj_id', is_numeric($a_attribs['obj_id'])?(int) $a_attribs["obj_id"] : ilUtil::__extractId($a_attribs["obj_id"], IL_INST_ID));
112  break;
113 
114  case 'Title':
115  break;
116 
117  case 'Description':
118  break;
119 
120  case 'Owner':
121  break;
122 
123  case 'CreateDate':
124  break;
125 
126  case 'LastUpdate':
127  break;
128 
129  case 'ImportId':
130  break;
131 
132  case 'References':
133  $this->time_target = array();
134  $this->ref_id = $a_attribs["ref_id"];
135  $this->parent_id = $a_attribs['parent_id'];
136  break;
137 
138  case 'TimeTarget':
139  $this->time_target['timing_type'] = $a_attribs['type'];
140  break;
141 
142  case 'Timing':
143  $this->time_target['timing_visibility'] = $a_attribs['visibility'];
144  if (isset($a_attribs['starting_time'])) {
145  $this->time_target['starting_time'] = $a_attribs['starting_time'];
146  }
147  if (isset($a_attribs['ending_time'])) {
148  $this->time_target['ending_time'] = $a_attribs['ending_time'];
149  }
150 
151  if ($a_attribs['ending_time'] < $a_attribs['starting_time']) {
152  throw new ilObjectXMLException('Starting time must be earlier than ending time.');
153  }
154  break;
155 
156  case 'Suggestion':
157  $this->time_target['changeable'] = $a_attribs['changeable'];
158 
159 
160  if (isset($a_attribs['starting_time'])) {
161  $this->time_target['suggestion_start'] = $a_attribs['starting_time'];
162  }
163  if (isset($a_attribs['ending_time'])) {
164  $this->time_target['suggestion_end'] = $a_attribs['ending_time'];
165  }
166  if (isset($a_attribs['earliest_start'])) {
167  $this->time_target['earliest_start'] = $a_attribs['earliest_start'];
168  }
169  if (isset($a_attribs['latest_end'])) {
170  $this->time_target['latest_end'] = $a_attribs['latest_end'];
171  }
172 
173  if ($a_attribs['latest_end'] < $a_attribs['earliest_start']) {
174  throw new ilObjectXMLException('Earliest start time must be earlier than latest ending time.');
175  }
176  if ($a_attribs['ending_time'] < $a_attribs['starting_time']) {
177  throw new ilObjectXMLException('Starting time must be earlier than ending time.');
178  }
179  break;
180 
181  }
182  }
183 
190  public function handlerEndTag($a_xml_parser, $a_name)
191  {
192  switch ($a_name) {
193  case 'Objects':
194  break;
195 
196  case 'Object':
197  break;
198 
199  case 'Title':
200  $this->__addProperty('title', trim($this->cdata));
201  break;
202 
203  case 'Description':
204  $this->__addProperty('description', trim($this->cdata));
205  break;
206 
207  case 'Owner':
208  $this->__addProperty('owner', trim($this->cdata));
209  break;
210 
211  case 'CreateDate':
212  $this->__addProperty('create_date', trim($this->cdata));
213  break;
214 
215  case 'LastUpdate':
216  $this->__addProperty('last_update', trim($this->cdata));
217  break;
218 
219  case 'ImportId':
220  $this->__addProperty('import_id', trim($this->cdata));
221  break;
222 
223  case 'References':
224  $this->__addReference($this->ref_id, $this->parent_id, $this->time_target);
225  break;
226  }
227 
228  $this->cdata = '';
229 
230  return;
231  }
232 
239  public function handlerCharacterData($a_xml_parser, $a_data)
240  {
241  if ($a_data != "\n") {
242  // Replace multiple tabs with one space
243  $a_data = preg_replace("/\t+/", " ", $a_data);
244 
245  $this->cdata .= $a_data;
246  }
247  }
248 
249  // PRIVATE
250  public function __addProperty($a_name, $a_value)
251  {
252  $this->object_data[$this->curr_obj][$a_name] = $a_value;
253  }
254 
258  public function __addReference($a_ref_id, $a_parent_id, $a_time_target)
259  {
260  $reference['ref_id'] = $a_ref_id;
261  $reference['parent_id'] = $a_parent_id;
262  $reference['time_target'] = $a_time_target;
263 
264  if (isset($reference['time_target']['changeable']) and $reference['time_target']['changeable']) {
265  if (!isset($reference['time_target']['earliest_start']) or !isset($reference['time_target']['latest_end'])) {
266  throw new ilObjectXMLException('Missing attributes: "earliest_start" and "latest_end" required for attribute "changeable"');
267  }
268  if (!isset($reference['time_target']['suggestion_start']) or !isset($reference['time_target']['suggestion_end'])) {
269  throw new ilObjectXMLException('Missing attributes: "starting_time" and "ending_time" required for attribute "changeable"');
270  }
271  if (($reference['time_target']['earliest_start'] < $reference['time_target']['suggestion_start']) or
272  ($reference['time_target']['earliest_start'] > $reference['time_target']['suggestion_end'])) {
273  throw new ilObjectXMLException('Invalid attributes: "earliest_start" must be within "starting_time" and "ending_time"');
274  }
275  if (($reference['time_target']['latest_end'] < $reference['time_target']['suggestion_start']) or
276  ($reference['time_target']['latest_end'] > $reference['time_target']['suggestion_end'])) {
277  throw new ilObjectXMLException('Invalid attributes: "latest_end" must be within "starting_time" and "ending_time"');
278  }
279  }
280 
281  $this->object_data[$this->curr_obj]['references'][] = $reference;
282  }
283 }
handlerEndTag($a_xml_parser, $a_name)
handler for end of element
handlerCharacterData($a_xml_parser, $a_data)
handler for character data
Exception class for ObjectXMLWriter and ObjectXMLParser.
Base class for sax-based expat parsing extended classes need to overwrite the method setHandlers and ...
handlerBeginTag($a_xml_parser, $a_name, $a_attribs)
handler for begin of element
__construct($a_xml_data='', $throwException=false)
Constructor.
Create styles array
The data for the language used.
__addReference($a_ref_id, $a_parent_id, $a_time_target)
setHandlers($a_xml_parser)
set event handlers
parse($a_xml_parser, $a_fp=null)
parse xml file
setXMLContent($a_xml_content)
static __extractId($ilias_id, $inst_id)
extract ref id from role title, e.g.
__addProperty($a_name, $a_value)