ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 
4 require_once 'Services/Xml/classes/class.ilSaxParser.php';
5 
13 {
17  private $poolOBJ;
18 
19  private $inSettingsTag;
20 
21  private $inMetaDataTag;
22  private $inMdGeneralTag;
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  {
51  case 'MetaData':
52  $this->inMetaDataTag = true;
53  break;
54 
55  case 'General':
56  if($this->inMetaDataTag)
57  {
58  $this->inMdGeneralTag = true;
59  }
60  break;
61 
62  case 'Description':
63  if($this->inMetaDataTag && $this->inMdGeneralTag)
64  {
65  $this->cdata = '';
66  }
67  break;
68 
69  case 'Settings':
70  $this->inSettingsTag = true;
71  break;
72 
73  case 'ShowTaxonomies':
74  case 'NavTaxonomy':
75  case 'SkillService':
76  if($this->inSettingsTag)
77  {
78  $this->cdata = '';
79  }
80  break;
81  }
82  }
83 
84  public function handlerEndTag($xmlParser, $tagName)
85  {
86  switch($tagName)
87  {
88  case 'MetaData':
89  $this->inMetaDataTag = false;
90  break;
91 
92  case 'General':
93  if($this->inMetaDataTag)
94  {
95  $this->inMdGeneralTag = false;
96  }
97  break;
98 
99  case 'Description':
100  if($this->inMetaDataTag && $this->inMdGeneralTag && !$this->descriptionProcessed)
101  {
102  $this->poolOBJ->setDescription($this->cdata);
103  $this->descriptionProcessed = true;
104  $this->cdata = '';
105  }
106  break;
107 
108  case 'Settings':
109  $this->inSettingsTag = false;
110  break;
111 
112  case 'ShowTaxonomies':
113  $this->poolOBJ->setShowTaxonomies((bool)$this->cdata);
114  $this->cdata = '';
115  break;
116 
117  case 'NavTaxonomy':
118  $this->poolOBJ->setNavTaxonomyId((int)$this->cdata);
119  $this->cdata = '';
120  break;
121 
122  case 'SkillService':
123  $this->poolOBJ->setSkillServiceEnabled((bool)$this->cdata);
124  $this->cdata = '';
125  break;
126  }
127  }
128 
129  public function handlerCharacterData($xmlParser, $charData)
130  {
131  if( $charData != "\n" )
132  {
133  // Replace multiple tabs with one space
134  $charData = preg_replace("/\t+/"," ",$charData);
135 
136  $this->cdata .= $charData;
137  }
138  }
139 }
handlerBeginTag($xmlParser, $tagName, $tagAttributes)
Base class for sax-based expat parsing extended classes need to overwrite the method setHandlers and ...
__construct(ilObjQuestionPool $poolOBJ, $xmlFile)