00001 #if !defined(_STREAMSAX2PARSER_HPP) 00002 #define _STREAMSAX2PARSER_HPP 00003 //============================================================================= 00004 // 00005 // XDFLengine library 00006 // 00007 //----------------------------------------------------------------------------- 00008 // STREAMSAX2PARSER.HPP 00009 //----------------------------------------------------------------------------- 00015 //_____________________________________________________________________________ 00016 // 00017 // Copyright (C) 2003 Guillaume Baurand. All Rights Reserved. 00018 // 00019 // This file is part of the XDFLengine project. 00020 // 00021 // The XDFLengine is free software; you can redistribute it and/or modify 00022 // it under the terms of the GNU General Public License as published by 00023 // the Free Software Foundation; either version 2 of the License, or 00024 // (at your option) any later version. 00025 // 00026 // This program is distributed in the hope that it will be useful, 00027 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00028 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00029 // GNU General Public License for more details. 00030 // 00031 // You should have received a copy of the GNU General Public License 00032 // along with this program; if not, write to the Free Software 00033 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 00034 // USA. 00035 // 00036 // For more information, 00037 // contact : guillaume@baurand.net 00038 // or visit : http://xdflengine.sourceforge.net 00039 // 00040 //============================================================================= 00041 00042 // Xerces 00043 # include "xercesc/util/XercesDefs.hpp" 00044 # include "xercesc/util/BinMemInputStream.hpp" 00045 # include "xercesc/sax/InputSource.hpp" 00046 # include "xercesc/sax2/Attributes.hpp" 00047 # include "xercesc/sax2/ContentHandler.hpp" 00048 # include "xercesc/sax/ErrorHandler.hpp" 00049 # include "xercesc/sax2/XMLReaderFactory.hpp" 00050 # include "xercesc/sax2/SAX2XMLReader.hpp" 00051 # include "flow/buffers/filebuffer.hpp" 00052 00053 # include "config/commonincs.hpp" 00054 # include "flow/xmlstreamconsumer.hpp" 00055 00056 00057 XERCES_CPP_NAMESPACE_USE; 00058 00059 BEGIN_XDFLENGINE_NS 00060 00061 00062 class StreamInputSource; 00063 00064 //============================================================================= 00065 // CLASS PROGRESSIVEINPUTSTREAM 00066 //----------------------------------------------------------------------------- 00067 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 00068 class XDFLENGINE_EXPORT ProgressiveInputStream: public BinInputStream 00069 { 00070 00071 private: 00072 unsigned int m_uiVirtualPosition; 00073 StreamInputSource* m_pStreamInputSource; 00074 00075 public: 00076 00077 //_____________________________________________________________________ 00078 // PROGRESSIVEINPUTSTREAM 00079 //--------------------------------------------------------------------- 00080 ProgressiveInputStream(StreamInputSource* p_pStreamInputSource); 00081 00082 //_____________________________________________________________________ 00083 // PROGRESSIVEINPUTSTREAM 00084 //--------------------------------------------------------------------- 00085 ~ProgressiveInputStream(); 00086 00087 //_____________________________________________________________________ 00088 // CURPOS 00089 //--------------------------------------------------------------------- 00090 unsigned int curPos() const; 00091 00092 //_____________________________________________________________________ 00093 // READBYTES 00094 //--------------------------------------------------------------------- 00095 unsigned int readBytes( XMLByte* const toFill, const unsigned int maxToRead); 00096 }; 00097 //----------------------------------------------------------------------------- 00098 //============================================================================= 00099 00100 00101 //============================================================================= 00102 // CLASS STREAMINPUTSOURCE 00103 //----------------------------------------------------------------------------- 00104 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 00105 class XDFLENGINE_EXPORT StreamInputSource: public InputSource ,public XMLStreamConsumer 00106 { 00107 00108 00109 private: 00110 00111 char* m_pszDataBuf; 00112 unsigned int m_uiBeginIndex; 00113 unsigned int m_uiEndIndex; 00114 unsigned int m_uiBufSize; 00115 bool m_fComplete; 00116 XMLCh * m_pxchEncoding; 00117 //FileBuffer* OUTF; 00118 00119 00120 public: 00121 00122 00123 00124 // constructor and destructor 00125 00126 //_____________________________________________________________________ 00127 // STREAMINPUTSOURCE 00128 //--------------------------------------------------------------------- 00129 StreamInputSource(); 00130 00131 //_____________________________________________________________________ 00132 // STREAMINPUTSOURCE 00133 //--------------------------------------------------------------------- 00134 ~StreamInputSource(); 00135 00136 // Data buffer management 00137 00138 //_____________________________________________________________________ 00139 // SETENCODING 00140 //--------------------------------------------------------------------- 00141 void setEncoding(const char* m_pszEncoding); 00142 00143 //_____________________________________________________________________ 00144 // WRITEDATA 00145 //--------------------------------------------------------------------- 00146 void writeData( const char* p_pszData, unsigned int p_uiDataLen); 00147 00148 //_____________________________________________________________________ 00149 // READDATA 00150 //--------------------------------------------------------------------- 00151 unsigned int readData( char* const p_pszToFill, const unsigned int p_uiMaxToRead); 00152 00153 //_____________________________________________________________________ 00154 // FLUSHDATA 00155 //--------------------------------------------------------------------- 00156 void flushData(); 00157 00158 //_____________________________________________________________________ 00159 // AVAILABLE 00160 //--------------------------------------------------------------------- 00161 unsigned int available(); 00162 00163 // INPUTSOURCE const 00164 00165 //_____________________________________________________________________ 00166 // STREAMSAX2PARSER 00167 //--------------------------------------------------------------------- 00168 const XMLCh * getEncoding () const; 00169 00170 //_____________________________________________________________________ 00171 // STREAMSAX2PARSER 00172 //--------------------------------------------------------------------- 00173 BinInputStream* makeStream() const; 00174 00175 00176 void setComplete(); 00177 00178 00179 }; 00180 //----------------------------------------------------------------------------- 00181 //============================================================================= 00182 00183 00184 00185 00186 00187 00188 00189 00190 //============================================================================= 00191 // CLASS STREAMSAX2PARSER 00192 //----------------------------------------------------------------------------- 00193 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 00194 class StreamSAX2Parser : public XMLStreamConsumer 00195 { 00196 00197 private: 00198 bool m_fParseStarted; 00199 StreamInputSource m_StreamInputSource; 00200 XMLPScanToken m_ScanToken; 00201 SAX2XMLReader* m_pSAX2XMLReader; 00202 00203 ContentHandler* m_pContentHandler; 00204 ErrorHandler* m_pErrorHandler; 00205 00206 00207 public: 00208 00209 // CONSTRUCTOR & DESTRUCTOR 00210 00211 //_____________________________________________________________________ 00212 // STREAMSAX2PARSER 00213 //--------------------------------------------------------------------- 00214 StreamSAX2Parser(ContentHandler* p_pContentHandler, ErrorHandler* p_pErrorHandler); 00215 00216 //_____________________________________________________________________ 00217 // ~STREAMSAX2PARSER 00218 //--------------------------------------------------------------------- 00219 ~StreamSAX2Parser(); 00220 00221 // STREAM OPERATORS 00222 00223 //_____________________________________________________________________ 00224 // WRITEDATA 00225 //--------------------------------------------------------------------- 00226 void writeData( const char* p_pszData, unsigned int p_uiDataLen); 00227 00228 //_____________________________________________________________________ 00229 // COMMITSTREAM 00230 //--------------------------------------------------------------------- 00231 bool commitStream(bool fFinal = false); 00232 00233 00234 }; 00235 //----------------------------------------------------------------------------- 00236 //============================================================================= 00237 00238 END_XDFLENGINE_NS 00239 00240 #endif