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 #ifndef __RTSAXCPPPARSER_H_
00026 #define __RTSAXCPPPARSER_H_
00027
00028 #include <string.h>
00029 #include "rtxsrc/rtxErrCodes.h"
00030 #include "rtxsrc/OSRTContext.h"
00031 #include "rtxmlsrc/rtSaxCppParserIF.h"
00032 #include "rtxmlsrc/osrtxml.h"
00033 #include "rtxmlsrc/rtSaxDefs.h"
00034
00035 class EXTXMLCLASS OSXMLBasePtr {
00036 OSXMLBase* mPtr;
00037 public:
00038 OSXMLBasePtr ():mPtr (0) {}
00039 OSXMLBasePtr (OSXMLBase* ptr):mPtr (ptr) {}
00040 ~OSXMLBasePtr () { if (mPtr) mPtr->release (); }
00041
00042 operator OSXMLBase* () const { return mPtr; }
00043
00044 OSXMLBase* operator= (OSXMLBase* ptr) {
00045 if (mPtr) mPtr->release ();
00046 mPtr = ptr;
00047 return mPtr;
00048 }
00049 };
00050
00058 class EXTERNXML OSXMLDefaultHandler : public OSXMLDefaultHandlerIF
00059 {
00060 protected:
00061 OSRTCtxtPtr mpContext;
00062 const OSUTF8CHAR* mpElemName;
00063 OSINT32 mLevel;
00064 OSINT16 mStartLevel;
00065 OSINT16 mReqElemCnt;
00066 OSINT16 mCurrElemIdx;
00067 OSINT16 mState;
00068
00069 struct EXTXMLCLASS ErrorInfo {
00070 int stat;
00071 const char* file;
00072 int line;
00073
00074 inline ErrorInfo ():stat (0),file (0), line (0) {}
00075 } errorInfo;
00076
00077 public:
00078 OSXMLDefaultHandler (OSRTContext* pContext,
00079 const OSUTF8CHAR* elemName = 0, OSINT32 level = 0) :
00080 mpContext (pContext),
00081 mpElemName(elemName), mLevel(level),
00082 mStartLevel (0), mReqElemCnt (0), mCurrElemIdx(0), mState (0)
00083 { }
00084
00085 virtual ~OSXMLDefaultHandler () {}
00086
00087 EXTXMLMETHOD virtual int startElement
00088 (const OSUTF8CHAR* const uri,
00089 const OSUTF8CHAR* const localname,
00090 const OSUTF8CHAR* const qname,
00091 const OSUTF8CHAR* const* attrs);
00092
00093 EXTXMLMETHOD virtual int characters
00094 (const OSUTF8CHAR* const chars, unsigned int length);
00095
00096 EXTXMLMETHOD virtual int endElement
00097 (const OSUTF8CHAR* const uri,
00098 const OSUTF8CHAR* const localname,
00099 const OSUTF8CHAR* const qname);
00100
00101 EXTXMLMETHOD virtual void startDocument();
00102 EXTXMLMETHOD virtual void endDocument ();
00103
00104 EXTXMLMETHOD virtual int finalize ();
00105
00106
00107 EXTXMLMETHOD virtual void resetErrorInfo ();
00108 EXTXMLMETHOD virtual void setErrorInfo (int status, const char* file = 0, int line = 0);
00109 EXTXMLMETHOD virtual int getErrorInfo (int* status, const char** file, int* line);
00110
00111
00112
00113
00114
00115
00116
00117
00124 inline OSINT16 getState() { return mState; }
00125
00126 virtual void init (int level = 0) {
00127 mState = 0; mLevel = (OSINT16)level;
00128 }
00129
00130 void setElemName (const OSUTF8CHAR* elemName) {
00131 mpElemName = elemName;
00132 }
00133
00134 inline OSBOOL isComplete () { return (mLevel <= mStartLevel); }
00135
00136 #ifndef _COMPACT
00137 EXTXMLMETHOD void traceStartElement (const char* funcName, const OSUTF8CHAR* localName);
00138 EXTXMLMETHOD void traceEndElement (const char* funcName, const OSUTF8CHAR* localName);
00139 #else
00140 inline void traceStartElement
00141 (const char* funcName, const OSUTF8CHAR* localName) {}
00142 inline void traceEndElement
00143 (const char* funcName, const OSUTF8CHAR* localName) {}
00144 #endif
00145 } ;
00146
00147 class EXTXMLCLASS OSXMLDefaultHandlerPtr {
00148 OSXMLDefaultHandler* mPtr;
00149 public:
00150 inline OSXMLDefaultHandlerPtr ():mPtr (0) {}
00151 inline OSXMLDefaultHandlerPtr (OSXMLDefaultHandler* ptr):mPtr (ptr) {}
00152 inline ~OSXMLDefaultHandlerPtr () { delete mPtr; }
00153
00154 inline operator OSXMLDefaultHandler* () { return mPtr; }
00155 inline operator const OSXMLDefaultHandler* () const { return mPtr; }
00156 inline OSXMLDefaultHandler* operator-> () const { return mPtr; }
00157
00158 inline OSXMLDefaultHandler* operator= (OSXMLDefaultHandler* ptr) {
00159 delete mPtr;
00160 mPtr = ptr;
00161 return mPtr;
00162 }
00163 inline int operator == (const OSXMLDefaultHandler* ptr) const
00164 { return ptr == mPtr; }
00165 inline int operator != (const OSXMLDefaultHandler* ptr) const
00166 { return ptr != mPtr; }
00167 inline int operator ! () const { return mPtr == 0; }
00168
00169 friend int operator != (const void* ptr, const OSXMLDefaultHandlerPtr& ptr2);
00170 friend int operator == (const void* ptr, const OSXMLDefaultHandlerPtr& ptr2);
00171 } ;
00172
00173 inline int operator != (const void* ptr, const OSXMLDefaultHandlerPtr& ptr2)
00174 { return ptr != (const void*)ptr2.mPtr; }
00175
00176 inline int operator == (const void* ptr, const OSXMLDefaultHandlerPtr& ptr2)
00177 { return ptr == (const void*)ptr2.mPtr; }
00178
00179 class EXTXMLCLASS OSXMLParserCtxt : public OSXMLParserCtxtIF {
00180 OSRTCtxtPtr mpContext;
00181
00182 public:
00183 OSXMLParserCtxt (OSRTContext *pContext);
00184
00185 EXTXMLMETHOD virtual OSRTInputStreamIF* createInputStream ();
00186 EXTXMLMETHOD virtual OSRTInputStreamIF* createFileInputStream
00187 (const char* const filename);
00188 EXTXMLMETHOD virtual OSRTInputStreamIF* createMemoryInputStream
00189 (OSOCTET* pMemBuf, size_t bufSize);
00190 EXTXMLMETHOD virtual OSCTXT* getContext ();
00191 EXTXMLMETHOD virtual const OSUTF8CHAR* parseQName (const OSUTF8CHAR* const qname);
00192 } ;
00193
00194 #ifndef _COMPACT
00195 #define OSCPPSAXDIAGSTART(funcName,localName) \
00196 traceStartElement (funcName, localName)
00197
00198 #define OSCPPSAXDIAGEND(funcName,localName) \
00199 traceEndElement (funcName, localName)
00200
00201 #else
00202 #define OSCPPSAXDIAGSTART(funcName,localName)
00203 #define OSCPPSAXDIAGEND(funcName,localName)
00204 #endif
00205
00206 #endif
00207