Update ooo320-m1
[ooovba.git] / configmgr / source / localbe / localmultistratum.cxx
blob5dd93334bad49d051a4c07e1a1e2a624c762b011
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: localmultistratum.cxx,v $
10 * $Revision: 1.9 $
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 "localmultistratum.hxx"
35 #include "localfilehelper.hxx"
36 #include "filehelper.hxx"
38 #ifndef CONFIGMGR_API_FACTORY_HXX_
39 #include "confapifactory.hxx"
40 #endif // CONFIGMGR_API_FACTORY_HXX_
41 #include "serviceinfohelper.hxx"
42 #include <rtl/ustrbuf.hxx>
43 #include <com/sun/star/uno/XComponentContext.hpp>
44 #include <com/sun/star/configuration/backend/InsufficientAccessRightsException.hpp>
45 #include <osl/file.hxx>
47 namespace configmgr { namespace localbe {
49 //==============================================================================
51 static inline
52 rtl::OUString const & impl_getLayerDataDirectory(rtl::OUString const & aLayerBaseUrl)
53 { return aLayerBaseUrl; }
54 //------------------------------------------------------------------------------
55 static //inline
56 rtl::OUString makeLayerId(rtl::OUString const & aComponent,rtl::OUString const & aParticleFile)
58 OSL_ASSERT(aParticleFile.endsWithIgnoreAsciiCaseAsciiL(RTL_CONSTASCII_STRINGPARAM(kLocalDataSuffix)));
59 const sal_Int32 kExtLength = RTL_CONSTASCII_LENGTH(kLocalDataSuffix);
60 rtl::OUString const aParticleName = aParticleFile.copy(0,aParticleFile.getLength() - kExtLength);
62 rtl::OUStringBuffer aLayerId(aComponent);
63 aLayerId.append(k_cLayerIdSeparator);
64 aLayerId.append(aParticleName);
66 return aLayerId.makeStringAndClear();
69 LocalMultiStratum::LocalMultiStratum(const uno::Reference<uno::XComponentContext>& xContext)
70 : cppu::ImplInheritanceHelper1< LocalStratumBase, backend::XMultiLayerStratum >(xContext)
73 //------------------------------------------------------------------------------
75 LocalMultiStratum::~LocalMultiStratum() {}
77 //------------------------------------------------------------------------------
78 uno::Sequence< rtl::OUString > SAL_CALL
79 LocalMultiStratum::listLayerIds( const rtl::OUString& aComponent,
80 const rtl::OUString& /*aEntity*/ )
81 throw (backend::BackendAccessException, lang::IllegalArgumentException, uno::RuntimeException)
83 rtl::OUString const aLayerUrl = impl_getLayerDataDirectory(getBaseUrl());
84 rtl::OUString const aComponentUrl = aLayerUrl + componentToPath(aComponent);
86 const sal_uInt32 k_STATUS_FIELDS = FileStatusMask_FileName;
87 osl::Directory aComponentDirectory(aComponentUrl);
88 osl::DirectoryItem aItem;
89 std::vector< rtl::OUString > aResult;
91 osl::Directory::RC errcode = aComponentDirectory.open();
92 switch (errcode)
94 case osl::Directory::E_NOENT:
95 return uno::Sequence< rtl::OUString >();
97 case osl::Directory::E_None:
98 while (osl::Directory::E_None == (errcode=aComponentDirectory.getNextItem(aItem)))
100 osl::FileStatus aItemDescriptor( k_STATUS_FIELDS );
101 errcode = aItem.getFileStatus(aItemDescriptor);
103 if ( errcode != osl::DirectoryItem::E_None )
105 OSL_ASSERT(errcode != osl::Directory::E_NOENT); // unexpected failure for getFileStatus for existing file
106 if (errcode == osl::Directory::E_NOENT) continue;
108 OSL_TRACE("Reading Component Directory - Error (%u) getting status of directory item.\n", unsigned(errcode));
109 break;
112 OSL_ENSURE( aItemDescriptor.isValid(FileStatusMask_FileName), "Could not get name of component found");
113 rtl::OUString const aFileName = aItemDescriptor.getFileName();
115 // It is reasonable to assume a .xcu file is not a directory & =>
116 // not stat each directory entry at considerable cost.
117 if (!aFileName.endsWithIgnoreAsciiCaseAsciiL(RTL_CONSTASCII_STRINGPARAM(kLocalDataSuffix)))
118 continue;
120 aResult.push_back( makeLayerId(aComponent,aFileName) );
122 OSL_ASSERT(errcode != osl::Directory::E_None); // Loop postcond
124 // joint error handling with open failure
125 if (errcode != osl::Directory::E_NOENT) // normal loop termination
127 default: // if open() truly failed we also go here
128 rtl::OUStringBuffer errbuf;
129 errbuf.appendAscii("LocalMultiStratum::listLayerIds: ");
130 errbuf.appendAscii("Error scanning directory ").append(aComponentUrl)
131 .appendAscii(" for particle files. ");
132 errbuf.appendAscii("Error: ").append(FileHelper::createOSLErrorString(errcode));
133 rtl::OUString const errmsg = errbuf.makeStringAndClear();
134 throw backend::BackendAccessException(errmsg,*this,uno::Any());
137 return aResult.empty()
138 ? uno::Sequence< rtl::OUString >()
139 : uno::Sequence< rtl::OUString >(
140 &aResult.front(), static_cast<sal_Int32>(aResult.size()));
144 //------------------------------------------------------------------------------
145 rtl::OUString SAL_CALL
146 LocalMultiStratum::getUpdateLayerId( const rtl::OUString& aComponent,
147 const rtl::OUString& /*aEntity*/ )
148 throw (backend::BackendAccessException, lang::NoSupportException,
149 lang::IllegalArgumentException, uno::RuntimeException)
151 failReadonly();
152 return aComponent;
155 //------------------------------------------------------------------------------
156 uno::Reference< backend::XLayer > SAL_CALL
157 LocalMultiStratum::getLayer( const rtl::OUString& aLayerId,
158 const rtl::OUString& aTimestamp )
159 throw (backend::BackendAccessException, lang::IllegalArgumentException,
160 uno::RuntimeException)
162 return LocalStratumBase::getLayer(aLayerId,aTimestamp);
164 //------------------------------------------------------------------------------
165 uno::Sequence< uno::Reference< backend::XLayer > > SAL_CALL
166 LocalMultiStratum::getLayers( const uno::Sequence< rtl::OUString >& aLayerIds,
167 const rtl::OUString& aTimestamp )
168 throw (backend::BackendAccessException, lang::IllegalArgumentException,
169 uno::RuntimeException)
171 sal_Int32 const nLayers = aLayerIds.getLength();
172 uno::Sequence< uno::Reference< backend::XLayer > > aResult(nLayers);
173 for (sal_Int32 ix=0; ix<nLayers; ++ix)
175 aResult[ix] = LocalStratumBase::getLayer(aLayerIds[ix],aTimestamp);
177 return aResult;
180 //------------------------------------------------------------------------------
181 uno::Sequence< uno::Reference< backend::XLayer > > SAL_CALL
182 LocalMultiStratum::getMultipleLayers( const uno::Sequence< rtl::OUString >& aLayerIds,
183 const uno::Sequence< rtl::OUString >& aTimestamps )
184 throw (backend::BackendAccessException, lang::IllegalArgumentException,
185 uno::RuntimeException)
187 if (aLayerIds.getLength() != aTimestamps.getLength()) {
188 throw lang::IllegalArgumentException(
189 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
190 "LocalStratum::getMultipleLayers(): Timestamp count does not match layer count")),
191 *this, 0) ;
193 sal_Int32 const nLayers = aLayerIds.getLength();
194 uno::Sequence< uno::Reference< backend::XLayer > > aResult(nLayers);
195 for (sal_Int32 ix=0; ix<nLayers; ++ix)
197 aResult[ix] = LocalStratumBase::getLayer(aLayerIds[ix],aTimestamps[ix]);
199 return aResult;
202 //------------------------------------------------------------------------------
203 uno::Reference< backend::XUpdatableLayer > SAL_CALL
204 LocalMultiStratum::getUpdatableLayer( const rtl::OUString& /*aLayerId*/ )
205 throw (backend::BackendAccessException, lang::IllegalArgumentException,
206 lang::NoSupportException, uno::RuntimeException)
208 failReadonly();
209 return 0;
211 //------------------------------------------------------------------------------
213 void LocalMultiStratum::getLayerDirectories(rtl::OUString& aLayerUrl,
214 rtl::OUString& aSubLayerUrl) const
216 aLayerUrl = impl_getLayerDataDirectory(getBaseUrl());
217 aSubLayerUrl = rtl::OUString();
219 //------------------------------------------------------------------------------
220 //------------------------------------------------------------------------------
222 static const sal_Char * const kMultiStratumImplementation =
223 "com.sun.star.comp.configuration.backend.LocalMultiStratum" ;
224 static const sal_Char * const kBackendService =
225 "com.sun.star.configuration.backend.MultiStratum" ;
226 static const sal_Char * const kLocalService =
227 "com.sun.star.configuration.backend.LocalMultiStratum" ;
229 static sal_Char const * kServiceNames [] = { kLocalService, 0, kBackendService, 0 } ;
230 static const ServiceImplementationInfo kMultiStratumServiceInfo = { kMultiStratumImplementation , kServiceNames, kServiceNames + 2 } ;
232 const ServiceRegistrationInfo *getLocalMultiStratumServiceInfo()
233 { return getRegistrationInfo(&kMultiStratumServiceInfo) ; }
235 uno::Reference<uno::XInterface> SAL_CALL
236 instantiateLocalMultiStratum(const uno::Reference< uno::XComponentContext >& xContext) {
237 return *new LocalMultiStratum(xContext) ;
240 //------------------------------------------------------------------------------
242 const ServiceImplementationInfo * LocalMultiStratum::getServiceInfoData() const
244 return &kMultiStratumServiceInfo;
246 //------------------------------------------------------------------------------
247 // ---------------------------------------------------------------------------------------
249 } } // configmgr.localsinglestratum