Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #ifndef INCLUDED_UCBHELPER_CONTENTHELPER_HXX
21 : #define INCLUDED_UCBHELPER_CONTENTHELPER_HXX
22 :
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>
36 :
37 : #include <osl/mutex.hxx>
38 : #include <rtl/ref.hxx>
39 : #include <ucbhelper/macros.hxx>
40 : #include <ucbhelper/ucbhelperdllapi.h>
41 :
42 : namespace com { namespace sun { namespace star { namespace ucb {
43 : struct CommandInfo;
44 : class XCommandEnvironment;
45 : class XCommandInfo;
46 : class XPersistentPropertySet;
47 : } } } }
48 :
49 : namespace com { namespace sun { namespace star { namespace beans {
50 : struct Property;
51 : class XPropertySetInfo;
52 : } } } }
53 :
54 : namespace ucbhelper_impl { struct ContentImplHelper_Impl; }
55 :
56 : namespace ucbhelper
57 : {
58 :
59 :
60 :
61 : class ContentProviderImplHelper;
62 :
63 : /**
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.
68 : *
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
82 : */
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
95 : {
96 : friend class PropertySetInfo;
97 : friend class CommandProcessorInfo;
98 :
99 : ucbhelper_impl::ContentImplHelper_Impl* m_pImpl;
100 :
101 : protected:
102 : osl::Mutex m_aMutex;
103 : com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext >
104 : m_xContext;
105 : com::sun::star::uno::Reference< com::sun::star::ucb::XContentIdentifier >
106 : m_xIdentifier;
107 : rtl::Reference< ContentProviderImplHelper >
108 : m_xProvider;
109 : sal_uInt32 m_nCommandId;
110 :
111 : private:
112 : /**
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 ).
120 : *
121 : * @param xEnv is an environment to use for example, for interactions.
122 : * @return a sequence containing the property meta data.
123 : */
124 : UCBHELPER_DLLPRIVATE
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;
128 :
129 : /**
130 : * Your implementation of this method must return a sequence containing
131 : * the meta data of the commands supported by the content.
132 : *
133 : * @param xEnv is an environment to use for example, for interactions.
134 : * @return a sequence containing the command meta data.
135 : */
136 : UCBHELPER_DLLPRIVATE
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;
140 :
141 : /**
142 : * The implementation of this method shall return the URL of the parent
143 : * of your content.
144 : *
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.
150 : */
151 : UCBHELPER_DLLPRIVATE virtual OUString getParentURL() = 0;
152 :
153 : protected:
154 : /**
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.
159 : *
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.
165 : */
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 );
170 :
171 : /**
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.
175 : *
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.
181 : */
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 );
186 :
187 : /**
188 : * This method can be used to propagate changes of property values.
189 : *
190 : * @param evt is a sequence of property change events.
191 : */
192 : void notifyPropertiesChange(
193 : const com::sun::star::uno::Sequence<
194 : com::sun::star::beans::PropertyChangeEvent >& evt ) const;
195 :
196 : /**
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.
203 : *
204 : * @param evt is a sequence of property change events.
205 : */
206 : void notifyPropertySetInfoChange(
207 : const com::sun::star::beans::PropertySetInfoChangeEvent& evt ) const;
208 :
209 : /**
210 : * This method can be used to propagate content events.
211 : *
212 : * @param evt is a sequence of content events.
213 : */
214 : void notifyContentEvent(
215 : const com::sun::star::ucb::ContentEvent& evt ) const;
216 :
217 : /**
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 ).
221 : */
222 : void inserted();
223 :
224 : /**
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.
230 : */
231 : void deleted();
232 :
233 : /**
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 ).
237 : *
238 : * @param rNewId is the new content identifier for the contant.
239 : * @return a success indicator.
240 : */
241 : bool exchange( const com::sun::star::uno::Reference<
242 : com::sun::star::ucb::XContentIdentifier >& rNewId );
243 :
244 : /**
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.
249 : *
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.
254 : */
255 : com::sun::star::uno::Reference<
256 : com::sun::star::ucb::XPersistentPropertySet >
257 : getAdditionalPropertySet( bool bCreate );
258 :
259 : /**
260 : * This method renames the propertyset containing the Additional Core
261 : * Properties of the content.
262 : *
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.
268 : */
269 : bool renameAdditionalPropertySet( const OUString& rOldKey,
270 : const OUString& rNewKey,
271 : bool bRecursive );
272 :
273 : /**
274 : * This method copies the propertyset containing the Additional Core
275 : * Properties of the content.
276 : *
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.
282 : */
283 : bool copyAdditionalPropertySet( const OUString& rSourceKey,
284 : const OUString& rTargetKey,
285 : bool bRecursive );
286 :
287 : /**
288 : * This method removes the propertyset containing the Additional Core
289 : * Properties of the content.
290 : *
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.
294 : */
295 : bool removeAdditionalPropertySet( bool bRecursive );
296 :
297 : public:
298 : /**
299 : * Constructor.
300 : *
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.
305 : *
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.
309 : */
310 : ContentImplHelper(
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 );
316 :
317 : /**
318 : * Destructor.
319 : *
320 : * Note that the implementation of this dtor deregisters itself from its
321 : * content provider. The provider implementation removes the content
322 : * from a hash map.
323 : */
324 : virtual ~ContentImplHelper();
325 :
326 : // XInterface
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;
333 :
334 : // XTypeProvider
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
339 : getTypes()
340 : throw( com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
341 :
342 : // XServiceInfo
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;
352 :
353 : // XComponent
354 : virtual void SAL_CALL
355 : dispose()
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;
365 :
366 : // XContent
367 : virtual com::sun::star::uno::Reference<
368 : com::sun::star::ucb::XContentIdentifier > SAL_CALL
369 : getIdentifier()
370 : throw( com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
371 : virtual OUString SAL_CALL
372 : getContentType()
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;
384 :
385 : // XCommandProcessor
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,
391 : sal_Int32 CommandId,
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;
400 :
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;
414 :
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;
426 :
427 : // XPropertyContainer
428 :
429 : /**
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.
433 : *
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.
438 : */
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;
447 :
448 : /**
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.
452 : *
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.
457 : */
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;
463 :
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;
475 :
476 : // XChild
477 :
478 : /**
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.
482 : */
483 : virtual com::sun::star::uno::Reference<
484 : com::sun::star::uno::XInterface > SAL_CALL
485 : getParent()
486 : throw( com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
487 :
488 : /**
489 : * The implementation of this method always throws a NoSupportException.
490 : */
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;
496 :
497 :
498 : // Non-interface methods.
499 :
500 :
501 : /**
502 : * This method returns the provider of the content.
503 : *
504 : * @return the provider of the content.
505 : */
506 64 : const rtl::Reference< ContentProviderImplHelper >& getProvider() const
507 64 : { return m_xProvider; }
508 : };
509 :
510 : } // namespace ucbhelper
511 :
512 : #endif /* ! INCLUDED_UCBHELPER_CONTENTHELPER_HXX */
513 :
514 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|