util/parser/XmlHandlerBase.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/I_Log.h>
00014 #include <util/Timestamp.h>
00015 #include <string>
00016 #include <map>
00017 #include <util/StringTrim.h>
00018 #include <util/thread/ThreadImpl.h>
00019 
00020 namespace org { namespace xmlBlaster { namespace util { namespace parser {
00021     
00022 typedef std::map<std::string, std::string> AttributeMap;
00023 
00028 class Dll_Export XmlHandlerBase {
00029 
00030 private:
00031    std::string ME; // SaxHandlerBase
00032 
00037    void parse(const std::string &xmlData);
00038 
00039 protected:
00040    std::string character_;
00041    std::string attributeCharacter_;
00042    bool inAttribute_; // Nested <attribute>WITH OWN VALUES (attributeCharacter_)</attribute>
00043    bool doTrimStrings_;
00044    org::xmlBlaster::util::StringTrim trimmer_;
00045    std::string locale_;
00046 
00047    std::string getStartElementAsString(const std::string &name, const AttributeMap &attrMap);
00048 
00053    std::string  xmlLiteral_;
00054    org::xmlBlaster::util::Global& global_;
00055    org::xmlBlaster::util::I_Log&    log_;
00056 
00057    org::xmlBlaster::util::thread::Mutex invocationMutex_;
00058 
00059 public:
00064    XmlHandlerBase(org::xmlBlaster::util::Global& global);
00065 
00066    virtual ~XmlHandlerBase() { };
00067 
00068    /*
00069     * This method parses the XML std::string using the SAX parser.
00070     * @param xmlLiteral The XML std::string
00071     */
00072    void init(const std::string &xmlLiteral);
00073 
00078    std::string getLocale();
00079 
00083    std::string toString() 
00084    {
00085       return xmlLiteral_;
00086    }
00087 
00091    std::string toXml() 
00092    {
00093       return xmlLiteral_;
00094    }
00095 
00097    virtual void startDocument();
00098 
00100    virtual void startElement(const std::string &name, const AttributeMap& attrs);
00101 
00109    virtual void characters(const std::string &ch);
00110 
00112    virtual void endElement(const std::string &name);
00113 
00115    virtual void endDocument();
00116 
00118    virtual void warning(const std::string &exTxt);
00119    
00121    virtual void error(const std::string &exTxt);
00122 
00124    virtual void fatalError(const std::string &exTxt);
00125 
00126    virtual void endCDATA();
00127    
00128    virtual void startCDATA();
00129    
00133    int getIntValue(const std::string &value) const;
00134 
00138    long getLongValue(const std::string &value) const;
00139 
00143    Timestamp getTimestampValue(const std::string &value) const;
00144 
00148    bool getBoolValue(const std::string &value) const;
00149 
00156    bool getStringAttr(const AttributeMap &attrs, const std::string &name, std::string& value, bool doTrim=true) const;
00157 
00164    bool getIntAttr(const AttributeMap &attrs, const std::string &name, int& value) const;
00165 
00172    bool getLongAttr(const AttributeMap &attrs, const std::string &name, long& value) const;
00173 
00180    bool getTimestampAttr(const AttributeMap &attrs, const std::string &name, Timestamp& value) const;
00181 
00188    bool getBoolAttr(const AttributeMap &attrs, const std::string &name, bool& value) const;
00189 
00190 };
00191 }}}} // namespace
00192 
00193 #endif