ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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
47 function ilCategoryImportParser($a_xml_file, $a_parent,$withrol)
48
49 {
50 $this->parent_cnt = 0;
51 $this->parent[$this->parent_cnt] = $a_parent;
52 $this->parent_cnt++;
53 $this->withrol = $withrol;
54 parent::ilSaxParser($a_xml_file);
55 }
56
57
63 function setHandlers($a_xml_parser)
64 {
65 xml_set_object($a_xml_parser,$this);
66 xml_set_element_handler($a_xml_parser,'handlerBeginTag','handlerEndTag');
67 xml_set_character_data_handler($a_xml_parser,'handlerCharacterData');
68 }
69
73 function startParsing()
74 {
75 parent::startParsing();
76 }
77
85 function buildTag ($type, $name, $attr="")
86 {
87 $tag = "<";
88
89 if ($type == "end")
90 $tag.= "/";
91
92 $tag.= $name;
93
94 if (is_array($attr))
95 {
96 while (list($k,$v) = each($attr))
97 $tag.= " ".$k."=\"$v\"";
98 }
99
100 $tag.= ">";
101
102 return $tag;
103 }
104
108 function handlerBeginTag($a_xml_parser, $a_name, $a_attribs)
109
110 {
111
112 global $rbacadmin, $rbacreview, $rbacsystem;
113
114 switch($a_name)
115 {
116 case "Category":
117 $cur_parent = $this->parent[$this->parent_cnt - 1];
118 require_once("Modules/Category/classes/class.ilObjCategory.php");
119 $this->category = new ilObjCategory;
120 $this->category->setImportId($a_attribs["Id"]." (#".$cur_parent.")");
121 $this->default_language = $a_attribs["DefaultLanguage"];
122 $this->category->setTitle($a_attribs["Id"]);
123 $this->category->create();
124 $this->category->createReference();
125 $this->category->putInTree($cur_parent);
126 $this->parent[$this->parent_cnt++] = $this->category->getRefId();
127 break;
128
129 case "CategorySpec":
130 $this->cur_spec_lang = $a_attribs["Language"];
131 break;
132
133 }
134
135 }
136
137
141 function handlerEndTag($a_xml_parser, $a_name)
142 {
143 global $ilias, $rbacadmin;
144
145 switch($a_name)
146 {
147 case "Category":
148 unset($this->category);
149 unset($this->parent[$this->parent_cnt - 1]);
150 $this->parent_cnt--;
151 break;
152
153 case "CategorySpec":
154 $is_def = 0;
155 if ($this->cur_spec_lang == $this->default_language)
156 {
157 $this->category->setTitle($this->cur_title);
158 $this->category->setDescription($this->cur_description);
159 $this->category->update();
160 $is_def = 1;
161 }
162 $this->category->addTranslation($this->cur_title,
163 $this->cur_description, $this->cur_spec_lang, $is_def);
164 break;
165
166 case "Title":
167 $this->cur_title = $this->cdata;
168 break;
169
170 case "Description":
171 $this->cur_description = $this->cdata;
172 break;
173 }
174
175 $this->cdata = "";
176 }
177
181 function handlerCharacterData($a_xml_parser, $a_data)
182 {
183 // i don't know why this is necessary, but
184 // the parser seems to convert "&gt;" to ">" and "&lt;" to "<"
185 // in character data, but we don't want that, because it's the
186 // way we mask user html in our content, so we convert back...
187 $a_data = str_replace("<","&lt;",$a_data);
188 $a_data = str_replace(">","&gt;",$a_data);
189
190 // DELETE WHITESPACES AND NEWLINES OF CHARACTER DATA
191 $a_data = preg_replace("/\n/","",$a_data);
192 $a_data = preg_replace("/\t+/","",$a_data);
193 if(!empty($a_data))
194 {
195 $this->cdata .= $a_data;
196 }
197 }
198
199}
200?>
ilCategoryImportParser($a_xml_file, $a_parent, $withrol)
Constructor.
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
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 ...