2 /************************************************************************/
4 /************************************************************************/
5 /* Copyright (c) 2002-2010 */
6 /* Inclusive Design Institute */
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. */
11 /************************************************************************/
16 * Class for parsing XML module info and returning a Module Object
18 * @author Joel Kronenberg
24 var $parser; // the XML handler
25 var $rows = array(); // the module data used for creating the Module Object
26 var $character_data; // tmp variable for storing the data
27 var $element_path; // array of element paths (basically a stack)
31 var $maintainers = array();
34 function ModuleParser() {
38 function parse($xml_data) {
39 $this->element_path = array();
40 $this->rows = array();
41 $this->character_data = '';
43 $this->maintainer_num = 0;
45 $this->parser = xml_parser_create('');
47 xml_set_object($this->parser, $this);
48 xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, false); /* conform to W3C specs */
49 xml_set_element_handler($this->parser, 'startElement', 'endElement');
50 xml_set_character_data_handler($this->parser, 'characterData');
51 xml_parse($this->parser, $xml_data, TRUE);
55 function getModule($row_num) {
56 return new Module($this->rows[$row_num]);
60 function getNewModule($row_num) {
61 //return new LanguageEditor($this->language_rows[$row_num]);
65 function startElement($parser, $name, $attributes) {
66 array_push($this->element_path, $name);
68 $this->attributes = $attributes;
72 /* called when an element ends */
73 /* removed the current element from the $path */
74 function endElement($parser, $name) {
75 if ($this->element_path == array('module', 'name')) {
76 if (isset($this->attributes['lang'])) {
77 $this->rows[$this->row_num]['name'][$this->attributes['lang']] = trim($this->character_data);
79 $this->rows[$this->row_num]['name'][] = trim($this->character_data);
82 } else if ($this->element_path === array('module', 'description')) {
83 if (isset($this->attributes['lang'])) {
84 $this->rows[$this->row_num]['description'][$this->attributes['lang']] = trim($this->character_data);
86 $this->rows[$this->row_num]['description'][] = trim($this->character_data);
89 } else if ($this->element_path === array('module', 'url')) {
90 $this->rows[$this->row_num]['url'] = trim($this->character_data);
92 } else if ($this->element_path === array('module', 'license')) {
93 $this->rows[$this->row_num]['license'] = trim($this->character_data);
95 } else if ($this->element_path === array('module', 'maintainers', 'maintainer', 'name')) {
96 $this->rows[$this->row_num]['maintainers'][$this->maintainer_num]['name'] = trim($this->character_data);
98 } else if ($this->element_path === array('module', 'maintainers', 'maintainer', 'email')) {
99 $this->rows[$this->row_num]['maintainers'][$this->maintainer_num]['email'] = trim($this->character_data);
101 $this->maintainer_num++;
103 } else if ($this->element_path === array('module', 'release', 'version')) {
104 $this->rows[$this->row_num]['version'] = trim($this->character_data);
106 } else if ($this->element_path === array('module', 'release', 'date')) {
107 $this->rows[$this->row_num]['date'] = trim($this->character_data);
109 } else if ($this->element_path === array('module', 'release', 'state')) {
110 $this->rows[$this->row_num]['state'] = trim($this->character_data);
112 } else if ($this->element_path === array('module', 'release', 'notes')) {
113 $this->rows[$this->row_num]['notes'] = trim($this->character_data);
115 } else if ($this->element_path === array('module')) {
118 array_pop($this->element_path);
119 $this->character_data = '';
123 function characterData($parser, $data){
124 $this->character_data .= $data;