1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 #ifndef METADATABLE_HXX
20 #define METADATABLE_HXX
22 #include <sal/config.h>
24 #include <sfx2/dllapi.h>
26 #include <cppuhelper/implbase1.hxx>
27 #include <com/sun/star/rdf/XMetadatable.hpp>
29 #include <boost/utility.hpp>
30 #include <boost/shared_ptr.hpp>
33 namespace com
{ namespace sun
{ namespace star
{
34 namespace frame
{ class XModel
; }
44 class MetadatableUndo
;
47 // XML ID handling ---------------------------------------------------
50 /// create a sfx2::XmlIdRegistryDocument or a sfx2::XmlIdRegistryClipboard
51 SFX2_DLLPUBLIC ::sfx2::IXmlIdRegistry
*
52 createXmlIdRegistry(const bool i_DocIsClipboard
);
55 /** base class for core objects that may have xml:id.
57 <p>The interface of this class consists of 3 parts:
58 <ul><li>implementations that are used by the <type>MetadatableMixin</type>
60 <li>hooks to be called by the sw core whenever actions that are
61 relevant to the uniqueness of xml:ids are taken (copying,
62 splitting, merging, deletion, undo, etc.)</li>
63 <li>abstract methods that are called by the implementation of the
64 previous hooks</li></ul>
67 class SFX2_DLLPUBLIC Metadatable
: private boost::noncopyable
71 Metadatable() : m_pReg(0) {}
73 // destructor calls RemoveMetadataReference
74 virtual ~Metadatable();
76 // for MetadatableMixin ----------------------------------------------
78 ::com::sun::star::beans::StringPair
GetMetadataReference() const;
79 void SetMetadataReference(
80 const ::com::sun::star::beans::StringPair
& i_rReference
);
81 void EnsureMetadataReference();
83 // hooks -------------------------------------------------------------
86 void RemoveMetadataReference();
88 /** register this as a copy of i_rSource */
89 void RegisterAsCopyOf(Metadatable
const & i_rSource
,
90 const bool i_bCopyPrecedesSource
= false);
92 /** create an Undo Metadatable, which remembers this' reference */
93 ::boost::shared_ptr
<MetadatableUndo
> CreateUndo() const;
94 ::boost::shared_ptr
<MetadatableUndo
> CreateUndoForDelete();
96 /** restore this from Undo Metadatable */
97 void RestoreMetadata(::boost::shared_ptr
<MetadatableUndo
> const& i_pUndo
);
99 /** merge this and i_rOther into this */
100 void JoinMetadatable(Metadatable
const & i_rOther
,
101 const bool i_isMergedEmpty
, const bool i_isOtherEmpty
);
103 // abstract methods --------------------------------------------------
105 /** get the registry from the SwDoc */
106 virtual ::sfx2::IXmlIdRegistry
& GetRegistry() = 0;
108 /** is this in a clipboard document? */
109 virtual bool IsInClipboard() const = 0;
111 /** is this in undo array? */
112 virtual bool IsInUndo() const = 0;
114 /** which stream is this in? true: content.xml; false: styles.xml */
115 virtual bool IsInContent() const = 0;
117 /** create XMetadatable from this.
118 note: if IsInUndo or IsInClipboard return true,
119 MakeUnoObject <em>must not</em> be called!
121 virtual ::com::sun::star::uno::Reference
<
122 ::com::sun::star::rdf::XMetadatable
> MakeUnoObject() = 0;
125 friend class MetadatableClipboard
;
126 friend class MetadatableUndo
;
128 // note that Reg may be a XmlIdRegistryDocument or a XmlIdRegistryClipboard
129 XmlIdRegistry
* m_pReg
; // null => no XmlId
133 /** base class for UNO objects that implement <type>XMetadatable</type>.
135 <p>An instance of this base class is associated with an instance of
136 <type>Metadatable</type>.</p>
138 class SFX2_DLLPUBLIC MetadatableMixin
:
139 public ::cppu::WeakImplHelper1
<
140 ::com::sun::star::rdf::XMetadatable
>
144 MetadatableMixin() {};
146 virtual ~MetadatableMixin() {}
148 // ::com::sun::star::rdf::XNode:
149 virtual OUString SAL_CALL
getStringValue()
150 throw (::com::sun::star::uno::RuntimeException
);
152 // ::com::sun::star::rdf::XURI:
153 virtual OUString SAL_CALL
getLocalName()
154 throw (::com::sun::star::uno::RuntimeException
);
155 virtual OUString SAL_CALL
getNamespace()
156 throw (::com::sun::star::uno::RuntimeException
);
158 // ::com::sun::star::rdf::XMetadatable:
159 virtual ::com::sun::star::beans::StringPair SAL_CALL
getMetadataReference()
160 throw (::com::sun::star::uno::RuntimeException
);
161 virtual void SAL_CALL
setMetadataReference(
162 const ::com::sun::star::beans::StringPair
& i_rReference
)
163 throw (::com::sun::star::uno::RuntimeException
,
164 ::com::sun::star::lang::IllegalArgumentException
);
165 virtual void SAL_CALL
ensureMetadataReference()
166 throw (::com::sun::star::uno::RuntimeException
);
169 /// get the core object corresponding to this UNO object.
170 virtual Metadatable
* GetCoreObject() = 0;
171 /// get the <type>XModel</type> for the document
172 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XModel
>
179 #endif // METADATABLE_HXX
181 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */