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