ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
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 
34 include_once 'Services/MetaData/classes/class.ilMDSaxParser.php';
35 
37 {
38  var $filter = array();
39 
40  function ilMDXMLCopier($content,$a_rbac_id,$a_obj_id,$a_obj_type)
41  {
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  function setHandlers($a_xml_parser)
53  {
54  xml_set_object($a_xml_parser,$this);
55  xml_set_element_handler($a_xml_parser,'handlerBeginTag','handlerEndTag');
56  xml_set_character_data_handler($a_xml_parser,'handlerCharacterData');
57  }
58 
59  function handlerBeginTag($a_xml_parser,$a_name,$a_attribs)
60  {
61  if($this->in_meta_data and !$this->__inFilter($a_name))
62  {
63  parent::handlerBeginTag($a_xml_parser,$a_name,$a_attribs);
64  return true;
65  }
66 
67 
68  switch($a_name)
69  {
70  case 'MetaData':
71  $this->in_meta_data = true;
72  parent::handlerBeginTag($a_xml_parser,$a_name,$a_attribs);
73  break;
74 
75  case 'Identifier':
76  $par =& $this->__getParent();
77  $this->md_ide =& $par->addIdentifier();
78  $this->md_ide->setCatalog($a_attribs['Catalog']);
79  $this->md_ide->setEntry('il__'.$this->md->getObjType().'_'.$this->md->getObjId());
80  $this->md_ide->save();
81  $this->__pushParent($this->md_ide);
82  break;
83  }
84  return true;
85  }
86  function handlerEndTag($a_xml_parser,$a_name)
87  {
88  if($this->in_meta_data and !$this->__inFilter($a_name))
89  {
90  parent::handlerEndTag($a_xml_parser,$a_name);
91  return true;
92  }
93  switch($a_name)
94  {
95  case 'Identifier':
96  $par =& $this->__getParent();
97  $par->update();
98  $this->__popParent();
99  break;
100 
101 
102  case 'MetaData':
103  $this->in_meta_data = false;
104  parent::handlerEndTag($a_xml_parser,$a_name);
105  break;
106  }
107  return true;
108  }
109 
110  function handlerCharacterData($a_xml_parser,$a_data)
111  {
112  if($this->in_meta_data)
113  {
114  parent::handlerCharacterData($a_xml_parser,$a_data);
115  return true;
116  }
117  }
118  /*
119  * Set filter of tags which are handled in this class.
120  * @access protected
121  *
122  */
123  function __setFilter()
124  {
125  $this->filter[] = 'Identifier';
126  }
127  /*
128  * Check if tag is filtered
129  * @access protected
130  *
131  */
132  function __inFilter($a_tag_name)
133  {
134  return in_array($a_tag_name,$this->filter);
135  }
136 }
137 ?>