00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #ifndef ULXR_WBXMLPARSE
00031 #define ULXR_WBXMLPARSE
00032
00033 #include <ulxmlrpcpp/ulxmlrpcpp.h>
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 }
00217
00218
00219 #endif // ULXR_WBXMLPARSE