00001 /* -*- mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: t -*- */ 00002 /* AbiSource 00003 * 00004 * Copyright (C) 2007 Philippe Milot <PhilMilot@gmail.com> 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 _OXML_ELEMENT_H_ 00023 #define _OXML_ELEMENT_H_ 00024 00025 #include <string> 00026 #include <vector> 00027 #include <memory> 00028 #include <map> 00029 00030 #include "ut_types.h" 00031 #include "pp_AttrProp.h" 00032 #include "pd_Document.h" 00033 #include "OXML_Types.h" 00034 #include "OXML_ObjectWithAttrProp.h" 00035 #include "OXML_Style.h" 00036 #include "OXML_List.h" 00037 #include "OXML_Image.h" 00038 00039 class OXML_Element; 00040 class IE_Exp_OpenXML; 00041 00042 typedef std::shared_ptr<OXML_Element> OXML_SharedElement; 00043 typedef std::vector<OXML_SharedElement> OXML_ElementVector; 00044 00045 /* \class OXML_Element 00046 * \brief This class represents any element in the OpenXML data model. 00047 * OXML_Element can represent any tag, whether it is block-level or character-level. 00048 * The tags it can represent are listed in the ElementTag enum of OXML_Types.h. 00049 * If additional logic is required for a specific tag, this class can be derived 00050 * (see the documentation on the virtual methods in this case). 00051 */ 00052 class OXML_Element : public OXML_ObjectWithAttrProp 00053 , public std::enable_shared_from_this<OXML_Element> 00054 { 00055 public: 00061 OXML_Element(const std::string & id, OXML_ElementTag tag, OXML_ElementType type); 00062 virtual ~OXML_Element(); 00063 00064 inline const std::string & getId() const { return m_id; } 00065 inline void setId(const std::string & id) { m_id = id; } 00066 inline OXML_ElementTag getTag() const { return m_tag; } 00067 inline OXML_ElementType getType() const { return m_type; } 00068 inline void setType(OXML_ElementType type) { m_type = type; } 00069 00070 bool operator ==(const std::string & id); 00071 friend bool operator ==(const OXML_SharedElement& lhs, const std::string & id) { return (*lhs) == id; } 00072 00073 OXML_SharedElement getElement(const std::string & id) const; 00074 UT_Error appendElement(const OXML_SharedElement & obj); 00075 inline const OXML_ElementVector & getChildren() const { return m_children; } 00076 UT_Error clearChildren(); 00077 00079 00084 virtual UT_Error serialize(IE_Exp_OpenXML* exporter); 00086 00091 virtual UT_Error addToPT(PD_Document * pDocument); 00093 00095 UT_Error addChildrenToPT(PD_Document * pDocument); 00096 00097 void setTarget(int target); 00098 00099 protected: 00101 00103 UT_Error serializeChildren(IE_Exp_OpenXML* exporter); 00104 00105 int TARGET; 00106 00107 private: 00108 std::string m_id; 00109 OXML_ElementTag m_tag; 00110 OXML_ElementType m_type; 00111 OXML_ElementVector m_children; 00112 00113 }; 00114 00115 typedef std::map<std::string, OXML_SharedStyle > OXML_StyleMap; 00116 typedef std::map<UT_uint32, OXML_SharedList > OXML_ListMap; 00117 typedef std::map<std::string, OXML_SharedImage > OXML_ImageMap; 00118 00119 #endif //_OXML_ELEMENT_H_ 00120