Main Page Class Hierarchy Alphabetical List Compound List File List Compound Members

FXXmlParser.h

Go to the documentation of this file.
00001 /********************************************************************************
00002 *                                                                               *
00003 *                  XML event generator object                                   *
00004 *                                                                               *
00005 *********************************************************************************
00006 * Copyright (C) 2003 by Mathew Robertson.   All Rights Reserved.                *
00007 *********************************************************************************
00008 * This library is free software; you can redistribute it and/or                 *
00009 * modify it under the terms of the GNU Lesser General Public                    *
00010 * License as published by the Free Software Foundation; either                  *
00011 * version 2.1 of the License, or (at your option) any later version.            *
00012 *                                                                               *
00013 * This library is distributed in the hope that it will be useful,               *
00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of                *
00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU             *
00016 * Lesser General Public License for more details.                               *
00017 *                                                                               *
00018 * You should have received a copy of the GNU Lesser General Public              *
00019 * License along with this library; if not, write to the Free Software           *
00020 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.    *
00021 *********************************************************************************/
00022 #ifndef FXXMLPARSER_H
00023 #define FXXMLPARSER_H
00024 
00025 #ifndef FXBASEOBJECT_H
00026 #include "FXBaseObject.h"
00027 #endif
00028 namespace FXEX {
00029 class FXXmlReader;
00030 
00031 /**
00032  * This XML parser is designed to absorb FOX XML tag events.
00033  *
00034  * Each time a tag is encountered, the XmlReader embedded in FXXmlParser, forwards tag
00035  * events to this class.  We then do some handling of the tag and content by transposing
00036  * embedded &...; characters, etc.
00037  */
00038 class FXAPI FXXmlParser : public FXBaseObject {
00039   FXDECLARE(FXXmlParser)
00040 
00041 private:
00042   FXXmlReader *reader;
00043   FXbool       state;
00044   FXbool       whitespace;
00045   FXuint       stopPolling;
00046 
00047 protected:
00048   /// for serialization
00049   FXXmlParser() : FXBaseObject() {}
00050 
00051   /// removes specified characters, provided they are not embedded in double quotes
00052   void stripChar(FXString& s,FXchar c='\n');
00053 
00054   /**
00055    * takes a string containing &...; embeded characters, replacing
00056    * them with the real thing
00057    */
00058   void replaceEmbedded(FXString& s);
00059 
00060   /// lookup table that takes the incoming string, transposing it to the outgoing string
00061   virtual FXString lookup(const FXString& s);
00062 
00063   /// removes any white space found between tags, which space is (' ', \r, \n)
00064   void removeWhitespace(FXString& s);
00065 
00066 public:
00067   enum {
00068     ID_XML_PARSER=FXBaseObject::ID_LAST,
00069     ID_LAST
00070     };
00071 
00072 public:
00073   long onTimeout(FXObject*,FXSelector,void*);
00074   long onChore(FXObject*,FXSelector,void*);
00075   long onTag(FXObject*,FXSelector,void*);
00076   long onContent(FXObject*,FXSelector,void*);
00077   long onReadError(FXObject*,FXSelector,void*);
00078 
00079 public:
00080   /// create a reader for the incoming stream
00081   FXXmlParser(FXApp* a,FXStream* s,FXObject* tgt,FXSelector sel);
00082 
00083   /// create resources
00084   void create();
00085 
00086   /// get the current state of parsing
00087   FXbool getState() { return state; }
00088 
00089   /// set to new stream
00090   void setStream(FXStream *s);
00091 
00092   /// returns the stream
00093   FXStream* getStream();
00094 
00095   /// should we automatically discard whitespace
00096   void keepWhitespace(FXbool ws) { whitespace=ws; }
00097 
00098   /// get the state of whitespace discarding
00099   FXbool keepWhitespace() { return whitespace; }
00100 
00101   /// parse the stream
00102   FXbool parse();
00103 
00104   /// stop parsing the input stream and close all remaining tags
00105   void stop() { stopPolling=1; state=FALSE; }
00106 
00107   /// cleanup
00108   virtual ~FXXmlParser();
00109   };
00110 
00111 } // namespace FXEX
00112 #endif // FXXMLPARSER_H