00001 <?php
00002
00016
00017
00018
00019 import('xml.XMLParser');
00020 import('rt.RTStruct');
00021
00022 class RTXMLParser {
00023
00025 var $parser;
00026
00027
00031 function RTXMLParser() {
00032 $this->parser = &new XMLParser();
00033 }
00034
00040 function &parse($file) {
00041 $tree = $this->parser->parse($file);
00042 $version = false;
00043
00044 if ($tree !== false) {
00045 $version = &$this->parseVersion($tree);
00046 }
00047
00048 return $version;
00049 }
00050
00051
00057 function &parseAll($dir) {
00058 $versions = array();
00059
00060 if(($fd = opendir($dir)) !== false) {
00061 while (($file = readdir($fd)) !== false) {
00062 if (preg_match('/\.xml$/', $file)) {
00063 if (($version = $this->parse($dir . '/' . $file))) {
00064 array_push($versions, $version);
00065 }
00066 }
00067 }
00068 closedir($fd);
00069 }
00070
00071 return $versions;
00072 }
00073
00074
00075
00076
00077
00078
00079
00085 function &parseVersion(&$version) {
00086 $newVersion = &new RTVersion();
00087 $numContexts = 0;
00088
00089 $newVersion->key = $version->getAttribute('id');
00090 $newVersion->locale = $version->getAttribute('locale');
00091
00092 foreach ($version->getChildren() as $attrib) {
00093 switch ($attrib->getName()) {
00094 case 'version_title':
00095 $newVersion->title = $attrib->getValue();
00096 break;
00097 case 'version_description':
00098 $newVersion->description = $attrib->getValue();
00099 break;
00100 case 'context':
00101 $newContext = &$this->parseContext($attrib);
00102 $newContext->order = $numContexts++;
00103 $newVersion->addContext($newContext);
00104 break;
00105 }
00106 }
00107
00108 return $newVersion;
00109 }
00110
00116 function &parseContext(&$context) {
00117 $newContext = &new RTContext();
00118 $numSearches = 0;
00119
00120 foreach ($context->getChildren() as $attrib) {
00121 switch ($attrib->getName()) {
00122 case 'context_title':
00123 $newContext->title = $attrib->getValue();
00124 break;
00125 case 'context_abbrev':
00126 $newContext->abbrev = $attrib->getValue();
00127 break;
00128 case 'context_description':
00129 $newContext->description = $attrib->getValue();
00130 break;
00131 case 'cites_context':
00132 $newContext->citedBy = true;
00133 break;
00134 case 'author_terms':
00135 $newContext->authorTerms = true;
00136 break;
00137 case 'geo_terms':
00138 $newContext->geoTerms = true;
00139 break;
00140 case 'define_terms':
00141 $newContext->defineTerms = true;
00142 break;
00143 case 'search':
00144 $newSearch = &$this->parseSearch($attrib);
00145 $newSearch->order = $numSearches++;
00146 $newContext->addSearch($newSearch);
00147 break;
00148 }
00149 }
00150
00151 return $newContext;
00152 }
00153
00159 function &parseSearch(&$search) {
00160 $newSearch = &new RTSearch();
00161
00162 foreach ($search->getChildren() as $attrib) {
00163 switch ($attrib->getName()) {
00164 case 'search_title':
00165 $newSearch->title = $attrib->getValue();
00166 break;
00167 case 'search_description':
00168 $newSearch->description = $attrib->getValue();
00169 break;
00170 case 'url':
00171 $newSearch->url = $attrib->getValue();
00172 break;
00173 case 'search_url':
00174 $newSearch->searchUrl = $attrib->getValue();
00175 break;
00176 case 'search_post':
00177 $newSearch->searchPost = $attrib->getValue();
00178 break;
00179 }
00180 }
00181
00182 return $newSearch;
00183 }
00184
00185 }
00186
00187 ?>