remove old readme
[atutor.git] / mods / _core / languages / classes / LanguageParser.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 * LanguageParser
16 * Class for parsing XML language info and returning a Language Object
17 * @access       public
18 * @author       Joel Kronenberg
19 * @package      Language
20 */
21 class LanguageParser {
22
23         // all private
24         var $parser; // the XML handler
25         var $language_rows = array(); // the language data used for creating the Language 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
30         function LanguageParser() {
31                 $this->parser = xml_parser_create(''); 
32
33                 xml_set_object($this->parser, $this);
34                 xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, false); /* conform to W3C specs */
35                 xml_set_element_handler($this->parser, 'startElement', 'endElement');
36                 xml_set_character_data_handler($this->parser, 'characterData');
37         }
38
39         // public
40         function parse($xml_data) {
41                 $this->element_path   = array();
42                 $this->language_rows  = array();
43                 $this->character_data = '';
44                 $this->row_num        = 0;
45                 xml_parse($this->parser, $xml_data, TRUE);
46         }
47
48         // public
49         function getLanguage($row_num) {
50                 return new Language($this->language_rows[$row_num]);
51         }
52
53         // public
54         function getLanguageEditor($row_num) {
55                 require_once(AT_INCLUDE_PATH.'../mods/_core/languages/classes/LanguageEditor.class.php');
56                 return new LanguageEditor($this->language_rows[$row_num]);
57         }
58
59         // private
60         function startElement($parser, $name, $attributes) {
61                 array_push($this->element_path, $name);
62
63                 if ($this->element_path == array('language')) {
64                         $this->language_rows[$this->row_num]['language_code'] = $attributes['code'];
65                 }
66    }
67
68         // private
69         /* called when an element ends */
70         /* removed the current element from the $path */
71         function endElement($parser, $name) {
72                 if ($this->element_path == array('language', 'atutor-version')) {
73                         $this->language_rows[$this->row_num]['version'] = trim($this->character_data);
74
75                 } else if ($this->element_path === array('language', 'charset')) {
76                         $this->language_rows[$this->row_num]['char_set'] = trim($this->character_data);
77
78                 } else if ($this->element_path === array('language', 'direction')) {
79                         $this->language_rows[$this->row_num]['direction'] = trim($this->character_data);
80
81                 } else if ($this->element_path === array('language', 'reg-exp')) {
82                         $this->language_rows[$this->row_num]['reg_exp'] = trim($this->character_data);
83
84                 } else if ($this->element_path === array('language', 'native-name')) {
85                         $this->language_rows[$this->row_num]['native_name'] = trim($this->character_data);
86
87                 } else if ($this->element_path === array('language', 'english-name')) {
88                         $this->language_rows[$this->row_num]['english_name'] = trim($this->character_data);
89
90                 } else if ($this->element_path === array('language', 'status')) {
91                         $this->language_rows[$this->row_num]['status'] = trim($this->character_data);
92
93                 } else if ($this->element_path === array('language')) {
94                         $this->row_num++;
95                 }
96
97                 array_pop($this->element_path);
98                 $this->character_data = '';
99         }
100
101         // private
102         function characterData($parser, $data){
103                 $this->character_data .= $data;
104         }
105
106         // public
107         function getNumLanguages() {
108                 return count($this->language_rows);
109         }
110 }
111
112
113
114 ?>