1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 #ifndef METADATABLE_HXX 28 #define METADATABLE_HXX 29 30 #include <sal/config.h> 31 32 #include <sfx2/dllapi.h> 33 34 #include <cppuhelper/implbase1.hxx> 35 #include <com/sun/star/rdf/XMetadatable.hpp> 36 37 #include <boost/utility.hpp> 38 #include <boost/shared_ptr.hpp> 39 40 41 namespace com { namespace sun { namespace star { 42 namespace frame { class XModel; } 43 } } } 44 45 namespace sfx2 { 46 class IXmlIdRegistry; 47 } 48 49 namespace sfx2 { 50 51 class XmlIdRegistry; 52 class MetadatableUndo; 53 54 55 // XML ID handling --------------------------------------------------- 56 57 58 /// create a sfx2::XmlIdRegistryDocument or a sfx2::XmlIdRegistryClipboard 59 SFX2_DLLPUBLIC ::sfx2::IXmlIdRegistry * 60 createXmlIdRegistry(const bool i_DocIsClipboard); 61 62 63 /** base class for core objects that may have xml:id. 64 65 <p>The interface of this class consists of 3 parts: 66 <ul><li>implementations that are used by the <type>MetadatableMixin</type> 67 below</li> 68 <li>hooks to be called by the sw core whenever actions that are 69 relevant to the uniqueness of xml:ids are taken (copying, 70 splitting, merging, deletion, undo, etc.)</li> 71 <li>abstract methods that are called by the implementation of the 72 previous hooks</li></ul> 73 </p> 74 */ 75 class SFX2_DLLPUBLIC Metadatable : private boost::noncopyable 76 { 77 78 public: 79 Metadatable() : m_pReg(0) {} 80 81 // destructor calls RemoveMetadataReference 82 virtual ~Metadatable(); 83 84 // for MetadatableMixin ---------------------------------------------- 85 86 ::com::sun::star::beans::StringPair GetMetadataReference() const; 87 void SetMetadataReference( 88 const ::com::sun::star::beans::StringPair & i_rReference); 89 void EnsureMetadataReference(); 90 91 // hooks ------------------------------------------------------------- 92 93 // called from dtor! 94 void RemoveMetadataReference(); 95 96 /** register this as a copy of i_rSource */ 97 void RegisterAsCopyOf(Metadatable const & i_rSource, 98 const bool i_bCopyPrecedesSource = false); 99 100 /** create an Undo Metadatable, which remembers this' reference */ 101 ::boost::shared_ptr<MetadatableUndo> CreateUndo() const; 102 ::boost::shared_ptr<MetadatableUndo> CreateUndoForDelete(); 103 104 /** restore this from Undo Metadatable */ 105 void RestoreMetadata(::boost::shared_ptr<MetadatableUndo> const& i_pUndo); 106 107 /** merge this and i_rOther into this */ 108 void JoinMetadatable(Metadatable const & i_rOther, 109 const bool i_isMergedEmpty, const bool i_isOtherEmpty); 110 111 // abstract methods -------------------------------------------------- 112 113 /** get the registry from the SwDoc */ 114 virtual ::sfx2::IXmlIdRegistry& GetRegistry() = 0; 115 116 /** is this in a clipboard document? */ 117 virtual bool IsInClipboard() const = 0; 118 119 /** is this in undo array? */ 120 virtual bool IsInUndo() const = 0; 121 122 /** which stream is this in? true: content.xml; false: styles.xml */ 123 virtual bool IsInContent() const = 0; 124 125 /** create XMetadatable from this. 126 note: if IsInUndo or IsInClipboard return true, 127 MakeUnoObject <em>must not</em> be called! 128 */ 129 virtual ::com::sun::star::uno::Reference< 130 ::com::sun::star::rdf::XMetadatable > MakeUnoObject() = 0; 131 132 private: 133 friend class MetadatableClipboard; 134 friend class MetadatableUndo; 135 136 // note that Reg may be a XmlIdRegistryDocument or a XmlIdRegistryClipboard 137 XmlIdRegistry* m_pReg; // null => no XmlId 138 }; 139 140 141 /** base class for UNO objects that implement <type>XMetadatable</type>. 142 143 <p>An instance of this base class is associated with an instance of 144 <type>Metadatable</type>.</p> 145 */ 146 class SFX2_DLLPUBLIC MetadatableMixin : 147 public ::cppu::WeakImplHelper1< 148 ::com::sun::star::rdf::XMetadatable> 149 { 150 151 public: 152 MetadatableMixin() {}; 153 154 virtual ~MetadatableMixin() {} 155 156 // ::com::sun::star::rdf::XNode: 157 virtual ::rtl::OUString SAL_CALL getStringValue() 158 throw (::com::sun::star::uno::RuntimeException); 159 160 // ::com::sun::star::rdf::XURI: 161 virtual ::rtl::OUString SAL_CALL getLocalName() 162 throw (::com::sun::star::uno::RuntimeException); 163 virtual ::rtl::OUString SAL_CALL getNamespace() 164 throw (::com::sun::star::uno::RuntimeException); 165 166 // ::com::sun::star::rdf::XMetadatable: 167 virtual ::com::sun::star::beans::StringPair SAL_CALL getMetadataReference() 168 throw (::com::sun::star::uno::RuntimeException); 169 virtual void SAL_CALL setMetadataReference( 170 const ::com::sun::star::beans::StringPair & i_rReference) 171 throw (::com::sun::star::uno::RuntimeException, 172 ::com::sun::star::lang::IllegalArgumentException); 173 virtual void SAL_CALL ensureMetadataReference() 174 throw (::com::sun::star::uno::RuntimeException); 175 176 protected: 177 /// get the core object corresponding to this UNO object. 178 virtual Metadatable * GetCoreObject() = 0; 179 /// get the <type>XModel</type> for the document 180 virtual ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel > 181 GetModel() = 0; 182 183 }; 184 185 } // namespace sfx2 186 187 #endif // METADATABLE_HXX 188