00001 /* AbiSource 00002 * 00003 * Copyright (C) 2005 Daniel d'Andrada T. de Carvalho 00004 * <daniel.carvalho@indt.org.br> 00005 * 00006 * This program is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU General Public License 00008 * as published by the Free Software Foundation; either version 2 00009 * of the License, or (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with this program; if not, write to the Free Software 00018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 00019 * 02110-1301 USA. 00020 */ 00021 00022 #ifndef _ODI_XMLRECORDER_H_ 00023 #define _ODI_XMLRECORDER_H_ 00024 00025 // AbiWord includes 00026 #include <ut_vector.h> 00027 00028 00034 class ODi_XMLRecorder { 00035 00036 public: 00037 00038 ~ODi_XMLRecorder(); 00039 00040 void startElement (const gchar* pName, const gchar** ppAtts); 00041 void endElement (const gchar* pName); 00042 void charData (const gchar* pBuffer, int length); 00043 00044 ODi_XMLRecorder& operator=(const ODi_XMLRecorder& rXMLRecorder); 00045 00046 enum XMLCallType { 00047 XMLCallType_StartElement, 00048 XMLCallType_EndElement, 00049 XMLCallType_CharData 00050 }; 00051 00052 class XMLCall { 00053 public: 00054 XMLCall(XMLCallType type) : m_type(type) {} 00055 virtual ~XMLCall() {} 00056 00057 XMLCallType getType() const {return m_type;} 00058 00059 protected: 00060 XMLCallType m_type; // startElement, endElement or charData 00061 }; 00062 00063 class StartElementCall : public XMLCall { 00064 public: 00065 StartElementCall() : XMLCall(XMLCallType_StartElement) {} 00066 00067 ~StartElementCall() 00068 { 00069 delete []m_pName; 00070 UT_uint32 i=0; 00071 while (m_ppAtts[i]!=0) { 00072 delete [](m_ppAtts[i]); 00073 i++; 00074 } 00075 delete [](m_ppAtts[i]); 00076 delete []m_ppAtts; 00077 } 00078 00079 gchar* m_pName; 00080 gchar** m_ppAtts; 00081 }; 00082 00083 00084 class EndElementCall : public XMLCall { 00085 public: 00086 EndElementCall() : XMLCall(XMLCallType_EndElement) {} 00087 00088 ~EndElementCall() { delete []m_pName; } 00089 00090 gchar* m_pName; 00091 }; 00092 00093 class CharDataCall : public XMLCall { 00094 public: 00095 00096 CharDataCall() : XMLCall(XMLCallType_CharData) {} 00097 ~CharDataCall() { delete []m_pBuffer; } 00098 00099 gchar* m_pBuffer; 00100 int m_length; 00101 }; 00102 00103 const XMLCall* getCall(UT_sint32 index) const {return m_XMLCalls[index];} 00104 UT_uint32 getCallCount() const {return m_XMLCalls.getItemCount(); } 00105 00106 void clear(); 00107 private: 00108 00109 UT_GenericVector<XMLCall*> m_XMLCalls; 00110 00111 }; 00112 00113 #endif //_ODI_XMLRECORDER_H_