util/I_XmlHandler.h

Go to the documentation of this file.
00001 /*-----------------------------------------------------------------------------
00002 Name:      XmlHandlerBase.h
00003 Project:   xmlBlaster.org
00004 Copyright: xmlBlaster.org, see xmlBlaster-LICENSE file
00005 Comment:   Default handling of Sax callbacks
00006 -----------------------------------------------------------------------------*/
00007 
00008 #ifndef _UTIL_XMLHANDLERBASE_H
00009 #define _UTIL_XMLHANDLERBASE_H
00010 
00011 #include <util/xmlBlasterDef.h>
00012 #include <util/XmlBlasterException.h>
00013 #include <util/Timestamp.h>
00014 #include <string>
00015 #include <map>
00016 
00017 namespace org { namespace xmlBlaster {
00018 namespace util {
00019     
00020 typedef std::map<std::string, std::string> Attributes;
00021 
00026 class Dll_Export XmlHandlerBase {
00027    
00028 public:
00029 
00030    /*
00031     * This method parses the XML std::string using the SAX parser.
00032     * @param xmlLiteral The XML std::string
00033     */
00034    virtual void init(const std::string &xmlLiteral) = 0;
00035 
00039    virtual std::string toString() = 0;
00040 
00044    virtual std::string toXml() = 0;
00045 
00047    virtual void startDocument() = 0;
00048 
00050    virtual void startElement(const std::string &name, Attributes& attrs) = 0;
00051 
00059    virtual void characters(const std::string &ch) = 0;
00060 
00062    virtual void ignorableWhitespace(const std::string &ch) = 0;
00063 
00065    void endElement(const std::string &name) = 0;
00066 
00068    virtual void endDocument() = 0;
00069 
00071    virtual void warning(const XmlBlasterException &ex) = 0;
00072    
00074    virtual void error(const XmlBlasterException &ex) = 0;
00075 
00077    virtual void fatalError(const XmlBlasterException &ex) = 0;
00078 
00079    void endCDATA() = 0;
00080    
00081    void startCDATA() = 0;
00082    
00086     int getIntValue(const std::string &value) const;
00087 
00091     long getLongValue(const std::string &value) const;
00092 
00096      Timestamp getTimestampValue(const std::string &value) const;
00097 
00101      bool getBoolValue(const std::string &value) const;
00102 
00109      bool getStringAttr(const Attributes &attrs, const std::string &name, std::string& value, bool doTrim=true) const;
00110 
00117      bool getIntAttr(const Attributes &attrs, const std::string &name, int& value) const;
00118 
00125      bool getLongAttr(const Attributes &attrs, const std::string &name, long& value) const;
00126 
00133      bool getTimestampAttr(const Attributes &attrs, const std::string &name, Timestamp& value) const;
00134 
00141      bool getBoolAttr(const Attributes &attrs, const std::string &name, bool& value) const;
00142 
00143    };
00144 }}} // namespace
00145 
00146 #endif