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