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 .
20 #ifndef INCLUDED_UCBHELPER_CONTENTHELPER_HXX
21 #define INCLUDED_UCBHELPER_CONTENTHELPER_HXX
23 #include <com/sun/star/beans/XPropertyContainer.hpp>
24 #include <com/sun/star/beans/XPropertiesChangeNotifier.hpp>
25 #include <com/sun/star/ucb/XCommandProcessor.hpp>
26 #include <com/sun/star/ucb/XContent.hpp>
27 #include <com/sun/star/beans/XPropertySetInfoChangeNotifier.hpp>
28 #include <com/sun/star/ucb/XCommandInfoChangeNotifier.hpp>
29 #include <com/sun/star/container/XChild.hpp>
30 #include <com/sun/star/lang/XTypeProvider.hpp>
31 #include <com/sun/star/lang/XServiceInfo.hpp>
32 #include <com/sun/star/lang/XComponent.hpp>
33 #include <cppuhelper/weak.hxx>
35 #include <rtl/ref.hxx>
36 #include <ucbhelper/ucbhelperdllapi.h>
39 namespace com::sun::star::ucb
{
41 class XCommandEnvironment
;
43 class XPersistentPropertySet
;
46 namespace com::sun::star::beans
{
48 class XPropertySetInfo
;
51 namespace com::sun::star::uno
{ class XComponentContext
; }
53 namespace ucbhelper_impl
{ struct ContentImplHelper_Impl
; }
59 class ContentProviderImplHelper
;
62 * This is an abstract base class for implementations of the service
63 * com.sun.star.ucb.Content. Implementations derived from this class are
64 * objects provided by implementations derived from
65 * class ucb::ContentProviderImplHelper.
67 * Features of the base class implementation:
68 * - standard interfaces ( XInterface, XTypeProvider, XServiceInfo )
69 * - all required interfaces for service css::ucb::Content
70 * - all required listener containers
71 * ( XComponent, XPropertiesChangeNotifier, XPropertySetInfoChangeNotifier,
72 * XCommandInfoChangeNotifier )
73 * - XPropertyContainer implementation ( persistence is implemented using
74 * service com.sun.star.ucb.Store )
75 * - complete XPropertySetInfo implementation ( including Additional Core
76 * Properties supplied via XPropertyContainer interface )
77 * -> protected method: getPropertySetInfo
78 * - complete XCommandInfo implementation
79 * -> protected method: getCommandInfo
81 class UCBHELPER_DLLPUBLIC ContentImplHelper
:
82 public cppu::OWeakObject
,
83 public css::lang::XTypeProvider
,
84 public css::lang::XServiceInfo
,
85 public css::lang::XComponent
,
86 public css::ucb::XContent
,
87 public css::ucb::XCommandProcessor
,
88 public css::beans::XPropertiesChangeNotifier
,
89 public css::beans::XPropertyContainer
,
90 public css::beans::XPropertySetInfoChangeNotifier
,
91 public css::ucb::XCommandInfoChangeNotifier
,
92 public css::container::XChild
94 friend class PropertySetInfo
;
95 friend class CommandProcessorInfo
;
97 std::unique_ptr
<ucbhelper_impl::ContentImplHelper_Impl
> m_pImpl
;
101 css::uno::Reference
< css::uno::XComponentContext
>
103 css::uno::Reference
< css::ucb::XContentIdentifier
>
105 rtl::Reference
< ContentProviderImplHelper
>
107 sal_uInt32 m_nCommandId
;
111 * Your implementation of this method must return a sequence containing
112 * the meta data of the properties supported by the content.
113 * Note: If you wish to provide your own implementation of the interface
114 * XPropertyContainer ( completely override addContent and removeContent
115 * implementation of this base class in this case ), you can supply the
116 * meta data for your Additional Core Properties here to get a fully
117 * featured getPropertySetInfo method ( see below ).
119 * @param xEnv is an environment to use for example, for interactions.
120 * @return a sequence containing the property meta data.
123 virtual css::uno::Sequence
< css::beans::Property
>
124 getProperties( const css::uno::Reference
< css::ucb::XCommandEnvironment
> & xEnv
) = 0;
127 * Your implementation of this method must return a sequence containing
128 * the meta data of the commands supported by the content.
130 * @param xEnv is an environment to use for example, for interactions.
131 * @return a sequence containing the command meta data.
134 virtual css::uno::Sequence
< css::ucb::CommandInfo
>
135 getCommands( const css::uno::Reference
< css::ucb::XCommandEnvironment
> & xEnv
) = 0;
138 * The implementation of this method shall return the URL of the parent
141 * @return the URL of the parent content or an empty string.
142 * Note that not all contents must have one parent. There may
143 * be contents with no parent. In that case an empty string must
144 * be returned. If your content has more than one parent you may
145 * return the URL of one "preferred" parent or an empty string.
147 UCBHELPER_DLLPRIVATE
virtual OUString
getParentURL() = 0;
151 * This method returns complete meta data for the properties ( including
152 * Additional Core Properties supplied via XPropertyContainer interface )
153 * supported by the content. To implement the required command
154 * "getPropertySetInfo" simply return the return value of this method.
156 * @param xEnv is an environment to use for example, for interactions.
157 * @param bCache indicates, whether the implementation should use
158 * cached data, if exist.
159 * @return an XPropertySetInfo implementation object containing meta data
160 * for the properties supported by this content.
162 css::uno::Reference
< css::beans::XPropertySetInfo
>
163 getPropertySetInfo( const css::uno::Reference
< css::ucb::XCommandEnvironment
> & xEnv
,
164 bool bCache
= true );
167 * This method returns complete meta data for the commands supported by
168 * the content. To implement the required command "getCommandInfo" simply
169 * return the return value of this method.
171 * @param xEnv is an environment to use for example, for interactions.
172 * @param bCache indicates, whether the implementation should use
173 * cached data, if exist.
174 * @return an XCommandInfo implementation object containing meta data
175 * for the commands supported by this content.
177 css::uno::Reference
< css::ucb::XCommandInfo
>
178 getCommandInfo( const css::uno::Reference
< css::ucb::XCommandEnvironment
> & xEnv
,
179 bool bCache
= true );
182 * This method can be used to propagate changes of property values.
184 * @param evt is a sequence of property change events.
186 void notifyPropertiesChange(
187 const css::uno::Sequence
< css::beans::PropertyChangeEvent
>& evt
) const;
190 * This method can be used to propagate changes of the propertyset
191 * info of your content (i.e. this happens if a new property is added
192 * to your content via its XPropertyContainer interface). This base class
193 * automatically generates events when the propertyset info changes. If
194 * you provide your own implementations of addproperty and removeProperty,
195 * then you must call "notifyPropertySetInfoChange" by yourself.
197 * @param evt is a sequence of property change events.
199 void notifyPropertySetInfoChange(
200 const css::beans::PropertySetInfoChangeEvent
& evt
) const;
203 * This method can be used to propagate content events.
205 * @param evt is a sequence of content events.
207 void notifyContentEvent(
208 const css::ucb::ContentEvent
& evt
) const;
211 * Use this method to announce the insertion of this content at
212 * the end of your implementation of the command "insert". The
213 * implementation of is method propagates a ContentEvent( INSERTED ).
218 * Use this method to announce the destruction of this content at
219 * the end of your implementation of the command "delete". The
220 * implementation of is method propagates a ContentEvent( DELETED )
221 * and a ContentEvent( REMOVED ) at the parent of the deleted content,
222 * if a parent exists.
227 * Use this method to change the identity of a content. The implementation
228 * of this method will replace the content identifier of the content and
229 * propagate the appropriate ContentEvent( EXCHANGED ).
231 * @param rNewId is the new content identifier for the content.
232 * @return a success indicator.
234 bool exchange( const css::uno::Reference
< css::ucb::XContentIdentifier
>& rNewId
);
237 * Use this method to get access to the Additional Core Properties of
238 * the content ( added using content's XPropertyContainer interface ).
239 * If you supply your own XPropertyContainer implementation, this method
240 * will always return an empty propertyset.
242 * @param bCreate indicates whether a new propertyset shall be created
243 * if it does not exist.
244 * @return the implementation of the service
245 * com.sun.star.ucb.PersistentPropertySet.
247 css::uno::Reference
< css::ucb::XPersistentPropertySet
>
248 getAdditionalPropertySet( bool bCreate
);
251 * This method renames the propertyset containing the Additional Core
252 * Properties of the content.
254 * @param rOldKey is the old key of the propertyset.
255 * @param rNewKey is the new key for the propertyset.
256 * @return True, if the operation succeeded - False, otherwise.
258 bool renameAdditionalPropertySet( const OUString
& rOldKey
,
259 const OUString
& rNewKey
);
262 * This method copies the propertyset containing the Additional Core
263 * Properties of the content.
265 * @param rSourceKey is the key of the source propertyset.
266 * @param rTargetKey is the key of the target propertyset.
267 * @return True, if the operation succeeded - False, otherwise.
269 bool copyAdditionalPropertySet( const OUString
& rSourceKey
,
270 const OUString
& rTargetKey
);
273 * This method removes the propertyset containing the Additional Core
274 * Properties of the content.
276 * Propertysets for children described by rOldKey are removed too.
278 * @return True, if the operation succeeded - False, otherwise.
280 bool removeAdditionalPropertySet();
286 * Note that the implementation of this ctor registers itself at its
287 * content provider. The provider implementation inserts the content
288 * in a hash map. So it easily can be found and reused when the provider
289 * is asked for a content.
291 * @param rxContext is a Service Manager.
292 * @param rxProvider is the provider for the content.
293 * @param Identifier is the content identifier for the content.
296 css::uno::Reference
< css::uno::XComponentContext
> xContext
,
297 rtl::Reference
< ContentProviderImplHelper
> xProvider
,
298 css::uno::Reference
< css::ucb::XContentIdentifier
> Identifier
);
303 * Note that the implementation of this dtor deregisters itself from its
304 * content provider. The provider implementation removes the content
307 virtual ~ContentImplHelper() override
;
310 virtual css::uno::Any SAL_CALL
queryInterface( const css::uno::Type
& rType
) override
;
311 virtual void SAL_CALL
acquire() noexcept override
312 { cppu::OWeakObject::acquire(); }
313 virtual void SAL_CALL
release() noexcept override
;
316 virtual css::uno::Sequence
< sal_Int8
> SAL_CALL
317 getImplementationId() override
;
318 virtual css::uno::Sequence
< css::uno::Type
> SAL_CALL
322 virtual OUString SAL_CALL
323 getImplementationName() override
= 0;
324 virtual sal_Bool SAL_CALL
325 supportsService( const OUString
& ServiceName
) override
;
326 virtual css::uno::Sequence
< OUString
> SAL_CALL
327 getSupportedServiceNames() override
= 0;
330 virtual void SAL_CALL
332 virtual void SAL_CALL
333 addEventListener( const css::uno::Reference
< css::lang::XEventListener
>& Listener
) override
;
334 virtual void SAL_CALL
335 removeEventListener( const css::uno::Reference
< css::lang::XEventListener
>& Listener
) override
;
338 virtual css::uno::Reference
< css::ucb::XContentIdentifier
> SAL_CALL
339 getIdentifier() override
;
340 virtual OUString SAL_CALL
341 getContentType() override
= 0;
342 virtual void SAL_CALL
343 addContentEventListener(
344 const css::uno::Reference
< css::ucb::XContentEventListener
>& Listener
) override
;
345 virtual void SAL_CALL
346 removeContentEventListener(
347 const css::uno::Reference
< css::ucb::XContentEventListener
>& Listener
) override
;
350 virtual sal_Int32 SAL_CALL
351 createCommandIdentifier() override
;
352 virtual css::uno::Any SAL_CALL
353 execute( const css::ucb::Command
& aCommand
,
355 const css::uno::Reference
< css::ucb::XCommandEnvironment
>& Environment
) override
= 0;
356 virtual void SAL_CALL
357 abort( sal_Int32 CommandId
) override
= 0;
359 // XPropertiesChangeNotifier
360 virtual void SAL_CALL
361 addPropertiesChangeListener(
362 const css::uno::Sequence
< OUString
>& PropertyNames
,
363 const css::uno::Reference
< css::beans::XPropertiesChangeListener
>& Listener
) override
;
364 virtual void SAL_CALL
365 removePropertiesChangeListener(
366 const css::uno::Sequence
< OUString
>& PropertyNames
,
367 const css::uno::Reference
< css::beans::XPropertiesChangeListener
>& Listener
) override
;
369 // XCommandInfoChangeNotifier
370 virtual void SAL_CALL
371 addCommandInfoChangeListener(
372 const css::uno::Reference
< css::ucb::XCommandInfoChangeListener
>& Listener
) override
;
373 virtual void SAL_CALL
374 removeCommandInfoChangeListener(
375 const css::uno::Reference
< css::ucb::XCommandInfoChangeListener
>& Listener
) override
;
377 // XPropertyContainer
380 * This method adds a property to the content according to the interface
381 * specification. The properties will be stored using the service
382 * com.sun.star.ucb.Store.
384 * Note: You may provide your own implementation of this method, for
385 * instance, if your data source supports adding/removing of properties.
386 * Don't forget to return the meta data for these properties in your
387 * implementation of getPropertyInfoTable.
389 virtual void SAL_CALL
390 addProperty( const OUString
& Name
,
391 sal_Int16 Attributes
,
392 const css::uno::Any
& DefaultValue
) override
;
395 * This method removes a property from the content according to the
396 * interface specification. The properties will be stored using the
397 * service com.sun.star.ucb.Store.
399 * Note: You may provide your own implementation of this method, for
400 * instance, if your data source supports adding/removing of properties.
401 * Don't forget to return the meta data for these properties in your
402 * implementation of getPropertyInfoTable.
404 virtual void SAL_CALL
405 removeProperty( const OUString
& Name
) override
;
407 // XPropertySetInfoChangeNotifier
408 virtual void SAL_CALL
409 addPropertySetInfoChangeListener(
410 const css::uno::Reference
< css::beans::XPropertySetInfoChangeListener
>& Listener
) override
;
411 virtual void SAL_CALL
412 removePropertySetInfoChangeListener(
413 const css::uno::Reference
< css::beans::XPropertySetInfoChangeListener
>& Listener
) override
;
418 * This method returns the content representing the parent of a content,
419 * if such a parent exists. The implementation of this method uses your
420 * implementation of getParentURL.
422 virtual css::uno::Reference
< css::uno::XInterface
> SAL_CALL
423 getParent() override
;
426 * The implementation of this method always throws a NoSupportException.
428 virtual void SAL_CALL
429 setParent( const css::uno::Reference
< css::uno::XInterface
>& Parent
) override
;
432 // Non-interface methods.
436 * This method returns the provider of the content.
438 * @return the provider of the content.
440 const rtl::Reference
< ContentProviderImplHelper
>& getProvider() const
441 { return m_xProvider
; }
444 } // namespace ucbhelper
446 #endif /* ! INCLUDED_UCBHELPER_CONTENTHELPER_HXX */
448 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */