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 __SAXPARSER_H_
00026 #define __SAXPARSER_H_
00027
00028 #include <string.h>
00029 #ifndef _NO_EXCEPTIONS
00030
00031 #if (defined(_HP_UX) || defined(__hpux) || defined(_HPUX_SOURCE)) && \
00032 __cplusplus >= 199707L && defined (__HP_aCC) && __HP_aCC >= 55000L
00033
00034
00035 #define __NEW_STREAM_HEADERS__ 1
00036 #endif
00037
00038 #if defined (__NEW_STREAM_HEADERS__) || defined (_MSC_VER) || \
00039 (defined (__GNUC__) && __GNUC__ >= 3)
00040 #include <iostream>
00041 using namespace std;
00042 #else
00043 #include <iostream.h>
00044 #endif
00045 #endif // _NO_EXCEPTION
00046 #include <stdlib.h>
00047
00048 #include "rtxersrc/asn1xer.h"
00049 #include "rtsrc/OSCInputStream.h"
00050 #include "rtxersrc/rtSAXDefs.h"
00051
00052 #ifndef _NO_EXCEPTIONS
00053 #define OSRTSAXEXCEPTION0 throw OSRTSAXExceptionImpl ()
00054 #define OSRTSAXEXCEPTION1(str) throw OSRTSAXExceptionImpl (str)
00055 #else // _NO_EXCEPTIONS
00056 #define OSRTSAXEXCEPTION0 { \
00057 fprintf (stderr, "Fatal Error, OSRTSAXExceptionImpl is thrown, in %s at %i\n", \
00058 __FILE__, __LINE__); \
00059 exit (-1); \
00060 }
00061 #define OSRTSAXEXCEPTION1(str) { \
00062 fprintf (stderr, "Fatal Error, OSRTSAXExceptionImpl(%s) is thrown, in %s at %i\n", \
00063 str, __FILE__, __LINE__); \
00064 exit (-1); \
00065 }
00066 #endif // _NO_EXCEPTIONS
00067
00076 class EXTERNXER OSRTSAXException
00077 {
00078 public:
00079 virtual ~OSRTSAXException () {}
00083 virtual const XMLCHAR* getMessage() = 0;
00084
00085 virtual int getStatus () = 0;
00086 virtual const XMLCHAR* getSrcFileName () = 0;
00087 virtual int getSrcLineNum() = 0;
00088 };
00089
00090 class EXTERNXER OSXMLErrorInfo {
00091 public:
00092 virtual void resetErrorInfo () = 0;
00093 virtual void setErrorInfo (int status, const char* file = 0, int line = 0) = 0;
00094 virtual int getErrorInfo (int* status, const char** file, int* line) = 0;
00095 };
00096
00097 class EXTERNXER OSXMLErrorHandler
00098 {
00099 public:
00100
00114 virtual void warning() = 0;
00115
00132 virtual void error() = 0;
00133
00148 virtual void fatalError() = 0;
00149
00157 virtual void resetErrors() = 0;
00159 };
00160
00177 class EXTERNXER OSXMLContentHandler
00178 {
00179 public:
00203 virtual void characters
00204 (
00205 const XMLCHAR* const chars,
00206 const unsigned int length
00207 ) = 0;
00208
00221 virtual void endElement
00222 (
00223 const XMLCHAR* const uri,
00224 const XMLCHAR* const localname,
00225 const XMLCHAR* const qname
00226 ) = 0;
00227
00247 virtual void startElement
00248 (
00249 const XMLCHAR* const uri,
00250 const XMLCHAR* const localname,
00251 const XMLCHAR* const qname,
00252 const XMLCHAR* const* attrs
00253 ) = 0;
00254
00256 };
00257
00258 class EXTERNXER OSXMLBase {
00259 protected:
00260 OSXMLBase () {}
00261
00262 virtual ~OSXMLBase ();
00263 public:
00264 virtual void release () = 0;
00265 };
00266
00267 #define DECLARE_XMLBASEIMP \
00268 public: void release () { delete this; }
00269
00270 class EXTERNXER OSXMLReader : public OSXMLBase
00271 {
00272 public:
00273
00292 virtual int parse
00293 (
00294 OSCInputStream& source
00295 ) = 0;
00296
00300 virtual int parse
00301 (
00302 const char* const pBuffer,
00303 int bufSize
00304 ) = 0;
00305
00319 virtual int parse
00320 (
00321 const char* const systemId
00322 ) = 0;
00323
00338 virtual void setContentHandler(OSXMLContentHandler* const handler) = 0;
00339
00354 virtual void setErrorHandler(OSXMLErrorHandler* const handler) = 0;
00355
00356 virtual void setErrorInfoHandler (OSXMLErrorInfo* const handler) = 0;
00357 };
00358
00359 class EXTERNXER StrX {
00360 private :
00361 char* fLocalForm;
00362 public :
00363
00364
00365
00366 StrX (const XMLCHAR* const toTranscode);
00367 ~StrX();
00368
00369
00370
00371
00372 const char* localForm() const
00373 {
00374 return fLocalForm;
00375 }
00376
00377 operator const char* () const
00378 {
00379 return fLocalForm;
00380 }
00381 };
00382
00383 #ifndef _NO_EXCEPTIONS
00384 inline ostream& operator<<(ostream& target, const StrX& toDump)
00385 {
00386 target << toDump.localForm();
00387 return target;
00388 }
00389 #endif // _NO_EXCEPTION
00390
00391
00392
00393 class EXTERNXER OSRTSAXExceptionImpl : public OSRTSAXException
00394 {
00395 DECLARE_XMLBASEIMP
00396 public:
00397 OSRTSAXExceptionImpl();
00398
00399 OSRTSAXExceptionImpl(const char* const msg);
00400
00401 OSRTSAXExceptionImpl(const char* const msg,
00402 int stat_, const char* const file_, int line_);
00403
00409 OSRTSAXExceptionImpl(int stat_, const char* file_, int line_);
00410
00416 OSRTSAXExceptionImpl(const OSRTSAXExceptionImpl& toCopy);
00417
00419 virtual ~OSRTSAXExceptionImpl();
00420
00421 OSRTSAXExceptionImpl& operator=(const OSRTSAXExceptionImpl& toCopy);
00422
00423 virtual const XMLCHAR* getMessage();
00424
00425 virtual int getStatus () { return stat; }
00426 virtual const XMLCHAR* getSrcFileName () { return file; }
00427 virtual int getSrcLineNum() { return line; }
00428
00429 protected :
00430
00431
00432
00433
00434
00435
00436 XMLCHAR* fMsg;
00437 int stat;
00438 XMLCHAR* file;
00439 int line;
00440 };
00441
00442 class OSXMLBasePtr {
00443 OSXMLBase* mPtr;
00444 public:
00445 OSXMLBasePtr ():mPtr (0) {}
00446 OSXMLBasePtr (OSXMLBase* ptr):mPtr (ptr) {}
00447 ~OSXMLBasePtr () { if (mPtr) mPtr->release (); }
00448
00449 operator OSXMLBase* () const { return mPtr; }
00450
00451 OSXMLBase* operator= (OSXMLBase* ptr) {
00452 if (mPtr) mPtr->release ();
00453 mPtr = ptr;
00454 return mPtr;
00455 }
00456 };
00457
00458
00459 OSXMLReader* saxCreateXmlReader (ASN1CtxtPtr ctxt,
00460 OSXMLContentHandler* pSaxHandler,
00461 OSXMLErrorInfo* pErrorInfoHandler);
00462
00463
00464 EXTERNXER OSRTSAXException* createSAXException ();
00465
00466 EXTERNXER OSRTSAXException* createSAXException (const char* const msg, int stat,
00467 const char* const fileName, int line);
00468
00469 #endif