Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include <sal/macros.h>
21 : #include "MColumnAlias.hxx"
22 : #include "MConnection.hxx"
23 :
24 : #include <com/sun/star/beans/XPropertySet.hpp>
25 : #include <com/sun/star/container/XNameAccess.hpp>
26 : #include <officecfg/Office/DataAccess.hxx>
27 :
28 : #include <tools/diagnose_ex.h>
29 :
30 : #include <algorithm>
31 : #include <functional>
32 :
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;
39 :
40 :
41 3 : OColumnAlias::OColumnAlias( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxORB )
42 : {
43 : static const sal_Char* s_pProgrammaticNames[] =
44 : {
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",
82 : };
83 :
84 114 : for ( size_t i = 0; i < sizeof( s_pProgrammaticNames ) / sizeof( s_pProgrammaticNames[0] ); ++i )
85 111 : m_aAliasMap[ OUString::createFromAscii( s_pProgrammaticNames[i] ) ] = AliasEntry( s_pProgrammaticNames[i], i );
86 :
87 3 : initialize( _rxORB );
88 3 : }
89 :
90 :
91 3 : void OColumnAlias::initialize( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxORB )
92 : {
93 : Reference< XNameAccess > xAliasesNode(
94 : officecfg::Office::DataAccess::DriverSettings::
95 : com_sun_star_comp_sdbc_MozabDriver::ColumnAliases::get(
96 : comphelper::getComponentContext(_rxORB)),
97 3 : UNO_QUERY_THROW);
98 6 : Sequence< OUString > aProgrammaticNames(xAliasesNode->getElementNames());
99 114 : for (sal_Int32 i = 0; i != aProgrammaticNames.getLength(); ++i) {
100 : OString sAsciiProgrammaticName(
101 : OUStringToOString(
102 111 : aProgrammaticNames[i], RTL_TEXTENCODING_ASCII_US));
103 111 : bool bFound = false;
104 2793 : for (AliasMap::iterator j(m_aAliasMap.begin()); j != m_aAliasMap.end();
105 : ++j)
106 : {
107 2793 : if (j->second.programmaticAsciiName == sAsciiProgrammaticName) {
108 111 : OUString sAssignedAlias;
109 222 : xAliasesNode->getByName(aProgrammaticNames[i]) >>=
110 111 : sAssignedAlias;
111 111 : if (sAssignedAlias.isEmpty()) {
112 0 : sAssignedAlias = aProgrammaticNames[i];
113 : }
114 222 : AliasEntry entry(j->second);
115 111 : m_aAliasMap.erase(j);
116 111 : m_aAliasMap[sAssignedAlias] = entry;
117 111 : bFound = true;
118 222 : break;
119 : }
120 : }
121 : SAL_WARN_IF(
122 : !bFound, "connectivity.mork",
123 : "unknown programmatic name " << aProgrammaticNames[i]
124 : <<" from configuration");
125 114 : }
126 3 : }
127 :
128 :
129 19 : OString OColumnAlias::getProgrammaticNameOrFallbackToUTF8Alias( const OUString& _rAlias ) const
130 : {
131 19 : AliasMap::const_iterator pos = m_aAliasMap.find( _rAlias );
132 19 : if ( pos == m_aAliasMap.end() )
133 : {
134 : OSL_FAIL( "OColumnAlias::getProgrammaticNameOrFallbackToUTF8Alias: no programmatic name for this alias!" );
135 0 : return OUStringToOString( _rAlias, RTL_TEXTENCODING_UTF8 );
136 : }
137 19 : return pos->second.programmaticAsciiName;
138 : }
139 :
140 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|