a_alxparser.cc
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include <iostream>
00024 #include <fstream>
00025 #include <sstream>
00026
00027 #include "a_alxparser.h"
00028
00029
00030 namespace Barry {
00031
00032
00033 namespace ALX {
00034
00035
00036 ALXParser::ALXParser(OSLoader& osloader, std::istream& input)
00037 : XML::XMLParser(input, "ISO-8859-1")
00038 , osloader(osloader)
00039 {
00040 node = MAIN_NONE;
00041 subnode = SUB_NONE;
00042 m_register = true;
00043 }
00044
00045
00046 ALXParser::~ALXParser(void)
00047 {
00048 }
00049
00050
00051 bool ALXParser::Run(const bool enable)
00052 {
00053 m_register = enable;
00054
00055 return XMLParser::Run();
00056 }
00057
00058
00059 void ALXParser::on_start_document()
00060 {
00061
00062 }
00063
00064
00065 void ALXParser::on_end_document()
00066 {
00067
00068 }
00069
00070
00071 void ALXParser::on_start_element(const Glib::ustring& name,
00072 const xmlpp::SaxParser::AttributeList& attrs)
00073 {
00074 depth++;
00075
00076 buffdata = "";
00077
00078 switch (node) {
00079 case MAIN_NONE:
00080 if (name == "loader")
00081 node = IN_LOADER;
00082
00083
00084 break;
00085
00086 case IN_LOADER:
00087 subnode = SUB_NONE;
00088
00089 if (name == "system") {
00090 node = IN_SYSTEM;
00091 }
00092 else if (name == "application") {
00093 node = IN_APPLICATION;
00094
00095 m_codsection.reset( new Application(attrs) );
00096 }
00097 else if (name == "library") {
00098 node = IN_LIBRARY;
00099
00100 m_codsection.reset( new Library(attrs) );
00101 }
00102 break;
00103
00104 case IN_SYSTEM:
00105 if (name == "directory")
00106 subnode = IN_DIRECTORY;
00107 else if (name == "osfiles") {
00108 subnode = IN_OSFILES;
00109 }
00110 else if (name == "application") {
00111 node = IN_SYSTEM_APPLICATION;
00112 subnode = SUB_NONE;
00113
00114 m_codsection.reset( new Application(attrs) );
00115 }
00116 else if (name == "library") {
00117 node = IN_SYSTEM_LIBRARY;
00118 subnode = SUB_NONE;
00119
00120 m_codsection.reset( new Application(attrs) );
00121 }
00122 else if ((subnode == IN_OSFILES) && (name == "os"))
00123 osloader.AddProperties(attrs);
00124 break;
00125
00126 case IN_LIBRARY:
00127 case IN_APPLICATION:
00128 case IN_APPLICATION_APPLICATION:
00129 case IN_SYSTEM_APPLICATION:
00130 case IN_SYSTEM_LIBRARY:
00131 if (subnode == SUB_NONE) {
00132 if ((node == IN_APPLICATION) && (name == "application")) {
00133 node = IN_APPLICATION_APPLICATION;
00134
00135 m_savecodsection = m_codsection;
00136 m_codsection.reset( new Application(attrs) );
00137 }
00138 else if (name == "name")
00139 subnode = IN_NAME;
00140 else if (name == "description")
00141 subnode = IN_DESCRIPTION;
00142 else if (name == "version")
00143 subnode = IN_VERSION;
00144 else if (name == "vendor")
00145 subnode = IN_VENDOR;
00146 else if (name == "copyright")
00147 subnode = IN_COPYRIGHT;
00148 else if (name == "directory") {
00149 if (osloader.IsSupported(attrs))
00150 subnode = IN_DIRECTORY;
00151 }
00152 else if (name == "language") {
00153 if (osloader.IsSupported(attrs))
00154 subnode = IN_LANGUAGE_SUPPORTED;
00155 else
00156 subnode = IN_LANGUAGE;
00157 }
00158 else if (name == "required")
00159 subnode = IN_REQUIRED;
00160 else if (name == "fileset") {
00161 if (osloader.IsSupported(attrs))
00162 subnode = IN_FILESET;
00163 }
00164 }
00165 break;
00166
00167 default:
00168 break;
00169 }
00170 }
00171
00172
00173 void ALXParser::on_end_element(const Glib::ustring& name)
00174 {
00175 depth--;
00176
00177 switch (node) {
00178 case MAIN_NONE:
00179
00180 break;
00181
00182 case IN_LOADER:
00183 if (name == "loader")
00184 node = MAIN_NONE;
00185 break;
00186
00187 case IN_SYSTEM:
00188 if (name == "system") {
00189 subnode = SUB_NONE;
00190 node = IN_LOADER;
00191 }
00192
00193 switch (subnode) {
00194 case IN_DIRECTORY:
00195 if (name == "directory")
00196 subnode = SUB_NONE;
00197 break;
00198
00199 case IN_OSFILES:
00200 if (name == "osfiles")
00201 subnode = SUB_NONE;
00202 else if (name == "os")
00203 osloader.SetSFIFile(buffdata);
00204 break;
00205 default:
00206 break;
00207 }
00208 break;
00209
00210 case IN_LIBRARY:
00211 case IN_APPLICATION:
00212 case IN_APPLICATION_APPLICATION:
00213 case IN_SYSTEM_APPLICATION:
00214 case IN_SYSTEM_LIBRARY:
00215 if (name == "application") {
00216 if (m_register)
00217 osloader.AddApplication(m_codsection);
00218 subnode = SUB_NONE;
00219 if (node == IN_APPLICATION)
00220 node = IN_LOADER;
00221 else if (node == IN_SYSTEM_APPLICATION)
00222 node = IN_SYSTEM;
00223 else if (node == IN_APPLICATION_APPLICATION) {
00224 node = IN_APPLICATION;
00225 m_codsection = m_savecodsection;
00226 }
00227 }
00228 else if (name == "library") {
00229 if (m_register)
00230 osloader.AddLibrary(m_codsection);
00231 subnode = SUB_NONE;
00232 if (node == IN_LIBRARY)
00233 node = IN_LOADER;
00234 else if (node == IN_SYSTEM_LIBRARY)
00235 node = IN_SYSTEM;
00236 }
00237
00238 switch (subnode) {
00239 case IN_NAME:
00240 if (name == "name") {
00241 m_codsection->SetName(buffdata);
00242 subnode = SUB_NONE;
00243 }
00244 break;
00245 case IN_DESCRIPTION:
00246 if (name == "description") {
00247 m_codsection->SetDescription(buffdata);
00248 subnode = SUB_NONE;
00249 }
00250 break;
00251 case IN_VERSION:
00252 if (name == "version") {
00253 m_codsection->SetVersion(buffdata);
00254 subnode = SUB_NONE;
00255 }
00256 break;
00257 case IN_VENDOR:
00258 if (name == "vendor") {
00259 m_codsection->SetVendor(buffdata);
00260 subnode = SUB_NONE;
00261 }
00262 break;
00263 case IN_COPYRIGHT:
00264 if (name == "copyright") {
00265 m_codsection->SetCopyright(buffdata);
00266 subnode = SUB_NONE;
00267 }
00268 break;
00269 case IN_DIRECTORY:
00270 if (name == "directory") {
00271 m_codsection->SetDirectory(buffdata);
00272 subnode = SUB_NONE;
00273 }
00274 break;
00275 case IN_LANGUAGE:
00276 if (name == "language") {
00277 subnode = SUB_NONE;
00278 }
00279 break;
00280 case IN_LANGUAGE_SUPPORTED:
00281 if (name == "language") {
00282 subnode = SUB_NONE;
00283 }
00284 else if (name == "name") {
00285 m_codsection->SetName(buffdata);
00286 }
00287 break;
00288 case IN_REQUIRED:
00289 if (name == "required") {
00290 subnode = SUB_NONE;
00291 m_codsection->SetRequired(buffdata);
00292 }
00293 break;
00294 case IN_FILESET:
00295 if (name == "fileset") {
00296 subnode = SUB_NONE;
00297 }
00298 else if (name == "files") {
00299 m_codsection->AddFiles(buffdata);
00300 }
00301 break;
00302
00303 default:
00304 break;
00305 }
00306 break;
00307
00308 default:
00309 break;
00310 }
00311 }
00312
00313
00314 void ALXParser::on_characters(const Glib::ustring& data)
00315 {
00316 buffdata.append(data);
00317 }
00318
00319
00320 void ALXParser::on_comment(const Glib::ustring& text)
00321 {
00322
00323 }
00324
00325
00326 void ALXParser::on_warning(const Glib::ustring& text)
00327 {
00328
00329 }
00330
00331
00332 void ALXParser::on_error(const Glib::ustring& text)
00333 {
00334
00335 }
00336
00337
00338 void ALXParser::on_fatal_error(const Glib::ustring& text)
00339 {
00340 std::cout << "on_fatal_error(): " << text << std::endl;
00341 }
00342
00343
00344 }
00345
00346 }
00347