1*353d8f4dSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*353d8f4dSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*353d8f4dSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*353d8f4dSAndrew Rist * distributed with this work for additional information 6*353d8f4dSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*353d8f4dSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*353d8f4dSAndrew Rist * "License"); you may not use this file except in compliance 9*353d8f4dSAndrew Rist * with the License. You may obtain a copy of the License at 10*353d8f4dSAndrew Rist * 11*353d8f4dSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*353d8f4dSAndrew Rist * 13*353d8f4dSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*353d8f4dSAndrew Rist * software distributed under the License is distributed on an 15*353d8f4dSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*353d8f4dSAndrew Rist * KIND, either express or implied. See the License for the 17*353d8f4dSAndrew Rist * specific language governing permissions and limitations 18*353d8f4dSAndrew Rist * under the License. 19*353d8f4dSAndrew Rist * 20*353d8f4dSAndrew Rist *************************************************************/ 21*353d8f4dSAndrew Rist 22*353d8f4dSAndrew Rist 23cdf0e10cSrcweir #ifndef METADATABLE_HXX 24cdf0e10cSrcweir #define METADATABLE_HXX 25cdf0e10cSrcweir 26cdf0e10cSrcweir #include <sal/config.h> 27cdf0e10cSrcweir 28cdf0e10cSrcweir #include <sfx2/dllapi.h> 29cdf0e10cSrcweir 30cdf0e10cSrcweir #include <cppuhelper/implbase1.hxx> 31cdf0e10cSrcweir #include <com/sun/star/rdf/XMetadatable.hpp> 32cdf0e10cSrcweir 33cdf0e10cSrcweir #include <boost/utility.hpp> 34cdf0e10cSrcweir #include <boost/shared_ptr.hpp> 35cdf0e10cSrcweir 36cdf0e10cSrcweir 37cdf0e10cSrcweir namespace com { namespace sun { namespace star { 38cdf0e10cSrcweir namespace frame { class XModel; } 39cdf0e10cSrcweir } } } 40cdf0e10cSrcweir 41cdf0e10cSrcweir namespace sfx2 { 42cdf0e10cSrcweir class IXmlIdRegistry; 43cdf0e10cSrcweir } 44cdf0e10cSrcweir 45cdf0e10cSrcweir namespace sfx2 { 46cdf0e10cSrcweir 47cdf0e10cSrcweir class XmlIdRegistry; 48cdf0e10cSrcweir class MetadatableUndo; 49cdf0e10cSrcweir 50cdf0e10cSrcweir 51cdf0e10cSrcweir // XML ID handling --------------------------------------------------- 52cdf0e10cSrcweir 53cdf0e10cSrcweir 54cdf0e10cSrcweir /// create a sfx2::XmlIdRegistryDocument or a sfx2::XmlIdRegistryClipboard 55cdf0e10cSrcweir SFX2_DLLPUBLIC ::sfx2::IXmlIdRegistry * 56cdf0e10cSrcweir createXmlIdRegistry(const bool i_DocIsClipboard); 57cdf0e10cSrcweir 58cdf0e10cSrcweir 59cdf0e10cSrcweir /** base class for core objects that may have xml:id. 60cdf0e10cSrcweir 61cdf0e10cSrcweir <p>The interface of this class consists of 3 parts: 62cdf0e10cSrcweir <ul><li>implementations that are used by the <type>MetadatableMixin</type> 63cdf0e10cSrcweir below</li> 64cdf0e10cSrcweir <li>hooks to be called by the sw core whenever actions that are 65cdf0e10cSrcweir relevant to the uniqueness of xml:ids are taken (copying, 66cdf0e10cSrcweir splitting, merging, deletion, undo, etc.)</li> 67cdf0e10cSrcweir <li>abstract methods that are called by the implementation of the 68cdf0e10cSrcweir previous hooks</li></ul> 69cdf0e10cSrcweir </p> 70cdf0e10cSrcweir */ 71cdf0e10cSrcweir class SFX2_DLLPUBLIC Metadatable : private boost::noncopyable 72cdf0e10cSrcweir { 73cdf0e10cSrcweir 74cdf0e10cSrcweir public: Metadatable()75cdf0e10cSrcweir Metadatable() : m_pReg(0) {} 76cdf0e10cSrcweir 77cdf0e10cSrcweir // destructor calls RemoveMetadataReference 78cdf0e10cSrcweir virtual ~Metadatable(); 79cdf0e10cSrcweir 80cdf0e10cSrcweir // for MetadatableMixin ---------------------------------------------- 81cdf0e10cSrcweir 82cdf0e10cSrcweir ::com::sun::star::beans::StringPair GetMetadataReference() const; 83cdf0e10cSrcweir void SetMetadataReference( 84cdf0e10cSrcweir const ::com::sun::star::beans::StringPair & i_rReference); 85cdf0e10cSrcweir void EnsureMetadataReference(); 86cdf0e10cSrcweir 87cdf0e10cSrcweir // hooks ------------------------------------------------------------- 88cdf0e10cSrcweir 89cdf0e10cSrcweir // called from dtor! 90cdf0e10cSrcweir void RemoveMetadataReference(); 91cdf0e10cSrcweir 92cdf0e10cSrcweir /** register this as a copy of i_rSource */ 93cdf0e10cSrcweir void RegisterAsCopyOf(Metadatable const & i_rSource, 94cdf0e10cSrcweir const bool i_bCopyPrecedesSource = false); 95cdf0e10cSrcweir 96cdf0e10cSrcweir /** create an Undo Metadatable, which remembers this' reference */ 97cdf0e10cSrcweir ::boost::shared_ptr<MetadatableUndo> CreateUndo() const; 98cdf0e10cSrcweir ::boost::shared_ptr<MetadatableUndo> CreateUndoForDelete(); 99cdf0e10cSrcweir 100cdf0e10cSrcweir /** restore this from Undo Metadatable */ 101cdf0e10cSrcweir void RestoreMetadata(::boost::shared_ptr<MetadatableUndo> const& i_pUndo); 102cdf0e10cSrcweir 103cdf0e10cSrcweir /** merge this and i_rOther into this */ 104cdf0e10cSrcweir void JoinMetadatable(Metadatable const & i_rOther, 105cdf0e10cSrcweir const bool i_isMergedEmpty, const bool i_isOtherEmpty); 106cdf0e10cSrcweir 107cdf0e10cSrcweir // abstract methods -------------------------------------------------- 108cdf0e10cSrcweir 109cdf0e10cSrcweir /** get the registry from the SwDoc */ 110cdf0e10cSrcweir virtual ::sfx2::IXmlIdRegistry& GetRegistry() = 0; 111cdf0e10cSrcweir 112cdf0e10cSrcweir /** is this in a clipboard document? */ 113cdf0e10cSrcweir virtual bool IsInClipboard() const = 0; 114cdf0e10cSrcweir 115cdf0e10cSrcweir /** is this in undo array? */ 116cdf0e10cSrcweir virtual bool IsInUndo() const = 0; 117cdf0e10cSrcweir 118cdf0e10cSrcweir /** which stream is this in? true: content.xml; false: styles.xml */ 119cdf0e10cSrcweir virtual bool IsInContent() const = 0; 120cdf0e10cSrcweir 121cdf0e10cSrcweir /** create XMetadatable from this. 122cdf0e10cSrcweir note: if IsInUndo or IsInClipboard return true, 123cdf0e10cSrcweir MakeUnoObject <em>must not</em> be called! 124cdf0e10cSrcweir */ 125cdf0e10cSrcweir virtual ::com::sun::star::uno::Reference< 126cdf0e10cSrcweir ::com::sun::star::rdf::XMetadatable > MakeUnoObject() = 0; 127cdf0e10cSrcweir 128cdf0e10cSrcweir private: 129cdf0e10cSrcweir friend class MetadatableClipboard; 130cdf0e10cSrcweir friend class MetadatableUndo; 131cdf0e10cSrcweir 132cdf0e10cSrcweir // note that Reg may be a XmlIdRegistryDocument or a XmlIdRegistryClipboard 133cdf0e10cSrcweir XmlIdRegistry* m_pReg; // null => no XmlId 134cdf0e10cSrcweir }; 135cdf0e10cSrcweir 136cdf0e10cSrcweir 137cdf0e10cSrcweir /** base class for UNO objects that implement <type>XMetadatable</type>. 138cdf0e10cSrcweir 139cdf0e10cSrcweir <p>An instance of this base class is associated with an instance of 140cdf0e10cSrcweir <type>Metadatable</type>.</p> 141cdf0e10cSrcweir */ 142cdf0e10cSrcweir class SFX2_DLLPUBLIC MetadatableMixin : 143cdf0e10cSrcweir public ::cppu::WeakImplHelper1< 144cdf0e10cSrcweir ::com::sun::star::rdf::XMetadatable> 145cdf0e10cSrcweir { 146cdf0e10cSrcweir 147cdf0e10cSrcweir public: MetadatableMixin()148cdf0e10cSrcweir MetadatableMixin() {}; 149cdf0e10cSrcweir ~MetadatableMixin()150cdf0e10cSrcweir virtual ~MetadatableMixin() {} 151cdf0e10cSrcweir 152cdf0e10cSrcweir // ::com::sun::star::rdf::XNode: 153cdf0e10cSrcweir virtual ::rtl::OUString SAL_CALL getStringValue() 154cdf0e10cSrcweir throw (::com::sun::star::uno::RuntimeException); 155cdf0e10cSrcweir 156cdf0e10cSrcweir // ::com::sun::star::rdf::XURI: 157cdf0e10cSrcweir virtual ::rtl::OUString SAL_CALL getLocalName() 158cdf0e10cSrcweir throw (::com::sun::star::uno::RuntimeException); 159cdf0e10cSrcweir virtual ::rtl::OUString SAL_CALL getNamespace() 160cdf0e10cSrcweir throw (::com::sun::star::uno::RuntimeException); 161cdf0e10cSrcweir 162cdf0e10cSrcweir // ::com::sun::star::rdf::XMetadatable: 163cdf0e10cSrcweir virtual ::com::sun::star::beans::StringPair SAL_CALL getMetadataReference() 164cdf0e10cSrcweir throw (::com::sun::star::uno::RuntimeException); 165cdf0e10cSrcweir virtual void SAL_CALL setMetadataReference( 166cdf0e10cSrcweir const ::com::sun::star::beans::StringPair & i_rReference) 167cdf0e10cSrcweir throw (::com::sun::star::uno::RuntimeException, 168cdf0e10cSrcweir ::com::sun::star::lang::IllegalArgumentException); 169cdf0e10cSrcweir virtual void SAL_CALL ensureMetadataReference() 170cdf0e10cSrcweir throw (::com::sun::star::uno::RuntimeException); 171cdf0e10cSrcweir 172cdf0e10cSrcweir protected: 173cdf0e10cSrcweir /// get the core object corresponding to this UNO object. 174cdf0e10cSrcweir virtual Metadatable * GetCoreObject() = 0; 175cdf0e10cSrcweir /// get the <type>XModel</type> for the document 176cdf0e10cSrcweir virtual ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel > 177cdf0e10cSrcweir GetModel() = 0; 178cdf0e10cSrcweir 179cdf0e10cSrcweir }; 180cdf0e10cSrcweir 181cdf0e10cSrcweir } // namespace sfx2 182cdf0e10cSrcweir 183cdf0e10cSrcweir #endif // METADATABLE_HXX 184