00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00030 #ifndef S3_XML_CONFIG_H
00031 #define S3_XML_CONFIG_H
00032
00033 #define XERCES_2 (1)
00034
00035 #ifdef XERCES_2
00036 #include <xercesc/util/PlatformUtils.hpp>
00037 #include <xercesc/dom/deprecated/DOM.hpp>
00038 #include <xercesc/dom/deprecated/DOMParser.hpp>
00039 #include <xercesc/sax2/DefaultHandler.hpp>
00040 #else
00041 #include <util/PlatformUtils.hpp>
00042 #include <dom/DOM.hpp>
00043 #include <parsers/DOMParser.hpp>
00044 #include <sax2/DefaultHandler.hpp>
00045 #endif
00046 #include <string>
00047 #include <stdlib.h>
00048 #include <iostream>
00049 #include <list>
00050
00051 #include <s3fc/s3_config_base.h>
00052 #include <s3fc/s3_config_node.h>
00053 #include <s3fc/s3_exception.h>
00054
00058 class s3_xml_exception : public s3_exception
00059 {
00060 public:
00064 s3_xml_exception(const std::string& errstr);
00065 };
00066
00070 class s3_xml_config : s3_config_base
00071 {
00072 protected:
00076 std::string config_file;
00081 DOM_Document doc;
00085 s3_config_node* rootnode;
00086
00087 public:
00095 s3_xml_config(const std::string& n_config_file, bool create_file = false) throw (s3_generic_exception);
00099 ~s3_xml_config();
00103 s3_config_node& get_rootnode() const;
00110 void refresh();
00115 void set_config_file(const std::string& n_config_file);
00120 static void write_node(const std::string& filename,
00121 const s3_config_node& node);
00130 static void write_node(std::ostream& os,
00131 const s3_config_node& node,
00132 unsigned int depth = 0);
00133
00134 static void write_spaces(std::ostream& os,
00135 unsigned int n);
00136 protected:
00141 static DOM_Document parse(const std::string& filename)
00142 throw (s3_generic_exception, s3_xml_exception);
00147 static s3_config_node* build_tree(const DOM_Node& doc);
00153 static std::string get_name(const DOM_Node& node);
00161 static std::string get_value(const DOM_Node& node);
00167 static std::map<std::string,std::string> get_attributes(const DOM_Node& node);
00173 static std::vector<s3_config_node*> get_children(const DOM_Node& node);
00179 static std::string domstr_to_string(const DOMString& dstr);
00180
00184 void dump_DOM_tree(const DOM_Node& domdoc) const;
00185
00191 class error_handler : public ErrorHandler
00192 {
00193 public:
00197 virtual void warning(const SAXParseException& e);
00201 virtual void error(const SAXParseException& e);
00205 virtual void fatalError(const SAXParseException& e);
00209 virtual void resetErrors();
00210 protected:
00218 void assemble_and_throw(const SAXParseException& e,
00219 const std::string& type);
00220 };
00221 friend class error_handler;
00222 };
00223
00224
00225
00229 std::ostream& operator<<(std::ostream& str, const DOMString& s);
00230
00231 #endif