2 /************************************************************************/
4 /************************************************************************/
5 /* Copyright (c) 2002-2004 by Greg Gay, Joel Kronenberg & Heidi Hazelton*/
6 /* Adaptive Technology Resource Centre / University of Toronto */
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 module info and returning a Module Object
19 * @author Joel Kronenberg
25 var $parser; // the XML handler
26 var $rows = array(); // the module data used for creating the Module Object
27 var $character_data; // tmp variable for storing the data
28 var $element_path; // array of element paths (basically a stack)
32 var $maintainers = array();
35 function ModuleParser() {
39 function parse($xml_data) {
40 $this->element_path = array();
41 $this->rows = array();
42 $this->character_data = '';
44 $this->maintainer_num = 0;
46 $this->parser = xml_parser_create('');
48 xml_set_object($this->parser, $this);
49 xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, false); /* conform to W3C specs */
50 xml_set_element_handler($this->parser, 'startElement', 'endElement');
51 xml_set_character_data_handler($this->parser, 'characterData');
52 xml_parse($this->parser, $xml_data, TRUE);
56 function getModule($row_num) {
57 return new Module($this->rows[$row_num]);
61 function getNewModule($row_num) {
62 //return new LanguageEditor($this->language_rows[$row_num]);
66 function startElement($parser, $name, $attributes) {
67 array_push($this->element_path, $name);
69 $this->attributes = $attributes;
73 /* called when an element ends */
74 /* removed the current element from the $path */
75 function endElement($parser, $name) {
76 if ($this->element_path == array('module', 'name')) {
77 if (isset($this->attributes['lang'])) {
78 $this->rows[$this->row_num]['name'][$this->attributes['lang']] = trim($this->character_data);
80 $this->rows[$this->row_num]['name'][] = trim($this->character_data);
83 } else if ($this->element_path === array('module', 'description')) {
84 if (isset($this->attributes['lang'])) {
85 $this->rows[$this->row_num]['description'][$this->attributes['lang']] = trim($this->character_data);
87 $this->rows[$this->row_num]['description'][] = trim($this->character_data);
90 } else if ($this->element_path === array('module', 'url')) {
91 $this->rows[$this->row_num]['url'] = trim($this->character_data);
93 } else if ($this->element_path === array('module', 'license')) {
94 $this->rows[$this->row_num]['license'] = trim($this->character_data);
96 } else if ($this->element_path === array('module', 'maintainers', 'maintainer', 'name')) {
97 $this->rows[$this->row_num]['maintainers'][$this->maintainer_num]['name'] = trim($this->character_data);
99 } else if ($this->element_path === array('module', 'maintainers', 'maintainer', 'email')) {
100 $this->rows[$this->row_num]['maintainers'][$this->maintainer_num]['email'] = trim($this->character_data);
102 $this->maintainer_num++;
104 } else if ($this->element_path === array('module', 'release', 'version')) {
105 $this->rows[$this->row_num]['version'] = trim($this->character_data);
107 } else if ($this->element_path === array('module', 'release', 'date')) {
108 $this->rows[$this->row_num]['date'] = trim($this->character_data);
110 } else if ($this->element_path === array('module', 'release', 'state')) {
111 $this->rows[$this->row_num]['state'] = trim($this->character_data);
113 } else if ($this->element_path === array('module', 'release', 'notes')) {
114 $this->rows[$this->row_num]['notes'] = trim($this->character_data);
116 } else if ($this->element_path === array('module')) {
119 array_pop($this->element_path);
120 $this->character_data = '';
124 function characterData($parser, $data){
125 $this->character_data .= $data;