2010-10-12 15:53:47 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-11-12 17:21:24 +00:00
|
|
|
/*
|
|
|
|
* 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/.
|
|
|
|
*
|
|
|
|
* This file incorporates work covered by the following license notice:
|
|
|
|
*
|
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed
|
|
|
|
* with this work for additional information regarding copyright
|
|
|
|
* ownership. The ASF licenses this file to you under the Apache
|
|
|
|
* License, Version 2.0 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
|
|
|
|
*/
|
2004-09-20 09:06:34 +00:00
|
|
|
|
|
|
|
#include <accelerators/presethandler.hxx>
|
|
|
|
|
2007-07-18 07:49:44 +00:00
|
|
|
#include <classes/fwkresid.hxx>
|
|
|
|
|
|
|
|
#include "classes/resource.hrc"
|
2004-09-20 09:06:34 +00:00
|
|
|
#include <services.h>
|
|
|
|
|
2013-05-08 15:02:35 +02:00
|
|
|
#include <com/sun/star/beans/XPropertySet.hpp>
|
2007-07-18 07:49:44 +00:00
|
|
|
#include <com/sun/star/configuration/CorruptedUIConfigurationException.hpp>
|
2004-09-20 09:06:34 +00:00
|
|
|
#include <com/sun/star/container/NoSuchElementException.hpp>
|
|
|
|
#include <com/sun/star/container/XNameAccess.hpp>
|
|
|
|
#include <com/sun/star/embed/ElementModes.hpp>
|
|
|
|
#include <com/sun/star/embed/XTransactedObject.hpp>
|
2012-12-10 14:39:29 +02:00
|
|
|
#include <com/sun/star/embed/FileSystemStorageFactory.hpp>
|
2004-09-20 09:06:34 +00:00
|
|
|
#include <com/sun/star/lang/XSingleServiceFactory.hpp>
|
2014-01-27 09:51:58 +01:00
|
|
|
#include <com/sun/star/util/thePathSettings.hpp>
|
2004-09-20 09:06:34 +00:00
|
|
|
|
|
|
|
#include <vcl/svapp.hxx>
|
2011-10-07 21:09:41 +02:00
|
|
|
#include <cppuhelper/exc_hlp.hxx>
|
2004-09-20 09:06:34 +00:00
|
|
|
#include <rtl/ustrbuf.hxx>
|
2013-04-05 18:40:39 +02:00
|
|
|
#include <i18nlangtag/languagetag.hxx>
|
2004-09-20 09:06:34 +00:00
|
|
|
|
2007-07-18 07:49:44 +00:00
|
|
|
static const ::sal_Int32 ID_CORRUPT_UICONFIG_SHARE = 1;
|
|
|
|
static const ::sal_Int32 ID_CORRUPT_UICONFIG_USER = 2;
|
|
|
|
static const ::sal_Int32 ID_CORRUPT_UICONFIG_GENERAL = 3;
|
|
|
|
|
2004-09-20 09:06:34 +00:00
|
|
|
namespace framework
|
|
|
|
{
|
|
|
|
|
2013-05-27 15:15:03 +02:00
|
|
|
PresetHandler::PresetHandler(const css::uno::Reference< css::uno::XComponentContext >& xContext)
|
2014-03-22 20:43:05 +00:00
|
|
|
: m_xContext(xContext)
|
|
|
|
, m_eConfigType(E_GLOBAL)
|
|
|
|
, m_aSharedStorages()
|
2013-01-31 10:19:52 +02:00
|
|
|
, m_lDocumentStorages()
|
2014-03-22 20:43:05 +00:00
|
|
|
, m_aLanguageTag(LANGUAGE_USER_PRIV_NOTRANSLATE)
|
2004-09-20 09:06:34 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
PresetHandler::PresetHandler(const PresetHandler& rCopy)
|
2014-03-18 08:26:59 +01:00
|
|
|
: m_aLanguageTag( rCopy.m_aLanguageTag)
|
2004-09-20 09:06:34 +00:00
|
|
|
{
|
2013-05-27 15:15:03 +02:00
|
|
|
m_xContext = rCopy.m_xContext;
|
2004-09-20 09:06:34 +00:00
|
|
|
m_eConfigType = rCopy.m_eConfigType;
|
|
|
|
m_sResourceType = rCopy.m_sResourceType;
|
|
|
|
m_sModule = rCopy.m_sModule;
|
|
|
|
m_aSharedStorages = rCopy.m_aSharedStorages;
|
|
|
|
m_xWorkingStorageShare = rCopy.m_xWorkingStorageShare;
|
2006-12-20 16:50:00 +00:00
|
|
|
m_xWorkingStorageNoLang = rCopy.m_xWorkingStorageNoLang;
|
2004-09-20 09:06:34 +00:00
|
|
|
m_xWorkingStorageUser = rCopy.m_xWorkingStorageUser;
|
|
|
|
m_lPresets = rCopy.m_lPresets;
|
|
|
|
m_lTargets = rCopy.m_lTargets;
|
|
|
|
m_lDocumentStorages = rCopy.m_lDocumentStorages;
|
2005-07-08 08:12:27 +00:00
|
|
|
m_sRelPathShare = rCopy.m_sRelPathShare;
|
2006-12-20 16:50:00 +00:00
|
|
|
m_sRelPathNoLang = rCopy.m_sRelPathNoLang;
|
2005-07-08 08:12:27 +00:00
|
|
|
m_sRelPathUser = rCopy.m_sRelPathUser;
|
2004-09-20 09:06:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PresetHandler::~PresetHandler()
|
|
|
|
{
|
2004-12-07 12:37:37 +00:00
|
|
|
m_xWorkingStorageShare.clear();
|
2006-12-20 16:50:00 +00:00
|
|
|
m_xWorkingStorageNoLang.clear();
|
2004-12-07 12:37:37 +00:00
|
|
|
m_xWorkingStorageUser.clear();
|
2005-07-08 08:12:27 +00:00
|
|
|
|
|
|
|
/* #i46497#
|
|
|
|
Dont call forgetCachedStorages() here for shared storages.
|
|
|
|
Because we opened different sub storages by using openPath().
|
|
|
|
And every already open path was reused and referenced (means it's
|
|
|
|
ref count was increased!)
|
|
|
|
So now we have to release our ref counts to these shared storages
|
|
|
|
only ... and not to free all used storages.
|
|
|
|
Otherwise we will disconnect all other open configuration access
|
|
|
|
objects which base on these storages.
|
|
|
|
*/
|
|
|
|
m_aSharedStorages->m_lStoragesShare.closePath(m_sRelPathShare);
|
|
|
|
m_aSharedStorages->m_lStoragesUser.closePath (m_sRelPathUser );
|
|
|
|
|
|
|
|
/* On the other side closePath() is not needed for our special handled
|
|
|
|
document storage. Because it's not shared with others ... so we can
|
|
|
|
free it.
|
|
|
|
*/
|
2004-12-07 12:37:37 +00:00
|
|
|
m_lDocumentStorages.forgetCachedStorages();
|
2004-12-07 12:18:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PresetHandler::forgetCachedStorages()
|
|
|
|
{
|
2014-03-18 08:26:59 +01:00
|
|
|
SolarMutexGuard g;
|
2004-12-07 12:18:17 +00:00
|
|
|
|
2004-12-07 12:37:37 +00:00
|
|
|
if (m_eConfigType == E_DOCUMENT)
|
|
|
|
{
|
|
|
|
m_xWorkingStorageShare.clear();
|
2006-12-20 16:50:00 +00:00
|
|
|
m_xWorkingStorageNoLang.clear();
|
2004-12-07 12:37:37 +00:00
|
|
|
m_xWorkingStorageUser.clear();
|
|
|
|
}
|
2004-12-07 12:18:17 +00:00
|
|
|
|
|
|
|
m_lDocumentStorages.forgetCachedStorages();
|
2004-09-20 09:06:34 +00:00
|
|
|
}
|
|
|
|
|
2011-10-07 21:09:41 +02:00
|
|
|
namespace {
|
|
|
|
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString lcl_getLocalizedMessage(::sal_Int32 nID)
|
2007-07-18 07:49:44 +00:00
|
|
|
{
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString sMessage("Unknown error.");
|
2007-07-18 07:49:44 +00:00
|
|
|
|
|
|
|
switch(nID)
|
|
|
|
{
|
|
|
|
case ID_CORRUPT_UICONFIG_SHARE :
|
2013-07-27 17:01:36 +01:00
|
|
|
sMessage = FWK_RESSTR(STR_CORRUPT_UICFG_SHARE);
|
2011-10-07 21:09:41 +02:00
|
|
|
|
2007-07-18 07:49:44 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_CORRUPT_UICONFIG_USER :
|
2013-07-27 17:01:36 +01:00
|
|
|
sMessage = FWK_RESSTR(STR_CORRUPT_UICFG_USER);
|
2007-07-18 07:49:44 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_CORRUPT_UICONFIG_GENERAL :
|
2013-07-27 17:01:36 +01:00
|
|
|
sMessage = FWK_RESSTR(STR_CORRUPT_UICFG_GENERAL);
|
2007-07-18 07:49:44 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return sMessage;
|
|
|
|
}
|
|
|
|
|
2011-10-07 21:09:41 +02:00
|
|
|
void lcl_throwCorruptedUIConfigurationException(
|
|
|
|
css::uno::Any const & exception, sal_Int32 id)
|
|
|
|
{
|
|
|
|
css::uno::Exception e;
|
|
|
|
bool ok = (exception >>= e);
|
|
|
|
OSL_ASSERT(ok); (void) ok; // avoid warnings
|
|
|
|
throw css::configuration::CorruptedUIConfigurationException(
|
|
|
|
lcl_getLocalizedMessage(id),
|
|
|
|
css::uno::Reference< css::uno::XInterface >(),
|
2014-12-18 13:19:13 +01:00
|
|
|
exception.getValueTypeName() + ": \"" + e.Message + "\"");
|
2011-10-07 21:09:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2004-09-20 09:06:34 +00:00
|
|
|
css::uno::Reference< css::embed::XStorage > PresetHandler::getOrCreateRootStorageShare()
|
|
|
|
{
|
|
|
|
css::uno::Reference< css::embed::XStorage > xRoot = m_aSharedStorages->m_lStoragesShare.getRootStorage();
|
|
|
|
if (xRoot.is())
|
|
|
|
return xRoot;
|
|
|
|
|
2014-03-18 08:26:59 +01:00
|
|
|
css::uno::Reference< css::uno::XComponentContext > xContext;
|
|
|
|
{
|
|
|
|
SolarMutexGuard g;
|
|
|
|
xContext = m_xContext;
|
|
|
|
}
|
2004-09-20 09:06:34 +00:00
|
|
|
|
2013-05-08 15:02:35 +02:00
|
|
|
css::uno::Reference< css::util::XPathSettings > xPathSettings =
|
2014-01-27 09:51:58 +01:00
|
|
|
css::util::thePathSettings::get( xContext );
|
2004-09-20 09:06:34 +00:00
|
|
|
|
2013-05-08 15:02:35 +02:00
|
|
|
OUString sShareLayer = xPathSettings->getBasePathShareLayer();
|
2004-09-20 09:06:34 +00:00
|
|
|
|
|
|
|
// "UIConfig" is a "multi path" ... use first part only here!
|
|
|
|
sal_Int32 nPos = sShareLayer.indexOf(';');
|
|
|
|
if (nPos > 0)
|
|
|
|
sShareLayer = sShareLayer.copy(0, nPos);
|
|
|
|
|
|
|
|
// Note: May be an user uses URLs without a final slash! Check it ...
|
|
|
|
nPos = sShareLayer.lastIndexOf('/');
|
|
|
|
if (nPos != sShareLayer.getLength()-1)
|
2013-10-25 17:17:50 +02:00
|
|
|
sShareLayer += "/";
|
2004-09-20 09:06:34 +00:00
|
|
|
|
2013-09-09 00:58:15 +03:00
|
|
|
sShareLayer += "soffice.cfg";
|
2004-09-20 09:06:34 +00:00
|
|
|
/*
|
|
|
|
// TODO remove me!
|
|
|
|
// Attention: This is temp. workaround ... We create a temp. storage file
|
2014-04-29 19:05:05 +00:00
|
|
|
// based of a system directory. This must be used so, till the storage implementation
|
2004-09-20 09:06:34 +00:00
|
|
|
// can work on directories too.
|
|
|
|
*/
|
|
|
|
css::uno::Sequence< css::uno::Any > lArgs(2);
|
|
|
|
lArgs[0] <<= sShareLayer;
|
|
|
|
lArgs[1] <<= css::embed::ElementModes::READ | css::embed::ElementModes::NOCREATE;
|
|
|
|
|
2013-05-27 15:15:03 +02:00
|
|
|
css::uno::Reference< css::lang::XSingleServiceFactory > xStorageFactory = css::embed::FileSystemStorageFactory::create( xContext );
|
2007-07-18 07:49:44 +00:00
|
|
|
css::uno::Reference< css::embed::XStorage > xStorage;
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
xStorage = css::uno::Reference< css::embed::XStorage >(xStorageFactory->createInstanceWithArguments(lArgs), css::uno::UNO_QUERY_THROW);
|
|
|
|
}
|
2011-10-07 21:09:41 +02:00
|
|
|
catch(const css::uno::Exception&)
|
2007-07-18 07:49:44 +00:00
|
|
|
{
|
2011-10-07 21:09:41 +02:00
|
|
|
css::uno::Any ex(cppu::getCaughtException());
|
|
|
|
lcl_throwCorruptedUIConfigurationException(
|
|
|
|
ex, ID_CORRUPT_UICONFIG_SHARE);
|
2007-07-18 07:49:44 +00:00
|
|
|
}
|
2004-09-20 09:06:34 +00:00
|
|
|
|
|
|
|
m_aSharedStorages->m_lStoragesShare.setRootStorage(xStorage);
|
|
|
|
|
|
|
|
return xStorage;
|
|
|
|
}
|
|
|
|
|
|
|
|
css::uno::Reference< css::embed::XStorage > PresetHandler::getOrCreateRootStorageUser()
|
|
|
|
{
|
|
|
|
css::uno::Reference< css::embed::XStorage > xRoot = m_aSharedStorages->m_lStoragesUser.getRootStorage();
|
|
|
|
if (xRoot.is())
|
|
|
|
return xRoot;
|
|
|
|
|
2014-03-18 08:26:59 +01:00
|
|
|
css::uno::Reference< css::uno::XComponentContext > xContext;
|
|
|
|
{
|
|
|
|
SolarMutexGuard g;
|
|
|
|
xContext = m_xContext;
|
|
|
|
}
|
2004-09-20 09:06:34 +00:00
|
|
|
|
2013-05-08 15:02:35 +02:00
|
|
|
css::uno::Reference< css::util::XPathSettings > xPathSettings =
|
2014-01-27 09:51:58 +01:00
|
|
|
css::util::thePathSettings::get( xContext );
|
2004-09-20 09:06:34 +00:00
|
|
|
|
2013-05-08 15:02:35 +02:00
|
|
|
OUString sUserLayer = xPathSettings->getBasePathUserLayer();
|
2004-09-20 09:06:34 +00:00
|
|
|
|
|
|
|
// Note: May be an user uses URLs without a final slash! Check it ...
|
|
|
|
sal_Int32 nPos = sUserLayer.lastIndexOf('/');
|
|
|
|
if (nPos != sUserLayer.getLength()-1)
|
2013-10-25 17:17:50 +02:00
|
|
|
sUserLayer += "/";
|
2004-09-20 09:06:34 +00:00
|
|
|
|
2013-09-09 00:58:15 +03:00
|
|
|
sUserLayer += "soffice.cfg"; // storage file
|
2004-09-20 09:06:34 +00:00
|
|
|
|
|
|
|
css::uno::Sequence< css::uno::Any > lArgs(2);
|
|
|
|
lArgs[0] <<= sUserLayer;
|
|
|
|
lArgs[1] <<= css::embed::ElementModes::READWRITE;
|
|
|
|
|
2013-05-27 15:15:03 +02:00
|
|
|
css::uno::Reference< css::lang::XSingleServiceFactory > xStorageFactory = css::embed::FileSystemStorageFactory::create( xContext );
|
2007-07-18 07:49:44 +00:00
|
|
|
css::uno::Reference< css::embed::XStorage > xStorage;
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
xStorage = css::uno::Reference< css::embed::XStorage >(xStorageFactory->createInstanceWithArguments(lArgs), css::uno::UNO_QUERY_THROW);
|
|
|
|
}
|
2011-10-07 21:09:41 +02:00
|
|
|
catch(const css::uno::Exception&)
|
2007-07-18 07:49:44 +00:00
|
|
|
{
|
2011-10-07 21:09:41 +02:00
|
|
|
css::uno::Any ex(cppu::getCaughtException());
|
|
|
|
lcl_throwCorruptedUIConfigurationException(
|
|
|
|
ex, ID_CORRUPT_UICONFIG_USER);
|
2007-07-18 07:49:44 +00:00
|
|
|
}
|
|
|
|
|
2004-09-20 09:06:34 +00:00
|
|
|
m_aSharedStorages->m_lStoragesUser.setRootStorage(xStorage);
|
|
|
|
|
|
|
|
return xStorage;
|
|
|
|
}
|
|
|
|
|
|
|
|
css::uno::Reference< css::embed::XStorage > PresetHandler::getWorkingStorageShare()
|
|
|
|
{
|
2014-03-18 08:26:59 +01:00
|
|
|
SolarMutexGuard g;
|
2004-09-20 09:06:34 +00:00
|
|
|
return m_xWorkingStorageShare;
|
|
|
|
}
|
|
|
|
|
|
|
|
css::uno::Reference< css::embed::XStorage > PresetHandler::getWorkingStorageUser()
|
|
|
|
{
|
2014-03-18 08:26:59 +01:00
|
|
|
SolarMutexGuard g;
|
2004-09-20 09:06:34 +00:00
|
|
|
return m_xWorkingStorageUser;
|
|
|
|
}
|
|
|
|
|
2006-06-19 10:11:15 +00:00
|
|
|
css::uno::Reference< css::embed::XStorage > PresetHandler::getParentStorageShare(const css::uno::Reference< css::embed::XStorage >& /*xChild*/)
|
2004-09-20 09:06:34 +00:00
|
|
|
{
|
2014-03-18 08:26:59 +01:00
|
|
|
css::uno::Reference< css::embed::XStorage > xWorking;
|
|
|
|
{
|
|
|
|
SolarMutexGuard g;
|
|
|
|
xWorking = m_xWorkingStorageShare;
|
|
|
|
}
|
2004-09-20 09:06:34 +00:00
|
|
|
|
|
|
|
return m_aSharedStorages->m_lStoragesShare.getParentStorage(xWorking);
|
|
|
|
}
|
|
|
|
|
2006-06-19 10:11:15 +00:00
|
|
|
css::uno::Reference< css::embed::XStorage > PresetHandler::getParentStorageUser(const css::uno::Reference< css::embed::XStorage >& /*xChild*/)
|
2004-09-20 09:06:34 +00:00
|
|
|
{
|
2014-03-18 08:26:59 +01:00
|
|
|
css::uno::Reference< css::embed::XStorage > xWorking;
|
|
|
|
{
|
|
|
|
SolarMutexGuard g;
|
|
|
|
xWorking = m_xWorkingStorageUser;
|
|
|
|
}
|
2004-09-20 09:06:34 +00:00
|
|
|
|
|
|
|
return m_aSharedStorages->m_lStoragesUser.getParentStorage(xWorking);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PresetHandler::connectToResource( PresetHandler::EConfigType eConfigType ,
|
2013-04-07 12:06:47 +02:00
|
|
|
const OUString& sResource ,
|
|
|
|
const OUString& sModule ,
|
2004-09-20 09:06:34 +00:00
|
|
|
const css::uno::Reference< css::embed::XStorage >& xDocumentRoot,
|
2013-03-28 00:13:14 +01:00
|
|
|
const LanguageTag& rLanguageTag )
|
2004-09-20 09:06:34 +00:00
|
|
|
{
|
|
|
|
// TODO free all current open storages!
|
|
|
|
|
2014-03-18 08:26:59 +01:00
|
|
|
{
|
|
|
|
SolarMutexGuard g;
|
2014-04-06 19:36:08 +03:00
|
|
|
m_eConfigType = eConfigType;
|
|
|
|
m_sResourceType = sResource;
|
|
|
|
m_sModule = sModule;
|
|
|
|
m_aLanguageTag = rLanguageTag;
|
2014-03-18 08:26:59 +01:00
|
|
|
}
|
2004-09-20 09:06:34 +00:00
|
|
|
|
|
|
|
css::uno::Reference< css::embed::XStorage > xShare;
|
2006-12-20 16:50:00 +00:00
|
|
|
css::uno::Reference< css::embed::XStorage > xNoLang;
|
2004-09-20 09:06:34 +00:00
|
|
|
css::uno::Reference< css::embed::XStorage > xUser;
|
|
|
|
|
|
|
|
// special case for documents
|
|
|
|
// use outside root storage, if we run in E_DOCUMENT mode!
|
|
|
|
if (eConfigType == E_DOCUMENT)
|
|
|
|
{
|
|
|
|
if (!xDocumentRoot.is())
|
|
|
|
throw css::uno::RuntimeException(
|
2014-05-23 12:03:21 +02:00
|
|
|
"There is valid root storage, where the UI configuration can work on.");
|
2004-09-20 09:06:34 +00:00
|
|
|
m_lDocumentStorages.setRootStorage(xDocumentRoot);
|
|
|
|
xShare = xDocumentRoot;
|
|
|
|
xUser = xDocumentRoot;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
xShare = getOrCreateRootStorageShare();
|
|
|
|
xUser = getOrCreateRootStorageUser();
|
|
|
|
}
|
|
|
|
|
2007-07-18 07:49:44 +00:00
|
|
|
// #...#
|
|
|
|
try
|
|
|
|
{
|
|
|
|
|
2004-12-07 12:18:17 +00:00
|
|
|
// a) inside share layer we should not create any new structures ... We jave to use
|
|
|
|
// existing ones only!
|
2013-09-26 11:44:54 +02:00
|
|
|
// b) inside user layer we can (SOFT mode!) but sometimes we should not (HARD mode!)
|
2004-12-07 12:18:17 +00:00
|
|
|
// create new empty structures. We should preferr using of any existing structure.
|
2004-12-07 13:16:36 +00:00
|
|
|
sal_Int32 eShareMode = (css::embed::ElementModes::READ | css::embed::ElementModes::NOCREATE);
|
|
|
|
sal_Int32 eUserMode = (css::embed::ElementModes::READWRITE );
|
2004-09-20 09:06:34 +00:00
|
|
|
|
2013-04-07 12:06:47 +02:00
|
|
|
OUStringBuffer sRelPathBuf(1024);
|
|
|
|
OUString sRelPathShare;
|
|
|
|
OUString sRelPathNoLang;
|
|
|
|
OUString sRelPathUser;
|
2004-09-20 09:06:34 +00:00
|
|
|
switch(eConfigType)
|
|
|
|
{
|
|
|
|
case E_GLOBAL :
|
|
|
|
{
|
2013-09-09 00:58:15 +03:00
|
|
|
sRelPathBuf.append("global");
|
|
|
|
sRelPathBuf.append("/");
|
|
|
|
sRelPathBuf.append(sResource);
|
2005-07-08 08:12:27 +00:00
|
|
|
sRelPathShare = sRelPathBuf.makeStringAndClear();
|
|
|
|
sRelPathUser = sRelPathShare;
|
2004-09-20 09:06:34 +00:00
|
|
|
|
2014-04-04 15:53:21 +02:00
|
|
|
xShare = impl_openPathIgnoringErrors(sRelPathShare, eShareMode, true );
|
|
|
|
xUser = impl_openPathIgnoringErrors(sRelPathUser , eUserMode , false);
|
2004-09-20 09:06:34 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case E_MODULES :
|
|
|
|
{
|
2013-09-09 00:58:15 +03:00
|
|
|
sRelPathBuf.append("modules");
|
|
|
|
sRelPathBuf.append("/");
|
|
|
|
sRelPathBuf.append(sModule);
|
|
|
|
sRelPathBuf.append("/");
|
|
|
|
sRelPathBuf.append(sResource);
|
2005-07-08 08:12:27 +00:00
|
|
|
sRelPathShare = sRelPathBuf.makeStringAndClear();
|
|
|
|
sRelPathUser = sRelPathShare;
|
2004-09-20 09:06:34 +00:00
|
|
|
|
2014-04-04 15:53:21 +02:00
|
|
|
xShare = impl_openPathIgnoringErrors(sRelPathShare, eShareMode, true );
|
|
|
|
xUser = impl_openPathIgnoringErrors(sRelPathUser , eUserMode , false);
|
2004-09-20 09:06:34 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case E_DOCUMENT :
|
|
|
|
{
|
2005-09-30 09:11:22 +00:00
|
|
|
// A document does not have a share layer in real.
|
|
|
|
// It has one layer only, and this one should be opened READ_WRITE.
|
|
|
|
// So we open the user layer here only and set the share layer equals to it .-)
|
|
|
|
|
2004-09-20 09:06:34 +00:00
|
|
|
sRelPathBuf.append(sResource);
|
2005-09-30 09:11:22 +00:00
|
|
|
sRelPathUser = sRelPathBuf.makeStringAndClear();
|
|
|
|
sRelPathShare = sRelPathUser;
|
2004-09-20 09:06:34 +00:00
|
|
|
|
2004-11-16 13:52:37 +00:00
|
|
|
try
|
|
|
|
{
|
2005-09-30 09:11:22 +00:00
|
|
|
xUser = m_lDocumentStorages.openPath(sRelPathUser , eUserMode );
|
|
|
|
xShare = xUser;
|
2004-11-16 13:52:37 +00:00
|
|
|
}
|
2012-02-02 22:53:48 +01:00
|
|
|
catch(const css::uno::RuntimeException&)
|
|
|
|
{ throw; }
|
2004-11-16 13:52:37 +00:00
|
|
|
catch(const css::uno::Exception&)
|
|
|
|
{ xShare.clear(); xUser.clear(); }
|
2004-09-20 09:06:34 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2006-12-20 16:50:00 +00:00
|
|
|
// Non-localized global share
|
|
|
|
xNoLang = xShare;
|
|
|
|
sRelPathNoLang = sRelPathShare;
|
|
|
|
|
2004-11-16 13:52:37 +00:00
|
|
|
if (
|
2013-03-28 00:13:14 +01:00
|
|
|
(rLanguageTag != LanguageTag(LANGUAGE_USER_PRIV_NOTRANSLATE)) && // localized level?
|
2004-11-16 13:52:37 +00:00
|
|
|
(eConfigType != E_DOCUMENT ) // no localization in document mode!
|
|
|
|
)
|
2004-09-20 09:06:34 +00:00
|
|
|
{
|
2005-02-24 16:11:12 +00:00
|
|
|
// First try to find the right localized set inside share layer.
|
|
|
|
// Fallbacks are allowed there.
|
2014-04-04 15:53:21 +02:00
|
|
|
OUString aShareLocale( rLanguageTag.getBcp47());
|
|
|
|
OUString sLocalizedSharePath(sRelPathShare);
|
|
|
|
bool bAllowFallbacks = true;
|
|
|
|
xShare = impl_openLocalizedPathIgnoringErrors(sLocalizedSharePath, eShareMode, true , aShareLocale, bAllowFallbacks);
|
2005-02-24 16:11:12 +00:00
|
|
|
|
|
|
|
// The try to locate the right sub dir inside user layer ... without using fallbacks!
|
2014-09-10 22:35:39 +02:00
|
|
|
// Normally the corresponding sub dir should be created matching the specified locale.
|
2005-02-24 16:11:12 +00:00
|
|
|
// Because we allow creation of storages inside user layer by default.
|
2014-04-04 15:53:21 +02:00
|
|
|
OUString aUserLocale( rLanguageTag.getBcp47());
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString sLocalizedUserPath(sRelPathUser);
|
2014-04-04 15:53:21 +02:00
|
|
|
bAllowFallbacks = false;
|
|
|
|
xUser = impl_openLocalizedPathIgnoringErrors(sLocalizedUserPath, eUserMode, false, aUserLocale, bAllowFallbacks);
|
2005-02-24 16:11:12 +00:00
|
|
|
|
2005-07-08 08:12:27 +00:00
|
|
|
sRelPathShare = sLocalizedSharePath;
|
2014-04-06 19:36:08 +03:00
|
|
|
sRelPathUser = sLocalizedUserPath;
|
2004-09-20 09:06:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// read content of level 3 (presets, targets)
|
2014-04-06 19:36:08 +03:00
|
|
|
css::uno::Reference< css::container::XNameAccess > xAccess;
|
|
|
|
css::uno::Sequence< OUString > lNames;
|
|
|
|
const OUString* pNames;
|
|
|
|
sal_Int32 c;
|
|
|
|
sal_Int32 i;
|
2004-09-20 09:06:34 +00:00
|
|
|
OUStringList lPresets;
|
|
|
|
OUStringList lTargets;
|
|
|
|
|
|
|
|
// read preset names of share layer
|
2004-11-16 13:52:37 +00:00
|
|
|
xAccess = css::uno::Reference< css::container::XNameAccess >(xShare, css::uno::UNO_QUERY);
|
|
|
|
if (xAccess.is())
|
2004-09-20 09:06:34 +00:00
|
|
|
{
|
2004-11-16 13:52:37 +00:00
|
|
|
lNames = xAccess->getElementNames();
|
|
|
|
pNames = lNames.getConstArray();
|
|
|
|
c = lNames.getLength();
|
|
|
|
|
|
|
|
for (i=0; i<c; ++i)
|
|
|
|
{
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString sTemp = pNames[i];
|
2013-09-09 00:58:15 +03:00
|
|
|
sal_Int32 nPos = sTemp.indexOf(".xml");
|
2004-11-16 13:52:37 +00:00
|
|
|
if (nPos > -1)
|
|
|
|
sTemp = sTemp.copy(0,nPos);
|
|
|
|
lPresets.push_back(sTemp);
|
|
|
|
}
|
2004-09-20 09:06:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// read preset names of user layer
|
2004-11-16 13:52:37 +00:00
|
|
|
xAccess = css::uno::Reference< css::container::XNameAccess >(xUser, css::uno::UNO_QUERY);
|
|
|
|
if (xAccess.is())
|
2004-09-20 09:06:34 +00:00
|
|
|
{
|
2004-11-16 13:52:37 +00:00
|
|
|
lNames = xAccess->getElementNames();
|
|
|
|
pNames = lNames.getConstArray();
|
|
|
|
c = lNames.getLength();
|
|
|
|
|
|
|
|
for (i=0; i<c; ++i)
|
|
|
|
{
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString sTemp = pNames[i];
|
2013-09-09 00:58:15 +03:00
|
|
|
sal_Int32 nPos = sTemp.indexOf(".xml");
|
2004-11-16 13:52:37 +00:00
|
|
|
if (nPos > -1)
|
|
|
|
sTemp = sTemp.copy(0,nPos);
|
|
|
|
lTargets.push_back(sTemp);
|
|
|
|
}
|
2004-09-20 09:06:34 +00:00
|
|
|
}
|
|
|
|
|
2014-03-18 08:26:59 +01:00
|
|
|
{
|
|
|
|
SolarMutexGuard g;
|
2014-04-06 19:36:08 +03:00
|
|
|
m_xWorkingStorageShare = xShare;
|
2014-03-18 08:26:59 +01:00
|
|
|
m_xWorkingStorageNoLang= xNoLang;
|
2014-04-06 19:36:08 +03:00
|
|
|
m_xWorkingStorageUser = xUser;
|
2014-03-18 08:26:59 +01:00
|
|
|
m_lPresets = lPresets;
|
|
|
|
m_lTargets = lTargets;
|
|
|
|
m_sRelPathShare = sRelPathShare;
|
|
|
|
m_sRelPathNoLang = sRelPathNoLang;
|
|
|
|
m_sRelPathUser = sRelPathUser;
|
|
|
|
}
|
2007-07-18 07:49:44 +00:00
|
|
|
|
|
|
|
}
|
2011-10-07 21:09:41 +02:00
|
|
|
catch(const css::uno::Exception&)
|
2007-07-18 07:49:44 +00:00
|
|
|
{
|
2011-10-07 21:09:41 +02:00
|
|
|
css::uno::Any ex(cppu::getCaughtException());
|
|
|
|
lcl_throwCorruptedUIConfigurationException(
|
|
|
|
ex, ID_CORRUPT_UICONFIG_GENERAL);
|
2007-07-18 07:49:44 +00:00
|
|
|
}
|
2004-09-20 09:06:34 +00:00
|
|
|
}
|
|
|
|
|
2013-04-07 12:06:47 +02:00
|
|
|
void PresetHandler::copyPresetToTarget(const OUString& sPreset,
|
|
|
|
const OUString& sTarget)
|
2004-09-20 09:06:34 +00:00
|
|
|
{
|
|
|
|
// dont check our preset list, if element exists
|
|
|
|
// We try to open it and forward all errors to the user!
|
|
|
|
|
2014-03-18 08:26:59 +01:00
|
|
|
css::uno::Reference< css::embed::XStorage > xWorkingShare;
|
|
|
|
css::uno::Reference< css::embed::XStorage > xWorkingNoLang;
|
|
|
|
css::uno::Reference< css::embed::XStorage > xWorkingUser;
|
|
|
|
{
|
|
|
|
SolarMutexGuard g;
|
|
|
|
xWorkingShare = m_xWorkingStorageShare;
|
|
|
|
xWorkingNoLang= m_xWorkingStorageNoLang;
|
2014-04-06 19:36:08 +03:00
|
|
|
xWorkingUser = m_xWorkingStorageUser;
|
2014-03-18 08:26:59 +01:00
|
|
|
}
|
2004-09-20 09:06:34 +00:00
|
|
|
|
2004-11-16 13:52:37 +00:00
|
|
|
// e.g. module without any config data ?!
|
|
|
|
if (
|
|
|
|
(!xWorkingShare.is()) ||
|
|
|
|
(!xWorkingUser.is() )
|
|
|
|
)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString sPresetFile(sPreset);
|
2013-09-09 00:58:15 +03:00
|
|
|
sPresetFile += ".xml";
|
2004-09-20 09:06:34 +00:00
|
|
|
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString sTargetFile(sTarget);
|
2013-09-09 00:58:15 +03:00
|
|
|
sTargetFile += ".xml";
|
2004-09-20 09:06:34 +00:00
|
|
|
|
|
|
|
// remove existing elements before you try to copy the preset to that location ...
|
|
|
|
// Otherwise w will get an ElementExistException inside copyElementTo()!
|
|
|
|
css::uno::Reference< css::container::XNameAccess > xCheckingUser(xWorkingUser, css::uno::UNO_QUERY_THROW);
|
|
|
|
if (xCheckingUser->hasByName(sTargetFile))
|
|
|
|
xWorkingUser->removeElement(sTargetFile);
|
|
|
|
|
|
|
|
xWorkingShare->copyElementTo(sPresetFile, xWorkingUser, sTargetFile);
|
|
|
|
|
|
|
|
// If our storages work in transacted mode, we have
|
|
|
|
// to commit all changes from bottom to top!
|
|
|
|
commitUserChanges();
|
|
|
|
}
|
|
|
|
|
2013-04-07 12:06:47 +02:00
|
|
|
css::uno::Reference< css::io::XStream > PresetHandler::openPreset(const OUString& sPreset,
|
2014-04-04 15:53:21 +02:00
|
|
|
bool bUseNoLangGlobal)
|
2004-09-20 09:06:34 +00:00
|
|
|
{
|
2014-03-18 08:26:59 +01:00
|
|
|
css::uno::Reference< css::embed::XStorage > xFolder;
|
|
|
|
{
|
|
|
|
SolarMutexGuard g;
|
|
|
|
xFolder = bUseNoLangGlobal? m_xWorkingStorageNoLang: m_xWorkingStorageShare;
|
|
|
|
}
|
2004-09-20 09:06:34 +00:00
|
|
|
|
2004-11-16 13:52:37 +00:00
|
|
|
// e.g. module without any config data ?!
|
|
|
|
if (!xFolder.is())
|
|
|
|
return css::uno::Reference< css::io::XStream >();
|
|
|
|
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString sFile(sPreset);
|
2013-09-09 00:58:15 +03:00
|
|
|
sFile += ".xml";
|
2004-09-20 09:06:34 +00:00
|
|
|
|
|
|
|
// inform user about errors (use original exceptions!)
|
|
|
|
css::uno::Reference< css::io::XStream > xStream = xFolder->openStreamElement(sFile, css::embed::ElementModes::READ);
|
|
|
|
return xStream;
|
|
|
|
}
|
|
|
|
|
2013-04-07 12:06:47 +02:00
|
|
|
css::uno::Reference< css::io::XStream > PresetHandler::openTarget(const OUString& sTarget ,
|
2014-04-04 15:53:21 +02:00
|
|
|
bool bCreateIfMissing)
|
2004-09-20 09:06:34 +00:00
|
|
|
{
|
2014-03-18 08:26:59 +01:00
|
|
|
css::uno::Reference< css::embed::XStorage > xFolder;
|
|
|
|
{
|
|
|
|
SolarMutexGuard g;
|
|
|
|
xFolder = m_xWorkingStorageUser;
|
|
|
|
}
|
2004-09-20 09:06:34 +00:00
|
|
|
|
2004-11-16 13:52:37 +00:00
|
|
|
// e.g. module without any config data ?!
|
|
|
|
if (!xFolder.is())
|
|
|
|
return css::uno::Reference< css::io::XStream >();
|
|
|
|
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString sFile(sTarget);
|
2013-09-09 00:58:15 +03:00
|
|
|
sFile += ".xml";
|
2004-09-20 09:06:34 +00:00
|
|
|
|
|
|
|
sal_Int32 nOpenMode = css::embed::ElementModes::READWRITE;
|
|
|
|
if (!bCreateIfMissing)
|
|
|
|
nOpenMode |= css::embed::ElementModes::NOCREATE;
|
|
|
|
|
|
|
|
// try it in read/write mode first and ignore errors.
|
|
|
|
css::uno::Reference< css::io::XStream > xStream;
|
|
|
|
try
|
|
|
|
{
|
|
|
|
xStream = xFolder->openStreamElement(sFile, nOpenMode);
|
|
|
|
return xStream;
|
|
|
|
}
|
|
|
|
catch(const css::uno::RuntimeException&)
|
|
|
|
{ throw; }
|
|
|
|
catch(const css::uno::Exception&)
|
|
|
|
{ xStream.clear(); }
|
|
|
|
|
|
|
|
// try it readonly if it failed before.
|
|
|
|
// inform user about errors (use original exceptions!)
|
|
|
|
nOpenMode &= ~css::embed::ElementModes::WRITE;
|
|
|
|
xStream = xFolder->openStreamElement(sFile, nOpenMode);
|
|
|
|
|
|
|
|
return xStream;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PresetHandler::commitUserChanges()
|
|
|
|
{
|
2014-03-18 08:26:59 +01:00
|
|
|
css::uno::Reference< css::embed::XStorage > xWorking;
|
|
|
|
EConfigType eCfgType;
|
|
|
|
{
|
|
|
|
SolarMutexGuard g;
|
|
|
|
xWorking = m_xWorkingStorageUser;
|
|
|
|
eCfgType = m_eConfigType;
|
|
|
|
}
|
2004-09-20 09:06:34 +00:00
|
|
|
|
2004-11-16 13:52:37 +00:00
|
|
|
// e.g. module without any config data ?!
|
|
|
|
if (!xWorking.is())
|
|
|
|
return;
|
|
|
|
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString sPath;
|
2004-09-20 09:06:34 +00:00
|
|
|
|
|
|
|
switch(eCfgType)
|
|
|
|
{
|
|
|
|
case E_GLOBAL :
|
|
|
|
case E_MODULES :
|
|
|
|
{
|
|
|
|
sPath = m_aSharedStorages->m_lStoragesUser.getPathOfStorage(xWorking);
|
|
|
|
m_aSharedStorages->m_lStoragesUser.commitPath(sPath);
|
|
|
|
m_aSharedStorages->m_lStoragesUser.notifyPath(sPath);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case E_DOCUMENT :
|
|
|
|
{
|
|
|
|
sPath = m_lDocumentStorages.getPathOfStorage(xWorking);
|
|
|
|
m_lDocumentStorages.commitPath(sPath);
|
|
|
|
m_lDocumentStorages.notifyPath(sPath);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PresetHandler::addStorageListener(IStorageListener* pListener)
|
|
|
|
{
|
2014-03-18 08:26:59 +01:00
|
|
|
OUString sRelPath;
|
|
|
|
EConfigType eCfgType;
|
|
|
|
{
|
|
|
|
SolarMutexGuard g;
|
|
|
|
sRelPath = m_sRelPathUser; // use user path ... because we dont work directly on the share layer!
|
|
|
|
eCfgType = m_eConfigType;
|
|
|
|
}
|
2004-09-20 09:06:34 +00:00
|
|
|
|
2011-12-26 14:20:50 -02:00
|
|
|
if (sRelPath.isEmpty())
|
2004-09-20 09:06:34 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
switch(eCfgType)
|
|
|
|
{
|
|
|
|
case E_GLOBAL :
|
|
|
|
case E_MODULES :
|
|
|
|
{
|
|
|
|
m_aSharedStorages->m_lStoragesUser.addStorageListener(pListener, sRelPath);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case E_DOCUMENT :
|
|
|
|
{
|
|
|
|
m_lDocumentStorages.addStorageListener(pListener, sRelPath);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PresetHandler::removeStorageListener(IStorageListener* pListener)
|
|
|
|
{
|
2014-03-18 08:26:59 +01:00
|
|
|
OUString sRelPath;
|
|
|
|
EConfigType eCfgType;
|
|
|
|
{
|
|
|
|
SolarMutexGuard g;
|
|
|
|
sRelPath = m_sRelPathUser; // use user path ... because we dont work directly on the share layer!
|
|
|
|
eCfgType = m_eConfigType;
|
|
|
|
}
|
2004-09-20 09:06:34 +00:00
|
|
|
|
2011-12-26 14:20:50 -02:00
|
|
|
if (sRelPath.isEmpty())
|
2004-09-20 09:06:34 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
switch(eCfgType)
|
|
|
|
{
|
|
|
|
case E_GLOBAL :
|
|
|
|
case E_MODULES :
|
|
|
|
{
|
|
|
|
m_aSharedStorages->m_lStoragesUser.removeStorageListener(pListener, sRelPath);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case E_DOCUMENT :
|
|
|
|
{
|
|
|
|
m_lDocumentStorages.removeStorageListener(pListener, sRelPath);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-07 12:06:47 +02:00
|
|
|
css::uno::Reference< css::embed::XStorage > PresetHandler::impl_openPathIgnoringErrors(const OUString& sPath ,
|
2004-11-16 13:52:37 +00:00
|
|
|
sal_Int32 eMode ,
|
2014-04-04 15:53:21 +02:00
|
|
|
bool bShare)
|
2004-11-16 13:52:37 +00:00
|
|
|
{
|
|
|
|
css::uno::Reference< css::embed::XStorage > xPath;
|
|
|
|
try
|
|
|
|
{
|
|
|
|
if (bShare)
|
|
|
|
xPath = m_aSharedStorages->m_lStoragesShare.openPath(sPath, eMode);
|
|
|
|
else
|
|
|
|
xPath = m_aSharedStorages->m_lStoragesUser.openPath(sPath, eMode);
|
|
|
|
}
|
2012-02-02 22:53:48 +01:00
|
|
|
catch(const css::uno::RuntimeException&)
|
|
|
|
{ throw; }
|
2004-11-16 13:52:37 +00:00
|
|
|
catch(const css::uno::Exception&)
|
|
|
|
{ xPath.clear(); }
|
|
|
|
return xPath;
|
|
|
|
}
|
|
|
|
|
2013-04-07 12:06:47 +02:00
|
|
|
::std::vector< OUString >::const_iterator PresetHandler::impl_findMatchingLocalizedValue(
|
|
|
|
const ::std::vector< OUString >& lLocalizedValues,
|
2013-03-28 00:39:06 +01:00
|
|
|
OUString& rLanguageTag,
|
2014-04-04 15:53:21 +02:00
|
|
|
bool bAllowFallbacks )
|
2005-02-24 16:11:12 +00:00
|
|
|
{
|
2013-04-07 12:06:47 +02:00
|
|
|
::std::vector< OUString >::const_iterator pFound = lLocalizedValues.end();
|
2005-02-24 16:11:12 +00:00
|
|
|
if (bAllowFallbacks)
|
|
|
|
{
|
2013-03-28 00:39:06 +01:00
|
|
|
pFound = LanguageTag::getFallback(lLocalizedValues, rLanguageTag);
|
2013-03-28 00:44:33 +01:00
|
|
|
// if we found a valid locale ... take it over to our in/out parameter
|
|
|
|
// rLanguageTag
|
|
|
|
if (pFound != lLocalizedValues.end())
|
|
|
|
{
|
|
|
|
rLanguageTag = *pFound;
|
|
|
|
}
|
2005-02-24 16:11:12 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for ( pFound = lLocalizedValues.begin();
|
2014-04-06 19:36:08 +03:00
|
|
|
pFound != lLocalizedValues.end();
|
2005-02-24 16:11:12 +00:00
|
|
|
++pFound )
|
|
|
|
{
|
2013-03-28 00:39:06 +01:00
|
|
|
if (*pFound == rLanguageTag)
|
2005-02-24 16:11:12 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return pFound;
|
|
|
|
}
|
|
|
|
|
2013-03-28 00:13:14 +01:00
|
|
|
css::uno::Reference< css::embed::XStorage > PresetHandler::impl_openLocalizedPathIgnoringErrors(
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString& sPath ,
|
2013-03-28 00:13:14 +01:00
|
|
|
sal_Int32 eMode ,
|
2014-04-04 15:53:21 +02:00
|
|
|
bool bShare ,
|
2013-03-28 00:39:06 +01:00
|
|
|
OUString& rLanguageTag ,
|
2014-04-04 15:53:21 +02:00
|
|
|
bool bAllowFallback)
|
2004-11-16 13:52:37 +00:00
|
|
|
{
|
2004-12-07 12:18:17 +00:00
|
|
|
css::uno::Reference< css::embed::XStorage > xPath = impl_openPathIgnoringErrors(sPath, eMode, bShare);
|
2013-04-07 12:06:47 +02:00
|
|
|
::std::vector< OUString > lSubFolders = impl_getSubFolderNames(xPath);
|
|
|
|
::std::vector< OUString >::const_iterator pLocaleFolder = impl_findMatchingLocalizedValue(lSubFolders, rLanguageTag, bAllowFallback);
|
2004-11-16 13:52:37 +00:00
|
|
|
|
2004-12-07 13:16:36 +00:00
|
|
|
// no fallback ... creation not allowed => no storage
|
|
|
|
if (
|
|
|
|
(pLocaleFolder == lSubFolders.end() ) &&
|
|
|
|
((eMode & css::embed::ElementModes::NOCREATE) == css::embed::ElementModes::NOCREATE)
|
|
|
|
)
|
2004-12-07 12:18:17 +00:00
|
|
|
return css::uno::Reference< css::embed::XStorage >();
|
|
|
|
|
2013-09-26 11:44:54 +02:00
|
|
|
// it doesn't matter, if there is a locale fallback or not
|
2004-12-07 13:16:36 +00:00
|
|
|
// If creation of storages is allowed, we do it anyway.
|
|
|
|
// Otherwhise we have no acc config at all, which can make other trouble.
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString sLocalizedPath;
|
2004-12-07 12:18:17 +00:00
|
|
|
sLocalizedPath = sPath;
|
2013-09-09 00:58:15 +03:00
|
|
|
sLocalizedPath += "/";
|
2004-12-07 13:16:36 +00:00
|
|
|
if (pLocaleFolder != lSubFolders.end())
|
|
|
|
sLocalizedPath += *pLocaleFolder;
|
|
|
|
else
|
2013-03-28 00:39:06 +01:00
|
|
|
sLocalizedPath += rLanguageTag;
|
2004-11-16 13:52:37 +00:00
|
|
|
|
2004-12-07 12:18:17 +00:00
|
|
|
css::uno::Reference< css::embed::XStorage > xLocalePath = impl_openPathIgnoringErrors(sLocalizedPath, eMode, bShare);
|
|
|
|
|
|
|
|
if (xLocalePath.is())
|
2004-11-16 13:52:37 +00:00
|
|
|
sPath = sLocalizedPath;
|
|
|
|
else
|
2014-11-12 14:24:10 +05:30
|
|
|
sPath.clear();
|
2004-12-07 12:18:17 +00:00
|
|
|
|
|
|
|
return xLocalePath;
|
|
|
|
}
|
|
|
|
|
2013-04-07 12:06:47 +02:00
|
|
|
::std::vector< OUString > PresetHandler::impl_getSubFolderNames(const css::uno::Reference< css::embed::XStorage >& xFolder)
|
2004-12-07 12:18:17 +00:00
|
|
|
{
|
|
|
|
css::uno::Reference< css::container::XNameAccess > xAccess(xFolder, css::uno::UNO_QUERY);
|
|
|
|
if (!xAccess.is())
|
2013-04-07 12:06:47 +02:00
|
|
|
return ::std::vector< OUString >();
|
2004-12-07 12:18:17 +00:00
|
|
|
|
2013-04-07 12:06:47 +02:00
|
|
|
::std::vector< OUString > lSubFolders;
|
|
|
|
const css::uno::Sequence< OUString > lNames = xAccess->getElementNames();
|
|
|
|
const OUString* pNames = lNames.getConstArray();
|
2004-12-07 12:18:17 +00:00
|
|
|
sal_Int32 c = lNames.getLength();
|
|
|
|
sal_Int32 i = 0;
|
|
|
|
|
|
|
|
for (i=0; i<c; ++i)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
if (xFolder->isStorageElement(pNames[i]))
|
|
|
|
lSubFolders.push_back(pNames[i]);
|
|
|
|
}
|
2012-02-02 22:53:48 +01:00
|
|
|
catch(const css::uno::RuntimeException&)
|
|
|
|
{ throw; }
|
2004-12-07 12:18:17 +00:00
|
|
|
catch(const css::uno::Exception&)
|
|
|
|
{}
|
|
|
|
}
|
|
|
|
|
|
|
|
return lSubFolders;
|
2004-11-16 13:52:37 +00:00
|
|
|
}
|
|
|
|
|
2004-09-20 09:06:34 +00:00
|
|
|
} // namespace framework
|
2010-10-12 15:53:47 +02:00
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|