• Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

ODi_StreamListener.h

Go to the documentation of this file.
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., 59 Temple Place - Suite 330, Boston, MA
00019  * 02111-1307, USA.
00020  */
00021 
00022 #ifndef _ODI_STREAMLISTENER_H_
00023 #define _ODI_STREAMLISTENER_H_
00024 
00025 // Internal includes
00026 #include "ODi_ListenerStateAction.h"
00027 #include "ODi_ElementStack.h"
00028 #include "ODi_FontFaceDecls.h"
00029 #include "ODi_XMLRecorder.h"
00030 
00031 // External includes
00032 #include <gsf/gsf.h>
00033 
00034 // AbiWord includes
00035 #include <ut_types.h>
00036 #include <ut_xml.h>
00037 #include <ut_vector.h>
00038 
00039 // Internal classes
00040 class ODi_Office_Styles;
00041 class ODi_Postpone_ListenerState;
00042 class ODi_Abi_Data;
00043 
00044 // AbiWord classes
00045 class PD_Document;
00046 
00055 class ODi_StreamListener : public virtual UT_XML::Listener {
00056 
00057 public:
00058 
00059     ODi_StreamListener(PD_Document* pAbiDocument, GsfInfile* pGsfInfile,
00060                       ODi_Office_Styles* pStyles, ODi_Abi_Data& rAbiData,
00061                       ODi_ElementStack* pElementStack = NULL);
00062 
00063     virtual ~ODi_StreamListener();
00064 
00065     void startElement (const gchar* pName, const gchar** ppAtts) {
00066         _startElement(pName, ppAtts, false);
00067     }
00068 
00069     void endElement (const gchar* pName) {
00070         _endElement(pName, false);
00071     }
00072 
00073     void charData (const gchar* pBuffer, int length);
00074 
00075     UT_Error setState(const char* pStateName);
00076     void setState(ODi_ListenerState* pState, bool deleteWhenPop);
00077 
00078     void clearFontFaceDecls() {m_fontFaceDecls.clear();}
00079 
00080     ODi_ElementStack* getElementStack() {return m_pElementStack;}
00081     ODi_ListenerState* getCurrentState() { return m_pCurrentState; }
00082 
00083 
00084 private:
00085 
00086     void _startElement (const gchar* pName, const gchar** ppAtts,
00087                        bool doingRecursion);
00088 
00089     void _endElement (const gchar* pName, bool doingRecursion);
00090 
00091     void _handleStateAction();
00092     void _clear();
00093     ODi_ListenerState* _createState(const char* pStateName);
00094     void _resumeParsing(ODi_Postpone_ListenerState* pPostponeState);
00095     void _playRecordedElement();
00096 
00097     PD_Document* m_pAbiDocument;
00098     GsfInfile* m_pGsfInfile;
00099     ODi_Office_Styles* m_pStyles;
00100     ODi_Abi_Data& m_rAbiData;
00101     ODi_FontFaceDecls m_fontFaceDecls;
00102 
00103     // Used by the current listener state to signal state changes, etc.
00104     ODi_ListenerStateAction m_stateAction;
00105 
00106     ODi_ElementStack* m_pElementStack;
00107 
00108     enum ODi_StreamListenerAction {
00109         ODI_NONE,
00110         ODI_RECORDING, // recording an element
00111         ODI_IGNORING   // ignoring an element
00112     } m_currentAction;
00113 
00114     // The stack size of the element being either recorded or ignored.
00115     UT_sint32 m_elemenStackSize;
00116 
00117     ODi_XMLRecorder m_xmlRecorder;
00118 
00119 
00121     // Listener state related variables:
00122 
00123     class StackCell {
00124     public:
00125         StackCell() {m_pState=NULL; m_deleteWhenPop=false;}
00126         StackCell(ODi_ListenerState* pState, bool deleteWhenPop) {
00127             m_deleteWhenPop = deleteWhenPop;
00128             m_pState = pState;
00129         }
00130         // Work around the "return 0" issue of the UT_GenericVector::getNhItem()
00131         StackCell(UT_uint32 /*i*/) {m_pState=NULL; m_deleteWhenPop=false;}
00132 
00133         StackCell& operator=(const StackCell& sc) {
00134             this->m_deleteWhenPop = sc.m_deleteWhenPop;
00135             this->m_pState = sc.m_pState;
00136 
00137             return *this;
00138         }
00139 
00140         bool m_deleteWhenPop;
00141         ODi_ListenerState* m_pState;
00142     };
00143 
00144     ODi_ListenerState* m_pCurrentState;
00145     bool m_deleteCurrentWhenPop;
00146     bool m_ownStack;
00147 
00148     UT_GenericVector <ODi_StreamListener::StackCell> m_stateStack;
00149     UT_GenericVector <ODi_Postpone_ListenerState*> m_postponedParsing;
00150 };
00151 
00152 #endif //_ODI_STREAMLISTENER_H_

Generated on Sun May 27 2012 for AbiWord by  doxygen 1.7.1