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/XMultiServiceFactory.hpp>
31 #include <com/sun/star/lang/XTypeProvider.hpp>
32 #include <com/sun/star/lang/XServiceInfo.hpp>
33 #include <com/sun/star/lang/XComponent.hpp>
34 #include <com/sun/star/ucb/CommandAbortedException.hpp>
35 #include <cppuhelper/weak.hxx>
37 #include <osl/mutex.hxx>
38 #include <rtl/ref.hxx>
39 #include <ucbhelper/macros.hxx>
40 #include <ucbhelper/ucbhelperdllapi.h>
43 namespace com
{ namespace sun
{ namespace star
{ namespace ucb
{
45 class XCommandEnvironment
;
47 class XPersistentPropertySet
;
50 namespace com
{ namespace sun
{ namespace star
{ namespace beans
{
52 class XPropertySetInfo
;
55 namespace ucbhelper_impl
{ struct ContentImplHelper_Impl
; }
61 class ContentProviderImplHelper
;
64 * This is an abstract base class for implementations of the service
65 * com.sun.star.ucb.Content. Implementations derived from this class are
66 * objects provided by implementations derived from
67 * class ucb::ContentProviderImplHelper.
69 * Features of the base class implementation:
70 * - standard interfaces ( XInterface, XTypeProvider, XServiceInfo )
71 * - all required interfaces for service css::ucb::Content
72 * - all required listener containers
73 * ( XComponent, XPropertiesChangeNotifier, XPropertySetInfoChangeNotifier,
74 * XCommandInfoChangeNotifier )
75 * - XPropertyContainer implementation ( persistence is implemented using
76 * service com.sun.star.ucb.Store )
77 * - complete XPropertySetInfo implementation ( including Additional Core
78 * Properties supplied via XPropertyContainer interface )
79 * -> protected method: getPropertySetInfo
80 * - complete XCommandInfo implementation
81 * -> protected method: getCommandInfo
83 class UCBHELPER_DLLPUBLIC ContentImplHelper
:
84 public cppu::OWeakObject
,
85 public css::lang::XTypeProvider
,
86 public css::lang::XServiceInfo
,
87 public css::lang::XComponent
,
88 public css::ucb::XContent
,
89 public css::ucb::XCommandProcessor
,
90 public css::beans::XPropertiesChangeNotifier
,
91 public css::beans::XPropertyContainer
,
92 public css::beans::XPropertySetInfoChangeNotifier
,
93 public css::ucb::XCommandInfoChangeNotifier
,
94 public css::container::XChild
96 friend class PropertySetInfo
;
97 friend class CommandProcessorInfo
;
99 std::unique_ptr
<ucbhelper_impl::ContentImplHelper_Impl
> m_pImpl
;
103 css::uno::Reference
< css::uno::XComponentContext
>
105 css::uno::Reference
< css::ucb::XContentIdentifier
>
107 rtl::Reference
< ContentProviderImplHelper
>
109 sal_uInt32 m_nCommandId
;
113 * Your implementation of this method must return a sequence containing
114 * the meta data of the properties supported by the content.
115 * Note: If you wish to provide your own implementation of the interface
116 * XPropertyContainer ( completely override addContent and removeContent
117 * implementation of this base class in this case ), you can supply the
118 * meta data for your Additional Core Properties here to get a fully
119 * featured getPropertySetInfo method ( see below ).
121 * @param xEnv is an environment to use for example, for interactions.
122 * @return a sequence containing the property meta data.
125 virtual css::uno::Sequence
< css::beans::Property
>
126 getProperties( const css::uno::Reference
< css::ucb::XCommandEnvironment
> & xEnv
) = 0;
129 * Your implementation of this method must return a sequence containing
130 * the meta data of the commands supported by the content.
132 * @param xEnv is an environment to use for example, for interactions.
133 * @return a sequence containing the command meta data.
136 virtual css::uno::Sequence
< css::ucb::CommandInfo
>
137 getCommands( const css::uno::Reference
< css::ucb::XCommandEnvironment
> & xEnv
) = 0;
140 * The implementation of this method shall return the URL of the parent
143 * @return the URL of the parent content or an empty string.
144 * Note that not all contents must have one parent. There may
145 * be contents with no parent. In that case an empty string must
146 * be returned. If your content has more than one parent you may
147 * return the URL of one "preferred" parent or an empty string.
149 UCBHELPER_DLLPRIVATE
virtual OUString
getParentURL() = 0;
153 * This method returns complete meta data for the properties ( including
154 * Additional Core Properties supplied via XPropertyContainer interface )
155 * supported by the content. To implement the required command
156 * "getPropertySetInfo" simply return the return value of this method.
158 * @param xEnv is an environment to use for example, for interactions.
159 * @param bCache indicates, whether the implementation should use
160 * cached data, if exist.
161 * @return an XPropertySetInfo implementation object containing meta data
162 * for the properties supported by this content.
164 css::uno::Reference
< css::beans::XPropertySetInfo
>
165 getPropertySetInfo( const css::uno::Reference
< css::ucb::XCommandEnvironment
> & xEnv
,
166 bool bCache
= true );
169 * This method returns complete meta data for the commands supported by
170 * the content. To implement the required command "getCommandInfo" simply
171 * return the return value of this method.
173 * @param xEnv is an environment to use for example, for interactions.
174 * @param bCache indicates, whether the implementation should use
175 * cached data, if exist.
176 * @return an XCommandInfo implementation object containing meta data
177 * for the commands supported by this content.
179 css::uno::Reference
< css::ucb::XCommandInfo
>
180 getCommandInfo( const css::uno::Reference
< css::ucb::XCommandEnvironment
> & xEnv
,
181 bool bCache
= true );
184 * This method can be used to propagate changes of property values.
186 * @param evt is a sequence of property change events.
188 void notifyPropertiesChange(
189 const css::uno::Sequence
< css::beans::PropertyChangeEvent
>& evt
) const;
192 * This method can be used to propagate changes of the propertyset
193 * info of your content (i.e. this happens if a new property is added
194 * to your content via its XPropertyContainer interface). This base class
195 * automatically generates events when the propertyset info changes. If
196 * you provide your own implementations of addproperty and removeProperty,
197 * then you must call "notifyPropertySetInfoChange" by yourself.
199 * @param evt is a sequence of property change events.
201 void notifyPropertySetInfoChange(
202 const css::beans::PropertySetInfoChangeEvent
& evt
) const;
205 * This method can be used to propagate content events.
207 * @param evt is a sequence of content events.
209 void notifyContentEvent(
210 const css::ucb::ContentEvent
& evt
) const;
213 * Use this method to announce the insertion of this content at
214 * the end of your implementation of the command "insert". The
215 * implementation of is method propagates a ContentEvent( INSERTED ).
220 * Use this method to announce the destruction of this content at
221 * the end of your implementation of the command "delete". The
222 * implementation of is method propagates a ContentEvent( DELETED )
223 * and a ContentEvent( REMOVED ) at the parent of the deleted content,
224 * if a parent exists.
229 * Use this method to change the identity of a content. The implementation
230 * of this method will replace the content identifier of the content and
231 * propagate the appropriate ContentEvent( EXCHANGED ).
233 * @param rNewId is the new content identifier for the content.
234 * @return a success indicator.
236 bool exchange( const css::uno::Reference
< css::ucb::XContentIdentifier
>& rNewId
);
239 * Use this method to get access to the Additional Core Properties of
240 * the content ( added using content's XPropertyContainer interface ).
241 * If you supply your own XPropertyContainer implementation, this method
242 * will always return an empty propertyset.
244 * @param bCreate indicates whether a new propertyset shall be created
245 * if it does not exist.
246 * @return the implementation of the service
247 * com.sun.star.ucb.PersistentPropertySet.
249 css::uno::Reference
< css::ucb::XPersistentPropertySet
>
250 getAdditionalPropertySet( bool bCreate
);
253 * This method renames the propertyset containing the Additional Core
254 * Properties of the content.
256 * @param rOldKey is the old key of the propertyset.
257 * @param rNewKey is the new key for the propertyset.
258 * @return True, if the operation succeeded - False, otherwise.
260 bool renameAdditionalPropertySet( const OUString
& rOldKey
,
261 const OUString
& rNewKey
);
264 * This method copies the propertyset containing the Additional Core
265 * Properties of the content.
267 * @param rSourceKey is the key of the source propertyset.
268 * @param rTargetKey is the key of the target propertyset.
269 * @return True, if the operation succeeded - False, otherwise.
271 bool copyAdditionalPropertySet( const OUString
& rSourceKey
,
272 const OUString
& rTargetKey
);
275 * This method removes the propertyset containing the Additional Core
276 * Properties of the content.
278 * Propertysets for children described by rOldKey are removed too.
280 * @return True, if the operation succeeded - False, otherwise.
282 bool removeAdditionalPropertySet();
288 * Note that the implementation of this ctor registers itself at its
289 * content provider. The provider implementation inserts the content
290 * in a hash map. So it easily can be found and reused when the provider
291 * is asked for a content.
293 * @param rxContext is a Service Manager.
294 * @param rxProvider is the provider for the content.
295 * @param Identifier is the content identifier for the content.
298 const css::uno::Reference
< css::uno::XComponentContext
>& rxContext
,
299 const rtl::Reference
< ContentProviderImplHelper
>& rxProvider
,
300 const css::uno::Reference
< css::ucb::XContentIdentifier
>& Identifier
);
305 * Note that the implementation of this dtor deregisters itself from its
306 * content provider. The provider implementation removes the content
309 virtual ~ContentImplHelper() override
;
312 virtual css::uno::Any SAL_CALL
queryInterface( const css::uno::Type
& rType
) override
;
313 virtual void SAL_CALL
acquire()
315 virtual void SAL_CALL
release()
319 virtual css::uno::Sequence
< sal_Int8
> SAL_CALL
320 getImplementationId() override
;
321 virtual css::uno::Sequence
< css::uno::Type
> SAL_CALL
325 virtual OUString SAL_CALL
326 getImplementationName() override
= 0;
327 virtual sal_Bool SAL_CALL
328 supportsService( const OUString
& ServiceName
) override
;
329 virtual css::uno::Sequence
< OUString
> SAL_CALL
330 getSupportedServiceNames() override
= 0;
333 virtual void SAL_CALL
335 virtual void SAL_CALL
336 addEventListener( const css::uno::Reference
< css::lang::XEventListener
>& Listener
) override
;
337 virtual void SAL_CALL
338 removeEventListener( const css::uno::Reference
< css::lang::XEventListener
>& Listener
) override
;
341 virtual css::uno::Reference
< css::ucb::XContentIdentifier
> SAL_CALL
342 getIdentifier() override
;
343 virtual OUString SAL_CALL
344 getContentType() override
= 0;
345 virtual void SAL_CALL
346 addContentEventListener(
347 const css::uno::Reference
< css::ucb::XContentEventListener
>& Listener
) override
;
348 virtual void SAL_CALL
349 removeContentEventListener(
350 const css::uno::Reference
< css::ucb::XContentEventListener
>& Listener
) override
;
353 virtual sal_Int32 SAL_CALL
354 createCommandIdentifier() override
;
355 virtual css::uno::Any SAL_CALL
356 execute( const css::ucb::Command
& aCommand
,
358 const css::uno::Reference
< css::ucb::XCommandEnvironment
>& Environment
) override
= 0;
359 virtual void SAL_CALL
360 abort( sal_Int32 CommandId
) override
= 0;
362 // XPropertiesChangeNotifier
363 virtual void SAL_CALL
364 addPropertiesChangeListener(
365 const css::uno::Sequence
< OUString
>& PropertyNames
,
366 const css::uno::Reference
< css::beans::XPropertiesChangeListener
>& Listener
) override
;
367 virtual void SAL_CALL
368 removePropertiesChangeListener(
369 const css::uno::Sequence
< OUString
>& PropertyNames
,
370 const css::uno::Reference
< css::beans::XPropertiesChangeListener
>& Listener
) override
;
372 // XCommandInfoChangeNotifier
373 virtual void SAL_CALL
374 addCommandInfoChangeListener(
375 const css::uno::Reference
< css::ucb::XCommandInfoChangeListener
>& Listener
) override
;
376 virtual void SAL_CALL
377 removeCommandInfoChangeListener(
378 const css::uno::Reference
< css::ucb::XCommandInfoChangeListener
>& Listener
) override
;
380 // XPropertyContainer
383 * This method adds a property to the content according to the interface
384 * specification. The properties will be stored using the service
385 * com.sun.star.ucb.Store.
387 * Note: You may provide your own implementation of this method, for
388 * instance, if your data source supports adding/removing of properties.
389 * Don't forget to return the meta data for these properties in your
390 * implementation of getPropertyInfoTable.
392 virtual void SAL_CALL
393 addProperty( const OUString
& Name
,
394 sal_Int16 Attributes
,
395 const css::uno::Any
& DefaultValue
) override
;
398 * This method removes a property from the content according to the
399 * interface specification. The properties will be stored using the
400 * service com.sun.star.ucb.Store.
402 * Note: You may provide your own implementation of this method, for
403 * instance, if your data source supports adding/removing of properties.
404 * Don't forget to return the meta data for these properties in your
405 * implementation of getPropertyInfoTable.
407 virtual void SAL_CALL
408 removeProperty( const OUString
& Name
) override
;
410 // XPropertySetInfoChangeNotifier
411 virtual void SAL_CALL
412 addPropertySetInfoChangeListener(
413 const css::uno::Reference
< css::beans::XPropertySetInfoChangeListener
>& Listener
) override
;
414 virtual void SAL_CALL
415 removePropertySetInfoChangeListener(
416 const css::uno::Reference
< css::beans::XPropertySetInfoChangeListener
>& Listener
) override
;
421 * This method returns the content representing the parent of a content,
422 * if such a parent exists. The implementation of this method uses your
423 * implementation of getParentURL.
425 virtual css::uno::Reference
< css::uno::XInterface
> SAL_CALL
426 getParent() override
;
429 * The implementation of this method always throws a NoSupportException.
431 virtual void SAL_CALL
432 setParent( const css::uno::Reference
< css::uno::XInterface
>& Parent
) override
;
435 // Non-interface methods.
439 * This method returns the provider of the content.
441 * @return the provider of the content.
443 const rtl::Reference
< ContentProviderImplHelper
>& getProvider() const
444 { return m_xProvider
; }
447 } // namespace ucbhelper
449 #endif /* ! INCLUDED_UCBHELPER_CONTENTHELPER_HXX */
451 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */