2013-01-15 16:28:30 +01:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "sal/config.h"
|
|
|
|
|
|
|
|
#include <cassert>
|
2013-01-18 12:46:16 +01:00
|
|
|
#include <vector>
|
2013-01-15 16:28:30 +01:00
|
|
|
|
2013-01-18 12:46:16 +01:00
|
|
|
#include "com/sun/star/container/XHierarchicalNameAccess.hpp"
|
2013-01-15 16:28:30 +01:00
|
|
|
#include "com/sun/star/lang/XInitialization.hpp"
|
2013-01-15 18:05:07 +01:00
|
|
|
#include "com/sun/star/lang/XMultiComponentFactory.hpp"
|
2013-01-15 16:28:30 +01:00
|
|
|
#include "com/sun/star/registry/InvalidRegistryException.hpp"
|
|
|
|
#include "com/sun/star/registry/XSimpleRegistry.hpp"
|
|
|
|
#include "com/sun/star/uno/DeploymentException.hpp"
|
|
|
|
#include "com/sun/star/uno/Reference.hxx"
|
2013-01-18 12:46:16 +01:00
|
|
|
#include "com/sun/star/uno/Sequence.hxx"
|
2013-01-15 18:05:07 +01:00
|
|
|
#include "com/sun/star/uno/XComponentContext.hpp"
|
|
|
|
#include "com/sun/star/uno/XInterface.hpp"
|
2013-01-15 16:28:30 +01:00
|
|
|
#include "osl/file.hxx"
|
|
|
|
#include "rtl/ustring.hxx"
|
|
|
|
|
|
|
|
#include "paths.hxx"
|
|
|
|
#include "typedescriptionprovider.hxx"
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2013-01-18 12:46:16 +01:00
|
|
|
void readTypeRdbFile(
|
2013-01-15 16:28:30 +01:00
|
|
|
rtl::OUString const & uri, bool optional,
|
2013-01-15 18:05:07 +01:00
|
|
|
css::uno::Reference< css::lang::XMultiComponentFactory > const &
|
|
|
|
serviceManager,
|
2013-01-18 12:46:16 +01:00
|
|
|
css::uno::Reference< css::uno::XComponentContext > const & context,
|
|
|
|
std::vector<
|
|
|
|
css::uno::Reference< css::container::XHierarchicalNameAccess > > *
|
|
|
|
providers)
|
2013-01-15 16:28:30 +01:00
|
|
|
{
|
2013-01-15 18:05:07 +01:00
|
|
|
assert(serviceManager.is());
|
2013-01-18 12:46:16 +01:00
|
|
|
assert(providers != 0);
|
|
|
|
css::uno::Reference< css::registry::XSimpleRegistry > reg(
|
|
|
|
serviceManager->createInstanceWithContext(
|
|
|
|
"com.sun.star.comp.stoc.SimpleRegistry", context),
|
|
|
|
css::uno::UNO_QUERY_THROW);
|
2013-01-15 16:28:30 +01:00
|
|
|
try {
|
2013-01-18 12:46:16 +01:00
|
|
|
reg->open(uri, true, false);
|
2013-01-15 16:28:30 +01:00
|
|
|
} catch (css::registry::InvalidRegistryException & e) {
|
2013-01-18 12:46:16 +01:00
|
|
|
if (optional) {
|
|
|
|
SAL_INFO("cppuhelper", "Ignored optional " << uri);
|
|
|
|
return;
|
2013-01-15 16:28:30 +01:00
|
|
|
}
|
2013-01-18 12:46:16 +01:00
|
|
|
throw css::uno::DeploymentException(
|
|
|
|
"Invalid registry " + uri + ":" + e.Message,
|
|
|
|
css::uno::Reference< css::uno::XInterface >());
|
2013-01-15 16:28:30 +01:00
|
|
|
}
|
2013-01-18 12:46:16 +01:00
|
|
|
css::uno::Sequence< css::uno::Any > arg(1);
|
|
|
|
arg[0] <<= reg;
|
|
|
|
providers->push_back(
|
|
|
|
css::uno::Reference< css::container::XHierarchicalNameAccess >(
|
|
|
|
serviceManager->createInstanceWithArgumentsAndContext(
|
|
|
|
"com.sun.star.comp.stoc.RegistryTypeDescriptionProvider", arg,
|
|
|
|
context),
|
|
|
|
css::uno::UNO_QUERY_THROW));
|
2013-01-15 16:28:30 +01:00
|
|
|
}
|
|
|
|
|
2013-01-18 12:46:16 +01:00
|
|
|
void readTypeRdbDirectory(
|
2013-01-15 16:28:30 +01:00
|
|
|
rtl::OUString const & uri, bool optional,
|
2013-01-15 18:05:07 +01:00
|
|
|
css::uno::Reference< css::lang::XMultiComponentFactory > const &
|
|
|
|
serviceManager,
|
2013-01-18 12:46:16 +01:00
|
|
|
css::uno::Reference< css::uno::XComponentContext > const & context,
|
|
|
|
std::vector<
|
|
|
|
css::uno::Reference< css::container::XHierarchicalNameAccess > > *
|
|
|
|
providers)
|
2013-01-15 16:28:30 +01:00
|
|
|
{
|
|
|
|
osl::Directory dir(uri);
|
|
|
|
switch (dir.open()) {
|
|
|
|
case osl::FileBase::E_None:
|
|
|
|
break;
|
|
|
|
case osl::FileBase::E_NOENT:
|
|
|
|
if (optional) {
|
|
|
|
SAL_INFO("cppuhelper", "Ignored optional " << uri);
|
2013-01-18 12:46:16 +01:00
|
|
|
return;
|
2013-01-15 16:28:30 +01:00
|
|
|
}
|
|
|
|
// fall through
|
|
|
|
default:
|
|
|
|
throw css::uno::DeploymentException(
|
|
|
|
"Cannot open directory " + uri,
|
|
|
|
css::uno::Reference< css::uno::XInterface >());
|
|
|
|
}
|
|
|
|
for (;;) {
|
|
|
|
rtl::OUString fileUri;
|
|
|
|
if (!cppu::nextDirectoryItem(dir, &fileUri)) {
|
|
|
|
break;
|
|
|
|
}
|
2013-01-18 12:46:16 +01:00
|
|
|
readTypeRdbFile(fileUri, optional, serviceManager, context, providers);
|
2013-01-15 16:28:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-18 12:46:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
css::uno::Sequence<
|
|
|
|
css::uno::Reference< css::container::XHierarchicalNameAccess > >
|
|
|
|
cppuhelper::createTypeDescriptionProviders(
|
2013-01-15 18:05:07 +01:00
|
|
|
rtl::OUString const & uris,
|
|
|
|
css::uno::Reference< css::lang::XMultiComponentFactory > const &
|
|
|
|
serviceManager,
|
|
|
|
css::uno::Reference< css::uno::XComponentContext > const & context)
|
2013-01-15 16:28:30 +01:00
|
|
|
{
|
2013-01-18 12:46:16 +01:00
|
|
|
std::vector<
|
|
|
|
css::uno::Reference< css::container::XHierarchicalNameAccess > > provs;
|
2013-01-15 16:28:30 +01:00
|
|
|
for (sal_Int32 i = 0; i != -1;) {
|
|
|
|
rtl::OUString uri(uris.getToken(0, ' ', i));
|
|
|
|
if (uri.isEmpty()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
bool optional;
|
|
|
|
bool directory;
|
|
|
|
cppu::decodeRdbUri(&uri, &optional, &directory);
|
2013-01-18 12:46:16 +01:00
|
|
|
if (directory) {
|
|
|
|
readTypeRdbDirectory(
|
|
|
|
uri, optional, serviceManager, context, &provs);
|
|
|
|
} else {
|
|
|
|
readTypeRdbFile(uri, optional, serviceManager, context, &provs);
|
|
|
|
}
|
2013-01-15 16:28:30 +01:00
|
|
|
}
|
2013-01-18 12:46:16 +01:00
|
|
|
css::uno::Sequence<
|
|
|
|
css::uno::Reference< css::container::XHierarchicalNameAccess > > provs2(
|
|
|
|
static_cast< sal_Int32 >(provs.size())); //TODO: check overflow
|
|
|
|
std::vector<
|
|
|
|
css::uno::Reference<
|
|
|
|
css::container::XHierarchicalNameAccess > >::iterator i(
|
|
|
|
provs.begin());
|
|
|
|
for (sal_Int32 j = 0; j != provs2.getLength(); ++j) {
|
|
|
|
provs2[j] = *i++;
|
2013-01-15 18:05:07 +01:00
|
|
|
}
|
2013-01-18 12:46:16 +01:00
|
|
|
return provs2;
|
2013-01-15 18:05:07 +01:00
|
|
|
}
|
|
|
|
|
2013-01-15 16:28:30 +01:00
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|