ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilCategoryImportParser.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
24require_once("./Services/Xml/classes/class.ilSaxParser.php");
25
35{
36 var $parent; // current parent ref id
37 var $withrol; // must have value '1' when creating a hierarchy of local roles
38
39 protected $cat_log;
40
41
49 public function __construct($a_xml_file, $a_parent,$withrol)
50 {
51 $this->parent_cnt = 0;
52 $this->parent[$this->parent_cnt] = $a_parent;
53 $this->parent_cnt++;
54 $this->withrol = $withrol;
55
56 parent::__construct($a_xml_file);
57 }
58
59
65 function setHandlers($a_xml_parser)
66 {
67 xml_set_object($a_xml_parser,$this);
68 xml_set_element_handler($a_xml_parser,'handlerBeginTag','handlerEndTag');
69 xml_set_character_data_handler($a_xml_parser,'handlerCharacterData');
70 }
71
75 function startParsing()
76 {
77 parent::startParsing();
78 }
79
87 function buildTag ($type, $name, $attr="")
88 {
89 $tag = "<";
90
91 if ($type == "end")
92 $tag.= "/";
93
94 $tag.= $name;
95
96 if (is_array($attr))
97 {
98 while (list($k,$v) = each($attr))
99 $tag.= " ".$k."=\"$v\"";
100 }
101
102 $tag.= ">";
103
104 return $tag;
105 }
106
110 function handlerBeginTag($a_xml_parser, $a_name, $a_attribs)
111
112 {
113
114 global $rbacadmin, $rbacreview, $rbacsystem;
115
116 switch($a_name)
117 {
118 case "Category":
119 $cur_parent = $this->parent[$this->parent_cnt - 1];
120 require_once("Modules/Category/classes/class.ilObjCategory.php");
121 $this->category = new ilObjCategory;
122 $this->category->setImportId($a_attribs["Id"]." (#".$cur_parent.")");
123 $this->default_language = $a_attribs["DefaultLanguage"];
124 $this->category->setTitle($a_attribs["Id"]);
125 $this->category->create();
126 $this->category->createReference();
127 $this->category->putInTree($cur_parent);
128 $this->parent[$this->parent_cnt++] = $this->category->getRefId();
129 break;
130
131 case "CategorySpec":
132 $this->cur_spec_lang = $a_attribs["Language"];
133 break;
134
135 }
136
137 }
138
139
143 function handlerEndTag($a_xml_parser, $a_name)
144 {
145 global $ilias, $rbacadmin;
146
147 switch($a_name)
148 {
149 case "Category":
150 unset($this->category);
151 unset($this->parent[$this->parent_cnt - 1]);
152 $this->parent_cnt--;
153 break;
154
155 case "CategorySpec":
156 $is_def = 0;
157 if ($this->cur_spec_lang == $this->default_language)
158 {
159 $this->category->setTitle($this->cur_title);
160 $this->category->setDescription($this->cur_description);
161 $this->category->update();
162 $is_def = 1;
163 }
164 $this->category->addTranslation($this->cur_title,
165 $this->cur_description, $this->cur_spec_lang, $is_def);
166 break;
167
168 case "Title":
169 $this->cur_title = $this->cdata;
170 break;
171
172 case "Description":
173 $this->cur_description = $this->cdata;
174 break;
175 }
176
177 $this->cdata = "";
178 }
179
183 function handlerCharacterData($a_xml_parser, $a_data)
184 {
185 // i don't know why this is necessary, but
186 // the parser seems to convert "&gt;" to ">" and "&lt;" to "<"
187 // in character data, but we don't want that, because it's the
188 // way we mask user html in our content, so we convert back...
189 $a_data = str_replace("<","&lt;",$a_data);
190 $a_data = str_replace(">","&gt;",$a_data);
191
192 // DELETE WHITESPACES AND NEWLINES OF CHARACTER DATA
193 $a_data = preg_replace("/\n/","",$a_data);
194 $a_data = preg_replace("/\t+/","",$a_data);
195 if(!empty($a_data))
196 {
197 $this->cdata .= $a_data;
198 }
199 }
200
201}
202?>
An exception for terminatinating execution or to throw for unit testing.
handlerEndTag($a_xml_parser, $a_name)
handler for end of element
handlerCharacterData($a_xml_parser, $a_data)
handler for character data
setHandlers($a_xml_parser)
set event handler should be overwritten by inherited class @access private
buildTag($type, $name, $attr="")
generate a tag with given name and attributes
__construct($a_xml_file, $a_parent, $withrol)
Constructor.
handlerBeginTag($a_xml_parser, $a_name, $a_attribs)
handler for begin of element
Class ilObjCategory.
setImportId($a_import_id)
set import id
Base class for sax-based expat parsing extended classes need to overwrite the method setHandlers and ...