ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
_parse_lockinfo.php
Go to the documentation of this file.
1 <?php
2 //
3 // +----------------------------------------------------------------------+
4 // | PHP Version 4 |
5 // +----------------------------------------------------------------------+
6 // | Copyright (c) 1997-2003 The PHP Group |
7 // +----------------------------------------------------------------------+
8 // | This source file is subject to version 2.02 of the PHP license, |
9 // | that is bundled with this package in the file LICENSE, and is |
10 // | available at through the world-wide-web at |
11 // | http://www.php.net/license/2_02.txt. |
12 // | If you did not receive a copy of the PHP license and are unable to |
13 // | obtain it through the world-wide-web, please send a note to |
14 // | license@php.net so we can mail you a copy immediately. |
15 // +----------------------------------------------------------------------+
16 // | Authors: Hartmut Holzgraefe <hholzgra@php.net> |
17 // | Christian Stocker <chregu@bitflux.ch> |
18 // +----------------------------------------------------------------------+
19 //
20 // $Id: _parse_lockinfo.php,v 1.2 2004/01/05 12:32:40 hholzgra Exp $
21 //
22 
31 {
38  var $success = false;
39 
46  var $locktype = "";
47 
54  var $lockscope = "";
55 
62  var $owner = "";
63 
70  var $collect_owner = false;
71 
79  {
80  // we assume success unless problems occur
81  $this->success = true;
82 
83  // remember if any input was parsed
84  $had_input = false;
85 
86  // open stream
87  $f_in = fopen($path, "r");
88  if (!$f_in) {
89  $this->success = false;
90  return;
91  }
92 
93  // create namespace aware parser
94  $xml_parser = xml_parser_create_ns("UTF-8", " ");
95 
96  // set tag and data handlers
97  xml_set_element_handler($xml_parser,
98  array(&$this, "_startElement"),
99  array(&$this, "_endElement"));
100  xml_set_character_data_handler($xml_parser,
101  array(&$this, "_data"));
102 
103  // we want a case sensitive parser
104  xml_parser_set_option($xml_parser,
105  XML_OPTION_CASE_FOLDING, false);
106 
107  // parse input
108  while($this->success && !feof($f_in)) {
109  $line = fgets($f_in);
110  if (is_string($line)) {
111  $had_input = true;
112  $this->success &= xml_parse($xml_parser, $line, false);
113  }
114  }
115 
116  // finish parsing
117  if($had_input) {
118  $this->success &= xml_parse($xml_parser, "", true);
119  }
120 
121  // check if required tags where found
122  $this->success &= !empty($this->locktype);
123  $this->success &= !empty($this->lockscope);
124 
125  // free parser resource
126  xml_parser_free($xml_parser);
127 
128  // close input stream
129  fclose($f_in);
130  }
131 
132 
142  function _startElement($parser, $name, $attrs)
143  {
144  // namespace handling
145  if (strstr($name, " ")) {
146  list($ns, $tag) = explode(" ", $name);
147  } else {
148  $ns = "";
149  $tag = $name;
150  }
151 
152 
153  if ($this->collect_owner) {
154  // everything within the <owner> tag needs to be collected
155  $ns_short = "";
156  $ns_attr = "";
157  if ($ns) {
158  if ($ns == "DAV:") {
159  $ns_short = "D:";
160  } else {
161  $ns_attr = " xmlns='$ns'";
162  }
163  }
164  $this->owner .= "<$ns_short$tag$ns_attr>";
165  } else if ($ns == "DAV:") {
166  // parse only the essential tags
167  switch ($tag) {
168  case "write":
169  $this->locktype = $tag;
170  break;
171  case "exclusive":
172  case "shared":
173  $this->lockscope = $tag;
174  break;
175  case "owner":
176  $this->collect_owner = true;
177  break;
178  }
179  }
180  }
181 
190  function _data($parser, $data)
191  {
192  // only the <owner> tag has data content
193  if ($this->collect_owner) {
194  $this->owner .= $data;
195  }
196  }
197 
206  function _endElement($parser, $name)
207  {
208  // namespace handling
209  if (strstr($name, " ")) {
210  list($ns, $tag) = explode(" ", $name);
211  } else {
212  $ns = "";
213  $tag = $name;
214  }
215 
216  // <owner> finished?
217  if (($ns == "DAV:") && ($tag == "owner")) {
218  $this->collect_owner = false;
219  }
220 
221  // within <owner> we have to collect everything
222  if ($this->collect_owner) {
223  $ns_short = "";
224  $ns_attr = "";
225  if ($ns) {
226  if ($ns == "DAV:") {
227  $ns_short = "D:";
228  } else {
229  $ns_attr = " xmlns='$ns'";
230  }
231  }
232  $this->owner .= "</$ns_short$tag$ns_attr>";
233  }
234  }
235 }
236 
237 ?>