xref: /trunk/main/ucbhelper/inc/ucbhelper/providerhelper.hxx (revision 91144cd0085a7583d2099b982122deb2184ab956)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef _UCBHELPER_PROVIDERHELPER_HXX
25 #define _UCBHELPER_PROVIDERHELPER_HXX
26 
27 #ifndef __LIST__
28 #include <list>
29 #endif
30 #include <com/sun/star/ucb/XContentProvider.hpp>
31 #include <com/sun/star/lang/XServiceInfo.hpp>
32 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
33 #include <com/sun/star/lang/XTypeProvider.hpp>
34 #include <cppuhelper/weak.hxx>
35 
36 #include "osl/mutex.hxx"
37 #include "rtl/ref.hxx"
38 #include <ucbhelper/macros.hxx>
39 #include "ucbhelper/ucbhelperdllapi.h"
40 
41 //=========================================================================
42 
43 namespace com { namespace sun { namespace star { namespace ucb {
44     class XPropertySetRegistry;
45     class XPersistentPropertySet;
46 } } } }
47 
48 namespace ucbhelper_impl { struct ContentProviderImplHelper_Impl; }
49 
50 namespace ucbhelper {
51 
52 //=========================================================================
53 
54 class ContentImplHelper;
55 typedef rtl::Reference< ContentImplHelper > ContentImplHelperRef;
56 typedef std::list< ContentImplHelperRef > ContentRefList;
57 
58 /**
59   * This is an abstract base class for implementations of the service
60   * com.sun.star.ucb.ContentProvider. It provides contents derived from
61   * class ucb::ContentImplHelper.
62   *
63   * Features of the base class implementation:
64   * - standard interfaces ( XInterface, XTypeProvider, XServiceInfo )
65   * - maintains a set of ContentImplHelper objects, which were created by
66   *   the provider implementation. So there will be exactly one object for
67   *   one Content Identifier.
68   * - Provides access to the Additional Core PropertySet of a content.
69   *   ( These set contains the properties added to a content using its
70   *   XPropertyContainer interface )
71   */
72 class UCBHELPER_DLLPUBLIC ContentProviderImplHelper : public cppu::OWeakObject,
73                                   public com::sun::star::lang::XTypeProvider,
74                                   public com::sun::star::lang::XServiceInfo,
75                                   public com::sun::star::ucb::XContentProvider
76 {
77     friend class ContentImplHelper;
78 
79     ucbhelper_impl::ContentProviderImplHelper_Impl* m_pImpl;
80 
81 protected:
82     osl::Mutex m_aMutex;
83     ::com::sun::star::uno::Reference<
84             ::com::sun::star::lang::XMultiServiceFactory >  m_xSMgr;
85 
86 private:
87     UCBHELPER_DLLPRIVATE void removeContent( ContentImplHelper* pContent );
88 
89     UCBHELPER_DLLPRIVATE ::com::sun::star::uno::Reference<
90         ::com::sun::star::ucb::XPropertySetRegistry >
91     getAdditionalPropertySetRegistry();
92 
93     UCBHELPER_DLLPRIVATE void cleanupRegisteredContents();
94 
95 protected:
96     /**
97       * This method returns a content with the given id, if it already exists.
98       * Use this method in your "queryContent" implementation to ensure unique
99       * objects.
100       *
101       * @param  Identifier is the content identifier, for that an existing
102       *         content object is requested.
103       * @return the content with the given identifier, if it exists or 0, if it
104       *         does not exist.
105       */
106     rtl::Reference< ContentImplHelper >
107     queryExistingContent( const ::com::sun::star::uno::Reference<
108                 ::com::sun::star::ucb::XContentIdentifier >& Identifier );
109 
110     /**
111       * This method returns a content with the given URL, if it already exists.
112       *
113       * @param  rURL is the URL ( content identifier string ), for that an
114       *         existing content object is requested.
115       * @return the content with the given URL, if it exists or 0, if it
116       *         does not exist.
117       */
118     rtl::Reference< ContentImplHelper >
119     queryExistingContent( const ::rtl::OUString& rURL );
120 
121     /**
122       * This method registers a newly created content instance with the
123       * content provider. It should be called directly after creating a new
124       * content instance. The provider can reuse a registered instance upon
125       * subsedent requests for content instances with an idententifier
126       * of a registered instance.
127       * Note that the provider does not hold a hard reference on the
128       * registered instance. If last external reference is gone, the provider
129       * will remove the instance from its inventory of known instances.
130       * Nothing will happen in case an already registered instance shall
131       * be registered more than once.
132       *
133       * @param  the content instance that is to be registered.
134      */
135     void registerNewContent(
136         const com::sun::star::uno::Reference<
137             ::com::sun::star::ucb::XContent > & xContent );
138 
139 public:
140 
141     //////////////////////////////////////////////////////////////////////
142     // Construction/Destruction
143     //////////////////////////////////////////////////////////////////////
144 
145     ContentProviderImplHelper(
146                 const ::com::sun::star::uno::Reference<
147                     ::com::sun::star::lang::XMultiServiceFactory >& rXSMgr );
148     virtual ~ContentProviderImplHelper();
149 
150     //////////////////////////////////////////////////////////////////////
151     // XInterface
152     //////////////////////////////////////////////////////////////////////
153 
154     XINTERFACE_DECL()
155 
156     //////////////////////////////////////////////////////////////////////
157     // XTypeProvider
158     //////////////////////////////////////////////////////////////////////
159 
160     XTYPEPROVIDER_DECL()
161 
162     //////////////////////////////////////////////////////////////////////
163     // XServiceInfo
164     //////////////////////////////////////////////////////////////////////
165 
166     virtual ::rtl::OUString SAL_CALL
167     getImplementationName() = 0;
168     virtual sal_Bool SAL_CALL
169     supportsService( const ::rtl::OUString& ServiceName );
170     virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL
171     getSupportedServiceNames() = 0;
172 
173     //////////////////////////////////////////////////////////////////////
174     // XContentProvider
175     //////////////////////////////////////////////////////////////////////
176 
177     /**
178       * This method returns a content with the requested id.
179       *
180       * The implementation should:
181       *
182       * - Check, whether the Identifier is valid ( URL syntax ).
183       * - Use queryExistingContent(...) to determine, whether there exists
184       *   already a content with the given id.
185       * - Return the possibly existing content.Create and return a new
186       *   content, otherwise
187       */
188     virtual ::com::sun::star::uno::Reference<
189                 ::com::sun::star::ucb::XContent > SAL_CALL
190     queryContent( const ::com::sun::star::uno::Reference<
191                     ::com::sun::star::ucb::XContentIdentifier >& Identifier ) = 0;
192     virtual sal_Int32 SAL_CALL
193     compareContentIds( const ::com::sun::star::uno::Reference<
194                             ::com::sun::star::ucb::XContentIdentifier >& Id1,
195                        const ::com::sun::star::uno::Reference<
196                             ::com::sun::star::ucb::XContentIdentifier >& Id2 );
197 
198     //////////////////////////////////////////////////////////////////////
199     // Non-interface methods.
200     //////////////////////////////////////////////////////////////////////
201 
202     /**
203       * This method returns a mutex, which protects the content list of the
204       * provider. So you can prevent modifications of that list easyly.
205       *
206       * @return the mutex.
207       */
getContentListMutex()208     osl::Mutex& getContentListMutex() { return m_aMutex; }
209 
210     /**
211       * This method fills a list with all contents existing at calling time.
212       * Note: You may prevent modifications of the content list at any time
213       * by acquiring the content list mutex of the provider.
214       *
215       * @param  rContents is the list to fill with the children.
216       */
217     void queryExistingContents( ContentRefList& rContents );
218 
219     /**
220       * This method returns the propertyset containing the Additional Core
221       * Properties of a content.
222       *
223       * @param  rKey is the key for the propertyset.
224       * @param  bCreate is a flag indicating whether the propertyset shall
225       *         be created in case it does not exist.
226       * @return the propertyset containing the Additional Core Properties.
227       */
228     ::com::sun::star::uno::Reference<
229         com::sun::star::ucb::XPersistentPropertySet >
230     getAdditionalPropertySet( const ::rtl::OUString& rKey, sal_Bool bCreate );
231 
232     /**
233       * This method renames the propertyset containing the Additional Core
234       * Properties of a content.
235       *
236       * @param  rOldKey is the old key of the propertyset.
237       * @param  rNewKey is the new key for the propertyset.
238       * @param  bRecursive is a flag indicating whether propertysets for
239       *         children described by rOldKey shall be renamed, too.
240       * @return True, if the operation succeeded - False, otherwise.
241       */
242     sal_Bool renameAdditionalPropertySet( const ::rtl::OUString& rOldKey,
243                                           const ::rtl::OUString& rNewKey,
244                                           sal_Bool bRecursive );
245 
246     /**
247       * This method copies the propertyset containing the Additional Core
248       * Properties of a content.
249       *
250       * @param  rSourceKey is the key of the source propertyset.
251       * @param  rTargetKey is the key of the target propertyset.
252       * @param  bRecursive is a flag indicating whether propertysets for
253       *         children described by rSourceKey shall be copied, too.
254       * @return True, if the operation succeeded - False, otherwise.
255       */
256     sal_Bool copyAdditionalPropertySet( const ::rtl::OUString& rSourceKey,
257                                         const ::rtl::OUString& rTargetKey,
258                                         sal_Bool bRecursive );
259 
260     /**
261       * This method removes the propertyset containing the Additional Core
262       * Properties of a content.
263       *
264       * @param  rKey is the key of the propertyset.
265       * @param  bRecursive is a flag indicating whether propertysets for
266       *         children described by rOldKey shall be removed, too.
267       * @return True, if the operation succeeded - False, otherwise.
268       */
269     sal_Bool removeAdditionalPropertySet( const ::rtl::OUString& rKey,
270                                           sal_Bool bRecursive );
271 };
272 
273 } // namespace ucbhelper
274 
275 #endif /* !_UCBHELPER_PROVIDERHELPER_HXX */
276