ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilMDXMLCopier.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
34include_once 'Services/MetaData/classes/class.ilMDSaxParser.php';
35include_once 'Services/MetaData/classes/class.ilMD.php';
36
38{
39 public $filter = array();
40
41 public function __construct($content, $a_rbac_id, $a_obj_id, $a_obj_type)
42 {
43 $this->setMDObject(new ilMD($a_rbac_id, $a_obj_id, $a_obj_type));
44
46 $this->setXMLContent($content);
47
48 // set filter of tags which are handled in this class
49 $this->__setFilter();
50 }
51
52 public function startParsing()
53 {
54 // delete existing entries from creations process
55 $clone_md = $this->getMDObject();
56 $clone_md->deleteAll();
57
58 // rewrite autogenerated entry
59 $identifier = new ilMDIdentifier(
60 $clone_md->getRBACId(),
61 $clone_md->getObjId(),
62 $clone_md->getObjType(),
63 );
64 $identifier->setEntry('il__' . $clone_md->getObjType() . '_' . $clone_md->getObjId());
65 $identifier->update();
66
67 parent::startParsing();
68 }
69
70 public function setHandlers($a_xml_parser)
71 {
72 xml_set_object($a_xml_parser, $this);
73 xml_set_element_handler($a_xml_parser, 'handlerBeginTag', 'handlerEndTag');
74 xml_set_character_data_handler($a_xml_parser, 'handlerCharacterData');
75 }
76
77 public function handlerBeginTag($a_xml_parser, $a_name, $a_attribs)
78 {
79 if ($this->in_meta_data and !$this->__inFilter($a_name)) {
80 parent::handlerBeginTag($a_xml_parser, $a_name, $a_attribs);
81 return true;
82 }
83
84
85 switch ($a_name) {
86 case 'MetaData':
87 $this->in_meta_data = true;
88 parent::handlerBeginTag($a_xml_parser, $a_name, $a_attribs);
89 break;
90
91 case 'Identifier':
92 $par = &$this->__getParent();
93 $this->md_ide = &$par->addIdentifier();
94 $this->md_ide->setCatalog($a_attribs['Catalog']);
95 $this->md_ide->setEntry('il__' . $this->md->getObjType() . '_' . $this->md->getObjId());
96 $this->md_ide->save();
97 $this->__pushParent($this->md_ide);
98 break;
99 }
100 return true;
101 }
102 public function handlerEndTag($a_xml_parser, $a_name)
103 {
104 if ($this->in_meta_data and !$this->__inFilter($a_name)) {
105 parent::handlerEndTag($a_xml_parser, $a_name);
106 return true;
107 }
108 switch ($a_name) {
109 case 'Identifier':
110 $par = &$this->__getParent();
111 $par->update();
112 $this->__popParent();
113 break;
114
115
116 case 'MetaData':
117 $this->in_meta_data = false;
118 parent::handlerEndTag($a_xml_parser, $a_name);
119 break;
120 }
121 return true;
122 }
123
124 public function handlerCharacterData($a_xml_parser, $a_data)
125 {
126 if ($this->in_meta_data) {
127 parent::handlerCharacterData($a_xml_parser, $a_data);
128 return true;
129 }
130 }
131 /*
132 * Set filter of tags which are handled in this class.
133 * @access protected
134 *
135 */
136 public function __setFilter()
137 {
138 $this->filter[] = 'Identifier';
139 }
140 /*
141 * Check if tag is filtered
142 * @access protected
143 *
144 */
145 public function __inFilter($a_tag_name)
146 {
147 return in_array($a_tag_name, $this->filter);
148 }
149}
An exception for terminatinating execution or to throw for unit testing.
__inFilter($a_tag_name)
startParsing()
stores xml data in array
handlerCharacterData($a_xml_parser, $a_data)
handler for character data
handlerBeginTag($a_xml_parser, $a_name, $a_attribs)
handler for begin of element
__construct($content, $a_rbac_id, $a_obj_id, $a_obj_type)
handlerEndTag($a_xml_parser, $a_name)
handler for end of element
setHandlers($a_xml_parser)
set event handlers
setXMLContent($a_xml_content)
filter()
Definition: filter.php:2
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc