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 	// Contsruction/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()
168 		throw( ::com::sun::star::uno::RuntimeException ) = 0;
169     virtual sal_Bool SAL_CALL
170 	supportsService( const ::rtl::OUString& ServiceName )
171 		throw( ::com::sun::star::uno::RuntimeException );
172     virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL
173 	getSupportedServiceNames()
174 		throw( ::com::sun::star::uno::RuntimeException ) = 0;
175 
176 	//////////////////////////////////////////////////////////////////////
177 	// XContentProvider
178 	//////////////////////////////////////////////////////////////////////
179 
180 	/**
181 	  *	This method returns a content with the requested id.
182 	  *
183 	  *	The implementation should:
184 	  *
185 	  *	- Check, whether the Identifier is valid ( URL syntax ).
186 	  *	- Use queryExistingContent(...) to determine, whether there exists
187 	  *	  already a content with the given id.
188 	  *	- Return the possibly existing content.Create and return a new
189 	  *	  content, otherwise
190 	  */
191 	virtual ::com::sun::star::uno::Reference<
192 				::com::sun::star::ucb::XContent > SAL_CALL
193 	queryContent( const ::com::sun::star::uno::Reference<
194 					::com::sun::star::ucb::XContentIdentifier >& Identifier )
195 		throw( ::com::sun::star::ucb::IllegalIdentifierException,
196 			   ::com::sun::star::uno::RuntimeException ) = 0;
197     virtual sal_Int32 SAL_CALL
198 	compareContentIds( const ::com::sun::star::uno::Reference<
199 							::com::sun::star::ucb::XContentIdentifier >& Id1,
200 					   const ::com::sun::star::uno::Reference<
201 					   		::com::sun::star::ucb::XContentIdentifier >& Id2 )
202 		throw( ::com::sun::star::uno::RuntimeException );
203 
204 	//////////////////////////////////////////////////////////////////////
205 	// Non-interface methods.
206 	//////////////////////////////////////////////////////////////////////
207 
208 	/**
209 	  *	This method returns a mutex, which protects the content list of the
210 	  * provider. So you can prevent modifications of that list easyly.
211 	  *
212 	  * @return the mutex.
213 	  */
getContentListMutex()214 	osl::Mutex& getContentListMutex() { return m_aMutex; }
215 
216 	/**
217 	  *	This method fills a list with all contents existing at calling time.
218 	  * Note: You may prevent modifications of the content list at any time
219 	  * by acquiring the content list mutex of the provider.
220 	  *
221 	  * @param  rContents is the list to fill with the children.
222 	  */
223 	void queryExistingContents( ContentRefList& rContents );
224 
225 	/**
226 	  *	This method returns the propertyset containing the Additional Core
227 	  * Properties of a content.
228 	  *
229 	  * @param  rKey is the key for the propertyset.
230 	  * @param  bCreate is a flag indicating whether the propertyset shall
231 	  *         be created in case it does not exist.
232 	  * @return the propertyset containing the Additional Core Properties.
233 	  */
234 	::com::sun::star::uno::Reference<
235 		com::sun::star::ucb::XPersistentPropertySet >
236 	getAdditionalPropertySet( const ::rtl::OUString& rKey, sal_Bool bCreate );
237 
238 	/**
239 	  *	This method renames the propertyset containing the Additional Core
240 	  * Properties of a content.
241 	  *
242 	  * @param  rOldKey is the old key of the propertyset.
243 	  * @param  rNewKey is the new key for the propertyset.
244 	  * @param  bRecursive is a flag indicating whether propertysets for
245 	  *         children described by rOldKey shall be renamed, too.
246 	  * @return True, if the operation succeeded - False, otherwise.
247 	  */
248 	sal_Bool renameAdditionalPropertySet( const ::rtl::OUString& rOldKey,
249 										  const ::rtl::OUString& rNewKey,
250 										  sal_Bool bRecursive );
251 
252 	/**
253 	  *	This method copies the propertyset containing the Additional Core
254 	  * Properties of a content.
255 	  *
256 	  * @param  rSourceKey is the key of the source propertyset.
257 	  * @param  rTargetKey is the key of the target propertyset.
258 	  * @param  bRecursive is a flag indicating whether propertysets for
259 	  *         children described by rSourceKey shall be copied, too.
260 	  * @return True, if the operation succeeded - False, otherwise.
261 	  */
262 	sal_Bool copyAdditionalPropertySet( const ::rtl::OUString& rSourceKey,
263 										const ::rtl::OUString& rTargetKey,
264 										sal_Bool bRecursive );
265 
266 	/**
267 	  *	This method removes the propertyset containing the Additional Core
268 	  * Properties of a content.
269 	  *
270 	  * @param  rKey is the key of the propertyset.
271 	  * @param  bRecursive is a flag indicating whether propertysets for
272 	  *         children described by rOldKey shall be removed, too.
273 	  * @return True, if the operation succeeded - False, otherwise.
274 	  */
275 	sal_Bool removeAdditionalPropertySet( const ::rtl::OUString& rKey,
276 										  sal_Bool bRecursive );
277 };
278 
279 } // namespace ucbhelper
280 
281 #endif /* !_UCBHELPER_PROVIDERHELPER_HXX */
282