ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilMDSaxParser.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 
37 include_once './Services/Xml/classes/class.ilSaxParser.php';
38 
39 class ilMDSaxParser extends ilSaxParser
40 {
41  public $md_in_md = false;
42  public $md_chr_data = '';
43 
44  public $md_cur_el = null;
45 
46  /*
47  * @var object ilMD
48  */
49  public $md = null;
50 
51  /*
52  * @var object ilMDGeneral
53  */
54  public $md_gen;
55 
56 
62  public function __construct($a_xml_file = '')
63  {
64  global $lng, $tree;
65 
66  parent::__construct($a_xml_file);
67  }
68 
69  public function setMDObject(&$md)
70  {
71  $this->md =&$md;
72  }
73 
74  public function inMetaData()
75  {
76  return $this->md_in_md;
77  }
78 
79 
83  public function handlerBeginTag($a_xml_parser, $a_name, $a_attribs)
84  {
85  include_once 'Services/Migration/DBUpdate_426/classes/class.ilMDLanguageItem.php';
86 
87  switch ($a_name) {
88  case 'MetaData':
89  $this->md_in_md = true;
90  $this->__pushParent($this->md);
91  break;
92 
93  case 'General':
94  $this->md_gen =&$this->md->addGeneral();
95  $this->md_gen->setStructure($a_attribs['Structure']);
96  $this->md_gen->save();
97  $this->__pushParent($this->md_gen);
98  break;
99 
100  case 'Identifier':
101  $par =&$this->__getParent();
102  $this->md_ide =&$par->addIdentifier();
103  $this->md_ide->setCatalog($a_attribs['Catalog']);
104  $this->md_ide->setEntry($a_attribs['Entry']);
105  $this->md_ide->save();
106  $this->__pushParent($this->md_ide);
107  break;
108 
109  case 'Title':
110  $par =&$this->__getParent();
111  $par->setTitleLanguage(new ilMDLanguageItem($a_attribs['Language']));
112  break;
113 
114  case 'Language':
115  $par =&$this->__getParent();
116  $this->md_lan =&$par->addLanguage();
117  $this->md_lan->setLanguage(new ilMDLanguageItem($a_attribs['Language']));
118  $this->md_lan->save();
119  $this->__pushParent($this->md_lan);
120  break;
121 
122  case 'Description':
123  $par =&$this->__getParent();
124 
125  if (strtolower(get_class($par)) == 'ilmdrights' or
126  strtolower(get_class($par)) == 'ilmdannotation' or
127  strtolower(get_class($par)) == 'ilmdclassification') {
128  $par->setDescriptionLanguage(new ilMDLanguageItem($a_attribs['Language']));
129  break;
130  } else {
131  $this->md_des =&$par->addDescription();
132  $this->md_des->setDescriptionLanguage(new ilMDLanguageItem($a_attribs['Language']));
133  $this->md_des->save();
134  $this->__pushParent($this->md_des);
135  break;
136  }
137 
138  // no break
139  case 'Keyword':
140  $par =&$this->__getParent();
141  $this->md_key =&$par->addKeyword();
142  $this->md_key->setKeywordLanguage(new ilMDLanguageItem($a_attribs['Language']));
143  $this->md_key->save();
144  $this->__pushParent($this->md_key);
145  break;
146 
147  case 'Coverage':
148  $par =&$this->__getParent();
149  $par->setCoverageLanguage(new ilMDLanguageItem($a_attribs['Language']));
150  break;
151 
152  case 'Lifecycle':
153  $par =&$this->__getParent();
154  $this->md_lif =&$par->addLifecycle();
155  $this->md_lif->setStatus($a_attribs['Status']);
156  $this->md_lif->save();
157  $this->__pushParent($this->md_lif);
158  break;
159 
160  case 'Version':
161  $par =&$this->__getParent();
162  $par->setVersionLanguage(new ilMDLanguageItem($a_attribs['Language']));
163  break;
164 
165  case 'Contribute':
166  $par =&$this->__getParent();
167  $this->md_con =&$par->addContribute();
168  $this->md_con->setRole($a_attribs['Role']);
169  $this->md_con->save();
170  $this->__pushParent($this->md_con);
171  break;
172 
173  case 'Entity':
174  $par =&$this->__getParent();
175 
176  if (strtolower(get_class($par)) == 'ilmdcontribute') {
177  $this->md_ent =&$par->addEntity();
178  $this->md_ent->save();
179  $this->__pushParent($this->md_ent);
180  break;
181  } else {
182  // single element in 'Annotation'
183  break;
184  }
185  // no break
186  case 'Date':
187  break;
188 
189  case 'Meta-Metadata':
190  $par =&$this->__getParent();
191  $this->md_met =&$par->addMetaMetadata();
192  $this->md_met->setMetaDataScheme($a_attribs['MetadataScheme']);
193  $this->md_met->setLanguage(new ilMDLanguageItem($a_attribs['Language']));
194  $this->md_met->save();
195  $this->__pushParent($this->md_met);
196  break;
197 
198  case 'Technical':
199  $par =&$this->__getParent();
200  $this->md_tec =&$par->addTechnical();
201  $this->md_tec->save();
202  $this->__pushParent($this->md_tec);
203  break;
204 
205  case 'Format':
206  $par =&$this->__getParent();
207  $this->md_for =&$par->addFormat();
208  $this->md_for->save();
209  $this->__pushParent($this->md_for);
210  break;
211 
212  case 'Size':
213  break;
214 
215  case 'Location':
216  $par =&$this->__getParent();
217  $this->md_loc =&$par->addLocation();
218  $this->md_loc->setLocationType($a_attribs['Type']);
219  $this->md_loc->save();
220  $this->__pushParent($this->md_loc);
221  break;
222 
223  case 'Requirement':
224  $par =&$this->__getParent();
225  $this->md_req =&$par->addRequirement();
226  $this->md_req->save();
227  $this->__pushParent($this->md_req);
228  break;
229 
230  case 'OrComposite':
231  $par =&$this->__getParent();
232  $this->md_orc =&$par->addOrComposite();
233  $this->__pushParent($this->md_orc);
234  break;
235 
236  case 'Type':
237  break;
238 
239  case 'OperatingSystem':
240  $par =&$this->__getParent();
241  $par->setOperatingSystemName($a_attribs['Name']);
242  $par->setOperatingSystemMinimumVersion($a_attribs['MinimumVersion']);
243  $par->setOperatingSystemMaximumVersion($a_attribs['MaximumVersion']);
244  break;
245 
246  case 'Browser':
247  $par =&$this->__getParent();
248  $par->setBrowserName($a_attribs['Name']);
249  $par->setBrowserMinimumVersion($a_attribs['MinimumVersion']);
250  $par->setBrowserMaximumVersion($a_attribs['MaximumVersion']);
251  break;
252 
253  case 'InstallationRemarks':
254  $par =&$this->__getParent();
255  $par->setInstallationRemarksLanguage(new ilMDLanguageItem($a_attribs['Language']));
256  break;
257 
258  case 'OtherPlatformRequirements':
259  $par =&$this->__getParent();
260  $par->setOtherPlatformRequirementsLanguage(new ilMDLanguageItem($a_attribs['Language']));
261  break;
262 
263  case 'Duration':
264  break;
265 
266  case 'Educational':
267  $par =&$this->__getParent();
268  $this->md_edu =&$par->addEducational();
269  $this->md_edu->setInteractivityType($a_attribs['InteractivityType']);
270  $this->md_edu->setLearningResourceType($a_attribs['LearningResourceType']);
271  $this->md_edu->setInteractivityLevel($a_attribs['InteractivityLevel']);
272  $this->md_edu->setSemanticDensity($a_attribs['SemanticDensity']);
273  $this->md_edu->setIntendedEndUserRole($a_attribs['IntendedEndUserRole']);
274  $this->md_edu->setContext($a_attribs['Context']);
275  $this->md_edu->setDifficulty($a_attribs['Difficulty']);
276  $this->md_edu->save();
277  $this->__pushParent($this->md_edu);
278  break;
279 
280  case 'TypicalAgeRange':
281  $par =&$this->__getParent();
282  $this->md_typ =&$par->addTypicalAgeRange();
283  $this->md_typ->setTypicalAgeRangeLanguage(new ilMDLanguageItem($a_attribs['Language']));
284  $this->md_typ->save();
285  $this->__pushParent($this->md_typ);
286  break;
287 
288  case 'TypicalLearningTime':
289  break;
290 
291  case 'Rights':
292  $par =&$this->__getParent();
293  $this->md_rig =&$par->addRights();
294  $this->md_rig->setCosts($a_attribs['Costs']);
295  $this->md_rig->setCopyrightAndOtherRestrictions($a_attribs['CopyrightAndOtherRestrictions']);
296  $this->md_rig->save();
297  $this->__pushParent($this->md_rig);
298  break;
299 
300  case 'Relation':
301  $par =&$this->__getParent();
302  $this->md_rel =&$par->addRelation();
303  $this->md_rel->setKind($a_attribs['Kind']);
304  $this->md_rel->save();
305  $this->__pushParent($this->md_rel);
306  break;
307 
308  case 'Resource':
309  break;
310 
311  case 'Identifier_':
312  $par =&$this->__getParent();
313  $this->md_ide_ =&$par->addIdentifier_();
314  $this->md_ide_->setCatalog($a_attribs['Catalog']);
315  $this->md_ide_->setEntry($a_attribs['Entry']);
316  $this->md_ide_->save();
317  $this->__pushParent($this->md_ide_);
318  break;
319 
320  case 'Annotation':
321  $par =&$this->__getParent();
322  $this->md_ann =&$par->addAnnotation();
323  $this->md_ann->save();
324  $this->__pushParent($this->md_ann);
325  break;
326 
327  case 'Classification':
328  $par =&$this->__getParent();
329  $this->md_cla =&$par->addClassification();
330  $this->md_cla->setPurpose($a_attribs['Purpose']);
331  $this->md_cla->save();
332  $this->__pushParent($this->md_cla);
333  break;
334 
335  case 'TaxonPath':
336  $par =&$this->__getParent();
337  $this->md_taxp =&$par->addTaxonPath();
338  $this->md_taxp->save();
339  $this->__pushParent($this->md_taxp);
340  break;
341 
342  case 'Source':
343  $par =&$this->__getParent();
344  $par->setSourceLanguage(new ilMDLanguageItem($a_attribs['Language']));
345  break;
346 
347  case 'Taxon':
348  $par =&$this->__getParent();
349  $this->md_tax =&$par->addTaxon();
350  $this->md_tax->setTaxonLanguage(new ilMDLanguageItem($a_attribs['Language']));
351  $this->md_tax->setTaxonId($a_attribs['Id']);
352  $this->md_tax->save();
353  $this->__pushParent($this->md_tax);
354  break;
355  }
356  }
357 
361  public function handlerEndTag($a_xml_parser, $a_name)
362  {
363  switch ($a_name) {
364  case 'MetaData':
365  $this->md_parent = array();
366  $this->md_in_md = false;
367  break;
368 
369  case 'General':
370  $par =&$this->__getParent();
371  $par->update();
372  $this->__popParent();
373  break;
374 
375  case 'Identifier':
376  $par =&$this->__getParent();
377  $par->update();
378  $this->__popParent();
379  break;
380 
381  case 'Title':
382  $par =&$this->__getParent();
383  $par->setTitle($this->__getCharacterData());
384  break;
385 
386  case 'Language':
387  $par =&$this->__getParent();
388  $par->update();
389  $this->__popParent();
390  break;
391 
392  case 'Description':
393  $par =&$this->__getParent();
394  if (strtolower(get_class($par)) == 'ilmddescription') {
395  $par->setDescription($this->__getCharacterData());
396  $par->update();
397  $this->__popParent();
398  break;
399  } else {
400  $par->setDescription($this->__getCharacterData());
401  break;
402  }
403 
404  // no break
405  case 'Keyword':
406  $par =&$this->__getParent();
407  $par->setKeyword($this->__getCharacterData());
408  $par->update();
409  $this->__popParent();
410  break;
411 
412  case 'Coverage':
413  $par =&$this->__getParent();
414  $par->setCoverage($this->__getCharacterData());
415  break;
416 
417  case 'Lifecycle':
418  $par =&$this->__getParent();
419  $par->update();
420  $this->__popParent();
421  break;
422 
423  case 'Version':
424  $par =&$this->__getParent();
425  $par->setVersion($this->__getCharacterData());
426  break;
427 
428  case 'Contribute':
429  $par =&$this->__getParent();
430  $par->update();
431  $this->__popParent();
432  break;
433 
434  case 'Entity':
435  $par =&$this->__getParent();
436 
437  if (strtolower(get_class($par)) == 'ilmdentity') {
438  $par->setEntity($this->__getCharacterData());
439  $par->update();
440  $this->__popParent();
441  } else {
442  // Single element in 'Annotation'
443  $par->setEntity($this->__getCharacterData());
444  }
445  break;
446 
447  case 'Date':
448  $par =&$this->__getParent();
449  $par->setDate($this->__getCharacterData());
450  break;
451 
452  case 'Meta-Metadata':
453  $par =&$this->__getParent();
454  $par->update();
455  $this->__popParent();
456  break;
457 
458  case 'Technical':
459  $par =&$this->__getParent();
460  $par->update();
461  $this->__popParent();
462  break;
463 
464  case 'Format':
465  $par =&$this->__getParent();
466  $par->setFormat($this->__getCharacterData());
467  $par->update();
468  $this->__popParent();
469  break;
470 
471  case 'Size':
472  $par =&$this->__getParent();
473  $par->setSize($this->__getCharacterData());
474  break;
475 
476  case 'Location':
477  $par =&$this->__getParent();
478  $par->setLocation($this->__getCharacterData());
479  $par->update();
480  $this->__popParent();
481  break;
482 
483  case 'Requirement':
484  $par =&$this->__getParent();
485  $par->update();
486  $this->__popParent();
487  break;
488 
489  case 'OrComposite':
490  $this->__popParent();
491  break;
492 
493  case 'Type':
494  break;
495 
496  case 'OperatingSystem':
497  break;
498 
499  case 'Browser':
500  break;
501 
502  case 'InstallationRemarks':
503  $par =&$this->__getParent();
504  $par->setInstallationRemarks($this->__getCharacterData());
505  break;
506 
507  case 'OtherPlatformRequirements':
508  $par =&$this->__getParent();
509  $par->setOtherPlatformRequirements($this->__getCharacterData());
510  break;
511 
512  case 'Duration':
513  $par =&$this->__getParent();
514  $par->setDuration($this->__getCharacterData());
515  break;
516 
517  case 'Educational':
518  $par =&$this->__getParent();
519  $par->update();
520  $this->__popParent();
521  break;
522 
523  case 'TypicalAgeRange':
524  $par =&$this->__getParent();
525  $par->setTypicalAgeRange($this->__getCharacterData());
526  $par->update();
527  $this->__popParent();
528  break;
529 
530  case 'TypicalLearningTime':
531  $par =&$this->__getParent();
532  $par->setTypicalLearningTime($this->__getCharacterData());
533  break;
534 
535  case 'Rights':
536  $par =&$this->__getParent();
537  $par->update();
538  $this->__popParent();
539  break;
540 
541  case 'Relation':
542  $par =&$this->__getParent();
543  $par->update();
544  $this->__popParent();
545  break;
546 
547  case 'Resource':
548  break;
549 
550  case 'Identifier_':
551  $par =&$this->__getParent();
552  $par->update();
553  $this->__popParent();
554  break;
555 
556  case 'Annotation':
557  $par =&$this->__getParent();
558  $par->update();
559  $this->__popParent();
560  break;
561 
562  case 'Classification':
563  $par =&$this->__getParent();
564  $par->update();
565  $this->__popParent();
566  break;
567 
568  case 'TaxonPath':
569  $par =&$this->__getParent();
570  $par->update();
571  $this->__popParent();
572  break;
573 
574  case 'Taxon':
575  $par =&$this->__getParent();
576  $par->setTaxon($this->__getCharacterData());
577  $par->update();
578  $this->__popParent();
579  break;
580 
581  case 'Source':
582  $par =&$this->__getParent();
583  $par->setSource($this->__getCharacterData());
584  break;
585 
586  }
587  $this->md_chr_data = '';
588  }
589 
593  public function handlerCharacterData($a_xml_parser, $a_data)
594  {
595  if ($this->inMetaData() and $a_data != "\n") {
596  // Replace multiple tabs with one space
597  $a_data = preg_replace("/\t+/", " ", $a_data);
598 
599  $this->md_chr_data .= $a_data;
600  }
601  }
602 
603 
604 
605  // PRIVATE
606  public function __getCharacterData()
607  {
608  return trim($this->md_chr_data);
609  }
610 
611  public function __pushParent(&$md_obj)
612  {
613  $this->md_parent[] =&$md_obj;
614  #echo '<br />';
615  foreach ($this->md_parent as $class) {
616  #echo get_class($class).' -> ';
617  }
618  }
619  public function &__popParent()
620  {
621  $class =&array_pop($this->md_parent);
622  unset($class);
623  #echo '<br />Popped '.get_class($class);
624  }
625  public function &__getParent()
626  {
627  return $this->md_parent[count($this->md_parent) - 1];
628  }
629 }
__construct($a_xml_file='')
Constructor.
handlerCharacterData($a_xml_parser, $a_data)
handler for character data
Base class for sax-based expat parsing extended classes need to overwrite the method setHandlers and ...
handlerEndTag($a_xml_parser, $a_name)
handler for end of element
handlerBeginTag($a_xml_parser, $a_name, $a_attribs)
handler for begin of element
Create styles array
The data for the language used.