LCOV - code coverage report
Current view: top level - connectivity/source/drivers/mork - MColumnAlias.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 28 30 93.3 %
Date: 2014-11-03 Functions: 3 3 100.0 %
Legend: Lines: hit not hit

          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           6 : 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         228 :     for ( size_t i = 0; i < sizeof( s_pProgrammaticNames ) / sizeof( s_pProgrammaticNames[0] ); ++i )
      85         222 :         m_aAliasMap[ OUString::createFromAscii( s_pProgrammaticNames[i] ) ] = AliasEntry( s_pProgrammaticNames[i], i );
      86             : 
      87           6 :     initialize( _rxORB );
      88           6 : }
      89             : 
      90             : 
      91           6 : 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           6 :         UNO_QUERY_THROW);
      98          12 :     Sequence< OUString > aProgrammaticNames(xAliasesNode->getElementNames());
      99         228 :     for (sal_Int32 i = 0; i != aProgrammaticNames.getLength(); ++i) {
     100             :         OString sAsciiProgrammaticName(
     101             :             OUStringToOString(
     102         222 :                 aProgrammaticNames[i], RTL_TEXTENCODING_ASCII_US));
     103         222 :         bool bFound = false;
     104        5232 :         for (AliasMap::iterator j(m_aAliasMap.begin()); j != m_aAliasMap.end();
     105             :              ++j)
     106             :         {
     107        5232 :             if (j->second.programmaticAsciiName == sAsciiProgrammaticName) {
     108         222 :                 OUString sAssignedAlias;
     109         444 :                 xAliasesNode->getByName(aProgrammaticNames[i]) >>=
     110         222 :                     sAssignedAlias;
     111         222 :                 if (sAssignedAlias.isEmpty()) {
     112           0 :                     sAssignedAlias = aProgrammaticNames[i];
     113             :                 }
     114         444 :                 AliasEntry entry(j->second);
     115         222 :                 m_aAliasMap.erase(j);
     116         222 :                 m_aAliasMap[sAssignedAlias] = entry;
     117         222 :                 bFound = true;
     118         444 :                 break;
     119             :             }
     120             :         }
     121             :         SAL_WARN_IF(
     122             :             !bFound, "connectivity.mork",
     123             :             "unknown programmatic name " << aProgrammaticNames[i]
     124             :                 <<" from configuration");
     125         228 :     }
     126           6 : }
     127             : 
     128             : 
     129          38 : OString OColumnAlias::getProgrammaticNameOrFallbackToUTF8Alias( const OUString& _rAlias ) const
     130             : {
     131          38 :     AliasMap::const_iterator pos = m_aAliasMap.find( _rAlias );
     132          38 :     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          38 :     return pos->second.programmaticAsciiName;
     138             : }
     139             : 
     140             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10