ulxr_wbxmlparse.h

Go to the documentation of this file.
00001 /***************************************************************************
00002                    ulxr_wbxmlparse.h  -  parse wbxml files
00003                              -------------------
00004     begin                : Fri Jan 09 2004
00005     copyright            : (C) 2002-2007 by Ewald Arnold
00006     email                : ulxmlrpcpp@ewald-arnold.de
00007 
00008     $Id: ulxr_wbxmlparse.h 940 2006-12-30 18:22:05Z ewald-arnold $
00009 
00010  ***************************************************************************/
00011 
00012 /**************************************************************************
00013  *
00014  * This program is free software; you can redistribute it and/or modify
00015  * it under the terms of the GNU Lesser General Public License as
00016  * published by the Free Software Foundation; either version 2 of the License,
00017  * or (at your option) any later version.
00018  *
00019  * This program is distributed in the hope that it will be useful,
00020  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00021  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00022  * GNU General Public License for more details.
00023  *
00024  * You should have received a copy of the GNU Lesser General Public License
00025  * along with this program; if not, write to the Free Software
00026  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00027  *
00028  ***************************************************************************/
00029 
00030 #ifndef ULXR_WBXMLPARSE
00031 #define ULXR_WBXMLPARSE
00032 
00033 #include <ulxmlrpcpp/ulxmlrpcpp.h>  // always first header
00034 
00035 #include <vector>
00036 
00037 #include <ulxmlrpcpp/ulxr_xmlparse_base.h>
00038 
00039 
00040 namespace ulxr {
00041 
00042 
00048 class ULXR_API_DECL0 WbXmlParser : public XmlParserBase
00049 {
00050  protected:
00051 
00055    virtual ~WbXmlParser();
00056 
00057  public:
00058 
00061    WbXmlParser();
00062 
00069     virtual int parse(const char* buffer, int len, int isFinal);
00070 
00074     virtual unsigned getErrorCode() const;
00075 
00080     virtual CppString getErrorString(unsigned code) const;
00081 
00087     virtual int getCurrentLineNumber() const;
00088 
00094     virtual int mapToFaultCode(int xpatcode) const;
00095 
00096     enum WbXmlToken
00097     {
00098       wbxml_SWITCH_PAGE  = 0x00,   
00099       wbxml_END          = 0x01,   
00100       wbxml_ENTITY       = 0x02,   
00101       wbxml_PI           = 0x43,   
00102       wbxml_OPAQUE       = 0xC3,   
00103 
00104       wbxml_LITERAL      = 0x04,   
00105       wbxml_LITERAL_C    = 0x44,   
00106       wbxml_LITERAL_A    = 0x84,   
00107       wbxml_LITERAL_AC   = 0xC4,   
00108 
00109       wbxml_EXT_I_0      = 0x40,   
00110       wbxml_EXT_I_1      = 0x41,   
00111       wbxml_EXT_I_2      = 0x42,   
00112 
00113       wbxml_EXT_T_0      = 0x80,   
00114       wbxml_EXT_T_1      = 0x81,   
00115       wbxml_EXT_T_2      = 0x82,   
00116 
00117       wbxml_EXT_0        = 0xC0,   
00118       wbxml_EXT_1        = 0xC1,   
00119       wbxml_EXT_2        = 0xC2,   
00120 
00121       wbxml_STR_I        = 0x03,   
00122       wbxml_STR_T        = 0x83,   
00123 
00124       wbxml_TAG_FIRST    = 0x05,   
00125       wbxml_TAG_LAST     = 0x3f,   
00126       wbxml_TAG_C_FIRST  = 0x45,   
00127       wbxml_TAG_C_LAST   = 0x7F,   
00128       wbxml_TAG_A_FIRST  = 0x85,   
00129       wbxml_TAG_A_LAST   = 0xBF,   
00130       wbxml_TAG_AC_FIRST = 0xC5,   
00131       wbxml_TAG_AC_LAST  = 0xFF    
00132     };
00133 
00134     static const char     wbxml_START_SEQ_STR[];
00135     static const unsigned wbxml_START_SEQ_LEN;
00136 
00137   protected:
00138 
00139     class Token;
00140     class Attribute;
00141 
00142     typedef std::vector<Attribute>  Attributes;
00143 
00150    bool testStartElement(unsigned token, const Attributes &attr);
00151 
00156    virtual void startElement(unsigned token, const Attributes &attr) =  0;
00157 
00161    bool testEndElement();
00162 
00165    virtual void endElement() = 0;
00166 
00170    virtual void charData(const std::string &s);
00171 
00172 private:
00173 
00174    void init();
00175 
00176    struct ULXR_API_DECL0 WbXmlState
00177    {
00178      WbXmlState(unsigned state);
00179 
00180      unsigned    state;
00181      std::string current_str;
00182    };
00183 
00184    std::stack<WbXmlState> wbxmlstates;
00185 
00186    unsigned    wb_version;
00187    unsigned    wb_pubId;
00188    unsigned    wb_charset;
00189 
00190    unsigned    lastErrorCode;
00191    unsigned    tag_count;
00192 };
00193 
00194 
00195 class ULXR_API_DECL0 WbXmlParser::Attribute
00196 {
00197   public:
00198 
00199     Attribute(const CppString &name, const CppString &value);
00200 
00201     CppString getName() const;
00202 
00203     CppString getValue() const;
00204 
00205   private:
00206 
00207     CppString attName;
00208     CppString attValue;
00209 };
00210 
00211 
00212 #define ULXR_MB_INT_14bit(x) (unsigned char) ((x >> 7) & 0x7F | 0x80) \
00213                              ,(unsigned char) (x & 0x7F)
00214 
00215 
00216 }  // namespace ulxr
00217 
00218 
00219 #endif // ULXR_WBXMLPARSE

Generated on Sun Aug 19 20:08:58 2007 for ulxmlrpcpp by  doxygen 1.5.1