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

Generated on Sun Feb 14 2021 for AbiWord by  doxygen 1.7.1