LCOV - code coverage report
Current view: top level - connectivity/source/drivers/mork - MColumnAlias.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 30 0.0 %
Date: 2014-04-14 Functions: 0 3 0.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           0 : 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           0 :     for ( size_t i = 0; i < sizeof( s_pProgrammaticNames ) / sizeof( s_pProgrammaticNames[0] ); ++i )
      85           0 :         m_aAliasMap[ OUString::createFromAscii( s_pProgrammaticNames[i] ) ] = AliasEntry( s_pProgrammaticNames[i], i );
      86             : 
      87           0 :     initialize( _rxORB );
      88           0 : }
      89             : 
      90             : 
      91           0 : 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           0 :         UNO_QUERY_THROW);
      98           0 :     Sequence< OUString > aProgrammaticNames(xAliasesNode->getElementNames());
      99           0 :     for (sal_Int32 i = 0; i != aProgrammaticNames.getLength(); ++i) {
     100             :         OString sAsciiProgrammaticName(
     101             :             OUStringToOString(
     102           0 :                 aProgrammaticNames[i], RTL_TEXTENCODING_ASCII_US));
     103           0 :         bool bFound = false;
     104           0 :         for (AliasMap::iterator j(m_aAliasMap.begin()); j != m_aAliasMap.end();
     105             :              ++j)
     106             :         {
     107           0 :             if (j->second.programmaticAsciiName == sAsciiProgrammaticName) {
     108           0 :                 OUString sAssignedAlias;
     109           0 :                 xAliasesNode->getByName(aProgrammaticNames[i]) >>=
     110           0 :                     sAssignedAlias;
     111           0 :                 if (sAssignedAlias.isEmpty()) {
     112           0 :                     sAssignedAlias = aProgrammaticNames[i];
     113             :                 }
     114           0 :                 AliasEntry entry(j->second);
     115           0 :                 m_aAliasMap.erase(j);
     116           0 :                 m_aAliasMap[sAssignedAlias] = entry;
     117           0 :                 bFound = true;
     118           0 :                 break;
     119             :             }
     120             :         }
     121             :         SAL_WARN_IF(
     122             :             !bFound, "connectivity.mork",
     123             :             "unknown programmatic name " << aProgrammaticNames[i]
     124             :                 <<" from configuration");
     125           0 :     }
     126           0 : }
     127             : 
     128             : 
     129           0 : OString OColumnAlias::getProgrammaticNameOrFallbackToUTF8Alias( const OUString& _rAlias ) const
     130             : {
     131           0 :     AliasMap::const_iterator pos = m_aAliasMap.find( _rAlias );
     132           0 :     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           0 :     return pos->second.programmaticAsciiName;
     138             : }
     139             : 
     140             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10