1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: localfilelayer.hxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef CONFIGMGR_LOCALBE_LOCALFILELAYER_HXX_
32 #define CONFIGMGR_LOCALBE_LOCALFILELAYER_HXX_
34 #include "propertysethelper.hxx"
35 #include <com/sun/star/configuration/backend/XUpdatableLayer.hpp>
36 #include <com/sun/star/configuration/backend/XCompositeLayer.hpp>
37 #include <com/sun/star/util/XTimeStamped.hpp>
38 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
39 #include <cppuhelper/implbase3.hxx>
40 #include <cppuhelper/implbase2.hxx>
41 #include <cppuhelper/implbase1.hxx>
43 #ifndef VECTOR_INCLUDED_
44 #define VECTOR_INCLUDED_
46 #endif // VECTOR_INCLUDED_
48 namespace configmgr
{ namespace localbe
{
50 namespace css
= com::sun::star
;
51 namespace uno
= css::uno
;
52 namespace lang
= css::lang
;
53 namespace util
= css::util
;
54 namespace backend
= css::configuration::backend
;
57 Basic Implementation of the readonly XLayer interfaces for a local file access.
58 The read data is accessible through a canned implementation of an XML parser.
59 The layer is defined by the URL of the file containing its contents.
61 class BasicLocalFileLayer
65 Constructor providing the base directory and the
66 file subpath describing the file to access.
67 An optional resource directory provides the location
68 of sublayers of the component.
70 @param xFactory service factory used to access canned services
71 @param aComponentFile path describing the component file
74 const uno::Reference
<lang::XMultiServiceFactory
>& xFactory
,
75 const rtl::OUString
& aComponentFile
) ;
77 ~BasicLocalFileLayer() ;
81 Describes the contents of a particular file to a handler.
83 @param xHandler handler to describe the data to
84 @param aFileUrl URL of the file
85 @throws com::sun::star::configuration::backend::MalformedDataException
86 if the file contains invalid data.
87 @throws com::sun::star::lang::NullPointerException
89 @throws com::sun::star::lang::WrappedTargetException
90 if an error occurs while accessing the data.
92 void readData(backend::XLayer
* pContext
,
93 const uno::Reference
<backend::XLayerHandler
>& xHandler
,
94 const rtl::OUString
& aFileUrl
)
95 throw (backend::MalformedDataException
, lang::NullPointerException
,
96 lang::WrappedTargetException
, uno::RuntimeException
);
99 Returns an object that can be used to write a layer.
101 uno::Reference
<backend::XLayerHandler
> createLayerWriter();
105 Returns a timestamp associated to a file defined by its URL.
107 @param aFileUrl URL of the file
110 static rtl::OUString
getTimestamp(const rtl::OUString
& aFileUrl
) ;
112 rtl::OUString
const & getFileUrl() const { return mFileUrl
; };
115 /** Service factory */
116 uno::Reference
<lang::XMultiServiceFactory
> const mFactory
;
117 /** URL of the file being accessed */
118 rtl::OUString
const mFileUrl
;
119 /** XLayer implementation used for readData */
120 uno::Reference
<backend::XLayer
> mLayerReader
;
124 // provides properties for file layers
125 class LayerPropertyHelper
: public apihelper::PropertySetHelper
128 LayerPropertyHelper(){};
129 virtual ~LayerPropertyHelper(){};
132 virtual rtl::OUString
const & getLayerUrl() const = 0;
135 // cppu::OPropertySetHelper
136 virtual cppu::IPropertyArrayHelper
* SAL_CALL
newInfoHelper();
138 virtual void SAL_CALL
setFastPropertyValue_NoBroadcast( sal_Int32 nHandle
, const uno::Any
& rValue
)
139 throw (uno::Exception
);
141 using PropertySetHelper::getFastPropertyValue
;
142 virtual void SAL_CALL
getFastPropertyValue( uno::Any
& rValue
, sal_Int32 nHandle
) const;
147 Implementation of the readonly XLayer interfaces for a local file access.
148 The read data is accessible through a canned implementation of
150 The layer is defined by the URL of the file containing its
153 class SimpleLocalFileLayer
: public BasicLocalFileLayer
154 , public cppu::ImplInheritanceHelper2
< LayerPropertyHelper
,
160 Constructor providing the base directory and the
161 file subpath describing the file to access.
162 An optional resource directory provides the location
163 of sublayers of the component.
165 @param xFactory service factory used to access canned services
166 @param aComponentFile URL describing the component file
168 SimpleLocalFileLayer(
169 const uno::Reference
<lang::XMultiServiceFactory
>& xFactory
,
170 const rtl::OUString
& aComponentFile
) ;
172 Constructor providing the base directory and the
173 file subpath describing the file to access.
174 An optional resource directory provides the location
175 of sublayers of the component.
177 @param xFactory service factory used to access canned services
178 @param aBaseDir base directory
179 @param aComponent subpath describing the component file
181 SimpleLocalFileLayer(
182 const uno::Reference
<lang::XMultiServiceFactory
>& xFactory
,
183 const rtl::OUString
& aBaseDir
,
184 const rtl::OUString
& aComponent
) ;
187 ~SimpleLocalFileLayer() ;
190 using BasicLocalFileLayer::readData
;
191 virtual void SAL_CALL
readData(
192 const uno::Reference
<backend::XLayerHandler
>& xHandler
)
193 throw (backend::MalformedDataException
, lang::NullPointerException
,
194 lang::WrappedTargetException
, uno::RuntimeException
);
197 virtual rtl::OUString SAL_CALL
getTimestamp()
198 throw (uno::RuntimeException
);
201 virtual rtl::OUString
const & getLayerUrl() const
202 { return getFileUrl(); }
206 Implementation of the XUpdatableLayer
207 interface for a local file access.
208 The read data is accessible through a canned implementation of
209 an XML parser, and the write data is defined through a canned
210 implementation of an XML writer.
211 The layer is defined by the URL of the file containing its
212 contents, and that file will be either read or updated by
213 the access to the handlers.
214 The timestamp is refreshed on each read operation only.
216 class FlatLocalFileLayer
: public BasicLocalFileLayer
217 , public cppu::ImplInheritanceHelper2
< LayerPropertyHelper
,
218 backend::XUpdatableLayer
,
223 Constructor providing the base directory and the
224 file subpath describing the file to access.
226 @param xFactory service factory used to access canned services
227 @param aBaseDir base directory
228 @param aComponent subpath describing the component file
231 const uno::Reference
<lang::XMultiServiceFactory
>& xFactory
,
232 const rtl::OUString
& aBaseDir
,
233 const rtl::OUString
& aComponent
) ;
235 ~FlatLocalFileLayer(void) ;
238 using BasicLocalFileLayer::readData
;
239 virtual void SAL_CALL
readData(
240 const uno::Reference
<backend::XLayerHandler
>& xHandler
)
241 throw (backend::MalformedDataException
, lang::NullPointerException
,
242 lang::WrappedTargetException
, uno::RuntimeException
);
245 virtual void SAL_CALL
replaceWith(
246 const uno::Reference
<backend::XLayer
>& aNewLayer
)
247 throw (backend::MalformedDataException
, lang::NullPointerException
,
248 lang::WrappedTargetException
, uno::RuntimeException
);
251 virtual rtl::OUString SAL_CALL
getTimestamp()
252 throw (uno::RuntimeException
);
255 virtual rtl::OUString
const & getLayerUrl() const
256 { return getFileUrl(); }
259 /** XLayerHandler implementation for getWriteHandler */
260 uno::Reference
<backend::XLayerHandler
> mLayerWriter
;
265 Implementation of the XCompositeLayer
266 interface for a local file access.
267 The read data is accessible through a canned implementation of
269 The layer is defined by the URL of the file containing its
270 contents, and that file will be either read or updated by
271 the access to the handlers.
272 The timestamp is refreshed on each read operation only.
274 class BasicCompositeLocalFileLayer
: public BasicLocalFileLayer
278 Constructor providing the base directory and the
279 file subpath describing the file to access.
280 An resource directory provides the location
281 of sublayers of the component.
283 @param xFactory service factory used to access canned services
284 @param aComponent path describing the component file
286 BasicCompositeLocalFileLayer(
287 const uno::Reference
<lang::XMultiServiceFactory
>& xFactory
,
288 const rtl::OUString
& aComponent
) ;
290 // XCompositeLayer helpers
291 uno::Sequence
<rtl::OUString
> SAL_CALL
listSubLayerIds()
292 throw (lang::WrappedTargetException
, uno::RuntimeException
)
293 { return mSubLayers
; }
295 void SAL_CALL
readSubLayerData(
296 backend::XCompositeLayer
* context
,
297 const uno::Reference
<backend::XLayerHandler
>& xHandler
,
298 const rtl::OUString
& aSubLayerId
)
299 throw (backend::MalformedDataException
, lang::NullPointerException
,
300 lang::WrappedTargetException
, lang::IllegalArgumentException
,
301 uno::RuntimeException
);
304 Fills the list of available sublayers.
306 @param aResDir resource directory containing potential sublayers
307 @param aComponent component subpath
309 void fillSubLayerLists(const std::vector
<rtl::OUString
>& aSublayerDirectories
,
310 const rtl::OUString
& aComponent
) ;
312 /** List of available sublayers... */
313 uno::Sequence
<rtl::OUString
> mSubLayers
;
314 /** .. and the corresponding file URLs. */
315 std::vector
<rtl::OUString
> mSubLayerFiles
;
320 Implementation of the XCompositeLayer
321 interface for a local file access.
322 The read data is accessible through a canned implementation of
324 The layer is defined by the URL of the file containing its
325 contents, and that file will be either read or updated by
326 the access to the handlers.
327 The timestamp is refreshed on each read operation only.
329 class CompositeLocalFileLayer
: public BasicCompositeLocalFileLayer
330 , public cppu::WeakImplHelper1
< backend::XCompositeLayer
>
334 Constructor providing the base directory and the
335 file subpath describing the file to access.
336 An resource directory provides the location
337 of sublayers of the component.
339 @param xFactory service factory used to access canned services
340 @param aBaseDir base directory
341 @param aComponent subpath describing the component file
342 @param aResDir resource directory, if empty it is
343 assumed the layer does not have sublayers.
345 CompositeLocalFileLayer(
346 const uno::Reference
<lang::XMultiServiceFactory
>& xFactory
,
347 const rtl::OUString
& aComponent
,
348 const std::vector
<rtl::OUString
>& aSublayerDirectories
) ;
350 ~CompositeLocalFileLayer(void) ;
352 using BasicCompositeLocalFileLayer::readData
;
353 virtual void SAL_CALL
readData(
354 const uno::Reference
<backend::XLayerHandler
>& xHandler
)
355 throw (backend::MalformedDataException
, lang::NullPointerException
,
356 lang::WrappedTargetException
, uno::RuntimeException
);
359 virtual uno::Sequence
<rtl::OUString
> SAL_CALL
listSubLayerIds()
360 throw (lang::WrappedTargetException
, uno::RuntimeException
)
361 { return BasicCompositeLocalFileLayer::listSubLayerIds() ; }
363 using BasicCompositeLocalFileLayer::readSubLayerData
;
364 virtual void SAL_CALL
readSubLayerData(
365 const uno::Reference
<backend::XLayerHandler
>& xHandler
,
366 const rtl::OUString
& aSubLayerId
)
367 throw (backend::MalformedDataException
, lang::NullPointerException
,
368 lang::WrappedTargetException
, lang::IllegalArgumentException
,
369 uno::RuntimeException
);
372 // not implemented: warn of attempts to use this here
373 void getFileUrl() const;
376 Implementation of the XUpdatableLayer and XCompositeLayer
377 interfaces for a local file access.
378 The read data is accessible through a canned implementation of
379 an XML parser, and the write data is defined through a canned
380 implementation of an XML writer.
381 The layer is defined by the URL of the file containing its
382 contents, and that file will be either read or updated by
383 the access to the handlers.
384 The timestamp is refreshed on each read operation only.
386 class FullCompositeLocalFileLayer
: public BasicCompositeLocalFileLayer
387 , public cppu::ImplInheritanceHelper3
<
389 backend::XUpdatableLayer
,
390 backend::XCompositeLayer
,
395 Constructor providing the base directory and the
396 file subpath describing the file to access.
397 An resource directory provides the location
398 of sublayers of the component.
400 @param xFactory service factory used to access canned services
401 @param aBaseDir base directory
402 @param aComponent subpath describing the component file
403 @param aResDir resource directory, if empty it is
404 assumed the layer does not have sublayers.
406 FullCompositeLocalFileLayer(
407 const uno::Reference
<lang::XMultiServiceFactory
>& xFactory
,
408 const rtl::OUString
& aBaseDir
,
409 const rtl::OUString
& aComponent
,
410 const std::vector
<rtl::OUString
>& aSublayerDirectories
) ;
412 ~FullCompositeLocalFileLayer(void) ;
414 using BasicCompositeLocalFileLayer::readData
;
415 virtual void SAL_CALL
readData(
416 const uno::Reference
<backend::XLayerHandler
>& xHandler
)
417 throw (backend::MalformedDataException
, lang::NullPointerException
,
418 lang::WrappedTargetException
, uno::RuntimeException
);
421 virtual void SAL_CALL
replaceWith(
422 const uno::Reference
<backend::XLayer
>& aNewLayer
)
423 throw (backend::MalformedDataException
, lang::NullPointerException
,
424 lang::WrappedTargetException
, uno::RuntimeException
);
427 virtual uno::Sequence
<rtl::OUString
> SAL_CALL
listSubLayerIds()
428 throw (lang::WrappedTargetException
, uno::RuntimeException
)
429 { return BasicCompositeLocalFileLayer::listSubLayerIds() ; }
431 using BasicCompositeLocalFileLayer::readSubLayerData
;
432 virtual void SAL_CALL
readSubLayerData(
433 const uno::Reference
<backend::XLayerHandler
>& xHandler
,
434 const rtl::OUString
& aSubLayerId
)
435 throw (backend::MalformedDataException
, lang::NullPointerException
,
436 lang::WrappedTargetException
, lang::IllegalArgumentException
,
437 uno::RuntimeException
);
440 virtual rtl::OUString SAL_CALL
getTimestamp()
441 throw (uno::RuntimeException
);
444 virtual rtl::OUString
const & getLayerUrl() const
445 { return getFileUrl(); }
448 /** XLayerHandler implementation for getWriteHandler */
449 uno::Reference
<backend::XLayerHandler
> mLayerWriter
;
452 Factory function to create the appropriate Flat- or Composite-
453 LocalFileLayer for a set of parameters.
455 Arguments provide the base directory and the
456 file subpath describing the file to access.
457 An optional resource directory provides the location
458 of sublayers of the component.
460 @param xFactory service factory used to access canned services
461 @param aBaseDir base directory
462 @param aComponent subpath describing the component file
463 @param aResDir resource directory, if empty it is
464 assumed the layer does not have sublayers.
466 uno::Reference
<backend::XLayer
> createReadonlyLocalFileLayer(
467 const uno::Reference
<lang::XMultiServiceFactory
>& xFactory
,
468 const rtl::OUString
& aBaseDir
,
469 const rtl::OUString
& aComponent
,
470 const rtl::OUString
& aResDir
) ;
473 Factory function to create the appropriate Flat- or Composite-
474 LocalFileLayer for a set of parameters.
476 Arguments provide the base directory and the
477 file subpath describing the file to access.
478 An optional resource directory provides the location
479 of sublayers of the component.
481 @param xFactory service factory used to access canned services
482 @param aBaseDir base directory
483 @param aComponent subpath describing the component file
484 @param aResDir resource directory, if empty it is
485 assumed the layer does not have sublayers.
487 uno::Reference
<backend::XUpdatableLayer
> createUpdatableLocalFileLayer(
488 const uno::Reference
<lang::XMultiServiceFactory
>& xFactory
,
489 const rtl::OUString
& aBaseDir
,
490 const rtl::OUString
& aComponent
,
491 const rtl::OUString
& aResDir
) ;
493 } } // configmgr.localbe
495 #endif // CONFIGMGR_LOCALBE_LOCALFILELAYER_HXX_