ulxr_expatwrap.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002                    ulxr_expatwrap.h  -  c++ wrapper for expat
00003                              -------------------
00004     begin                : Thu Apr 30 2002
00005     copyright            : (C) 2002-2007 by Ewald Arnold
00006     email                : ulxmlrpcpp@ewald-arnold.de
00007 
00008     $Id: ulxr_expatwrap.cpp 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 
00031 #define ULXR_NEED_EXPORTS
00032 #include <ulxmlrpcpp/ulxmlrpcpp.h>  // always first header
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)  // allows subclasses to avoid finishing parsing
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    // try to map error codes
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: // fallthrough
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 }  // namespace ulxr

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