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