2010-10-12 15:59:03 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-06-14 17:39:53 +01:00
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
2010-02-12 15:01:35 +01:00
|
|
|
*
|
2012-06-14 17:39:53 +01:00
|
|
|
* 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/.
|
2010-02-12 15:01:35 +01:00
|
|
|
*
|
2012-06-14 17:39:53 +01:00
|
|
|
* This file incorporates work covered by the following license notice:
|
2010-02-12 15:01:35 +01:00
|
|
|
*
|
2012-06-14 17:39:53 +01:00
|
|
|
* 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 .
|
|
|
|
*/
|
2009-11-16 12:01:50 +01:00
|
|
|
|
2017-02-06 17:08:38 +01:00
|
|
|
#include <sal/config.h>
|
|
|
|
|
|
|
|
#include <com/sun/star/lang/IllegalAccessException.hpp>
|
2018-10-20 12:00:50 +02:00
|
|
|
#include <com/sun/star/lang/IllegalArgumentException.hpp>
|
|
|
|
#include <com/sun/star/container/ElementExistException.hpp>
|
|
|
|
#include <com/sun/star/container/NoSuchElementException.hpp>
|
2009-11-16 12:01:50 +01:00
|
|
|
#include <com/sun/star/sdb/XDatabaseRegistrations.hpp>
|
|
|
|
|
|
|
|
#include <cppuhelper/basemutex.hxx>
|
2021-11-28 09:44:42 +02:00
|
|
|
#include <comphelper/interfacecontainer3.hxx>
|
2023-09-08 11:25:50 +02:00
|
|
|
#include <cppuhelper/implbase.hxx>
|
2018-09-20 20:26:40 +02:00
|
|
|
#include <osl/diagnose.h>
|
2010-01-19 12:39:03 +01:00
|
|
|
#include <unotools/pathoptions.hxx>
|
2009-11-16 12:01:50 +01:00
|
|
|
#include <tools/urlobj.hxx>
|
|
|
|
#include <unotools/confignode.hxx>
|
|
|
|
|
2017-10-23 22:42:52 +02:00
|
|
|
#include "databaseregistrations.hxx"
|
2014-04-13 22:40:55 +02:00
|
|
|
|
2009-11-16 12:01:50 +01:00
|
|
|
namespace dbaccess
|
|
|
|
{
|
|
|
|
using ::com::sun::star::uno::Reference;
|
|
|
|
using ::com::sun::star::uno::RuntimeException;
|
2022-05-04 14:42:03 +02:00
|
|
|
using ::com::sun::star::uno::Any;
|
2009-11-16 12:01:50 +01:00
|
|
|
using ::com::sun::star::uno::Sequence;
|
2013-03-19 13:08:47 +02:00
|
|
|
using ::com::sun::star::uno::XComponentContext;
|
2009-11-16 12:01:50 +01:00
|
|
|
using ::com::sun::star::container::NoSuchElementException;
|
|
|
|
using ::com::sun::star::lang::IllegalArgumentException;
|
|
|
|
using ::com::sun::star::lang::IllegalAccessException;
|
|
|
|
using ::com::sun::star::container::ElementExistException;
|
|
|
|
using ::com::sun::star::sdb::XDatabaseRegistrations;
|
|
|
|
using ::com::sun::star::sdb::XDatabaseRegistrationsListener;
|
|
|
|
using ::com::sun::star::sdb::DatabaseRegistrationEvent;
|
|
|
|
using ::com::sun::star::uno::XAggregation;
|
|
|
|
|
2024-04-21 21:39:13 +02:00
|
|
|
constexpr OUString CONF_ROOT_PATH = u"org.openoffice.Office.DataAccess/RegisteredNames"_ustr;
|
|
|
|
constexpr OUString LOCATION = u"Location"_ustr;
|
|
|
|
constexpr OUString NAME = u"Name"_ustr;
|
2009-11-16 12:01:50 +01:00
|
|
|
|
2013-08-17 23:43:14 +02:00
|
|
|
// DatabaseRegistrations - declaration
|
2023-09-08 11:25:50 +02:00
|
|
|
typedef ::cppu::WeakImplHelper< XDatabaseRegistrations
|
|
|
|
> DatabaseRegistrations_Base;
|
Extend loplugin:external to warn about classes
...following up on 314f15bff08b76bf96acf99141776ef64d2f1355 "Extend
loplugin:external to warn about enums".
Cases where free functions were moved into an unnamed namespace along with a
class, to not break ADL, are in:
filter/source/svg/svgexport.cxx
sc/source/filter/excel/xelink.cxx
sc/source/filter/excel/xilink.cxx
svx/source/sdr/contact/viewobjectcontactofunocontrol.cxx
All other free functions mentioning moved classes appear to be harmless and not
give rise to (silent, even) ADL breakage. (One remaining TODO in
compilerplugins/clang/external.cxx is that derived classes are not covered by
computeAffectedTypes, even though they could also be affected by ADL-breakage---
but don't seem to be in any acutal case across the code base.)
For friend declarations using elaborate type specifiers, like
class C1 {};
class C2 { friend class C1; };
* If C2 (but not C1) is moved into an unnamed namespace, the friend declaration
must be changed to not use an elaborate type specifier (i.e., "friend C1;"; see
C++17 [namespace.memdef]/3: "If the name in a friend declaration is neither
qualified nor a template-id and the declaration is a function or an
elaborated-type-specifier, the lookup to determine whether the entity has been
previously declared shall not consider any scopes outside the innermost
enclosing namespace.")
* If C1 (but not C2) is moved into an unnamed namespace, the friend declaration
must be changed too, see <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71882>
"elaborated-type-specifier friend not looked up in unnamed namespace".
Apart from that, to keep changes simple and mostly mechanical (which should help
avoid regressions), out-of-line definitions of class members have been left in
the enclosing (named) namespace. But explicit specializations of class
templates had to be moved into the unnamed namespace to appease
<https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92598> "explicit specialization of
template from unnamed namespace using unqualified-id in enclosing namespace".
Also, accompanying declarations (of e.g. typedefs or static variables) that
could arguably be moved into the unnamed namespace too have been left alone.
And in some cases, mention of affected types in blacklists in other loplugins
needed to be adapted.
And sc/qa/unit/mark_test.cxx uses a hack of including other .cxx, one of which
is sc/source/core/data/segmenttree.cxx where e.g. ScFlatUInt16SegmentsImpl is
not moved into an unnamed namespace (because it is declared in
sc/inc/segmenttree.hxx), but its base ScFlatSegmentsImpl is. GCC warns about
such combinations with enabled-by-default -Wsubobject-linkage, but "The compiler
doesn’t give this warning for types defined in the main .C file, as those are
unlikely to have multiple definitions."
(<https://gcc.gnu.org/onlinedocs/gcc-9.2.0/gcc/Warning-Options.html>) The
warned-about classes also don't have multiple definitions in the given test, so
disable the warning when including the .cxx.
Change-Id: Ib694094c0d8168be68f8fe90dfd0acbb66a3f1e4
Reviewed-on: https://gerrit.libreoffice.org/83239
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2019-11-19 16:32:49 +01:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2009-11-16 12:01:50 +01:00
|
|
|
class DatabaseRegistrations :public ::cppu::BaseMutex
|
|
|
|
,public DatabaseRegistrations_Base
|
|
|
|
{
|
|
|
|
public:
|
2015-07-05 21:05:13 +01:00
|
|
|
explicit DatabaseRegistrations( const Reference<XComponentContext>& _rxContext );
|
2009-11-16 12:01:50 +01:00
|
|
|
|
|
|
|
protected:
|
2016-09-13 13:09:01 +02:00
|
|
|
virtual ~DatabaseRegistrations() override;
|
2009-11-16 12:01:50 +01:00
|
|
|
|
|
|
|
public:
|
2017-01-26 12:28:58 +01:00
|
|
|
virtual sal_Bool SAL_CALL hasRegisteredDatabase( const OUString& Name ) override;
|
|
|
|
virtual Sequence< OUString > SAL_CALL getRegistrationNames() override;
|
|
|
|
virtual OUString SAL_CALL getDatabaseLocation( const OUString& Name ) override;
|
|
|
|
virtual void SAL_CALL registerDatabaseLocation( const OUString& Name, const OUString& Location ) override;
|
|
|
|
virtual void SAL_CALL revokeDatabaseLocation( const OUString& Name ) override;
|
|
|
|
virtual void SAL_CALL changeDatabaseLocation( const OUString& Name, const OUString& NewLocation ) override;
|
|
|
|
virtual sal_Bool SAL_CALL isDatabaseRegistrationReadOnly( const OUString& Name ) override;
|
|
|
|
virtual void SAL_CALL addDatabaseRegistrationsListener( const Reference< XDatabaseRegistrationsListener >& Listener ) override;
|
|
|
|
virtual void SAL_CALL removeDatabaseRegistrationsListener( const Reference< XDatabaseRegistrationsListener >& Listener ) override;
|
2009-11-16 12:01:50 +01:00
|
|
|
|
|
|
|
private:
|
2014-07-10 17:37:03 +01:00
|
|
|
void
|
2020-11-13 14:29:59 +02:00
|
|
|
impl_checkValidName_common(std::u16string_view _rName);
|
2009-11-16 14:45:02 +01:00
|
|
|
::utl::OConfigurationNode
|
2014-07-10 17:37:03 +01:00
|
|
|
impl_checkValidName_throw_must_exist(const OUString& _rName);
|
|
|
|
::utl::OConfigurationNode
|
|
|
|
impl_checkValidName_throw_must_not_exist(const OUString& _rName);
|
2009-11-16 14:45:02 +01:00
|
|
|
|
2022-04-28 14:12:35 +02:00
|
|
|
void impl_checkValidLocation_throw( std::u16string_view _rLocation );
|
2009-11-16 12:01:50 +01:00
|
|
|
|
2009-11-16 14:45:02 +01:00
|
|
|
/** retrieves the configuration node whose "Name" sub node has the given value
|
|
|
|
|
|
|
|
Since we separated the name of the registration node from the "Name" value of the registration, we cannot
|
|
|
|
simply do a "getByName" (equivalent) when we want to retrieve the node for a given registration name.
|
|
|
|
Instead, we must search all nodes.
|
|
|
|
|
2014-07-10 17:37:03 +01:00
|
|
|
If a node with the given display name does not exist, then a NoSuchElementException is thrown.
|
|
|
|
|
|
|
|
If no exception is thrown, then a valid node is returned: If the node existed it is returned.
|
|
|
|
*/
|
|
|
|
::utl::OConfigurationNode
|
|
|
|
impl_getNodeForName_throw_must_exist(const OUString& _rName);
|
|
|
|
|
|
|
|
/** retrieves the configuration node whose "Name" sub node has the given value
|
|
|
|
|
|
|
|
Since we separated the name of the registration node from the "Name" value of the registration, we cannot
|
|
|
|
simply do a "getByName" (equivalent) when we want to retrieve the node for a given registration name.
|
|
|
|
Instead, we must search all nodes.
|
2009-11-16 14:45:02 +01:00
|
|
|
|
2019-04-28 21:11:22 +00:00
|
|
|
If a node with the given name already exists, then an ElementExistException is thrown.
|
2009-11-16 14:45:02 +01:00
|
|
|
|
2014-07-10 17:37:03 +01:00
|
|
|
If no exception is thrown, then a valid node is returned: If the node did not yet exist a new node is created,
|
|
|
|
in this case the root node is not yet committed.
|
2009-11-16 14:45:02 +01:00
|
|
|
*/
|
|
|
|
::utl::OConfigurationNode
|
2014-07-10 17:37:03 +01:00
|
|
|
impl_getNodeForName_throw_must_not_exist(const OUString& _rName);
|
|
|
|
|
2009-11-16 14:45:02 +01:00
|
|
|
|
|
|
|
::utl::OConfigurationNode
|
2020-11-18 10:10:40 +02:00
|
|
|
impl_getNodeForName_nothrow(std::u16string_view _rName);
|
2009-11-16 14:45:02 +01:00
|
|
|
|
2009-11-16 12:01:50 +01:00
|
|
|
private:
|
2013-03-19 13:08:47 +02:00
|
|
|
Reference<XComponentContext> m_aContext;
|
2009-11-16 12:01:50 +01:00
|
|
|
::utl::OConfigurationTreeRoot m_aConfigurationRoot;
|
2021-11-28 09:44:42 +02:00
|
|
|
::comphelper::OInterfaceContainerHelper3<XDatabaseRegistrationsListener> m_aRegistrationListeners;
|
2009-11-16 12:01:50 +01:00
|
|
|
};
|
|
|
|
|
Extend loplugin:external to warn about classes
...following up on 314f15bff08b76bf96acf99141776ef64d2f1355 "Extend
loplugin:external to warn about enums".
Cases where free functions were moved into an unnamed namespace along with a
class, to not break ADL, are in:
filter/source/svg/svgexport.cxx
sc/source/filter/excel/xelink.cxx
sc/source/filter/excel/xilink.cxx
svx/source/sdr/contact/viewobjectcontactofunocontrol.cxx
All other free functions mentioning moved classes appear to be harmless and not
give rise to (silent, even) ADL breakage. (One remaining TODO in
compilerplugins/clang/external.cxx is that derived classes are not covered by
computeAffectedTypes, even though they could also be affected by ADL-breakage---
but don't seem to be in any acutal case across the code base.)
For friend declarations using elaborate type specifiers, like
class C1 {};
class C2 { friend class C1; };
* If C2 (but not C1) is moved into an unnamed namespace, the friend declaration
must be changed to not use an elaborate type specifier (i.e., "friend C1;"; see
C++17 [namespace.memdef]/3: "If the name in a friend declaration is neither
qualified nor a template-id and the declaration is a function or an
elaborated-type-specifier, the lookup to determine whether the entity has been
previously declared shall not consider any scopes outside the innermost
enclosing namespace.")
* If C1 (but not C2) is moved into an unnamed namespace, the friend declaration
must be changed too, see <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71882>
"elaborated-type-specifier friend not looked up in unnamed namespace".
Apart from that, to keep changes simple and mostly mechanical (which should help
avoid regressions), out-of-line definitions of class members have been left in
the enclosing (named) namespace. But explicit specializations of class
templates had to be moved into the unnamed namespace to appease
<https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92598> "explicit specialization of
template from unnamed namespace using unqualified-id in enclosing namespace".
Also, accompanying declarations (of e.g. typedefs or static variables) that
could arguably be moved into the unnamed namespace too have been left alone.
And in some cases, mention of affected types in blacklists in other loplugins
needed to be adapted.
And sc/qa/unit/mark_test.cxx uses a hack of including other .cxx, one of which
is sc/source/core/data/segmenttree.cxx where e.g. ScFlatUInt16SegmentsImpl is
not moved into an unnamed namespace (because it is declared in
sc/inc/segmenttree.hxx), but its base ScFlatSegmentsImpl is. GCC warns about
such combinations with enabled-by-default -Wsubobject-linkage, but "The compiler
doesn’t give this warning for types defined in the main .C file, as those are
unlikely to have multiple definitions."
(<https://gcc.gnu.org/onlinedocs/gcc-9.2.0/gcc/Warning-Options.html>) The
warned-about classes also don't have multiple definitions in the given test, so
disable the warning when including the .cxx.
Change-Id: Ib694094c0d8168be68f8fe90dfd0acbb66a3f1e4
Reviewed-on: https://gerrit.libreoffice.org/83239
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2019-11-19 16:32:49 +01:00
|
|
|
}
|
|
|
|
|
2013-08-17 23:43:14 +02:00
|
|
|
// DatabaseRegistrations - implementation
|
2013-03-19 13:08:47 +02:00
|
|
|
DatabaseRegistrations::DatabaseRegistrations( const Reference<XComponentContext> & _rxContext )
|
2009-11-16 12:01:50 +01:00
|
|
|
:m_aContext( _rxContext )
|
|
|
|
,m_aRegistrationListeners( m_aMutex )
|
|
|
|
{
|
2013-01-04 09:12:44 +02:00
|
|
|
m_aConfigurationRoot = ::utl::OConfigurationTreeRoot::createWithComponentContext(
|
2024-04-21 21:39:13 +02:00
|
|
|
m_aContext, CONF_ROOT_PATH );
|
2009-11-16 12:01:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
DatabaseRegistrations::~DatabaseRegistrations()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-11-18 10:10:40 +02:00
|
|
|
::utl::OConfigurationNode DatabaseRegistrations::impl_getNodeForName_nothrow( std::u16string_view _rName )
|
2009-11-16 14:45:02 +01:00
|
|
|
{
|
2019-08-15 11:26:29 +02:00
|
|
|
const Sequence< OUString > aNames( m_aConfigurationRoot.getNodeNames() );
|
2017-07-05 13:27:30 +02:00
|
|
|
for ( auto const & nodeName : aNames )
|
2009-11-16 14:45:02 +01:00
|
|
|
{
|
2017-07-05 13:27:30 +02:00
|
|
|
::utl::OConfigurationNode aNodeForName = m_aConfigurationRoot.openNode( nodeName );
|
2009-11-16 14:45:02 +01:00
|
|
|
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString sTestName;
|
2024-04-21 21:39:13 +02:00
|
|
|
OSL_VERIFY( aNodeForName.getNodeValue( NAME ) >>= sTestName );
|
2009-11-16 14:45:02 +01:00
|
|
|
if ( sTestName == _rName )
|
|
|
|
return aNodeForName;
|
|
|
|
}
|
|
|
|
return ::utl::OConfigurationNode();
|
|
|
|
}
|
|
|
|
|
2014-07-10 17:37:03 +01:00
|
|
|
::utl::OConfigurationNode DatabaseRegistrations::impl_getNodeForName_throw_must_exist(const OUString& _rName)
|
2009-11-16 14:45:02 +01:00
|
|
|
{
|
|
|
|
::utl::OConfigurationNode aNodeForName( impl_getNodeForName_nothrow( _rName ) );
|
|
|
|
|
2014-07-10 17:37:03 +01:00
|
|
|
if (!aNodeForName.isValid())
|
2009-11-16 14:45:02 +01:00
|
|
|
{
|
2014-07-10 17:37:03 +01:00
|
|
|
throw NoSuchElementException( _rName, *this );
|
2009-11-16 14:45:02 +01:00
|
|
|
}
|
|
|
|
|
2014-07-10 17:37:03 +01:00
|
|
|
return aNodeForName;
|
|
|
|
}
|
|
|
|
|
|
|
|
::utl::OConfigurationNode DatabaseRegistrations::impl_getNodeForName_throw_must_not_exist(const OUString& _rName)
|
|
|
|
{
|
|
|
|
::utl::OConfigurationNode aNodeForName( impl_getNodeForName_nothrow( _rName ) );
|
|
|
|
|
|
|
|
if (aNodeForName.isValid())
|
|
|
|
throw ElementExistException( _rName, *this );
|
2009-11-16 14:45:02 +01:00
|
|
|
|
2017-06-22 16:05:11 +02:00
|
|
|
// make unique
|
|
|
|
OUString sNewNodeName = "org.openoffice." + _rName;
|
|
|
|
while ( m_aConfigurationRoot.hasByName( sNewNodeName ) )
|
2009-11-16 14:45:02 +01:00
|
|
|
{
|
2017-06-22 16:05:11 +02:00
|
|
|
sNewNodeName = "org.openoffice." + _rName + " 2";
|
2009-11-16 14:45:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
::utl::OConfigurationNode aNewNode( m_aConfigurationRoot.createNode( sNewNodeName ) );
|
2024-04-21 21:39:13 +02:00
|
|
|
aNewNode.setNodeValue( NAME, Any( _rName ) );
|
2009-11-16 14:45:02 +01:00
|
|
|
return aNewNode;
|
|
|
|
}
|
|
|
|
|
2020-11-13 14:29:59 +02:00
|
|
|
void DatabaseRegistrations::impl_checkValidName_common(std::u16string_view _rName)
|
2009-11-16 12:01:50 +01:00
|
|
|
{
|
|
|
|
if ( !m_aConfigurationRoot.isValid() )
|
2013-04-07 12:06:47 +02:00
|
|
|
throw RuntimeException( OUString(), *this );
|
2009-11-16 12:01:50 +01:00
|
|
|
|
2020-11-13 14:29:59 +02:00
|
|
|
if ( _rName.empty() )
|
2013-04-07 12:06:47 +02:00
|
|
|
throw IllegalArgumentException( OUString(), *this, 1 );
|
2014-07-10 17:37:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
::utl::OConfigurationNode DatabaseRegistrations::impl_checkValidName_throw_must_exist(const OUString& _rName)
|
|
|
|
{
|
|
|
|
impl_checkValidName_common(_rName);
|
|
|
|
return impl_getNodeForName_throw_must_exist(_rName);
|
|
|
|
}
|
2009-11-16 12:01:50 +01:00
|
|
|
|
2014-07-10 17:37:03 +01:00
|
|
|
::utl::OConfigurationNode DatabaseRegistrations::impl_checkValidName_throw_must_not_exist(const OUString& _rName)
|
|
|
|
{
|
|
|
|
impl_checkValidName_common(_rName);
|
|
|
|
return impl_getNodeForName_throw_must_not_exist(_rName);
|
2009-11-16 12:01:50 +01:00
|
|
|
}
|
|
|
|
|
2022-04-28 14:12:35 +02:00
|
|
|
void DatabaseRegistrations::impl_checkValidLocation_throw( std::u16string_view _rLocation )
|
2009-11-16 12:01:50 +01:00
|
|
|
{
|
2022-04-28 14:12:35 +02:00
|
|
|
if ( _rLocation.empty() )
|
2013-04-07 12:06:47 +02:00
|
|
|
throw IllegalArgumentException( OUString(), *this, 2 );
|
2009-11-16 12:01:50 +01:00
|
|
|
|
|
|
|
INetURLObject aURL( _rLocation );
|
2015-04-02 18:32:36 +02:00
|
|
|
if ( aURL.GetProtocol() == INetProtocol::NotValid )
|
2013-04-07 12:06:47 +02:00
|
|
|
throw IllegalArgumentException( OUString(), *this, 2 );
|
2009-11-16 12:01:50 +01:00
|
|
|
}
|
|
|
|
|
2017-01-26 12:28:58 +01:00
|
|
|
sal_Bool SAL_CALL DatabaseRegistrations::hasRegisteredDatabase( const OUString& Name )
|
2009-11-16 12:01:50 +01:00
|
|
|
{
|
|
|
|
::osl::MutexGuard aGuard( m_aMutex );
|
2016-04-13 23:12:14 +02:00
|
|
|
::utl::OConfigurationNode aNodeForName = impl_getNodeForName_nothrow( Name );
|
2009-11-16 14:45:02 +01:00
|
|
|
return aNodeForName.isValid();
|
2009-11-16 12:01:50 +01:00
|
|
|
}
|
|
|
|
|
2017-01-26 12:28:58 +01:00
|
|
|
Sequence< OUString > SAL_CALL DatabaseRegistrations::getRegistrationNames()
|
2009-11-16 12:01:50 +01:00
|
|
|
{
|
|
|
|
::osl::MutexGuard aGuard( m_aMutex );
|
|
|
|
if ( !m_aConfigurationRoot.isValid() )
|
2013-04-07 12:06:47 +02:00
|
|
|
throw RuntimeException( OUString(), *this );
|
2009-11-16 12:01:50 +01:00
|
|
|
|
2019-08-15 11:26:29 +02:00
|
|
|
const Sequence< OUString > aProgrammaticNames( m_aConfigurationRoot.getNodeNames() );
|
2013-04-07 12:06:47 +02:00
|
|
|
Sequence< OUString > aDisplayNames( aProgrammaticNames.getLength() );
|
|
|
|
OUString* pDisplayName = aDisplayNames.getArray();
|
2009-11-16 14:45:02 +01:00
|
|
|
|
2017-07-05 13:27:30 +02:00
|
|
|
for ( auto const & name : aProgrammaticNames )
|
2009-11-16 14:45:02 +01:00
|
|
|
{
|
2017-07-05 13:27:30 +02:00
|
|
|
::utl::OConfigurationNode aRegistrationNode = m_aConfigurationRoot.openNode( name );
|
2024-04-21 21:39:13 +02:00
|
|
|
OSL_VERIFY( aRegistrationNode.getNodeValue( NAME ) >>= *pDisplayName );
|
2017-07-05 13:27:30 +02:00
|
|
|
++pDisplayName;
|
2009-11-16 14:45:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return aDisplayNames;
|
2009-11-16 12:01:50 +01:00
|
|
|
}
|
|
|
|
|
2017-01-26 12:28:58 +01:00
|
|
|
OUString SAL_CALL DatabaseRegistrations::getDatabaseLocation( const OUString& Name )
|
2009-11-16 12:01:50 +01:00
|
|
|
{
|
|
|
|
::osl::MutexGuard aGuard( m_aMutex );
|
|
|
|
|
2016-04-13 23:12:14 +02:00
|
|
|
::utl::OConfigurationNode aNodeForName = impl_checkValidName_throw_must_exist(Name);
|
2009-11-16 12:01:50 +01:00
|
|
|
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString sLocation;
|
2024-04-21 21:39:13 +02:00
|
|
|
OSL_VERIFY( aNodeForName.getNodeValue( LOCATION ) >>= sLocation );
|
2009-11-16 12:01:50 +01:00
|
|
|
sLocation = SvtPathOptions().SubstituteVariable( sLocation );
|
|
|
|
|
|
|
|
return sLocation;
|
|
|
|
}
|
|
|
|
|
2017-01-26 12:28:58 +01:00
|
|
|
void SAL_CALL DatabaseRegistrations::registerDatabaseLocation( const OUString& Name, const OUString& Location )
|
2009-11-16 12:01:50 +01:00
|
|
|
{
|
|
|
|
::osl::ClearableMutexGuard aGuard( m_aMutex );
|
|
|
|
|
|
|
|
// check
|
2016-04-13 23:12:14 +02:00
|
|
|
impl_checkValidLocation_throw( Location );
|
|
|
|
::utl::OConfigurationNode aDataSourceRegistration = impl_checkValidName_throw_must_not_exist(Name);
|
2009-11-16 12:01:50 +01:00
|
|
|
|
|
|
|
// register
|
2024-04-21 21:39:13 +02:00
|
|
|
aDataSourceRegistration.setNodeValue( LOCATION, Any( Location ) );
|
2009-11-16 12:01:50 +01:00
|
|
|
m_aConfigurationRoot.commit();
|
|
|
|
|
|
|
|
// notify
|
2016-04-13 23:12:14 +02:00
|
|
|
DatabaseRegistrationEvent aEvent( *this, Name, OUString(), Location );
|
2009-11-16 12:01:50 +01:00
|
|
|
aGuard.clear();
|
|
|
|
m_aRegistrationListeners.notifyEach( &XDatabaseRegistrationsListener::registeredDatabaseLocation, aEvent );
|
|
|
|
}
|
|
|
|
|
2017-01-26 12:28:58 +01:00
|
|
|
void SAL_CALL DatabaseRegistrations::revokeDatabaseLocation( const OUString& Name )
|
2009-11-16 12:01:50 +01:00
|
|
|
{
|
|
|
|
::osl::ClearableMutexGuard aGuard( m_aMutex );
|
|
|
|
|
|
|
|
// check
|
2016-04-13 23:12:14 +02:00
|
|
|
::utl::OConfigurationNode aNodeForName = impl_checkValidName_throw_must_exist(Name);
|
2009-11-16 12:01:50 +01:00
|
|
|
|
2009-11-16 14:45:02 +01:00
|
|
|
// obtain properties for notification
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString sLocation;
|
2024-04-21 21:39:13 +02:00
|
|
|
OSL_VERIFY( aNodeForName.getNodeValue( LOCATION ) >>= sLocation );
|
2009-11-16 12:01:50 +01:00
|
|
|
|
|
|
|
// revoke
|
2009-11-16 14:45:02 +01:00
|
|
|
if ( aNodeForName.isReadonly()
|
2009-11-16 14:59:34 +01:00
|
|
|
|| !m_aConfigurationRoot.removeNode( aNodeForName.getLocalName() )
|
2009-11-16 12:01:50 +01:00
|
|
|
)
|
2013-04-07 12:06:47 +02:00
|
|
|
throw IllegalAccessException( OUString(), *this );
|
2009-11-16 12:01:50 +01:00
|
|
|
|
|
|
|
m_aConfigurationRoot.commit();
|
|
|
|
|
|
|
|
// notify
|
2016-04-13 23:12:14 +02:00
|
|
|
DatabaseRegistrationEvent aEvent( *this, Name, sLocation, OUString() );
|
2009-11-16 12:01:50 +01:00
|
|
|
aGuard.clear();
|
|
|
|
m_aRegistrationListeners.notifyEach( &XDatabaseRegistrationsListener::revokedDatabaseLocation, aEvent );
|
|
|
|
}
|
|
|
|
|
2017-01-26 12:28:58 +01:00
|
|
|
void SAL_CALL DatabaseRegistrations::changeDatabaseLocation( const OUString& Name, const OUString& NewLocation )
|
2009-11-16 12:01:50 +01:00
|
|
|
{
|
|
|
|
::osl::ClearableMutexGuard aGuard( m_aMutex );
|
|
|
|
|
|
|
|
// check
|
2016-04-13 23:12:14 +02:00
|
|
|
impl_checkValidLocation_throw( NewLocation );
|
|
|
|
::utl::OConfigurationNode aDataSourceRegistration = impl_checkValidName_throw_must_exist(Name);
|
2009-11-16 12:01:50 +01:00
|
|
|
|
2009-11-16 14:45:02 +01:00
|
|
|
if ( aDataSourceRegistration.isReadonly() )
|
2013-04-07 12:06:47 +02:00
|
|
|
throw IllegalAccessException( OUString(), *this );
|
2009-11-16 12:01:50 +01:00
|
|
|
|
2009-11-16 14:45:02 +01:00
|
|
|
// obtain properties for notification
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString sOldLocation;
|
2024-04-21 21:39:13 +02:00
|
|
|
OSL_VERIFY( aDataSourceRegistration.getNodeValue( LOCATION ) >>= sOldLocation );
|
2009-11-16 12:01:50 +01:00
|
|
|
|
|
|
|
// change
|
2024-04-21 21:39:13 +02:00
|
|
|
aDataSourceRegistration.setNodeValue( LOCATION, Any( NewLocation ) );
|
2009-11-16 12:01:50 +01:00
|
|
|
m_aConfigurationRoot.commit();
|
|
|
|
|
|
|
|
// notify
|
2016-04-13 23:12:14 +02:00
|
|
|
DatabaseRegistrationEvent aEvent( *this, Name, sOldLocation, NewLocation );
|
2009-11-16 12:01:50 +01:00
|
|
|
aGuard.clear();
|
|
|
|
m_aRegistrationListeners.notifyEach( &XDatabaseRegistrationsListener::changedDatabaseLocation, aEvent );
|
|
|
|
}
|
|
|
|
|
2017-01-26 12:28:58 +01:00
|
|
|
sal_Bool SAL_CALL DatabaseRegistrations::isDatabaseRegistrationReadOnly( const OUString& Name )
|
2009-11-16 12:01:50 +01:00
|
|
|
{
|
|
|
|
::osl::MutexGuard aGuard( m_aMutex );
|
2016-04-13 23:12:14 +02:00
|
|
|
::utl::OConfigurationNode aDataSourceRegistration = impl_checkValidName_throw_must_exist(Name);
|
2009-11-16 13:37:25 +01:00
|
|
|
return aDataSourceRegistration.isReadonly();
|
2009-11-16 12:01:50 +01:00
|
|
|
}
|
|
|
|
|
2017-01-26 12:28:58 +01:00
|
|
|
void SAL_CALL DatabaseRegistrations::addDatabaseRegistrationsListener( const Reference< XDatabaseRegistrationsListener >& Listener )
|
2009-11-16 12:01:50 +01:00
|
|
|
{
|
2016-04-13 23:12:14 +02:00
|
|
|
if ( Listener.is() )
|
|
|
|
m_aRegistrationListeners.addInterface( Listener );
|
2009-11-16 12:01:50 +01:00
|
|
|
}
|
|
|
|
|
2017-01-26 12:28:58 +01:00
|
|
|
void SAL_CALL DatabaseRegistrations::removeDatabaseRegistrationsListener( const Reference< XDatabaseRegistrationsListener >& Listener )
|
2009-11-16 12:01:50 +01:00
|
|
|
{
|
2016-04-13 23:12:14 +02:00
|
|
|
if ( Listener.is() )
|
|
|
|
m_aRegistrationListeners.removeInterface( Listener );
|
2009-11-16 12:01:50 +01:00
|
|
|
}
|
|
|
|
|
2013-08-17 23:43:14 +02:00
|
|
|
// DatabaseRegistrations - factory
|
2023-09-08 11:25:50 +02:00
|
|
|
Reference< XDatabaseRegistrations > createDataSourceRegistrations( const Reference<XComponentContext> & _rxContext )
|
2009-11-16 12:01:50 +01:00
|
|
|
{
|
|
|
|
return new DatabaseRegistrations( _rxContext );
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace dbaccess
|
2013-08-17 23:43:14 +02:00
|
|
|
|
2010-10-12 15:59:03 +02:00
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|