1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <sal/macros.h>
21 #include "MColumnAlias.hxx"
22 #include "MConnection.hxx"
24 #include <com/sun/star/beans/XPropertySet.hpp>
25 #include <com/sun/star/container/XNameAccess.hpp>
26 #include <officecfg/Office/DataAccess.hxx>
28 #include <tools/diagnose_ex.h>
33 using namespace ::connectivity
;
34 using namespace ::connectivity::mork
;
35 using namespace ::com::sun::star::uno
;
36 using namespace ::com::sun::star::lang
;
37 using namespace ::com::sun::star::beans
;
38 using namespace ::com::sun::star::container
;
41 OColumnAlias::OColumnAlias( const ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XMultiServiceFactory
>& _rxORB
)
43 static const sal_Char
* s_pProgrammaticNames
[] =
84 for ( size_t i
= 0; i
< sizeof( s_pProgrammaticNames
) / sizeof( s_pProgrammaticNames
[0] ); ++i
)
85 m_aAliasMap
[ OUString::createFromAscii( s_pProgrammaticNames
[i
] ) ] = AliasEntry( s_pProgrammaticNames
[i
], i
);
91 void OColumnAlias::initialize( const ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XMultiServiceFactory
>& _rxORB
)
93 Reference
< XNameAccess
> xAliasesNode(
94 officecfg::Office::DataAccess::DriverSettings::
95 com_sun_star_comp_sdbc_MozabDriver::ColumnAliases::get(
96 comphelper::getComponentContext(_rxORB
)),
98 Sequence
< OUString
> aProgrammaticNames(xAliasesNode
->getElementNames());
99 for (sal_Int32 i
= 0; i
!= aProgrammaticNames
.getLength(); ++i
) {
100 OString
sAsciiProgrammaticName(
102 aProgrammaticNames
[i
], RTL_TEXTENCODING_ASCII_US
));
104 for (AliasMap::iterator
j(m_aAliasMap
.begin()); j
!= m_aAliasMap
.end();
107 if (j
->second
.programmaticAsciiName
== sAsciiProgrammaticName
) {
108 OUString sAssignedAlias
;
109 xAliasesNode
->getByName(aProgrammaticNames
[i
]) >>=
111 if (sAssignedAlias
.isEmpty()) {
112 sAssignedAlias
= aProgrammaticNames
[i
];
114 AliasEntry
entry(j
->second
);
115 m_aAliasMap
.erase(j
);
116 m_aAliasMap
[sAssignedAlias
] = entry
;
122 !bFound
, "connectivity.mork",
123 "unknown programmatic name " << aProgrammaticNames
[i
]
124 <<" from configuration");
129 OString
OColumnAlias::getProgrammaticNameOrFallbackToUTF8Alias( const OUString
& _rAlias
) const
131 AliasMap::const_iterator pos
= m_aAliasMap
.find( _rAlias
);
132 if ( pos
== m_aAliasMap
.end() )
134 OSL_FAIL( "OColumnAlias::getProgrammaticNameOrFallbackToUTF8Alias: no programmatic name for this alias!" );
135 return OUStringToOString( _rAlias
, RTL_TEXTENCODING_UTF8
);
137 return pos
->second
.programmaticAsciiName
;
140 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */