Version 4.3.0.0.beta1, tag libreoffice-4.3.0.0.beta1
[LibreOffice.git] / connectivity / source / drivers / mork / MColumnAlias.cxx
blob0ad8a3dc8685e43c8500472d3f6785af874d69eb
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
30 #include <algorithm>
31 #include <functional>
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[] =
45 "FirstName",
46 "LastName",
47 "DisplayName",
48 "NickName",
49 "PrimaryEmail",
50 "SecondEmail",
51 "PreferMailFormat",
52 "WorkPhone",
53 "HomePhone",
54 "FaxNumber",
55 "PagerNumber",
56 "CellularNumber",
57 "HomeAddress",
58 "HomeAddress2",
59 "HomeCity",
60 "HomeState",
61 "HomeZipCode",
62 "HomeCountry",
63 "WorkAddress",
64 "WorkAddress2",
65 "WorkCity",
66 "WorkState",
67 "WorkZipCode",
68 "WorkCountry",
69 "JobTitle",
70 "Department",
71 "Company",
72 "WebPage1",
73 "WebPage2",
74 "BirthYear",
75 "BirthMonth",
76 "BirthDay",
77 "Custom1",
78 "Custom2",
79 "Custom3",
80 "Custom4",
81 "Notes",
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 );
87 initialize( _rxORB );
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)),
97 UNO_QUERY_THROW);
98 Sequence< OUString > aProgrammaticNames(xAliasesNode->getElementNames());
99 for (sal_Int32 i = 0; i != aProgrammaticNames.getLength(); ++i) {
100 OString sAsciiProgrammaticName(
101 OUStringToOString(
102 aProgrammaticNames[i], RTL_TEXTENCODING_ASCII_US));
103 bool bFound = false;
104 for (AliasMap::iterator j(m_aAliasMap.begin()); j != m_aAliasMap.end();
105 ++j)
107 if (j->second.programmaticAsciiName == sAsciiProgrammaticName) {
108 OUString sAssignedAlias;
109 xAliasesNode->getByName(aProgrammaticNames[i]) >>=
110 sAssignedAlias;
111 if (sAssignedAlias.isEmpty()) {
112 sAssignedAlias = aProgrammaticNames[i];
114 AliasEntry entry(j->second);
115 m_aAliasMap.erase(j);
116 m_aAliasMap[sAssignedAlias] = entry;
117 bFound = true;
118 break;
121 SAL_WARN_IF(
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: */