LCOV - code coverage report
Current view: top level - dbaccess/source/filter/xml - xmlDataSource.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 78 133 58.6 %
Date: 2012-08-25 Functions: 5 5 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 72 242 29.8 %

           Branch data     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 "xmlDataSource.hxx"
      21                 :            : #include "xmlLogin.hxx"
      22                 :            : #include "xmlTableFilterList.hxx"
      23                 :            : #include "xmlDataSourceInfo.hxx"
      24                 :            : #include "xmlDataSourceSettings.hxx"
      25                 :            : #include "xmlDataSourceSetting.hxx"
      26                 :            : #include "xmlfilter.hxx"
      27                 :            : #include <xmloff/xmltoken.hxx>
      28                 :            : #include <xmloff/xmlnmspe.hxx>
      29                 :            : #include <xmloff/nmspmap.hxx>
      30                 :            : #include "xmlEnums.hxx"
      31                 :            : #include "xmlstrings.hrc"
      32                 :            : #include <tools/debug.hxx>
      33                 :            : #include <tools/diagnose_ex.h>
      34                 :            : #include "xmlConnectionData.hxx"
      35                 :            : 
      36                 :            : namespace dbaxml
      37                 :            : {
      38                 :            :     using namespace ::com::sun::star::uno;
      39                 :            :     using namespace ::com::sun::star::xml::sax;
      40                 :            : DBG_NAME(OXMLDataSource)
      41                 :            : 
      42                 :         42 : OXMLDataSource::OXMLDataSource( ODBFilter& rImport,
      43                 :            :                 sal_uInt16 nPrfx, const ::rtl::OUString& _sLocalName,
      44                 :            :                 const Reference< XAttributeList > & _xAttrList, const UsedFor _eUsedFor ) :
      45                 :         42 :     SvXMLImportContext( rImport, nPrfx, _sLocalName )
      46                 :            : {
      47                 :            :     DBG_CTOR(OXMLDataSource,NULL);
      48                 :            : 
      49                 :            :     OSL_ENSURE(_xAttrList.is(),"Attribute list is NULL!");
      50                 :         42 :     const SvXMLNamespaceMap& rMap = rImport.GetNamespaceMap();
      51         [ +  - ]:         42 :     const SvXMLTokenMap& rTokenMap = rImport.GetDataSourceElemTokenMap();
      52                 :            : 
      53         [ +  - ]:         42 :     Reference<XPropertySet> xDataSource = rImport.getDataSource();
      54                 :            : 
      55                 :         42 :     PropertyValue aProperty;
      56                 :         42 :     bool bFoundParamNameSubstitution = false;
      57                 :         42 :     bool bFoundTableNameLengthLimited = false;
      58                 :         42 :     bool bFoundAppendTableAliasName = false;
      59                 :         42 :     bool bFoundSuppressVersionColumns = false;
      60                 :            : 
      61 [ +  - ][ +  - ]:         42 :     const sal_Int16 nLength = (xDataSource.is() && _xAttrList.is()) ? _xAttrList->getLength() : 0;
         [ +  - ][ +  - ]
      62 [ +  + ][ +  - ]:         42 :     static const ::rtl::OUString s_sTRUE = ::xmloff::token::GetXMLToken(XML_TRUE);
         [ +  - ][ #  # ]
      63         [ +  + ]:        126 :     for(sal_Int16 i = 0; i < nLength; ++i)
      64                 :            :     {
      65                 :         84 :         ::rtl::OUString sLocalName;
      66 [ +  - ][ +  - ]:         84 :         rtl::OUString sAttrName = _xAttrList->getNameByIndex( i );
      67         [ +  - ]:         84 :         sal_uInt16 nPrefix = rMap.GetKeyByAttrName( sAttrName,&sLocalName );
      68 [ +  - ][ +  - ]:         84 :         rtl::OUString sValue = _xAttrList->getValueByIndex( i );
      69                 :            : 
      70                 :         84 :         aProperty.Name = ::rtl::OUString();
      71                 :         84 :         aProperty.Value = Any();
      72                 :            : 
      73   [ -  -  -  -  :         84 :         switch( rTokenMap.Get( nPrefix, sLocalName ) )
          -  -  +  +  -  
          +  +  -  -  -  
             +  +  -  - ]
                 [ +  - ]
      74                 :            :         {
      75                 :            :             case XML_TOK_CONNECTION_RESOURCE:
      76                 :            :                 try
      77                 :            :                 {
      78 [ #  # ][ #  # ]:          0 :                     xDataSource->setPropertyValue(PROPERTY_URL,makeAny(sValue));
         [ #  # ][ #  # ]
                 [ #  # ]
      79                 :            :                 }
      80         [ #  # ]:          0 :                 catch(const Exception&)
      81                 :            :                 {
      82                 :            :                     DBG_UNHANDLED_EXCEPTION();
      83                 :            :                 }
      84                 :          0 :                 break;
      85                 :            :             case XML_TOK_SUPPRESS_VERSION_COLUMNS:
      86                 :            :                 try
      87                 :            :                 {
      88 [ #  # ][ #  # ]:          0 :                     xDataSource->setPropertyValue(PROPERTY_SUPPRESSVERSIONCL,makeAny(sValue == s_sTRUE ? sal_True : sal_False));
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
      89                 :          0 :                     bFoundSuppressVersionColumns = true;
      90                 :            :                 }
      91         [ #  # ]:          0 :                 catch(const Exception&)
      92                 :            :                 {
      93                 :            :                     DBG_UNHANDLED_EXCEPTION();
      94                 :            :                 }
      95                 :          0 :                 break;
      96                 :            :             case XML_TOK_JAVA_DRIVER_CLASS:
      97         [ #  # ]:          0 :                 aProperty.Name = INFO_JDBCDRIVERCLASS;
      98                 :          0 :                 break;
      99                 :            :             case XML_TOK_EXTENSION:
     100         [ #  # ]:          0 :                 aProperty.Name = INFO_TEXTFILEEXTENSION;
     101                 :          0 :                 break;
     102                 :            :             case XML_TOK_IS_FIRST_ROW_HEADER_LINE:
     103         [ #  # ]:          0 :                 aProperty.Name = INFO_TEXTFILEHEADER;
     104 [ #  # ][ #  # ]:          0 :                 aProperty.Value <<= (sValue == s_sTRUE ? sal_True : sal_False);
     105                 :          0 :                 break;
     106                 :            :             case XML_TOK_SHOW_DELETED:
     107         [ #  # ]:          0 :                 aProperty.Name = INFO_SHOWDELETEDROWS;
     108 [ #  # ][ #  # ]:          0 :                 aProperty.Value <<= (sValue == s_sTRUE ? sal_True : sal_False);
     109                 :          0 :                 break;
     110                 :            :             case XML_TOK_IS_TABLE_NAME_LENGTH_LIMITED:
     111         [ +  - ]:         14 :                 aProperty.Name = INFO_ALLOWLONGTABLENAMES;
     112 [ +  - ][ -  + ]:         14 :                 aProperty.Value <<= (sValue == s_sTRUE ? sal_True : sal_False);
     113                 :         14 :                 bFoundTableNameLengthLimited = true;
     114                 :         14 :                 break;
     115                 :            :             case XML_TOK_SYSTEM_DRIVER_SETTINGS:
     116         [ +  - ]:         14 :                 aProperty.Name = INFO_ADDITIONALOPTIONS;
     117                 :         14 :                 break;
     118                 :            :             case XML_TOK_ENABLE_SQL92_CHECK:
     119         [ #  # ]:          0 :                 aProperty.Name = PROPERTY_ENABLESQL92CHECK;
     120 [ #  # ][ #  # ]:          0 :                 aProperty.Value <<= (sValue == s_sTRUE ? sal_True : sal_False);
     121                 :          0 :                 break;
     122                 :            :             case XML_TOK_APPEND_TABLE_ALIAS_NAME:
     123         [ +  - ]:         14 :                 aProperty.Name = INFO_APPEND_TABLE_ALIAS;
     124 [ +  - ][ -  + ]:         14 :                 aProperty.Value <<= (sValue == s_sTRUE ? sal_True : sal_False);
     125                 :         14 :                 bFoundAppendTableAliasName = true;
     126                 :         14 :                 break;
     127                 :            :             case XML_TOK_PARAMETER_NAME_SUBSTITUTION:
     128         [ +  - ]:         14 :                 aProperty.Name = INFO_PARAMETERNAMESUBST;
     129 [ +  - ][ -  + ]:         14 :                 aProperty.Value <<= (sValue == s_sTRUE ? sal_True : sal_False);
     130                 :         14 :                 bFoundParamNameSubstitution = true;
     131                 :         14 :                 break;
     132                 :            :             case XML_TOK_IGNORE_DRIVER_PRIVILEGES:
     133         [ #  # ]:          0 :                 aProperty.Name = INFO_IGNOREDRIVER_PRIV;
     134 [ #  # ][ #  # ]:          0 :                 aProperty.Value <<= (sValue == s_sTRUE ? sal_True : sal_False);
     135                 :          0 :                 break;
     136                 :            :             case XML_TOK_BOOLEAN_COMPARISON_MODE:
     137         [ #  # ]:          0 :                 aProperty.Name = PROPERTY_BOOLEANCOMPARISONMODE;
     138         [ #  # ]:          0 :                 if ( sValue == "equal-integer" )
     139         [ #  # ]:          0 :                     aProperty.Value <<= sal_Int32(0);
     140         [ #  # ]:          0 :                 else if ( sValue == "is-boolean" )
     141         [ #  # ]:          0 :                     aProperty.Value <<= sal_Int32(1);
     142         [ #  # ]:          0 :                 else if ( sValue == "equal-boolean" )
     143         [ #  # ]:          0 :                     aProperty.Value <<= sal_Int32(2);
     144         [ #  # ]:          0 :                 else if ( sValue == "equal-use-only-zero" )
     145         [ #  # ]:          0 :                     aProperty.Value <<= sal_Int32(3);
     146                 :          0 :                 break;
     147                 :            :             case XML_TOK_USE_CATALOG:
     148         [ #  # ]:          0 :                 aProperty.Name = INFO_USECATALOG;
     149 [ #  # ][ #  # ]:          0 :                 aProperty.Value <<= (sValue == s_sTRUE ? sal_True : sal_False);
     150                 :          0 :                 break;
     151                 :            :             case XML_TOK_BASE_DN:
     152         [ +  - ]:         14 :                 aProperty.Name = INFO_CONN_LDAP_BASEDN;
     153                 :         14 :                 break;
     154                 :            :             case XML_TOK_MAX_ROW_COUNT:
     155         [ +  - ]:         14 :                 aProperty.Name = INFO_CONN_LDAP_ROWCOUNT;
     156         [ +  - ]:         14 :                 aProperty.Value <<= sValue.toInt32();
     157                 :         14 :                 break;
     158                 :            :             case XML_TOK_JAVA_CLASSPATH:
     159         [ #  # ]:          0 :                 aProperty.Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("JavaDriverClassPath"));
     160                 :          0 :                 break;
     161                 :            :         }
     162         [ +  - ]:         84 :         if ( !aProperty.Name.isEmpty() )
     163                 :            :         {
     164         [ +  + ]:         84 :             if ( !aProperty.Value.hasValue() )
     165         [ +  - ]:         28 :                 aProperty.Value <<= sValue;
     166         [ +  - ]:         84 :             rImport.addInfo(aProperty);
     167                 :            :         }
     168                 :         84 :     }
     169         [ +  + ]:         42 :     if ( rImport.isNewFormat() )
     170                 :            :     {
     171 [ +  + ][ -  + ]:         28 :         if ( !bFoundTableNameLengthLimited && ( _eUsedFor == eAppSettings ) )
     172                 :            :         {
     173         [ #  # ]:          0 :             aProperty.Name = INFO_ALLOWLONGTABLENAMES;
     174         [ #  # ]:          0 :             aProperty.Value <<= sal_True;
     175         [ #  # ]:          0 :             rImport.addInfo(aProperty);
     176                 :            :         }
     177 [ +  + ][ -  + ]:         28 :         if ( !bFoundParamNameSubstitution && ( _eUsedFor == eDriverSettings ) )
     178                 :            :         {
     179         [ #  # ]:          0 :             aProperty.Name = INFO_PARAMETERNAMESUBST;
     180         [ #  # ]:          0 :             aProperty.Value <<= sal_True;
     181         [ #  # ]:          0 :             rImport.addInfo(aProperty);
     182                 :            :         }
     183 [ +  + ][ -  + ]:         28 :         if ( !bFoundAppendTableAliasName && ( _eUsedFor == eAppSettings ) )
     184                 :            :         {
     185         [ #  # ]:          0 :             aProperty.Name = INFO_APPEND_TABLE_ALIAS;
     186         [ #  # ]:          0 :             aProperty.Value <<= sal_True;
     187         [ #  # ]:          0 :             rImport.addInfo(aProperty);
     188                 :            :         }
     189 [ +  - ][ +  + ]:         28 :         if ( !bFoundSuppressVersionColumns && ( _eUsedFor == eAppSettings ) )
     190                 :            :         {
     191                 :            :             try
     192                 :            :             {
     193 [ +  - ][ +  - ]:         14 :                 xDataSource->setPropertyValue(PROPERTY_SUPPRESSVERSIONCL,makeAny(sal_True));
         [ +  - ][ +  - ]
                 [ #  # ]
     194                 :            :             }
     195         [ #  # ]:          0 :             catch(const Exception&)
     196                 :            :             {
     197                 :            :                 DBG_UNHANDLED_EXCEPTION();
     198                 :            :             }
     199                 :            :         }
     200                 :         42 :     }
     201                 :         42 : }
     202                 :            : // -----------------------------------------------------------------------------
     203                 :            : 
     204                 :         42 : OXMLDataSource::~OXMLDataSource()
     205                 :            : {
     206                 :            : 
     207                 :            :     DBG_DTOR(OXMLDataSource,NULL);
     208         [ -  + ]:         84 : }
     209                 :            : // -----------------------------------------------------------------------------
     210                 :            : 
     211                 :         68 : SvXMLImportContext* OXMLDataSource::CreateChildContext(
     212                 :            :         sal_uInt16 nPrefix,
     213                 :            :         const ::rtl::OUString& rLocalName,
     214                 :            :         const Reference< XAttributeList > & xAttrList )
     215                 :            : {
     216                 :         68 :     SvXMLImportContext *pContext = 0;
     217                 :         68 :     const SvXMLTokenMap&    rTokenMap   = GetOwnImport().GetDataSourceElemTokenMap();
     218                 :         68 :     const sal_uInt16 nToken = rTokenMap.Get( nPrefix, rLocalName );
     219                 :            : 
     220   [ -  +  +  -  :         68 :     switch( nToken )
             +  +  +  - ]
     221                 :            :     {
     222                 :            :         case XML_TOK_LOGIN:
     223                 :          0 :             GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
     224         [ #  # ]:          0 :             pContext = new OXMLLogin( GetOwnImport(), nPrefix, rLocalName,xAttrList );
     225                 :          0 :             break;
     226                 :            : 
     227                 :            :         case XML_TOK_TABLE_FILTER:
     228                 :            :         case XML_TOK_TABLE_TYPE_FILTER:
     229                 :         14 :             GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
     230         [ +  - ]:         14 :             pContext = new OXMLTableFilterList( GetImport(), nPrefix, rLocalName );
     231                 :         14 :             break;
     232                 :            :         case XML_TOK_AUTO_INCREMENT:
     233                 :            :         case XML_TOK_DELIMITER:
     234                 :            :         case XML_TOK_FONT_CHARSET:
     235                 :            :         case XML_TOK_CHARACTER_SET:
     236                 :         12 :             GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
     237         [ +  - ]:         12 :             pContext = new OXMLDataSourceInfo( GetOwnImport(), nPrefix, rLocalName,xAttrList,nToken);
     238                 :         12 :             break;
     239                 :            :         case XML_TOK_DATA_SOURCE_SETTINGS:
     240                 :          0 :             GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
     241         [ #  # ]:          0 :             pContext = new OXMLDataSourceSettings( GetOwnImport(), nPrefix, rLocalName);
     242                 :          0 :             break;
     243                 :            :         case XML_TOK_CONNECTION_DATA:
     244                 :         14 :             GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
     245         [ +  - ]:         14 :             pContext = new OXMLConnectionData( GetOwnImport(), nPrefix, rLocalName);
     246                 :         14 :             break;
     247                 :            :         case XML_TOK_DRIVER_SETTINGS:
     248                 :         14 :             GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
     249         [ +  - ]:         14 :             pContext = new OXMLDataSource( GetOwnImport(), nPrefix, rLocalName, xAttrList, OXMLDataSource::eDriverSettings );
     250                 :         14 :             break;
     251                 :            :         case XML_TOK_APPLICATION_CONNECTION_SETTINGS:
     252                 :         14 :             GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
     253         [ +  - ]:         14 :             pContext = new OXMLDataSource( GetOwnImport(), nPrefix, rLocalName, xAttrList, OXMLDataSource::eAppSettings );
     254                 :         14 :             break;
     255                 :            :     }
     256                 :            : 
     257         [ -  + ]:         68 :     if( !pContext )
     258         [ #  # ]:          0 :         pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
     259                 :            : 
     260                 :         68 :     return pContext;
     261                 :            : }
     262                 :            : // -----------------------------------------------------------------------------
     263                 :        190 : ODBFilter& OXMLDataSource::GetOwnImport()
     264                 :            : {
     265                 :        190 :     return static_cast<ODBFilter&>(GetImport());
     266                 :            : }
     267                 :            : // -----------------------------------------------------------------------------
     268                 :            : 
     269                 :            : //----------------------------------------------------------------------------
     270                 :            : } // namespace dbaxml
     271                 :            : // -----------------------------------------------------------------------------
     272                 :            : 
     273                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10