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: localsinglebackend.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_LOCALSINGLEBACKEND_HXX_
32 #define CONFIGMGR_LOCALBE_LOCALSINGLEBACKEND_HXX_
34 #include <com/sun/star/configuration/backend/XSchemaSupplier.hpp>
35 #include <com/sun/star/configuration/backend/XMultiLayerStratum.hpp>
36 #include <com/sun/star/configuration/backend/XBackendEntities.hpp>
37 #include <com/sun/star/uno/XComponentContext.hpp>
38 #include <com/sun/star/lang/XInitialization.hpp>
39 #include <com/sun/star/lang/XServiceInfo.hpp>
40 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
41 #include <com/sun/star/configuration/InvalidBootstrapFileException.hpp>
42 #include <com/sun/star/configuration/backend/CannotConnectException.hpp>
43 #include <cppuhelper/compbase5.hxx>
45 namespace configmgr
{ namespace localbe
{
47 namespace css
= com::sun::star
;
48 namespace uno
= css::uno
;
49 namespace lang
= css::lang
;
50 namespace backend
= css::configuration::backend
;
53 Implements the SingleBackend service for local file access.
54 Layer identifiers in that backend are file URLs.
56 class LocalSingleBackend
: public cppu::WeakComponentImplHelper5
<backend::XSchemaSupplier
, backend::XMultiLayerStratum
, backend::XBackendEntities
, lang::XInitialization
, lang::XServiceInfo
> {
59 Service constructor from a service factory.
61 @param xFactory service factory
63 LocalSingleBackend(const uno::Reference
<uno::XComponentContext
>& xContext
) ;
66 ~LocalSingleBackend(void) ;
71 initialize( const uno::Sequence
<uno::Any
>& aParameters
)
72 throw (uno::RuntimeException
, uno::Exception
,
73 css::configuration::InvalidBootstrapFileException
,
74 backend::CannotConnectException
,
75 backend::BackendSetupException
);
78 virtual uno::Reference
<backend::XSchema
> SAL_CALL
79 getComponentSchema( const rtl::OUString
& aComponent
)
80 throw (backend::BackendAccessException
,
81 lang::IllegalArgumentException
,
82 uno::RuntimeException
) ;
85 virtual uno::Sequence
<rtl::OUString
> SAL_CALL
86 listLayerIds( const rtl::OUString
& aComponent
, const rtl::OUString
& aEntity
)
87 throw (backend::BackendAccessException
,
88 lang::IllegalArgumentException
,
89 uno::RuntimeException
) ;
91 virtual rtl::OUString SAL_CALL
92 getUpdateLayerId( const rtl::OUString
& aComponent
, const rtl::OUString
& aEntity
)
93 throw (backend::BackendAccessException
,
94 lang::IllegalArgumentException
,
95 uno::RuntimeException
) ;
97 virtual uno::Reference
<backend::XLayer
> SAL_CALL
98 getLayer( const rtl::OUString
& aLayerId
, const rtl::OUString
& aTimestamp
)
99 throw (backend::BackendAccessException
,
100 lang::IllegalArgumentException
,
101 uno::RuntimeException
) ;
103 virtual uno::Sequence
<uno::Reference
<backend::XLayer
> > SAL_CALL
104 getLayers(const uno::Sequence
<rtl::OUString
>& aLayerIds
,
105 const rtl::OUString
& aTimestamp
)
106 throw (backend::BackendAccessException
,
107 lang::IllegalArgumentException
,
108 uno::RuntimeException
) ;
110 virtual uno::Sequence
<uno::Reference
<backend::XLayer
> > SAL_CALL
111 getMultipleLayers(const uno::Sequence
<rtl::OUString
>& aLayerIds
,
112 const uno::Sequence
<rtl::OUString
>& aTimestamps
)
113 throw (backend::BackendAccessException
,
114 lang::IllegalArgumentException
,
115 uno::RuntimeException
) ;
117 virtual uno::Reference
<backend::XUpdatableLayer
> SAL_CALL
118 getUpdatableLayer( const rtl::OUString
& aLayerId
)
119 throw (backend::BackendAccessException
,
120 lang::IllegalArgumentException
,
121 uno::RuntimeException
) ;
124 virtual rtl::OUString SAL_CALL
126 throw (uno::RuntimeException
);
128 virtual rtl::OUString SAL_CALL
130 throw (uno::RuntimeException
);
132 virtual sal_Bool SAL_CALL
133 supportsEntity( const rtl::OUString
& aEntity
)
134 throw (backend::BackendAccessException
, uno::RuntimeException
);
136 virtual sal_Bool SAL_CALL
137 isEqualEntity( const rtl::OUString
& aEntity
, const rtl::OUString
& aOtherEntity
)
138 throw (backend::BackendAccessException
, lang::IllegalArgumentException
, uno::RuntimeException
);
141 virtual rtl::OUString SAL_CALL
142 getImplementationName( )
143 throw (uno::RuntimeException
) ;
145 virtual sal_Bool SAL_CALL
146 supportsService( const rtl::OUString
& aServiceName
)
147 throw (uno::RuntimeException
) ;
149 virtual uno::Sequence
<rtl::OUString
> SAL_CALL
150 getSupportedServiceNames( )
151 throw (uno::RuntimeException
) ;
153 public: // helpers for other implementation that need to use the same data
155 Locates the main layer data and localized data directories in a layer directory hierarchy
157 static bool getLayerSubDirectories( rtl::OUString
const & aLayerBaseUrl
,
158 rtl::OUString
& aMainLayerUrl
,
159 rtl::OUString
& aSubLayerUrl
);
161 Creates a simple readonly non-composite layer for a component in a base directory
163 static uno::Reference
<backend::XLayer
>
164 createSimpleLayer(const uno::Reference
<lang::XMultiServiceFactory
>& xFactory
,
165 rtl::OUString
const & aLayerBaseUrl
,
166 rtl::OUString
const & aComponent
);
169 Creates a simple readonly non-composite layer for a component in a given file
171 static uno::Reference
<backend::XLayer
>
172 createSimpleLayer(const uno::Reference
<lang::XMultiServiceFactory
>& xFactory
,
173 rtl::OUString
const & aComponentUrl
);
175 /** Service factory */
176 uno::Reference
<lang::XMultiServiceFactory
> mFactory
;
177 /** Mutex for resources protection */
180 Base of the schema data. Is a list to allow
181 for multiple schema directories.
183 uno::Sequence
<rtl::OUString
> mSchemaDataUrls
;
185 Base of the default data. Is a list to allow
186 for multiple layers of default data.
188 uno::Sequence
<rtl::OUString
> mDefaultDataUrls
;
189 /** Base of the user data */
190 rtl::OUString mUserDataUrl
;
192 /** special index for entity */
193 sal_Int32
findEntity(rtl::OUString
const & _aEntity
);
194 /** parse and translate layer-id */
195 sal_Int32
resolveLayerId(rtl::OUString
const & _aLayerId
, rtl::OUString
& _aFile
);
198 Builds a LocalFileLayer object given a layer id.
199 Since the LocalFileLayer implements the various
200 interfaces a layer can be accessed as, a few methods
201 need one. This method handles the layer id mapping
202 and the existence or not of sublayers.
204 @param aLayerId layer id
205 @return local file layer
206 @throws com::sun::star::lang::IllegalArgumentException
207 if the layer id is invalid.
209 uno::Reference
<backend::XUpdatableLayer
> getFileLayer(const rtl::OUString
& aLayerId
)
210 throw (lang::IllegalArgumentException
) ;
212 Same as above, but using a component URL and layer index
213 combination instead of a layer id (which encodes both).
215 @param aComponent component URL
216 @param aLayerIndex layer index
217 @return local file layer
219 uno::Reference
<backend::XUpdatableLayer
> getFileLayer(const rtl::OUString
& aComponent
,
220 sal_Int32 aLayerIndex
) ;
222 Maps a layer index (-1 for user layer, 0-x for defaults)
223 to the appropriate layer and sublayers base directories.
225 @param aLayerIndex layer index
226 @param aLayerUrl layer base URL, filled on return
227 @param aSubLayerUrl sublayer base URL, filled on return
229 bool getLayerDirectories(sal_Int32 aLayerIndex
,
230 rtl::OUString
& aLayerUrl
,
231 rtl::OUString
& aSubLayerUrl
) ;
233 Tells if a file is more recent than a given date.
234 The date is formatted YYYYMMDDhhmmssZ.
236 @param aComponent URL of the component to check
237 @param aLayerIndex index of the layer involved (-1 = user)
238 @param aTimestamp timestamp to check against
239 @return sal_True if the file is more recent, sal_False otherwise
241 sal_Bool
isMoreRecent(const rtl::OUString
& aComponent
,
243 const rtl::OUString
& aTimestamp
) ;
246 } } // configmgr.localbe
248 #endif // CONFIGMGR_LOCALBE_LOCALSINGLEBACKEND_HXX_