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: localsinglestratum.cxx,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 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_configmgr.hxx"
34 #include "localsinglestratum.hxx"
35 #include "localfilehelper.hxx"
37 #ifndef CONFIGMGR_API_FACTORY_HXX_
38 #include "confapifactory.hxx"
39 #endif // CONFIGMGR_API_FACTORY_HXX_
40 #include "serviceinfohelper.hxx"
41 #include <rtl/ustrbuf.hxx>
42 #include <com/sun/star/uno/XComponentContext.hpp>
43 #include <com/sun/star/configuration/backend/InsufficientAccessRightsException.hpp>
45 namespace configmgr
{ namespace localbe
{
47 //==============================================================================
49 static inline rtl::OUString
getDataSubPath()
50 { return rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("/data")); }
52 static inline rtl::OUString
getLocalisedDataSubPath()
53 { return rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("/res")); }
54 //------------------------------------------------------------------------------
56 LocalSingleStratumBase::LocalSingleStratumBase(const uno::Reference
<uno::XComponentContext
>& xContext
)
57 : cppu::ImplInheritanceHelper1
< LocalStratumBase
, backend::XSingleLayerStratum
>(xContext
)
60 //------------------------------------------------------------------------------
62 LocalSingleStratumBase::~LocalSingleStratumBase() {}
64 //------------------------------------------------------------------------------
65 uno::Reference
<backend::XLayer
> SAL_CALL
66 LocalSingleStratumBase::getLayer( const rtl::OUString
& aComponent
, const rtl::OUString
& aTimestamp
)
67 throw (backend::BackendAccessException
, lang::IllegalArgumentException
,
68 uno::RuntimeException
)
70 return LocalStratumBase::getLayer(aComponent
,aTimestamp
);
72 //------------------------------------------------------------------------------
73 uno::Reference
<backend::XUpdatableLayer
> SAL_CALL
74 LocalSingleStratumBase::getUpdatableLayer(const rtl::OUString
& aComponent
)
75 throw (backend::BackendAccessException
, lang::IllegalArgumentException
,
76 lang::NoSupportException
, uno::RuntimeException
)
78 if (aComponent
.getLength() == 0){
79 throw lang::IllegalArgumentException(
80 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
81 "LocalSingleStratum:getLayer - no component specified")),
84 rtl::OUString
const componentSubPath
= componentToPath(aComponent
) + getDataSuffix();
85 return createUpdatableFileLayer( componentSubPath
) ;
87 //------------------------------------------------------------------------------
88 uno::Reference
<backend::XUpdatableLayer
> SAL_CALL
89 LocalReadonlyStratum::getUpdatableLayer(const rtl::OUString
& /*aComponent*/)
90 throw (backend::BackendAccessException
, lang::IllegalArgumentException
,
91 lang::NoSupportException
, uno::RuntimeException
)
96 uno::Reference
<backend::XUpdatableLayer
> SAL_CALL
97 LocalResourceStratum::getUpdatableLayer(const rtl::OUString
& /*aComponent*/)
98 throw (backend::BackendAccessException
, lang::IllegalArgumentException
,
99 lang::NoSupportException
, uno::RuntimeException
)
104 //------------------------------------------------------------------------------
107 void impl_getLayerDataDirectory(rtl::OUString
const & aLayerBaseUrl
,
108 rtl::OUString
& aMainLayerUrl
)
110 aMainLayerUrl
= aLayerBaseUrl
+ getDataSubPath() ;
112 //------------------------------------------------------------------------------
115 void impl_getLayerResDirectory(rtl::OUString
const & aLayerBaseUrl
,
116 rtl::OUString
& aSubLayerUrl
)
118 aSubLayerUrl
= aLayerBaseUrl
+ getLocalisedDataSubPath() ;
120 //------------------------------------------------------------------------------
122 void LocalSingleStratum::getLayerDirectories(rtl::OUString
& aLayerUrl
,
123 rtl::OUString
& aSubLayerUrl
) const
125 impl_getLayerDataDirectory(getBaseUrl(),aLayerUrl
);
126 impl_getLayerResDirectory(getBaseUrl(),aSubLayerUrl
);
128 //------------------------------------------------------------------------------
130 void LocalDataStratum::getLayerDirectories(rtl::OUString
& aLayerUrl
,
131 rtl::OUString
& aSubLayerUrl
) const
133 impl_getLayerDataDirectory(getBaseUrl(),aLayerUrl
);
134 aSubLayerUrl
= rtl::OUString();
136 //------------------------------------------------------------------------------
138 void LocalReadonlyStratum::getLayerDirectories(rtl::OUString
& aLayerUrl
,
139 rtl::OUString
& aSubLayerUrl
) const
141 impl_getLayerDataDirectory(getBaseUrl(),aLayerUrl
);
142 aSubLayerUrl
= rtl::OUString();
144 //------------------------------------------------------------------------------
146 void LocalResourceStratum::adjustBaseURL(rtl::OUString
& aBaseUrl
)
148 impl_getLayerResDirectory(aBaseUrl
,aBaseUrl
);
150 //------------------------------------------------------------------------------
152 void LocalResourceStratum::getLayerDirectories(rtl::OUString
& aLayerUrl
,
153 rtl::OUString
& aSubLayerUrl
) const
155 aLayerUrl
= rtl::OUString();
156 aSubLayerUrl
= getBaseUrl();
157 // impl_getLayerResDirectory(getBaseUrl(),aSubLayerUrl);
159 //------------------------------------------------------------------------------
160 //------------------------------------------------------------------------------
162 static const sal_Char
* const kLegacyStratumImplementation
=
163 "com.sun.star.comp.configuration.backend.LocalSingleStratum" ;
164 static const sal_Char
* const kDataStratumImplementation
=
165 "com.sun.star.comp.configuration.backend.LocalStratum" ;
166 static const sal_Char
* const kReadonlyStratumImplementation
=
167 "com.sun.star.comp.configuration.backend.LocalReadonlyStratum" ;
168 static const sal_Char
* const kResourceStratumImplementation
=
169 "com.sun.star.comp.configuration.backend.LocalResourceStratum" ;
170 static const sal_Char
* const kBackendService
=
171 "com.sun.star.configuration.backend.SingleStratum" ;
172 static const sal_Char
* const kLocalService
=
173 "com.sun.star.configuration.backend.LocalSingleStratum" ;
175 static sal_Char
const * kServiceNames
[] = { kLocalService
, 0, kBackendService
, 0 } ;
176 static const ServiceImplementationInfo kLegacyStratumServiceInfo
= { kLegacyStratumImplementation
, kServiceNames
, kServiceNames
+ 2 } ;
177 static const ServiceImplementationInfo kDataStratumServiceInfo
= { kDataStratumImplementation
, kServiceNames
, kServiceNames
+ 2 } ;
178 static const ServiceImplementationInfo kReadonlyStratumServiceInfo
= { kReadonlyStratumImplementation
, kServiceNames
, kServiceNames
+ 2 } ;
179 static const ServiceImplementationInfo kResourceStratumServiceInfo
= { kResourceStratumImplementation
, kServiceNames
, kServiceNames
+ 2 } ;
181 const ServiceRegistrationInfo
*getLocalLegacyStratumServiceInfo()
182 { return getRegistrationInfo(&kLegacyStratumServiceInfo
) ; }
184 const ServiceRegistrationInfo
*getLocalDataStratumServiceInfo()
185 { return getRegistrationInfo(&kDataStratumServiceInfo
) ; }
187 const ServiceRegistrationInfo
*getLocalReadonlyStratumServiceInfo()
188 { return getRegistrationInfo(&kReadonlyStratumServiceInfo
) ; }
190 const ServiceRegistrationInfo
*getLocalResourceStratumServiceInfo()
191 { return getRegistrationInfo(&kResourceStratumServiceInfo
) ; }
193 uno::Reference
<uno::XInterface
> SAL_CALL
194 instantiateLocalLegacyStratum(const uno::Reference
< uno::XComponentContext
>& xContext
) {
195 return *new LocalSingleStratum(xContext
) ;
198 uno::Reference
<uno::XInterface
> SAL_CALL
199 instantiateLocalDataStratum(const uno::Reference
< uno::XComponentContext
>& xContext
) {
200 return *new LocalDataStratum(xContext
) ;
203 uno::Reference
<uno::XInterface
> SAL_CALL
204 instantiateLocalReadonlyStratum(const uno::Reference
< uno::XComponentContext
>& xContext
) {
205 return *new LocalReadonlyStratum(xContext
) ;
208 uno::Reference
<uno::XInterface
> SAL_CALL
209 instantiateLocalResourceStratum(const uno::Reference
< uno::XComponentContext
>& xContext
) {
210 return *new LocalResourceStratum(xContext
) ;
212 //------------------------------------------------------------------------------
214 const ServiceImplementationInfo
* LocalSingleStratum::getServiceInfoData() const
216 return &kLegacyStratumServiceInfo
;
218 const ServiceImplementationInfo
* LocalDataStratum::getServiceInfoData() const
220 return &kDataStratumServiceInfo
;
222 const ServiceImplementationInfo
* LocalReadonlyStratum::getServiceInfoData() const
224 return &kReadonlyStratumServiceInfo
;
226 const ServiceImplementationInfo
* LocalResourceStratum::getServiceInfoData() const
228 return &kResourceStratumServiceInfo
;
230 //------------------------------------------------------------------------------
231 // ---------------------------------------------------------------------------------------
233 } } // configmgr.localsinglestratum