update dev300-m58
[ooovba.git] / configmgr / source / localbe / localstratumbase.cxx
blobc57af960dafcfc3dad4abc172308a071a71e70f5
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: localstratumbase.cxx,v $
10 * $Revision: 1.8 $
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 "localstratumbase.hxx"
35 #include "localfilehelper.hxx"
36 #include "localfilelayer.hxx"
37 #include "oslstream.hxx"
38 #include "serviceinfohelper.hxx"
39 #include "bootstrap.hxx"
40 #include "filehelper.hxx"
41 #include <rtl/ustrbuf.hxx>
42 #include <com/sun/star/uno/XComponentContext.hpp>
43 #include <com/sun/star/lang/NoSupportException.hpp>
44 #include <com/sun/star/configuration/backend/InsufficientAccessRightsException.hpp>
45 #include <osl/file.hxx>
46 #include <osl/process.h>
47 #include <memory>
49 namespace configmgr { namespace localbe {
51 //==============================================================================
53 //------------------------------------------------------------------------------
55 LocalStratumBase::LocalStratumBase(const uno::Reference<uno::XComponentContext>& xContext)
56 : cppu::WeakComponentImplHelper3<lang::XInitialization, backend::XBackendEntities, lang::XServiceInfo>(mMutex)
57 , mFactory(xContext->getServiceManager(),uno::UNO_QUERY)
60 //------------------------------------------------------------------------------
62 LocalStratumBase::~LocalStratumBase()
65 //------------------------------------------------------------------------------
66 void SAL_CALL LocalStratumBase::initialize(const uno::Sequence<uno::Any>& aParameters)
67 throw (uno::RuntimeException, uno::Exception,
68 css::configuration::InvalidBootstrapFileException,
69 backend::CannotConnectException,
70 backend::BackendSetupException)
75 if (aParameters.getLength() == 0)
77 throw lang::IllegalArgumentException(
78 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
79 "No parameters provided to local Stratum")),
80 *this, 0) ;
84 for (sal_Int32 i = 0 ; i < aParameters.getLength() ; ++ i)
86 if (aParameters [i] >>= mStrataDataUrl )
87 { break ; }
91 // get modified base for special layer implementations (e.g. resources)
92 this->adjustBaseURL(mStrataDataUrl);
94 validateFileURL(mStrataDataUrl, *this);
95 implEnsureAbsoluteURL(mStrataDataUrl);
96 normalizeURL(mStrataDataUrl,*this, true);
98 if(FileHelper::fileExists(mStrataDataUrl))
100 checkIfDirectory(mStrataDataUrl, *this);
104 //------------------------------------------------------------------------------
106 void LocalStratumBase::adjustBaseURL(rtl::OUString& )
109 //------------------------------------------------------------------------------
111 sal_Bool LocalStratumBase::isMoreRecent(const rtl::OUString& aFileUrl,
112 const rtl::OUString& aTimestamp) {
113 rtl::OUString layerUrl ;
114 rtl::OUString subLayerUrl ;
116 getLayerDirectories(layerUrl, subLayerUrl) ;
118 return layerUrl.getLength() == 0 ||
119 !BasicLocalFileLayer::getTimestamp(layerUrl + aFileUrl).equals( aTimestamp);
121 //------------------------------------------------------------------------------
123 uno::Reference<backend::XLayer> SAL_CALL
124 LocalStratumBase::getLayer( const rtl::OUString& aLayerId, const rtl::OUString& aTimestamp )
125 throw (backend::BackendAccessException, lang::IllegalArgumentException,
126 uno::RuntimeException)
129 if (aLayerId.getLength() == 0){
130 throw lang::IllegalArgumentException(
131 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
132 "LocalStratum:getLayer - no LayerId specified")),
133 *this, 0) ;
135 rtl::OUString const componentSubPath = layeridToPath(aLayerId) + getDataSuffix();
136 if (!isMoreRecent(componentSubPath, aTimestamp)) { return NULL ; }
138 return createReadonlyFileLayer(componentSubPath);
140 //------------------------------------------------------------------------------
141 //------------------------------------------------------------------------------
143 rtl::OUString SAL_CALL LocalStratumBase::getOwnerEntity()
144 throw (uno::RuntimeException)
146 return mStrataDataUrl ;
148 //------------------------------------------------------------------------------
150 rtl::OUString SAL_CALL LocalStratumBase::getAdminEntity()
151 throw (uno::RuntimeException)
153 return rtl::OUString();
155 //------------------------------------------------------------------------------
157 sal_Bool SAL_CALL LocalStratumBase::supportsEntity( const rtl::OUString& aEntity )
158 throw (backend::BackendAccessException, uno::RuntimeException)
160 if(mStrataDataUrl.getLength() == 0)
162 return false;
164 if (aEntity.getLength() == 0)
166 return false;
168 return isEqualEntity(mStrataDataUrl,aEntity);
170 //------------------------------------------------------------------------------
172 sal_Bool SAL_CALL LocalStratumBase::isEqualEntity(const rtl::OUString& aEntity, const rtl::OUString& aOtherEntity)
173 throw (backend::BackendAccessException, lang::IllegalArgumentException, uno::RuntimeException)
175 if (aEntity.getLength() == 0)
177 rtl::OUString const sMsg(RTL_CONSTASCII_USTRINGPARAM(
178 "LocalSingleBackend - Invalid empty entity."));
180 throw lang::IllegalArgumentException(sMsg, *this, 1);
182 if (aOtherEntity.getLength() == 0)
184 rtl::OUString const sMsg(RTL_CONSTASCII_USTRINGPARAM(
185 "LocalSingleBackend - Invalid empty entity."));
187 throw lang::IllegalArgumentException(sMsg, *this, 2);
189 rtl::OUString aNormalizedEntity(aEntity);
190 normalizeURL(aNormalizedEntity,*this);
192 rtl::OUString aNormalizedOther(aOtherEntity);
193 normalizeURL(aNormalizedOther,*this);
195 return aNormalizedEntity == aNormalizedOther;
197 //------------------------------------------------------------------------------
198 //------------------------------------------------------------------------------
199 uno::Reference<backend::XLayer>
200 LocalStratumBase::createReadonlyFileLayer(const rtl::OUString& aSubpath)
201 throw (lang::IllegalArgumentException)
203 rtl::OUString layerPath ;
204 rtl::OUString subLayerPath ;
206 getLayerDirectories(layerPath, subLayerPath) ;
207 return createReadonlyLocalFileLayer(mFactory, layerPath, aSubpath, subLayerPath) ;
209 //------------------------------------------------------------------------------
210 uno::Reference<backend::XUpdatableLayer>
211 LocalStratumBase::createUpdatableFileLayer(const rtl::OUString& aSubpath)
212 throw (lang::IllegalArgumentException)
214 rtl::OUString layerPath ;
215 rtl::OUString subLayerPath ;
217 getLayerDirectories(layerPath, subLayerPath) ;
218 return createUpdatableLocalFileLayer(mFactory, layerPath, aSubpath, subLayerPath) ;
220 //------------------------------------------------------------------------------
222 rtl::OUString SAL_CALL LocalStratumBase::getImplementationName()
223 throw (uno::RuntimeException)
225 return ServiceInfoHelper(getServiceInfoData()).getImplementationName() ;
227 //------------------------------------------------------------------------------
229 sal_Bool SAL_CALL LocalStratumBase::supportsService(const rtl::OUString& aServiceName)
230 throw (uno::RuntimeException)
232 return ServiceInfoHelper(getServiceInfoData()).supportsService(aServiceName);
234 //------------------------------------------------------------------------------
236 uno::Sequence<rtl::OUString> SAL_CALL LocalStratumBase::getSupportedServiceNames()
237 throw (uno::RuntimeException)
239 return ServiceInfoHelper(getServiceInfoData()).getSupportedServiceNames() ;
242 // ---------------------------------------------------------------------------------------
244 void LocalStratumBase::failReadonly()
246 rtl::OUStringBuffer aMessage;
247 aMessage.appendAscii("Configurations - ")
248 .appendAscii("Cannot get update access to layer: ")
249 .appendAscii("Local file-based stratum at ")
250 .append(this->getBaseUrl())
251 .appendAscii(" is readonly.");
252 throw lang::NoSupportException(aMessage.makeStringAndClear(),*this);
254 //------------------------------------------------------------------------------
256 } } // configmgr.localsinglestratum