update dev300-m58
[ooovba.git] / connectivity / source / drivers / mozab / MColumnAlias.cxx
blob3eb6d449bbae0597d3ecdcbd7be48469620323a0
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: MColumnAlias.cxx,v $
10 * $Revision: 1.10 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_connectivity.hxx"
33 #include "MColumnAlias.hxx"
34 #include "MConnection.hxx"
35 #include "MExtConfigAccess.hxx"
37 #include <com/sun/star/beans/XPropertySet.hpp>
38 #include <com/sun/star/container/XNameAccess.hpp>
40 #include <tools/diagnose_ex.h>
42 #include <algorithm>
43 #include <functional>
45 using namespace ::connectivity;
46 using namespace ::connectivity::mozab;
47 using namespace ::com::sun::star::uno;
48 using namespace ::com::sun::star::lang;
49 using namespace ::com::sun::star::beans;
50 using namespace ::com::sun::star::container;
52 //------------------------------------------------------------------------------
53 OColumnAlias::OColumnAlias( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxORB )
55 static const sal_Char* s_pProgrammaticNames[] =
57 "FirstName",
58 "LastName",
59 "DisplayName",
60 "NickName",
61 "PrimaryEmail",
62 "SecondEmail",
63 "PreferMailFormat",
64 "WorkPhone",
65 "HomePhone",
66 "FaxNumber",
67 "PagerNumber",
68 "CellularNumber",
69 "HomeAddress",
70 "HomeAddress2",
71 "HomeCity",
72 "HomeState",
73 "HomeZipCode",
74 "HomeCountry",
75 "WorkAddress",
76 "WorkAddress2",
77 "WorkCity",
78 "WorkState",
79 "WorkZipCode",
80 "WorkCountry",
81 "JobTitle",
82 "Department",
83 "Company",
84 "WebPage1",
85 "WebPage2",
86 "BirthYear",
87 "BirthMonth",
88 "BirthDay",
89 "Custom1",
90 "Custom2",
91 "Custom3",
92 "Custom4",
93 "Notes",
96 for ( size_t i = 0; i < sizeof( s_pProgrammaticNames ) / sizeof( s_pProgrammaticNames[0] ); ++i )
97 m_aAliasMap[ ::rtl::OUString::createFromAscii( s_pProgrammaticNames[i] ) ] = AliasEntry( s_pProgrammaticNames[i], i );
99 initialize( _rxORB );
102 //------------------------------------------------------------------------------
103 void OColumnAlias::initialize( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxORB )
105 // open our driver settings config node
107 // the config path for our own driver's settings
108 Reference< XPropertySet > xDriverNode = createDriverConfigNode( _rxORB );
109 if ( xDriverNode.is() )
113 //.............................................................
114 Reference< XNameAccess > xAliasesNode;
115 xDriverNode->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ColumnAliases")) ) >>= xAliasesNode;
116 OSL_ENSURE( xAliasesNode.is(), "OColumnAlias::setAlias: missing the aliases node!" );
118 // this is a set of string nodes
119 Sequence< ::rtl::OUString > aProgrammaticNames;
120 if ( xAliasesNode.is() )
121 aProgrammaticNames = xAliasesNode->getElementNames();
123 //.............................................................
124 // travel through all the set elements
125 const ::rtl::OUString* pProgrammaticNames = aProgrammaticNames.getConstArray();
126 const ::rtl::OUString* pProgrammaticNamesEnd = pProgrammaticNames + aProgrammaticNames.getLength();
127 ::rtl::OUString sAssignedAlias;
129 for ( ; pProgrammaticNames < pProgrammaticNamesEnd; ++pProgrammaticNames )
131 OSL_VERIFY( xAliasesNode->getByName( *pProgrammaticNames ) >>= sAssignedAlias );
133 // normalize in case the config data is corrupted
134 // (what we really don't need is an empty alias ...)
135 if ( 0 == sAssignedAlias.getLength() )
136 sAssignedAlias = *pProgrammaticNames;
138 ::rtl::OString sAsciiProgrammaticName( ::rtl::OUStringToOString( *pProgrammaticNames, RTL_TEXTENCODING_ASCII_US ) );
139 //.............................................................
140 #if OSL_DEBUG_LEVEL > 0
141 bool bFound = false;
142 #endif
143 for ( AliasMap::iterator search = m_aAliasMap.begin();
144 ( search != m_aAliasMap.end() );
145 ++search
148 if ( search->second.programmaticAsciiName.equals( sAsciiProgrammaticName ) )
150 AliasEntry entry( search->second );
151 m_aAliasMap.erase( search );
152 m_aAliasMap[ sAssignedAlias ] = entry;
154 #if OSL_DEBUG_LEVEL > 0
155 bFound = true;
156 #endif
158 break;
162 OSL_ENSURE( bFound, "OColumnAlias::setAlias: did not find a programmatic name which exists in the configuration!" );
165 catch( const Exception& )
167 DBG_UNHANDLED_EXCEPTION();
172 //------------------------------------------------------------------
173 ::rtl::OString OColumnAlias::getProgrammaticNameOrFallbackToUTF8Alias( const ::rtl::OUString& _rAlias ) const
175 AliasMap::const_iterator pos = m_aAliasMap.find( _rAlias );
176 if ( pos == m_aAliasMap.end() )
178 OSL_ENSURE( false, "OColumnAlias::getProgrammaticNameOrFallbackToUTF8Alias: no programmatic name for this alias!" );
179 return ::rtl::OUStringToOString( _rAlias, RTL_TEXTENCODING_UTF8 );
181 return pos->second.programmaticAsciiName;
184 //------------------------------------------------------------------
185 bool OColumnAlias::isColumnSearchable( const ::rtl::OUString _alias ) const
187 ::rtl::OString sProgrammatic = getProgrammaticNameOrFallbackToUTF8Alias( _alias );
189 return ( !sProgrammatic.equals( "HomeCountry" )
190 && !sProgrammatic.equals( "WorkCountry" )
192 // for those, we know that they're not searchable in the Mozilla/LDAP implementation.
193 // There might be more ...