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

Generated by: LCOV version 1.11