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 language info and returning a Language Object
18 * @author Joel Kronenberg
21 class LanguageParser {
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)
30 function LanguageParser() {
31 $this->parser = xml_parser_create('');
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');
40 function parse($xml_data) {
41 $this->element_path = array();
42 $this->language_rows = array();
43 $this->character_data = '';
45 xml_parse($this->parser, $xml_data, TRUE);
49 function getLanguage($row_num) {
50 return new Language($this->language_rows[$row_num]);
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]);
60 function startElement($parser, $name, $attributes) {
61 array_push($this->element_path, $name);
63 if ($this->element_path == array('language')) {
64 $this->language_rows[$this->row_num]['language_code'] = $attributes['code'];
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);
75 } else if ($this->element_path === array('language', 'charset')) {
76 $this->language_rows[$this->row_num]['char_set'] = trim($this->character_data);
78 } else if ($this->element_path === array('language', 'direction')) {
79 $this->language_rows[$this->row_num]['direction'] = trim($this->character_data);
81 } else if ($this->element_path === array('language', 'reg-exp')) {
82 $this->language_rows[$this->row_num]['reg_exp'] = trim($this->character_data);
84 } else if ($this->element_path === array('language', 'native-name')) {
85 $this->language_rows[$this->row_num]['native_name'] = trim($this->character_data);
87 } else if ($this->element_path === array('language', 'english-name')) {
88 $this->language_rows[$this->row_num]['english_name'] = trim($this->character_data);
90 } else if ($this->element_path === array('language', 'status')) {
91 $this->language_rows[$this->row_num]['status'] = trim($this->character_data);
93 } else if ($this->element_path === array('language')) {
97 array_pop($this->element_path);
98 $this->character_data = '';
102 function characterData($parser, $data){
103 $this->character_data .= $data;
107 function getNumLanguages() {
108 return count($this->language_rows);