2 /// \file a_alxparser.cc
3 /// ALX file parser (for one file)
7 Copyright (C) 2010, Nicolas VIVIEN
8 Copyright (C) 2005-2010, Net Direct Inc. (http://www.netdirect.ca/)
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19 See the GNU General Public License in the COPYING file at the
20 root directory of this project for more details.
27 #include "a_alxparser.h"
36 ALXParser::ALXParser(OSLoader
& osloader
, std::istream
& input
)
37 : XML::XMLParser(input
, "ISO-8859-1")
46 ALXParser::~ALXParser(void)
51 bool ALXParser::Run(const bool enable
)
55 return XMLParser::Run();
59 void ALXParser::on_start_document()
61 // std::cout << "on_start_document()" << std::endl;
65 void ALXParser::on_end_document()
67 // std::cout << "on_end_document()" << std::endl;
71 void ALXParser::on_start_element(const Glib::ustring
& name
,
72 const xmlpp::SaxParser::AttributeList
& attrs
)
89 if (name
== "system") {
92 else if (name
== "application") {
93 node
= IN_APPLICATION
;
95 m_codsection
.reset( new Application(attrs
) );
97 else if (name
== "library") {
100 m_codsection
.reset( new Library(attrs
) );
105 if (name
== "directory")
106 subnode
= IN_DIRECTORY
;
107 else if (name
== "osfiles") {
108 subnode
= IN_OSFILES
;
110 else if (name
== "application") {
111 node
= IN_SYSTEM_APPLICATION
;
114 m_codsection
.reset( new Application(attrs
) );
116 else if (name
== "library") {
117 node
= IN_SYSTEM_LIBRARY
;
120 m_codsection
.reset( new Application(attrs
) );
122 else if ((subnode
== IN_OSFILES
) && (name
== "os"))
123 osloader
.AddProperties(attrs
);
128 case IN_APPLICATION_APPLICATION
:
129 case IN_SYSTEM_APPLICATION
:
130 case IN_SYSTEM_LIBRARY
:
131 if (subnode
== SUB_NONE
) {
132 if ((node
== IN_APPLICATION
) && (name
== "application")) {
133 node
= IN_APPLICATION_APPLICATION
;
135 m_savecodsection
= m_codsection
;
136 m_codsection
.reset( new Application(attrs
) );
138 else if (name
== "name")
140 else if (name
== "description")
141 subnode
= IN_DESCRIPTION
;
142 else if (name
== "version")
143 subnode
= IN_VERSION
;
144 else if (name
== "vendor")
146 else if (name
== "copyright")
147 subnode
= IN_COPYRIGHT
;
148 else if (name
== "directory") {
149 if (osloader
.IsSupported(attrs
))
150 subnode
= IN_DIRECTORY
;
152 else if (name
== "language") {
153 if (osloader
.IsSupported(attrs
))
154 subnode
= IN_LANGUAGE_SUPPORTED
;
156 subnode
= IN_LANGUAGE
;
158 else if (name
== "required")
159 subnode
= IN_REQUIRED
;
160 else if (name
== "fileset") {
161 if (osloader
.IsSupported(attrs
))
162 subnode
= IN_FILESET
;
173 void ALXParser::on_end_element(const Glib::ustring
& name
)
183 if (name
== "loader")
188 if (name
== "system") {
195 if (name
== "directory")
200 if (name
== "osfiles")
202 else if (name
== "os")
203 osloader
.SetSFIFile(buffdata
);
212 case IN_APPLICATION_APPLICATION
:
213 case IN_SYSTEM_APPLICATION
:
214 case IN_SYSTEM_LIBRARY
:
215 if (name
== "application") {
217 osloader
.AddApplication(m_codsection
);
219 if (node
== IN_APPLICATION
)
221 else if (node
== IN_SYSTEM_APPLICATION
)
223 else if (node
== IN_APPLICATION_APPLICATION
) {
224 node
= IN_APPLICATION
;
225 m_codsection
= m_savecodsection
;
228 else if (name
== "library") {
230 osloader
.AddLibrary(m_codsection
);
232 if (node
== IN_LIBRARY
)
234 else if (node
== IN_SYSTEM_LIBRARY
)
240 if (name
== "name") {
241 m_codsection
->SetName(buffdata
);
246 if (name
== "description") {
247 m_codsection
->SetDescription(buffdata
);
252 if (name
== "version") {
253 m_codsection
->SetVersion(buffdata
);
258 if (name
== "vendor") {
259 m_codsection
->SetVendor(buffdata
);
264 if (name
== "copyright") {
265 m_codsection
->SetCopyright(buffdata
);
270 if (name
== "directory") {
271 m_codsection
->SetDirectory(buffdata
);
276 if (name
== "language") {
280 case IN_LANGUAGE_SUPPORTED
:
281 if (name
== "language") {
284 else if (name
== "name") {
285 m_codsection
->SetName(buffdata
);
289 if (name
== "required") {
291 m_codsection
->SetRequired(buffdata
);
295 if (name
== "fileset") {
298 else if (name
== "files") {
299 m_codsection
->AddFiles(buffdata
);
314 void ALXParser::on_characters(const Glib::ustring
& data
)
316 buffdata
.append(data
);
320 void ALXParser::on_comment(const Glib::ustring
& text
)
322 // std::cout << "on_comment(): " << text << std::endl;
326 void ALXParser::on_warning(const Glib::ustring
& text
)
328 // std::cout << "on_warning(): " << text << std::endl;
332 void ALXParser::on_error(const Glib::ustring
& text
)
334 // std::cout << "on_error(): " << text << std::endl;
338 void ALXParser::on_fatal_error(const Glib::ustring
& text
)
340 std::cout
<< "on_fatal_error(): " << text
<< std::endl
;