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>
42 namespace com
{ namespace sun
{ namespace star
{ namespace ucb
{
44 class XCommandEnvironment
;
46 class XPersistentPropertySet
;
49 namespace com
{ namespace sun
{ namespace star
{ namespace beans
{
51 class XPropertySetInfo
;
54 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 com::sun::star::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 Additioanl 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 com::sun::star::lang::XTypeProvider
,
86 public com::sun::star::lang::XServiceInfo
,
87 public com::sun::star::lang::XComponent
,
88 public com::sun::star::ucb::XContent
,
89 public com::sun::star::ucb::XCommandProcessor
,
90 public com::sun::star::beans::XPropertiesChangeNotifier
,
91 public com::sun::star::beans::XPropertyContainer
,
92 public com::sun::star::beans::XPropertySetInfoChangeNotifier
,
93 public com::sun::star::ucb::XCommandInfoChangeNotifier
,
94 public com::sun::star::container::XChild
96 friend class PropertySetInfo
;
97 friend class CommandProcessorInfo
;
99 ucbhelper_impl::ContentImplHelper_Impl
* m_pImpl
;
103 com::sun::star::uno::Reference
< com::sun::star::uno::XComponentContext
>
105 com::sun::star::uno::Reference
< com::sun::star::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 com::sun::star::uno::Sequence
< com::sun::star::beans::Property
>
126 getProperties( const com::sun::star::uno::Reference
<
127 com::sun::star::ucb::XCommandEnvironment
> & xEnv
) = 0;
130 * Your implementation of this method must return a sequence containing
131 * the meta data of the commands supported by the content.
133 * @param xEnv is an environment to use for example, for interactions.
134 * @return a sequence containing the command meta data.
137 virtual com::sun::star::uno::Sequence
< com::sun::star::ucb::CommandInfo
>
138 getCommands( const com::sun::star::uno::Reference
<
139 com::sun::star::ucb::XCommandEnvironment
> & xEnv
) = 0;
142 * The implementation of this method shall return the URL of the parent
145 * @return the URL of the parent content or an empty string.
146 * Note that not all contents must have one parent. There may
147 * be contents with no parent. In that case an empty string must
148 * be returned. If your content has more than one parent you may
149 * return the URL of one "preferred" parent or an empty string.
151 UCBHELPER_DLLPRIVATE
virtual OUString
getParentURL() = 0;
155 * This method returns complete meta data for the properties ( including
156 * Additional Core Properties supplied via XPropertyContainer interface )
157 * supported by the content. To implement the required command
158 * "getPropertySetInfo" simply return the return value of this method.
160 * @param xEnv is an environment to use for example, for interactions.
161 * @param bCache indicates, whether the implementation should use
162 * cached data, if exist.
163 * @return an XPropertySetInfo implementation object containing meta data
164 * for the properties supported by this content.
166 com::sun::star::uno::Reference
< com::sun::star::beans::XPropertySetInfo
>
167 getPropertySetInfo( const com::sun::star::uno::Reference
<
168 com::sun::star::ucb::XCommandEnvironment
> & xEnv
,
169 bool bCache
= true );
172 * This method returns complete meta data for the commands supported by
173 * the content. To implement the required command "getCommandInfo" simply
174 * return the return value of this method.
176 * @param xEnv is an environment to use for example, for interactions.
177 * @param bCache indicates, whether the implementation should use
178 * cached data, if exist.
179 * @return an XCommandInfo implementation object containing meta data
180 * for the commands supported by this content.
182 com::sun::star::uno::Reference
< com::sun::star::ucb::XCommandInfo
>
183 getCommandInfo( const com::sun::star::uno::Reference
<
184 com::sun::star::ucb::XCommandEnvironment
> & xEnv
,
185 bool bCache
= true );
188 * This method can be used to propagate changes of property values.
190 * @param evt is a sequence of property change events.
192 void notifyPropertiesChange(
193 const com::sun::star::uno::Sequence
<
194 com::sun::star::beans::PropertyChangeEvent
>& evt
) const;
197 * This method can be used to propagate changes of the propertyset
198 * info of your content (i.e. this happens if a new property is added
199 * to your content via its XPropertyContainer interface). This base class
200 * automatically generates events when the propertyset info changes. If
201 * you provide your own implementations of addproperty and removeProperty,
202 * then you must call "notifyPropertySetInfoChange" by yourself.
204 * @param evt is a sequence of property change events.
206 void notifyPropertySetInfoChange(
207 const com::sun::star::beans::PropertySetInfoChangeEvent
& evt
) const;
210 * This method can be used to propagate content events.
212 * @param evt is a sequence of content events.
214 void notifyContentEvent(
215 const com::sun::star::ucb::ContentEvent
& evt
) const;
218 * Use this method to announce the insertion of this content at
219 * the end of your implementation of the command "insert". The
220 * implementation of is method propagates a ContentEvent( INSERTED ).
225 * Use this method to announce the destruction of this content at
226 * the end of your implementation of the command "delete". The
227 * implementation of is method propagates a ContentEvent( DELETED )
228 * and a ContentEvent( REMOVED ) at the parent of the deleted content,
229 * if a parent exists.
234 * Use this method to change the identity of a content. The implementation
235 * of this method will replace the content identifier of the content and
236 * propagate the appropriate ContentEvent( EXCHANGED ).
238 * @param rNewId is the new content identifier for the contant.
239 * @return a success indicator.
241 bool exchange( const com::sun::star::uno::Reference
<
242 com::sun::star::ucb::XContentIdentifier
>& rNewId
);
245 * Use this method to get access to the Additional Core Properties of
246 * the content ( added using content's XPropertyContainer interface ).
247 * If you supply your own XPropertyContainer implementation, this method
248 * will always return an empty propertyset.
250 * @param bCreate indicates whether a new propertyset shall be created
251 * if it does not exist.
252 * @return the implementation of the service
253 * com.sun.star.ucb.PersistentPropertySet.
255 com::sun::star::uno::Reference
<
256 com::sun::star::ucb::XPersistentPropertySet
>
257 getAdditionalPropertySet( bool bCreate
);
260 * This method renames the propertyset containing the Additional Core
261 * Properties of the content.
263 * @param rOldKey is the old key of the propertyset.
264 * @param rNewKey is the new key for the propertyset.
265 * @param bRecursive is a flag indicating whether propertysets for
266 * children described by rOldKey shall be renamed too.
267 * @return True, if the operation succeeded - False, otherwise.
269 bool renameAdditionalPropertySet( const OUString
& rOldKey
,
270 const OUString
& rNewKey
,
274 * This method copies the propertyset containing the Additional Core
275 * Properties of the content.
277 * @param rSourceKey is the key of the source propertyset.
278 * @param rTargetKey is the key of the target propertyset.
279 * @param bRecursive is a flag indicating whether propertysets for
280 * children described by rSourceKey shall be copied too.
281 * @return True, if the operation succeeded - False, otherwise.
283 bool copyAdditionalPropertySet( const OUString
& rSourceKey
,
284 const OUString
& rTargetKey
,
288 * This method removes the propertyset containing the Additional Core
289 * Properties of the content.
291 * @param bRecursive is a flag indicating whether propertysets for
292 * children described by rOldKey shall be removed too.
293 * @return True, if the operation succeeded - False, otherwise.
295 bool removeAdditionalPropertySet( bool bRecursive
);
301 * Note that the implementation of this ctor registers itself at its
302 * content provider. The provider implementation inserts the content
303 * in a hash map. So it easily can be found and reused when the provider
304 * is asked for a content.
306 * @param rxContext is a Service Manager.
307 * @param rxProvider is the provider for the content.
308 * @param Identifier is the content identifier for the content.
311 const com::sun::star::uno::Reference
<
312 com::sun::star::uno::XComponentContext
>& rxContext
,
313 const rtl::Reference
< ContentProviderImplHelper
>& rxProvider
,
314 const com::sun::star::uno::Reference
<
315 com::sun::star::ucb::XContentIdentifier
>& Identifier
);
320 * Note that the implementation of this dtor deregisters itself from its
321 * content provider. The provider implementation removes the content
324 virtual ~ContentImplHelper();
327 virtual css::uno::Any SAL_CALL
queryInterface( const css::uno::Type
& rType
)
328 throw( css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
329 virtual void SAL_CALL
acquire()
330 throw() SAL_OVERRIDE
;
331 virtual void SAL_CALL
release()
332 throw() SAL_OVERRIDE
;
335 virtual com::sun::star::uno::Sequence
< sal_Int8
> SAL_CALL
336 getImplementationId()
337 throw( com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
338 virtual com::sun::star::uno::Sequence
< com::sun::star::uno::Type
> SAL_CALL
340 throw( com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
343 virtual OUString SAL_CALL
344 getImplementationName()
345 throw( ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
= 0;
346 virtual sal_Bool SAL_CALL
347 supportsService( const OUString
& ServiceName
)
348 throw( ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
349 virtual ::com::sun::star::uno::Sequence
< OUString
> SAL_CALL
350 getSupportedServiceNames()
351 throw( ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
= 0;
354 virtual void SAL_CALL
356 throw( com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
357 virtual void SAL_CALL
358 addEventListener( const com::sun::star::uno::Reference
<
359 com::sun::star::lang::XEventListener
>& Listener
)
360 throw( com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
361 virtual void SAL_CALL
362 removeEventListener( const com::sun::star::uno::Reference
<
363 com::sun::star::lang::XEventListener
>& Listener
)
364 throw( com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
367 virtual com::sun::star::uno::Reference
<
368 com::sun::star::ucb::XContentIdentifier
> SAL_CALL
370 throw( com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
371 virtual OUString SAL_CALL
373 throw( com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
= 0;
374 virtual void SAL_CALL
375 addContentEventListener(
376 const com::sun::star::uno::Reference
<
377 com::sun::star::ucb::XContentEventListener
>& Listener
)
378 throw( com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
379 virtual void SAL_CALL
380 removeContentEventListener(
381 const com::sun::star::uno::Reference
<
382 com::sun::star::ucb::XContentEventListener
>& Listener
)
383 throw( com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
386 virtual sal_Int32 SAL_CALL
387 createCommandIdentifier()
388 throw( com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
389 virtual com::sun::star::uno::Any SAL_CALL
390 execute( const com::sun::star::ucb::Command
& aCommand
,
392 const com::sun::star::uno::Reference
<
393 com::sun::star::ucb::XCommandEnvironment
>& Environment
)
394 throw( com::sun::star::uno::Exception
,
395 com::sun::star::ucb::CommandAbortedException
,
396 com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
= 0;
397 virtual void SAL_CALL
398 abort( sal_Int32 CommandId
)
399 throw( com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
= 0;
401 // XPropertiesChangeNotifier
402 virtual void SAL_CALL
403 addPropertiesChangeListener(
404 const com::sun::star::uno::Sequence
< OUString
>& PropertyNames
,
405 const com::sun::star::uno::Reference
<
406 com::sun::star::beans::XPropertiesChangeListener
>& Listener
)
407 throw( com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
408 virtual void SAL_CALL
409 removePropertiesChangeListener(
410 const com::sun::star::uno::Sequence
< OUString
>& PropertyNames
,
411 const com::sun::star::uno::Reference
<
412 com::sun::star::beans::XPropertiesChangeListener
>& Listener
)
413 throw( com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
415 // XCommandInfoChangeNotifier
416 virtual void SAL_CALL
417 addCommandInfoChangeListener(
418 const com::sun::star::uno::Reference
<
419 com::sun::star::ucb::XCommandInfoChangeListener
>& Listener
)
420 throw( com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
421 virtual void SAL_CALL
422 removeCommandInfoChangeListener(
423 const com::sun::star::uno::Reference
<
424 ::com::sun::star::ucb::XCommandInfoChangeListener
>& Listener
)
425 throw( com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
427 // XPropertyContainer
430 * This method adds a property to the content according to the interface
431 * specification. The properties will be stored using the service
432 * com.sun.star.ucb.Store.
434 * Note: You may provide your own implementation of this method, for
435 * instance, if your data source supports adding/removing of properties.
436 * Don't forget to return the meta data for these properties in your
437 * implementation of getPropertyInfoTable.
439 virtual void SAL_CALL
440 addProperty( const OUString
& Name
,
441 sal_Int16 Attributes
,
442 const com::sun::star::uno::Any
& DefaultValue
)
443 throw( com::sun::star::beans::PropertyExistException
,
444 com::sun::star::beans::IllegalTypeException
,
445 com::sun::star::lang::IllegalArgumentException
,
446 com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
449 * This method removes a property from the content according to the
450 * interface specification. The properties will be stored using the
451 * service com.sun.star.ucb.Store.
453 * Note: You may provide your own implementation of this method, for
454 * instance, if your data source supports adding/removing of properties.
455 * Don't forget to return the meta data for these properties in your
456 * implementation of getPropertyInfoTable.
458 virtual void SAL_CALL
459 removeProperty( const OUString
& Name
)
460 throw( com::sun::star::beans::UnknownPropertyException
,
461 com::sun::star::beans::NotRemoveableException
,
462 com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
464 // XPropertySetInfoChangeNotifier
465 virtual void SAL_CALL
466 addPropertySetInfoChangeListener(
467 const com::sun::star::uno::Reference
<
468 com::sun::star::beans::XPropertySetInfoChangeListener
>& Listener
)
469 throw( com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
470 virtual void SAL_CALL
471 removePropertySetInfoChangeListener(
472 const com::sun::star::uno::Reference
<
473 com::sun::star::beans::XPropertySetInfoChangeListener
>& Listener
)
474 throw( com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
479 * This method returns the content representing the parent of a content,
480 * if such a parent exists. The implementation of this method uses your
481 * implementation of getParentURL.
483 virtual com::sun::star::uno::Reference
<
484 com::sun::star::uno::XInterface
> SAL_CALL
486 throw( com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
489 * The implementation of this method always throws a NoSupportException.
491 virtual void SAL_CALL
492 setParent( const com::sun::star::uno::Reference
<
493 com::sun::star::uno::XInterface
>& Parent
)
494 throw( com::sun::star::lang::NoSupportException
,
495 com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
498 // Non-interface methods.
502 * This method returns the provider of the content.
504 * @return the provider of the content.
506 const rtl::Reference
< ContentProviderImplHelper
>& getProvider() const
507 { return m_xProvider
; }
510 } // namespace ucbhelper
512 #endif /* ! INCLUDED_UCBHELPER_CONTENTHELPER_HXX */
514 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */