ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilObjQuestionPoolXMLParser.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4require_once 'Services/Xml/classes/class.ilSaxParser.php';
5
13{
17 private $poolOBJ;
18
20
23 private $descriptionProcessed = false;
24
29 public function __construct(ilObjQuestionPool $poolOBJ, $xmlFile)
30 {
31 $this->poolOBJ = $poolOBJ;
32
33 $this->inSettingsTag = false;
34 $this->inMetaDataTag = false;
35 $this->inMdGeneralTag = false;
36
37 return parent::__construct($xmlFile);
38 }
39
40 public function setHandlers($xmlParser)
41 {
42 xml_set_object($xmlParser, $this);
43 xml_set_element_handler($xmlParser, 'handlerBeginTag', 'handlerEndTag');
44 xml_set_character_data_handler($xmlParser, 'handlerCharacterData');
45 }
46
47 public function handlerBeginTag($xmlParser, $tagName, $tagAttributes)
48 {
49 switch ($tagName) {
50 case 'MetaData':
51 $this->inMetaDataTag = true;
52 break;
53
54 case 'General':
55 if ($this->inMetaDataTag) {
56 $this->inMdGeneralTag = true;
57 }
58 break;
59
60 case 'Description':
61 if ($this->inMetaDataTag && $this->inMdGeneralTag) {
62 $this->cdata = '';
63 }
64 break;
65
66 case 'Settings':
67 $this->inSettingsTag = true;
68 break;
69
70 case 'ShowTaxonomies':
71 case 'NavTaxonomy':
72 case 'SkillService':
73 if ($this->inSettingsTag) {
74 $this->cdata = '';
75 }
76 break;
77 }
78 }
79
80 public function handlerEndTag($xmlParser, $tagName)
81 {
82 switch ($tagName) {
83 case 'MetaData':
84 $this->inMetaDataTag = false;
85 break;
86
87 case 'General':
88 if ($this->inMetaDataTag) {
89 $this->inMdGeneralTag = false;
90 }
91 break;
92
93 case 'Description':
94 if ($this->inMetaDataTag && $this->inMdGeneralTag && !$this->descriptionProcessed) {
95 $this->poolOBJ->setDescription($this->cdata);
96 $this->descriptionProcessed = true;
97 $this->cdata = '';
98 }
99 break;
100
101 case 'Settings':
102 $this->inSettingsTag = false;
103 break;
104
105 case 'ShowTaxonomies':
106 $this->poolOBJ->setShowTaxonomies((bool) $this->cdata);
107 $this->cdata = '';
108 break;
109
110 case 'NavTaxonomy':
111 $this->poolOBJ->setNavTaxonomyId((int) $this->cdata);
112 $this->cdata = '';
113 break;
114
115 case 'SkillService':
116 $this->poolOBJ->setSkillServiceEnabled((bool) $this->cdata);
117 $this->cdata = '';
118 break;
119 }
120 }
121
122 public function handlerCharacterData($xmlParser, $charData)
123 {
124 if ($charData != "\n") {
125 // Replace multiple tabs with one space
126 $charData = preg_replace("/\t+/", " ", $charData);
127
128 $this->cdata .= $charData;
129 }
130 }
131}
An exception for terminatinating execution or to throw for unit testing.
setHandlers($xmlParser)
set event handler should be overwritten by inherited class @access private
__construct(ilObjQuestionPool $poolOBJ, $xmlFile)
handlerBeginTag($xmlParser, $tagName, $tagAttributes)
Base class for sax-based expat parsing extended classes need to overwrite the method setHandlers and ...
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc