merge the formfield patch from ooo-build
[ooovba.git] / connectivity / source / drivers / evoab / LColumnAlias.cxx
blobc59404389c20c1ab253a38b7d1a2284a4dc44bec
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: LColumnAlias.cxx,v $
10 * $Revision: 1.7 $
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 "LColumnAlias.hxx"
34 #include "LDriver.hxx"
35 #include <com/sun/star/beans/XPropertySet.hpp>
36 #include <com/sun/star/container/XNameAccess.hpp>
37 #include "LConfigAccess.hxx"
39 using namespace ::connectivity;
40 using namespace ::connectivity::evoab;
41 using namespace ::com::sun::star::uno;
42 using namespace ::com::sun::star::lang;
43 using namespace ::com::sun::star::beans;
44 using namespace ::com::sun::star::container;
46 static const ::rtl::OUString sProgrammaticNames[] =
48 ::rtl::OUString::createFromAscii("FirstName"),
49 ::rtl::OUString::createFromAscii("LastName"),
50 ::rtl::OUString::createFromAscii("DisplayName"),
51 ::rtl::OUString::createFromAscii("NickName"),
52 ::rtl::OUString::createFromAscii("PrimaryEmail"),
53 ::rtl::OUString::createFromAscii("SecondEmail"),
54 ::rtl::OUString::createFromAscii("PreferMailFormat"),
55 ::rtl::OUString::createFromAscii("WorkPhone"),
56 ::rtl::OUString::createFromAscii("HomePhone"),
57 ::rtl::OUString::createFromAscii("FaxNumber"),
58 ::rtl::OUString::createFromAscii("PagerNumber"),
59 ::rtl::OUString::createFromAscii("CellularNumber"),
60 ::rtl::OUString::createFromAscii("HomeAddress"),
61 ::rtl::OUString::createFromAscii("HomeAddress2"),
62 ::rtl::OUString::createFromAscii("HomeCity"),
63 ::rtl::OUString::createFromAscii("HomeState"),
64 ::rtl::OUString::createFromAscii("HomeZipCode"),
65 ::rtl::OUString::createFromAscii("HomeCountry"),
66 ::rtl::OUString::createFromAscii("WorkAddress"),
67 ::rtl::OUString::createFromAscii("WorkAddress2"),
68 ::rtl::OUString::createFromAscii("WorkCity"),
69 ::rtl::OUString::createFromAscii("WorkState"),
70 ::rtl::OUString::createFromAscii("WorkZipCode"),
71 ::rtl::OUString::createFromAscii("WorkCountry"),
72 ::rtl::OUString::createFromAscii("JobTitle"),
73 ::rtl::OUString::createFromAscii("Department"),
74 ::rtl::OUString::createFromAscii("Company"),
75 ::rtl::OUString::createFromAscii("WebPage1"),
76 ::rtl::OUString::createFromAscii("WebPage2"),
77 ::rtl::OUString::createFromAscii("BirthYear"),
78 ::rtl::OUString::createFromAscii("BirthMonth"),
79 ::rtl::OUString::createFromAscii("BirthDay"),
80 ::rtl::OUString::createFromAscii("Notes")
82 //------------------------------------------------------------------------------
83 OColumnAlias::OColumnAlias()
85 // Initialise m_aAlias with the default values from sProgrammaticNames.
86 initialise();
88 // Initialise m_aAlias map with the default values from sProgrammaticNames.
89 setAliasMap();
91 //------------------------------------------------------------------
92 OColumnAlias::~OColumnAlias()
95 //------------------------------------------------------------------
96 void OColumnAlias::initialise()
98 m_aAlias.reserve( END - FIRSTNAME + 1 );
99 for (sal_Int32 i(FIRSTNAME); i < END; ++i)
101 m_aAlias.push_back(sProgrammaticNames[i]);
102 m_aHeadLineNames.push_back(sProgrammaticNames[i]);
105 return;
107 //------------------------------------------------------------------
108 void OColumnAlias::setAlias(const ::com::sun::star::uno::Reference<
109 ::com::sun::star::lang::XMultiServiceFactory >& _rxORB)
111 OSL_TRACE("OColumnAlias::setAlias()entered");
113 // open our driver settings config node
115 // the config path for our own driver's settings
116 Reference< XPropertySet > xEvoDriverNode = createDriverConfigNode( _rxORB, OEvoabDriver::getImplementationName_Static() );
117 //Reference< XPropertySet > xMozDriverNode = createDriverConfigNode( _rxORB, mozab::OConnection::getDriverImplementationName() );
118 Reference< XPropertySet > xMozDriverNode = createDriverConfigNode( _rxORB, ::rtl::OUString::createFromAscii ("com.sun.star.comp.sdbc.MozabDriver") );
119 if ( xEvoDriverNode.is() && xMozDriverNode.is() )
123 //=============================================================
124 Reference< XNameAccess > xEvoAliasesNode;
125 Reference< XNameAccess > xMozAliasesNode;
126 xEvoDriverNode->getPropertyValue( ::rtl::OUString::createFromAscii("ColumnAliases") ) >>= xEvoAliasesNode;
127 xMozDriverNode->getPropertyValue( ::rtl::OUString::createFromAscii("ColumnAliases") ) >>= xMozAliasesNode;
128 OSL_ENSURE( xEvoAliasesNode.is(), "OColumnAlias::setAlias: missing the evolution aliases node!" );
129 OSL_ENSURE( xMozAliasesNode.is(), "OColumnAlias::setAlias: missing the mozilla aliases node!" );
131 // this is a set of string nodes
132 Sequence< ::rtl::OUString > aColumnProgrammaticNames;
133 //OSL_TRACE("OColumnAlias::setAlias()before xAliasesNode->getElementNames()");
134 if ( xEvoAliasesNode.is() )
135 aColumnProgrammaticNames = xEvoAliasesNode->getElementNames();
136 //OSL_TRACE("OColumnAlias::setAlias()after xAliasesNode->getElementNames()");
138 //=============================================================
139 // travel through all the set elements
140 const ::rtl::OUString* pProgrammaticNames = aColumnProgrammaticNames.getConstArray();
141 const ::rtl::OUString* pProgrammaticNamesEnd = pProgrammaticNames + aColumnProgrammaticNames.getLength();
142 ::rtl::OUString sAssignedAlias;
143 ::rtl::OUString sHeadLineName;
145 for ( ; pProgrammaticNames < pProgrammaticNamesEnd; ++pProgrammaticNames )
147 //OSL_TRACE("OColumnAlias::setAlias()::*pProgrammaticNames = %s\n", ((OUtoCStr(*pProgrammaticNames)) ? (OUtoCStr(*pProgrammaticNames)):("NULL")) );
148 OSL_ENSURE( m_aAliasMap.end() != m_aAliasMap.find( *pProgrammaticNames ),
149 "OColumnAlias::setAlias: found an invalid programmtic name!" );
150 // if this asserts, somebody stored a programmatic name in the configuration
151 // which is not allowed (i.e. not in the list of known programmatics).
152 //OSL_TRACE("OColumnAlias::setAlias()before xAliasesNode->getByName()");
154 #if OSL_DEBUG_LEVEL > 0
155 sal_Bool bExtractionSuccess =
156 #endif
157 xMozAliasesNode->getByName( *pProgrammaticNames) >>= sAssignedAlias;
158 OSL_ENSURE( bExtractionSuccess, "OColumnAlias::setAlias: invalid mozilla config data!" );
159 #if OSL_DEBUG_LEVEL > 0
160 bExtractionSuccess =
161 #endif
162 xEvoAliasesNode->getByName( *pProgrammaticNames) >>= sHeadLineName;
163 OSL_ENSURE( bExtractionSuccess, "OColumnAlias::setAlias: invalid evolution config data!" );
164 //OSL_TRACE("OColumnAlias::setAlias()after xAliasesNode->getByName()");
166 // normalize in case the config data is corrupted
167 // (what we really don't need is an empty alias ...)
168 if ( 0 == sAssignedAlias.getLength() )
169 sAssignedAlias = *pProgrammaticNames;
170 if ( 0 == sHeadLineName.getLength() )
171 sHeadLineName = *pProgrammaticNames;
172 //OSL_TRACE("OColumnAlias::setAlias()::sAssignedAlias = %s\n", ((OUtoCStr(sAssignedAlias)) ? (OUtoCStr(sAssignedAlias)):("NULL")) );
173 //OSL_TRACE("OColumnAlias::setAlias()::sHeadLineName = %s\n", ((OUtoCStr(sHeadLineName)) ? (OUtoCStr(sHeadLineName)):("NULL")) );
175 //=============================================================
176 // check the value
177 // look up the programmatic indicated by pProgrammaticNames in the known programmatics
178 const ::rtl::OUString* pProgrammatic = sProgrammaticNames + FIRSTNAME;
179 const ::rtl::OUString* pProgrammaticEnd = sProgrammaticNames + END;
181 OSL_ENSURE( (sal_Int32)m_aAlias.size() == pProgrammaticEnd - pProgrammatic,
182 "OColumnAlias::setAlias: aliases vector not yet initialized!" );
184 // the destination where we want to remember the alias
185 ::std::vector< ::rtl::OUString >::iterator aAlias = m_aAlias.begin();
186 ::std::vector< ::rtl::OUString >::iterator aHeadLineName = m_aHeadLineNames.begin();
188 for ( ; pProgrammatic < pProgrammaticEnd; ++pProgrammatic, ++aAlias, ++aHeadLineName )
190 //OSL_TRACE("OColumnAlias::setAlias()::*pProgrammatic = %s\n", ((OUtoCStr(*pProgrammatic)) ? (OUtoCStr(*pProgrammatic)):("NULL")) );
191 if ( pProgrammaticNames->equals( *pProgrammatic ) )
193 // add alias to the vector
194 *aAlias = sAssignedAlias;
195 *aHeadLineName = sHeadLineName;
196 break;
201 catch( const Exception& )
203 OSL_ENSURE( sal_False, "OColumnAlias::setAlias: could not read my driver's configuration data!" );
207 // Initialise m_aAliasMap.
208 setAliasMap();
210 return;
212 //------------------------------------------------------------------
213 const ::std::vector< ::rtl::OUString> & OColumnAlias::getAlias() const
215 return m_aAlias;
217 //------------------------------------------------------------------
218 const ::std::map< ::rtl::OUString, ::rtl::OUString> & OColumnAlias::getAliasMap() const
220 return m_aAliasMap;
222 //------------------------------------------------------------------
223 void OColumnAlias::setAliasMap()
225 // Fill the map with the values of m_aAlias
226 // and the sProgrammaticNames array.
227 for (sal_Int32 i(FIRSTNAME); i < END; ++i) {
228 m_aAliasMap[m_aAlias[i]] = m_aHeadLineNames[i];
229 //OSL_TRACE("OColumnAlias::setAliasMap()::m_aAlias[i] = %s\n", ((OUtoCStr(m_aAlias[i])) ? (OUtoCStr(m_aAlias[i])):("NULL")) );
230 //OSL_TRACE("OColumnAlias::setAliasMap()::m_aAliasMap[m_aAlias[i]] = %s\n", ((OUtoCStr(m_aAliasMap[m_aAlias[i]])) ? (OUtoCStr(m_aAliasMap[m_aAlias[i]])):("NULL")) );
233 return;
235 //------------------------------------------------------------------