2 /************************************************************************/
4 /************************************************************************/
5 /* Copyright (c) 2002-2010 */
6 /* Inclusive Design Institute */
9 /* This program is free software. You can redistribute it and/or */
10 /* modify it under the terms of the GNU General Public License */
11 /* as published by the Free Software Foundation. */
12 /************************************************************************/
17 * Class for parsing XML patch list info
22 class PatchListParser {
25 var $parser; // the XML handler
26 var $patch_rows = array(); // the patch data
27 var $character_data; // tmp variable for storing the data
28 var $element_path; // array of element paths (basically a stack)
30 var $dependent_patches_num;
32 function PatchListParser() {
33 $this->parser = xml_parser_create('');
35 xml_set_object($this->parser, $this);
36 xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, false); /* conform to W3C specs */
37 xml_set_element_handler($this->parser, 'startElement', 'endElement');
38 xml_set_character_data_handler($this->parser, 'characterData');
42 function parse($xml_data) {
43 $this->element_path = array();
44 $this->patch_rows = array();
45 $this->character_data = '';
47 xml_parse($this->parser, $xml_data, TRUE);
51 function startElement($parser, $name, $attributes)
53 array_push($this->element_path, $name);
57 /* called when an element ends */
58 /* removed the current element from the $path */
59 function endElement($parser, $name) {
60 if ($this->element_path == array('patch_list', 'patch', 'atutor_patch_id'))
62 $this->patch_rows[$this->row_num]['atutor_patch_id'] = trim($this->character_data);
64 else if ($this->element_path === array('patch_list', 'patch', 'applied_version'))
66 $this->patch_rows[$this->row_num]['applied_version'] = trim($this->character_data);
68 else if ($this->element_path === array('patch_list', 'patch', 'patch_folder'))
70 $this->patch_rows[$this->row_num]['patch_folder'] = trim($this->character_data);
72 else if ($this->element_path === array('patch_list', 'patch', 'description'))
74 $this->patch_rows[$this->row_num]['description'] = trim($this->character_data);
76 else if ($this->element_path === array('patch_list', 'patch', 'available_to'))
78 $this->patch_rows[$this->row_num]['available_to'] = trim($this->character_data);
80 else if ($this->element_path === array('patch_list', 'patch', 'author'))
82 $this->patch_rows[$this->row_num]['author'] = trim($this->character_data);
84 else if ($this->element_path === array('patch_list', 'patch', 'dependent_patches', 'dependent_patch'))
86 $this->patch_rows[$this->row_num]['dependent_patches'][$this->dependent_patches_num++] = trim($this->character_data);
88 else if ($this->element_path === array('patch_list', 'patch'))
91 $this->dependent_patches_num = 0;
94 array_pop($this->element_path);
95 $this->character_data = '';
99 function characterData($parser, $data){
100 $this->character_data .= $data;
104 function getNumPathes()
106 return count($this->patch_rows);
110 function getParsedArray()
112 return $this->patch_rows;
116 // return parsed array only for given name & version
117 function getMyParsedArrayForVersion($version, $who='public')
121 // filter out the patch for given version
122 foreach ($this->patch_rows as $key => $row)
124 if ($row['applied_version'] == $version && $row['available_to']==$who)
125 array_push($my_array, $row);