Reader.h
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 #ifndef BASE_READER_H
00024 #define BASE_READER_H
00025
00026
00027 #include <string>
00028 #include <map>
00029
00030 #include <xercesc/framework/XMLPScanToken.hpp>
00031 #include <xercesc/sax2/Attributes.hpp>
00032 #include <xercesc/sax2/DefaultHandler.hpp>
00033
00034 #include "FileInfo.h"
00035 #include "Writer.h"
00036
00037 namespace zipios {
00038 class ZipInputStream;
00039 }
00040
00041 XERCES_CPP_NAMESPACE_BEGIN
00042 class DefaultHandler;
00043 class SAX2XMLReader;
00044 XERCES_CPP_NAMESPACE_END
00045
00046 namespace Base
00047 {
00048
00049
00115 class BaseExport XMLReader : public XERCES_CPP_NAMESPACE_QUALIFIER DefaultHandler
00116 {
00117 public:
00119 XMLReader(const char* FileName, std::istream&);
00120 ~XMLReader();
00121
00122 bool isValid() const { return _valid; }
00123
00126
00127 const char* localName(void) const;
00129 void readElement (const char* ElementName=0);
00131 void readEndElement(const char* ElementName=0);
00133 void readCharacters(void);
00135
00138
00139 unsigned int getAttributeCount(void) const;
00141 bool hasAttribute(const char* AttrName) const;
00143 long getAttributeAsInteger(const char* AttrName) const;
00144 unsigned long getAttributeAsUnsigned(const char* AttrName) const;
00146 double getAttributeAsFloat(const char* AttrName) const;
00148 const char* getAttribute(const char* AttrName) const;
00150
00153
00154 const char *addFile(const char* Name, Base::Persistence *Object);
00156 void readFiles(zipios::ZipInputStream &zipstream) const;
00158 const std::vector<std::string>& getFilenames() const;
00159 bool isRegistered(Base::Persistence *Object) const;
00161
00163 int DocumentSchema;
00164
00165 protected:
00167 bool read(void);
00168
00169
00170
00171
00172 virtual void startElement(const XMLCh* const uri, const XMLCh* const localname, const XMLCh* const qname, const XERCES_CPP_NAMESPACE_QUALIFIER Attributes& attrs);
00173 virtual void endElement (const XMLCh* const uri, const XMLCh *const localname, const XMLCh *const qname);
00174 virtual void characters (const XMLCh* const chars, const unsigned int length);
00175 virtual void ignorableWhitespace(const XMLCh* const chars, const unsigned int length);
00176 virtual void resetDocument();
00177
00178
00179
00180
00181
00182 void warning(const XERCES_CPP_NAMESPACE_QUALIFIER SAXParseException& exc);
00183 void error(const XERCES_CPP_NAMESPACE_QUALIFIER SAXParseException& exc);
00184 void fatalError(const XERCES_CPP_NAMESPACE_QUALIFIER SAXParseException& exc);
00185 void resetErrors();
00186
00187
00188 int Level;
00189 std::string LocalName;
00190 std::string Characters;
00191 unsigned int CharacterCount;
00192
00193 std::map<std::string,std::string> AttrMap;
00194 typedef std::map<std::string,std::string> AttrMapType;
00195
00196 enum {
00197 None = 0,
00198 Chars,
00199 StartElement,
00200 StartEndElement,
00201 EndElement
00202 } ReadType;
00203
00204
00205 FileInfo _File;
00206 XERCES_CPP_NAMESPACE_QUALIFIER SAX2XMLReader* parser;
00207 XERCES_CPP_NAMESPACE_QUALIFIER XMLPScanToken token;
00208 bool _valid;
00209
00210 struct FileEntry {
00211 std::string FileName;
00212 Base::Persistence *Object;
00213 };
00214 std::vector<FileEntry> FileList;
00215 std::vector<std::string> FileNames;
00216 };
00217
00218 }
00219
00220
00221 #endif