diff options
author | Cyrille Moureaux <cyrillem@openoffice.org> | 2002-07-03 12:39:56 +0000 |
---|---|---|
committer | Cyrille Moureaux <cyrillem@openoffice.org> | 2002-07-03 12:39:56 +0000 |
commit | c1654159f1f7d2636ae61642c50d4e11cc513a42 (patch) | |
tree | 0922048fc0eb148ef742c2ef095e53acbbbbc9f9 /configmgr/source/localbe/localfilelayer.cxx | |
parent | 1dc5899f13f6141b62924c5ed3ac535df87b9376 (diff) |
Added exceptions and extended to implement XCompositeLayer
Diffstat (limited to 'configmgr/source/localbe/localfilelayer.cxx')
-rw-r--r-- | configmgr/source/localbe/localfilelayer.cxx | 116 |
1 files changed, 98 insertions, 18 deletions
diff --git a/configmgr/source/localbe/localfilelayer.cxx b/configmgr/source/localbe/localfilelayer.cxx index ccc20093e1..ebf1aaa922 100644 --- a/configmgr/source/localbe/localfilelayer.cxx +++ b/configmgr/source/localbe/localfilelayer.cxx @@ -2,9 +2,9 @@ * * $RCSfile: localfilelayer.cxx,v $ * - * $Revision: 1.3 $ + * $Revision: 1.4 $ * - * last change: $Author: cyrillem $ $Date: 2002-06-17 14:30:52 $ + * last change: $Author: cyrillem $ $Date: 2002-07-03 13:39:55 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -71,6 +71,10 @@ #include "oslstream.hxx" #endif // _CONFIGMGR_OSLSTREAM_HXX_ +#ifndef _RTL_USTRBUF_HXX_ +#include <rtl/ustrbuf.hxx> +#endif // _RTL_USTRBUF_HXX_ + #ifndef _COM_SUN_STAR_LANG_XINITIALIZATION_HPP_ #include <com/sun/star/lang/XInitialization.hpp> #endif // _COM_SUN_STAR_LANG_XINITIALIZATION_HPP_ @@ -83,8 +87,10 @@ namespace configmgr { namespace localbe { LocalFileLayer::LocalFileLayer( const uno::Reference<lang::XMultiServiceFactory>& xFactory, - const rtl::OUString& aFileUrl) -: mFactory(xFactory), mFileUrl(aFileUrl) { + const rtl::OUString& aBaseDir, + const rtl::OUString& aComponent, + const rtl::OUString& aResDir) +: mFactory(xFactory), mFileUrl(aBaseDir + aComponent) { static const rtl::OUString kXMLLayerParser(RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.configuration.backend.xml.LayerParser")) ; static const rtl::OUString kXMLLayerWriter(RTL_CONSTASCII_USTRINGPARAM( @@ -94,6 +100,9 @@ LocalFileLayer::LocalFileLayer( mFactory->createInstance(kXMLLayerParser)) ; mLayerWriter = uno::Reference<backend::XLayerHandler>::query( mFactory->createInstance(kXMLLayerWriter)) ; + if (aResDir.getLength() != 0) { + fillSubLayerList(aResDir, aComponent) ; + } } //------------------------------------------------------------------------------ @@ -102,31 +111,43 @@ LocalFileLayer::~LocalFileLayer(void) {} void SAL_CALL LocalFileLayer::readData( const uno::Reference<backend::XLayerHandler>& xHandler) - throw (uno::RuntimeException) + throw (lang::WrappedTargetException, uno::RuntimeException) { - osl::File blobFile(mFileUrl) ; - osl::FileBase::RC errorCode = blobFile.open(OpenFlag_Read) ; - - if (errorCode != osl_File_E_None) { return ; } - uno::Reference<io::XInputStream> stream = - new OSLInputStreamWrapper(blobFile) ; - uno::Sequence<uno::Any> arguments(1) ; - - arguments [0] <<= stream ; - uno::Reference<lang::XInitialization>::query(mLayerReader)->initialize( - arguments) ; - mLayerReader->readData(xHandler) ; + readData(xHandler, mFileUrl) ; } //------------------------------------------------------------------------------ void SAL_CALL LocalFileLayer::replaceWith( const uno::Reference<backend::XLayer>& aNewLayer) - throw (uno::RuntimeException) + throw (lang::WrappedTargetException, uno::RuntimeException) { aNewLayer->readData(getLayerWriter()) ; } //------------------------------------------------------------------------------ +void SAL_CALL LocalFileLayer::readSubLayerData( + const uno::Reference<backend::XLayerHandler>& xHandler, + const rtl::OUString& aSubLayerId) + throw (lang::IllegalArgumentException, lang::WrappedTargetException, + uno::RuntimeException) +{ + sal_Int32 i ; + + for (i = 0 ; i < mSubLayers.getLength() ; ++ i) { + if (mSubLayers [i].equals(aSubLayerId)) { break ; } + } + if (i == mSubLayers.getLength()) { + rtl::OUStringBuffer message ; + + message.appendAscii("Sublayer Id '").append(aSubLayerId) ; + message.appendAscii("' is unknown") ; + throw lang::IllegalArgumentException(message.makeStringAndClear(), + *this, 1) ; + } + readData(xHandler, mSubLayerFiles [i]) ; +} +//------------------------------------------------------------------------------ + const uno::Reference<backend::XLayerHandler>& LocalFileLayer::getLayerWriter(void) const { uno::Reference<io::XOutputStream> stream = new LocalOutputStream(mFileUrl) ; @@ -156,5 +177,64 @@ rtl::OUString LocalFileLayer::getTimestamp(const rtl::OUString& aFileUrl) { } //------------------------------------------------------------------------------ +void LocalFileLayer::fillSubLayerList(const rtl::OUString& aResDir, + const rtl::OUString& aComponent) { + // Extract the directory where the file is located + osl::Directory directory(aResDir) ; + + if (directory.open() != osl_File_E_None) { return ; } + osl::DirectoryItem item ; + osl::FileStatus status(osl_FileStatus_Mask_Type | + osl_FileStatus_Mask_FileURL) ; + std::vector<rtl::OUString> subLayerDirs ; + + while (directory.getNextItem(item) == osl_File_E_None) { + if (item.getFileStatus(status) == osl_File_E_None) { + if (status.getFileType() == osl::FileStatus::Directory) { + // Let's check whether the sublayer exists for the + // particular component. + rtl::OUString subLayerFile(status.getFileURL() + aComponent) ; + + if (FileHelper::fileExists(subLayerFile)) { + mSubLayerFiles.push_back(subLayerFile) ; + subLayerDirs.push_back( + FileHelper::getFileName(status.getFileURL())) ; + } + } + } + } + if (subLayerDirs.size() > 0) { + mSubLayers.realloc(subLayerDirs.size()) ; + std::vector<rtl::OUString>::const_iterator subLayer ; + sal_Int32 i = 0 ; + + for (subLayer = subLayerDirs.begin() ; + subLayer != subLayerDirs.end() ; ++ subLayer) { + mSubLayers [i ++] = *subLayer ; + } + } +} +//------------------------------------------------------------------------------ + +void LocalFileLayer::readData( + const uno::Reference<backend::XLayerHandler>& xHandler, + const rtl::OUString& aFileUrl) + throw (lang::WrappedTargetException, uno::RuntimeException) +{ + osl::File blobFile(aFileUrl) ; + osl::FileBase::RC errorCode = blobFile.open(OpenFlag_Read) ; + + if (errorCode != osl_File_E_None) { return ; } + uno::Reference<io::XInputStream> stream = + new OSLInputStreamWrapper(blobFile) ; + uno::Sequence<uno::Any> arguments(1) ; + + arguments [0] <<= stream ; + uno::Reference<lang::XInitialization>::query(mLayerReader)->initialize( + arguments) ; + mLayerReader->readData(xHandler) ; +} +//------------------------------------------------------------------------------ + } } // configmgr.localbe |