# a_alxparser.cc

Go to the documentation of this file.

    00001 ///
    00002 /// \file       a_alxparser.cc
    00003 ///             ALX file parser (for one file)
    00004 ///
    00005
    00006 /*
    00007     Copyright (C) 2010, Nicolas VIVIEN
    00008     Copyright (C) 2005-2011, Net Direct Inc. (http://www.netdirect.ca/)
    00009
    00010     This program is free software; you can redistribute it and/or modify
    00011     it under the terms of the GNU General Public License as published by
    00012     the Free Software Foundation; either version 2 of the License, or
    00013     (at your option) any later version.
    00014
    00015     This program is distributed in the hope that it will be useful,
    00016     but WITHOUT ANY WARRANTY; without even the implied warranty of
    00017     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    00018
    00019     See the GNU General Public License in the COPYING file at the
    00020     root directory of this project for more details.
    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 //      std::cout << "on_start_document()" << std::endl;
    00062 }
    00063
    00064
    00065 void ALXParser::on_end_document()
    00066 {
    00067 //      std::cout << "on_end_document()" << std::endl;
    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 //              else
    00083 //                      exit(-1);
    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 //              exit(-1);
    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 //      std::cout << "on_comment(): " << text << std::endl;
    00323 }
    00324
    00325
    00326 void ALXParser::on_warning(const Glib::ustring& text)
    00327 {
    00328 //      std::cout << "on_warning(): " << text << std::endl;
    00329 }
    00330
    00331
    00332 void ALXParser::on_error(const Glib::ustring& text)
    00333 {
    00334 //      std::cout << "on_error(): " << text << std::endl;
    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 } // namespace ALX
    00345
    00346 } // namespace Barry
    00347