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"
23 #include "MExtConfigAccess.hxx"
25 #include <com/sun/star/beans/XPropertySet.hpp>
26 #include <com/sun/star/container/XNameAccess.hpp>
28 #include <tools/diagnose_ex.h>
33 using namespace ::connectivity
;
34 using namespace ::connectivity::mozab
;
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 // open our driver settings config node
95 // the config path for our own driver's settings
96 Reference
< XPropertySet
> xDriverNode
= createDriverConfigNode( _rxORB
);
97 if ( xDriverNode
.is() )
102 Reference
< XNameAccess
> xAliasesNode
;
103 xDriverNode
->getPropertyValue("ColumnAliases") >>= xAliasesNode
;
104 OSL_ENSURE( xAliasesNode
.is(), "OColumnAlias::setAlias: missing the aliases node!" );
106 // this is a set of string nodes
107 Sequence
< OUString
> aProgrammaticNames
;
108 if ( xAliasesNode
.is() )
109 aProgrammaticNames
= xAliasesNode
->getElementNames();
112 // travel through all the set elements
113 const OUString
* pProgrammaticNames
= aProgrammaticNames
.getConstArray();
114 const OUString
* pProgrammaticNamesEnd
= pProgrammaticNames
+ aProgrammaticNames
.getLength();
115 OUString sAssignedAlias
;
117 for ( ; pProgrammaticNames
< pProgrammaticNamesEnd
; ++pProgrammaticNames
)
119 OSL_VERIFY( xAliasesNode
->getByName( *pProgrammaticNames
) >>= sAssignedAlias
);
121 // normalize in case the config data is corrupted
122 // (what we really don't need is an empty alias ...)
123 if ( sAssignedAlias
.isEmpty() )
124 sAssignedAlias
= *pProgrammaticNames
;
126 OString
sAsciiProgrammaticName( OUStringToOString( *pProgrammaticNames
, RTL_TEXTENCODING_ASCII_US
) );
128 #if OSL_DEBUG_LEVEL > 0
131 for ( AliasMap::iterator search
= m_aAliasMap
.begin();
132 ( search
!= m_aAliasMap
.end() );
136 if ( search
->second
.programmaticAsciiName
.equals( sAsciiProgrammaticName
) )
138 AliasEntry
entry( search
->second
);
139 m_aAliasMap
.erase( search
);
140 m_aAliasMap
[ sAssignedAlias
] = entry
;
142 #if OSL_DEBUG_LEVEL > 0
150 OSL_ENSURE( bFound
, "OColumnAlias::setAlias: did not find a programmatic name which exists in the configuration!" );
153 catch( const Exception
& )
155 DBG_UNHANDLED_EXCEPTION();
161 OString
OColumnAlias::getProgrammaticNameOrFallbackToUTF8Alias( const OUString
& _rAlias
) const
163 AliasMap::const_iterator pos
= m_aAliasMap
.find( _rAlias
);
164 if ( pos
== m_aAliasMap
.end() )
166 OSL_FAIL( "OColumnAlias::getProgrammaticNameOrFallbackToUTF8Alias: no programmatic name for this alias!" );
167 return OUStringToOString( _rAlias
, RTL_TEXTENCODING_UTF8
);
169 return pos
->second
.programmaticAsciiName
;
173 bool OColumnAlias::isColumnSearchable( const OUString _alias
) const
175 OString sProgrammatic
= getProgrammaticNameOrFallbackToUTF8Alias( _alias
);
177 return ( !sProgrammatic
.equals( "HomeCountry" )
178 && !sProgrammatic
.equals( "WorkCountry" )
180 // for those, we know that they're not searchable in the Mozilla/LDAP implementation.
181 // There might be more ...
184 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */