summaryrefslogtreecommitdiff
path: root/cppuhelper/source/bootstrap.cxx
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2011-11-02 16:57:23 +0100
committerStephan Bergmann <sbergman@redhat.com>2011-11-02 17:25:36 +0100
commit8524330a746da6bd26ca5676b48cdce6bb722380 (patch)
tree3ab7235160fdc8e67b9f0436f4381d71757bf98c /cppuhelper/source/bootstrap.cxx
parent4ab6d2841dc47219d443e18f007f7b9893705966 (diff)
Simplify addition of optional components to URE_MORE_{SERVICES,TYPES}.
Those bootstrap variables now support <XXX>* syntax to include all files (non- recursively) contained in the directory denoted by XXX. Optional components can put their data simply into program/services/ and program/types/.
Diffstat (limited to 'cppuhelper/source/bootstrap.cxx')
-rw-r--r--cppuhelper/source/bootstrap.cxx163
1 files changed, 120 insertions, 43 deletions
diff --git a/cppuhelper/source/bootstrap.cxx b/cppuhelper/source/bootstrap.cxx
index 90a16af1be41..7aefa0b26b59 100644
--- a/cppuhelper/source/bootstrap.cxx
+++ b/cppuhelper/source/bootstrap.cxx
@@ -75,6 +75,8 @@ using namespace ::osl;
using namespace ::com::sun::star;
using namespace ::com::sun::star::uno;
+namespace css = com::sun::star;
+
namespace cppu
{
@@ -198,6 +200,105 @@ OUString findBootstrapArgument(
return result;
}
+css::uno::Reference< css::registry::XSimpleRegistry > readRdbFile(
+ rtl::OUString const & url, bool fatalErrors,
+ css::uno::Reference< css::registry::XSimpleRegistry > const & lastRegistry,
+ css::uno::Reference< css::lang::XSingleServiceFactory > const &
+ simpleRegistryFactory,
+ css::uno::Reference< css::lang::XSingleServiceFactory > const &
+ nestedRegistryFactory)
+{
+ OSL_ASSERT(simpleRegistryFactory.is() && nestedRegistryFactory.is());
+ try {
+ css::uno::Reference< css::registry::XSimpleRegistry > simple(
+ simpleRegistryFactory->createInstance(), css::uno::UNO_QUERY_THROW);
+ simple->open(url, true, false);
+ if (lastRegistry.is()) {
+ css::uno::Reference< css::registry::XSimpleRegistry > nested(
+ nestedRegistryFactory->createInstance(),
+ css::uno::UNO_QUERY_THROW);
+ css::uno::Sequence< css::uno::Any > args(2);
+ args[0] <<= lastRegistry;
+ args[1] <<= simple;
+ css::uno::Reference< css::lang::XInitialization >(
+ nested, css::uno::UNO_QUERY_THROW)->
+ initialize(args);
+ return nested;
+ } else {
+ return simple;
+ }
+ } catch (css::registry::InvalidRegistryException & e) {
+ (void) e; // avoid warnings
+ OSL_TRACE(
+ OSL_LOG_PREFIX "warning, could not open \"%s\": \"%s\"",
+ rtl::OUStringToOString(url, RTL_TEXTENCODING_UTF8).getStr(),
+ rtl::OUStringToOString(e.Message, RTL_TEXTENCODING_UTF8).getStr());
+ if (fatalErrors) {
+ throw;
+ }
+ return lastRegistry;
+ }
+}
+
+Reference< registry::XSimpleRegistry > readRdbDirectory(
+ rtl::OUString const & url, bool fatalErrors,
+ css::uno::Reference< css::registry::XSimpleRegistry > const & lastRegistry,
+ css::uno::Reference< css::lang::XSingleServiceFactory > const &
+ simpleRegistryFactory,
+ css::uno::Reference< css::lang::XSingleServiceFactory > const &
+ nestedRegistryFactory)
+{
+ OSL_ASSERT(simpleRegistryFactory.is() && nestedRegistryFactory.is());
+ osl::Directory dir(url);
+ switch (dir.open()) {
+ case osl::FileBase::E_None:
+ break;
+ case osl::FileBase::E_NOENT:
+ if (!fatalErrors) {
+ return lastRegistry;
+ }
+ // fall through
+ default:
+ throw css::uno::RuntimeException(
+ (rtl::OUString(
+ RTL_CONSTASCII_USTRINGPARAM("cannot open directory ")) +
+ url),
+ css::uno::Reference< css::uno::XInterface >());
+ }
+ for (css::uno::Reference< css::registry::XSimpleRegistry > last(
+ lastRegistry);;)
+ {
+ osl::DirectoryItem i;
+ switch (dir.getNextItem(i, SAL_MAX_UINT32)) {
+ case osl::FileBase::E_None:
+ break;
+ case osl::FileBase::E_NOENT:
+ return last;
+ default:
+ throw css::uno::RuntimeException(
+ (rtl::OUString(
+ RTL_CONSTASCII_USTRINGPARAM("cannot iterate directory ")) +
+ url),
+ css::uno::Reference< css::uno::XInterface >());
+ }
+ osl::FileStatus stat(
+ osl_FileStatus_Mask_Type | osl_FileStatus_Mask_FileName |
+ osl_FileStatus_Mask_FileURL);
+ if (i.getFileStatus(stat) != osl::FileBase::E_None) {
+ throw css::uno::RuntimeException(
+ (rtl::OUString(
+ RTL_CONSTASCII_USTRINGPARAM("cannot stat in directory ")) +
+ url),
+ css::uno::Reference< css::uno::XInterface >());
+ }
+ if (stat.getFileType() != osl::FileStatus::Directory) { //TODO: symlinks
+ last = readRdbFile(
+ stat.getFileURL(), fatalErrors, last, simpleRegistryFactory,
+ nestedRegistryFactory);
+ }
+ }
+}
+
Reference< registry::XSimpleRegistry > nestRegistries(
const OUString &baseDir,
const Reference< lang::XSingleServiceFactory > & xSimRegFac,
@@ -238,54 +339,30 @@ Reference< registry::XSimpleRegistry > nestRegistries(
OUString rdb_name = (index == -1) ? csl_rdbs : csl_rdbs.copy(0, index);
csl_rdbs = (index == -1) ? OUString() : csl_rdbs.copy(index + 1);
- if (! rdb_name.getLength())
+ if (rdb_name.isEmpty()) {
continue;
+ }
- bool optional = ('?' == rdb_name[ 0 ]);
- if (optional)
- rdb_name = rdb_name.copy( 1 );
-
- try
- {
- Reference<registry::XSimpleRegistry> simpleRegistry(
- xSimRegFac->createInstance(), UNO_QUERY_THROW );
-
- osl::FileBase::getAbsoluteFileURL(baseDir, rdb_name, rdb_name);
- simpleRegistry->open(rdb_name, sal_True, sal_False);
-
- if(lastRegistry.is())
- {
- Reference< registry::XSimpleRegistry > nestedRegistry(
- xNesRegFac->createInstance(), UNO_QUERY );
- Reference< lang::XInitialization > nestedRegistry_xInit(
- nestedRegistry, UNO_QUERY );
-
- Sequence<Any> aArgs(2);
- aArgs[0] <<= lastRegistry;
- aArgs[1] <<= simpleRegistry;
-
- nestedRegistry_xInit->initialize(aArgs);
-
- lastRegistry = nestedRegistry;
- }
- else
- lastRegistry = simpleRegistry;
+ bool fatalErrors = !bFallenBack;
+ if (rdb_name[0] == '?') {
+ rdb_name = rdb_name.copy(1);
+ fatalErrors = false;
}
- catch(registry::InvalidRegistryException & e)
- {
- (void) e; // avoid warnings
- OSL_TRACE(
- OSL_LOG_PREFIX "warning, could not open \"%s\": \"%s\"",
- OUStringToOString(rdb_name, RTL_TEXTENCODING_UTF8).getStr(),
- OUStringToOString(e.Message, RTL_TEXTENCODING_UTF8).getStr());
- if (! optional)
- {
- // if a registry was explicitly given, the exception shall fly
- if( ! bFallenBack )
- throw;
- }
+ bool directory = rdb_name.getLength() >= 3 && rdb_name[0] == '<' &&
+ rdb_name[rdb_name.getLength() - 2] == '>' &&
+ rdb_name[rdb_name.getLength() -1] == '*';
+ if (directory) {
+ rdb_name = rdb_name.copy(1, rdb_name.getLength() - 3);
}
+
+ osl::FileBase::getAbsoluteFileURL(baseDir, rdb_name, rdb_name);
+
+ lastRegistry = directory
+ ? readRdbDirectory(
+ rdb_name, fatalErrors, lastRegistry, xSimRegFac, xNesRegFac)
+ : readRdbFile(
+ rdb_name, fatalErrors, lastRegistry, xSimRegFac, xNesRegFac);
}
while(index != -1 && csl_rdbs.getLength()); // are there more rdbs in list?