remove old readme
[atutor.git] / docs / mods / _core / modules / classes / ModuleParser.class.php
1 <?php
2 /************************************************************************/
3 /* ATutor                                                                                                                               */
4 /************************************************************************/
5 /* Copyright (c) 2002-2010                                              */
6 /* Inclusive Design Institute                                           */
7 /* http://atutor.ca                                                     */
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 /************************************************************************/
12 // $Id$
13
14 /**
15 * ModuleParser
16 * Class for parsing XML module info and returning a Module Object
17 * @access       public
18 * @author       Joel Kronenberg
19 * @package      Module
20 */
21 class ModuleParser {
22
23         // all private
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)
28         var $row_num;
29         var $maintainer_num;
30
31         var $maintainers = array();
32         var $attributes;
33
34         function ModuleParser() {
35         }
36
37         // public
38         function parse($xml_data) {
39                 $this->element_path = array();
40                 $this->rows         = array();
41                 $this->character_data = '';
42                 $this->row_num        = 0;
43                 $this->maintainer_num = 0;
44
45                 $this->parser = xml_parser_create(''); 
46
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);
52         }
53
54         // public
55         function getModule($row_num) {
56                 return new Module($this->rows[$row_num]);
57         }
58
59         // public
60         function getNewModule($row_num) {
61                 //return new LanguageEditor($this->language_rows[$row_num]);
62         }
63
64         // private
65         function startElement($parser, $name, $attributes) {
66                 array_push($this->element_path, $name);
67
68                 $this->attributes = $attributes;
69    }
70
71         // private
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);
78                         } else {
79                                 $this->rows[$this->row_num]['name'][] = trim($this->character_data);
80                         }
81
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);
85                         } else {
86                                 $this->rows[$this->row_num]['description'][] = trim($this->character_data);
87                         }
88
89                 } else if ($this->element_path === array('module', 'url')) {
90                         $this->rows[$this->row_num]['url'] = trim($this->character_data);
91
92                 } else if ($this->element_path === array('module', 'license')) {
93                         $this->rows[$this->row_num]['license'] = trim($this->character_data);
94
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);
97
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);
100
101                         $this->maintainer_num++;
102
103                 } else if ($this->element_path === array('module', 'release', 'version')) {
104                         $this->rows[$this->row_num]['version'] = trim($this->character_data);
105
106                 } else if ($this->element_path === array('module', 'release', 'date')) {
107                         $this->rows[$this->row_num]['date'] = trim($this->character_data);
108
109                 } else if ($this->element_path === array('module', 'release', 'state')) {
110                         $this->rows[$this->row_num]['state'] = trim($this->character_data);
111
112                 } else if ($this->element_path === array('module', 'release', 'notes')) {
113                         $this->rows[$this->row_num]['notes'] = trim($this->character_data);
114
115                 } else if ($this->element_path === array('module')) {
116                         $this->row_num++;
117                 }
118                 array_pop($this->element_path);
119                 $this->character_data = '';
120         }
121
122         // private
123         function characterData($parser, $data){
124                 $this->character_data .= $data;
125         }
126
127 }
128
129
130 ?>