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
00031 #define ULXR_NEED_EXPORTS
00032 #include <ulxmlrpcpp/ulxmlrpcpp.h>
00033
00034 #include <ulxmlrpcpp/ulxr_expatwrap.h>
00035
00036
00037 namespace ulxr {
00038
00039
00040 ULXR_API_IMPL0 ExpatWrapper::ExpatWrapper(bool createParser)
00041 : XmlParserBase()
00042 {
00043 if (createParser)
00044 {
00045 expatParser = ::XML_ParserCreate(0);
00046 setHandler();
00047 }
00048 }
00049
00050
00051 ULXR_API_IMPL0 ExpatWrapper::~ExpatWrapper()
00052 {
00053 if (expatParser)
00054 ::XML_ParserFree(expatParser);
00055 }
00056
00057
00058 ULXR_API_IMPL(void) ExpatWrapper::setHandler()
00059 {
00060 ::XML_SetUserData(expatParser, this);
00061 ::XML_SetElementHandler(expatParser, startElementCallback, endElementCallback);
00062 ::XML_SetCharacterDataHandler(expatParser, charDataCallback);
00063 }
00064
00065
00066 ULXR_API_IMPL(void) ExpatWrapper::reset()
00067 {
00068 ::XML_ParserReset(expatParser, 0);
00069 setHandler();
00070 }
00071
00072
00073 ULXR_API_IMPL(void) ExpatWrapper::startElement(const XML_Char*, const XML_Char**)
00074 {
00075 }
00076
00077
00078 ULXR_API_IMPL(void) ExpatWrapper::endElement(const XML_Char*)
00079 {
00080 }
00081
00082
00083 ULXR_API_IMPL(void) ExpatWrapper::charData(const XML_Char*, int )
00084 {
00085 }
00086
00087
00088 ULXR_API_IMPL(int) ExpatWrapper::mapToFaultCode(int xpatcode) const
00089 {
00090 int fc = NotWellformedError;
00091
00092 switch (xpatcode)
00093 {
00094 case XML_ERROR_UNKNOWN_ENCODING:
00095 fc = UnsupportedEncodingError;
00096 break;
00097
00098 case XML_ERROR_BAD_CHAR_REF:
00099 case XML_ERROR_PARTIAL_CHAR:
00100 case XML_ERROR_INCORRECT_ENCODING:
00101 fc = InvalidCharacterError;
00102 break;
00103
00104 default:
00105 fc = NotWellformedError;
00106 }
00107 return fc;
00108 }
00109
00110
00111 ULXR_API_IMPL(void)
00112 ExpatWrapper::startElementCallback(void *userData,
00113 const XML_Char* name,
00114 const XML_Char** atts)
00115 {
00116 ((ExpatWrapper*)userData)->startElement(name, atts);
00117 }
00118
00119
00120 ULXR_API_IMPL(void)
00121 ExpatWrapper::endElementCallback(void *userData, const XML_Char* name)
00122 {
00123 ((ExpatWrapper*)userData)->endElement(name);
00124 }
00125
00126
00127 ULXR_API_IMPL(void)
00128 ExpatWrapper::charDataCallback(void *userData, const XML_Char* s, int len)
00129 {
00130 ((ExpatWrapper*)userData)->charData(s, len);
00131 }
00132
00133
00134 ULXR_API_IMPL(int) ExpatWrapper::parse(const char* buffer, int len, int isFinal)
00135 {
00136 return ::XML_Parse(expatParser, buffer, len, isFinal);
00137 }
00138
00139
00140 ULXR_API_IMPL(unsigned) ExpatWrapper::getErrorCode() const
00141 {
00142 return ::XML_GetErrorCode(expatParser);
00143 }
00144
00145
00146 ULXR_API_IMPL(CppString) ExpatWrapper::getErrorString(unsigned code) const
00147 {
00148 #ifdef ULXR_UNICODE
00149 return ULXR_GET_STRING(XML_ErrorString((XML_Error) code));
00150 #else
00151 return XML_ErrorString((XML_Error) code);
00152 #endif
00153 }
00154
00155
00156 ULXR_API_IMPL(int) ExpatWrapper::getCurrentLineNumber() const
00157 {
00158 return ::XML_GetCurrentLineNumber(expatParser);
00159 }
00160
00161
00162 }