Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/lib/pear/HTTP/WebDAV/Tools/_parse_propfind.php
Go to the documentation of this file.
00001 <?php // $Id: _parse_propfind.php,v 1.2 2010/12/14 17:36:02 moodlerobot Exp $
00002 /*
00003    +----------------------------------------------------------------------+
00004    | Copyright (c) 2002-2007 Christian Stocker, Hartmut Holzgraefe        |
00005    | All rights reserved                                                  |
00006    |                                                                      |
00007    | Redistribution and use in source and binary forms, with or without   |
00008    | modification, are permitted provided that the following conditions   |
00009    | are met:                                                             |
00010    |                                                                      |
00011    | 1. Redistributions of source code must retain the above copyright    |
00012    |    notice, this list of conditions and the following disclaimer.     |
00013    | 2. Redistributions in binary form must reproduce the above copyright |
00014    |    notice, this list of conditions and the following disclaimer in   |
00015    |    the documentation and/or other materials provided with the        |
00016    |    distribution.                                                     |
00017    | 3. The names of the authors may not be used to endorse or promote    |
00018    |    products derived from this software without specific prior        |
00019    |    written permission.                                               |
00020    |                                                                      |
00021    | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS  |
00022    | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT    |
00023    | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS    |
00024    | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE       |
00025    | COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,  |
00026    | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
00027    | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;     |
00028    | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER     |
00029    | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT   |
00030    | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN    |
00031    | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE      |
00032    | POSSIBILITY OF SUCH DAMAGE.                                          |
00033    +----------------------------------------------------------------------+
00034 */
00035 
00043 class _parse_propfind 
00044 {
00051     var $success = false;
00052 
00059     var $props = false;
00060 
00067     var $depth = 0;
00068 
00069     
00075     function _parse_propfind($path) 
00076     {
00077         // success state flag
00078         $this->success = true;
00079         
00080         // property storage array
00081         $this->props = array();
00082 
00083         // internal tag depth counter
00084         $this->depth = 0;
00085 
00086         // remember if any input was parsed
00087         $had_input = false;
00088 
00089         // open input stream
00090         $f_in = fopen($path, "r");
00091         if (!$f_in) {
00092             $this->success = false;
00093             return;
00094         }
00095 
00096         // create XML parser
00097         $xml_parser = xml_parser_create_ns("UTF-8", " ");
00098 
00099         // set tag and data handlers
00100         xml_set_element_handler($xml_parser,
00101                                 array(&$this, "_startElement"),
00102                                 array(&$this, "_endElement"));
00103 
00104         // we want a case sensitive parser
00105         xml_parser_set_option($xml_parser, 
00106                               XML_OPTION_CASE_FOLDING, false);
00107 
00108 
00109         // parse input
00110         while ($this->success && !feof($f_in)) {
00111             $line = fgets($f_in);
00112             if (is_string($line)) {
00113                 $had_input = true;
00114                 $this->success &= xml_parse($xml_parser, $line, false);
00115             }
00116         } 
00117         
00118         // finish parsing
00119         if ($had_input) {
00120             $this->success &= xml_parse($xml_parser, "", true);
00121         }
00122 
00123         // free parser
00124         xml_parser_free($xml_parser);
00125         
00126         // close input stream
00127         fclose($f_in);
00128 
00129         // if no input was parsed it was a request
00130         if(!count($this->props)) $this->props = "all"; // default
00131     }
00132     
00133 
00142     function _startElement($parser, $name, $attrs) 
00143     {
00144         // name space handling
00145         if (strstr($name, " ")) {
00146             list($ns, $tag) = explode(" ", $name);
00147             if ($ns == "")
00148                 $this->success = false;
00149         } else {
00150             $ns  = "";
00151             $tag = $name;
00152         }
00153 
00154         // special tags at level 1: <allprop> and <propname>
00155         if ($this->depth == 1) {
00156             if ($tag == "allprop")
00157                 $this->props = "all";
00158 
00159             if ($tag == "propname")
00160                 $this->props = "names";
00161         }
00162 
00163         // requested properties are found at level 2
00164         if ($this->depth == 2) {
00165             $prop = array("name" => $tag);
00166             if ($ns)
00167                 $prop["xmlns"] = $ns;
00168             $this->props[] = $prop;
00169         }
00170 
00171         // increment depth count
00172         $this->depth++;
00173     }
00174     
00175 
00183     function _endElement($parser, $name) 
00184     {
00185         // here we only need to decrement the depth count
00186         $this->depth--;
00187     }
00188 }
00189 
00190 
00191 ?>
 All Data Structures Namespaces Files Functions Variables Enumerations