LCOV - code coverage report
Current view: top level - dbaccess/source/filter/xml - xmlLogin.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 20 37 54.1 %
Date: 2015-06-13 12:38:46 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 "xmlLogin.hxx"
      21             : #include "xmlfilter.hxx"
      22             : #include <xmloff/xmltoken.hxx>
      23             : #include <xmloff/xmlnmspe.hxx>
      24             : #include <xmloff/nmspmap.hxx>
      25             : #include "xmlEnums.hxx"
      26             : #include "xmlstrings.hrc"
      27             : #include <tools/debug.hxx>
      28             : #include <tools/diagnose_ex.h>
      29             : #include <com/sun/star/sdbc/XDataSource.hpp>
      30             : #include <vector>
      31             : 
      32             : namespace dbaxml
      33             : {
      34             :     using namespace ::com::sun::star::uno;
      35             :     using namespace ::com::sun::star::sdbc;
      36             :     using namespace ::com::sun::star::xml::sax;
      37             : 
      38          16 : OXMLLogin::OXMLLogin( ODBFilter& rImport,
      39             :                 sal_uInt16 nPrfx, const OUString& _sLocalName,
      40             :                 const Reference< XAttributeList > & _xAttrList ) :
      41          16 :     SvXMLImportContext( rImport, nPrfx, _sLocalName )
      42             : {
      43             : 
      44             :     OSL_ENSURE(_xAttrList.is(),"Attribute list is NULL!");
      45          16 :     const SvXMLNamespaceMap& rMap = rImport.GetNamespaceMap();
      46          16 :     const SvXMLTokenMap& rTokenMap = rImport.GetLoginElemTokenMap();
      47             : 
      48          16 :     Reference<XPropertySet> xDataSource(rImport.getDataSource());
      49             : 
      50          16 :     const sal_Int16 nLength = (xDataSource.is() && _xAttrList.is()) ? _xAttrList->getLength() : 0;
      51          16 :     static const OUString s_sTRUE = ::xmloff::token::GetXMLToken(XML_TRUE);
      52          16 :     bool bUserFound = false;
      53          32 :     for(sal_Int16 i = 0; i < nLength; ++i)
      54             :     {
      55          16 :         OUString sLocalName;
      56          32 :         OUString sAttrName = _xAttrList->getNameByIndex( i );
      57          16 :         sal_uInt16 nPrefix = rMap.GetKeyByAttrName( sAttrName,&sLocalName );
      58          32 :         OUString sValue = _xAttrList->getValueByIndex( i );
      59             : 
      60             :         try
      61             :         {
      62          16 :             switch( rTokenMap.Get( nPrefix, sLocalName ) )
      63             :             {
      64             :                 case XML_TOK_USER_NAME:
      65           0 :                     if ( !bUserFound )
      66             :                     {
      67           0 :                         bUserFound = true;
      68             :                         try
      69             :                         {
      70           0 :                             xDataSource->setPropertyValue(PROPERTY_USER,makeAny(sValue));
      71             :                         }
      72           0 :                         catch(const Exception&)
      73             :                         {
      74             :                             DBG_UNHANDLED_EXCEPTION();
      75             :                         }
      76             :                     }
      77           0 :                     break;
      78             :                 case XML_TOK_IS_PASSWORD_REQUIRED:
      79             :                     try
      80             :                     {
      81          16 :                         xDataSource->setPropertyValue(PROPERTY_ISPASSWORDREQUIRED,makeAny((sValue == s_sTRUE ? sal_True : sal_False)));
      82             :                     }
      83           0 :                     catch(const Exception&)
      84             :                     {
      85             :                         DBG_UNHANDLED_EXCEPTION();
      86             :                     }
      87          16 :                     break;
      88             :                 case XML_TOK_USE_SYSTEM_USER:
      89           0 :                     if ( !bUserFound )
      90             :                     {
      91           0 :                         bUserFound = true;
      92           0 :                         PropertyValue aProperty;
      93           0 :                         aProperty.Name = "UseSystemUser";
      94           0 :                         aProperty.Value <<= (sValue == s_sTRUE ? sal_True : sal_False);
      95           0 :                         rImport.addInfo(aProperty);
      96             :                     }
      97           0 :                     break;
      98             :                 case XML_TOK_LOGIN_TIMEOUT:
      99             :                     try
     100             :                     {
     101           0 :                         Reference< XDataSource>(xDataSource,UNO_QUERY_THROW)->setLoginTimeout(sValue.toInt32());
     102             :                     }
     103           0 :                     catch(const Exception&)
     104             :                     {
     105             :                         DBG_UNHANDLED_EXCEPTION();
     106             :                     }
     107           0 :                     break;
     108             :             }
     109             :         }
     110           0 :         catch(const Exception&)
     111             :         {
     112             :             DBG_UNHANDLED_EXCEPTION();
     113             :         }
     114          32 :     }
     115          16 : }
     116             : 
     117          32 : OXMLLogin::~OXMLLogin()
     118             : {
     119             : 
     120          32 : }
     121             : 
     122             : } // namespace dbaxml
     123             : 
     124             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11