LCOV - code coverage report
Current view: top level - dbaccess/source/filter/xml - xmlDataSourceInfo.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 33 63 52.4 %
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 "xmlDataSourceInfo.hxx"
      21             : #include "xmlDataSource.hxx"
      22             : #include "xmlfilter.hxx"
      23             : #include <xmloff/xmltoken.hxx>
      24             : #include <xmloff/xmlnmspe.hxx>
      25             : #include <xmloff/nmspmap.hxx>
      26             : #include "xmlEnums.hxx"
      27             : #include "xmlstrings.hrc"
      28             : #include <com/sun/star/beans/PropertyValue.hpp>
      29             : #include <tools/debug.hxx>
      30             : #include <vector>
      31             : 
      32             : namespace dbaxml
      33             : {
      34             :     using namespace ::com::sun::star::uno;
      35             :     using namespace ::com::sun::star::xml::sax;
      36             : 
      37           7 : OXMLDataSourceInfo::OXMLDataSourceInfo( ODBFilter& rImport
      38             :                 ,sal_uInt16 nPrfx
      39             :                 ,const OUString& _sLocalName
      40             :                 ,const Reference< XAttributeList > & _xAttrList
      41             :                 ,const sal_uInt16 _nToken) :
      42           7 :     SvXMLImportContext( rImport, nPrfx, _sLocalName )
      43             : {
      44             : 
      45             :     OSL_ENSURE(_xAttrList.is(),"Attribute list is NULL!");
      46           7 :     const SvXMLNamespaceMap& rMap = rImport.GetNamespaceMap();
      47           7 :     const SvXMLTokenMap& rTokenMap = rImport.GetDataSourceInfoElemTokenMap();
      48             : 
      49           7 :     PropertyValue aProperty;
      50           7 :     sal_Int16 nLength = (_xAttrList.is()) ? _xAttrList->getLength() : 0;
      51           7 :     bool bAutoEnabled = false;
      52           7 :     bool bFoundField = false,bFoundThousand = false, bFoundCharset = false;
      53          14 :     ::std::vector< sal_uInt16 > aTokens;
      54          14 :     for(sal_Int16 i = 0; i < nLength; ++i)
      55             :     {
      56           7 :         OUString sLocalName;
      57          14 :         OUString sAttrName = _xAttrList->getNameByIndex( i );
      58           7 :         sal_uInt16 nPrefix = rMap.GetKeyByAttrName( sAttrName,&sLocalName );
      59          14 :         OUString sValue = _xAttrList->getValueByIndex( i );
      60             : 
      61           7 :         aProperty.Name.clear();
      62             : 
      63           7 :         sal_uInt16 nToken = rTokenMap.Get( nPrefix, sLocalName );
      64           7 :         aTokens.push_back(nToken);
      65           7 :         switch( nToken )
      66             :         {
      67             :             case XML_TOK_ADDITIONAL_COLUMN_STATEMENT:
      68           0 :                 aProperty.Name = PROPERTY_AUTOINCREMENTCREATION;
      69           0 :                 bAutoEnabled = true;
      70           0 :                 break;
      71             :             case XML_TOK_ROW_RETRIEVING_STATEMENT:
      72           0 :                 aProperty.Name = INFO_AUTORETRIEVEVALUE;
      73           0 :                 bAutoEnabled = true;
      74           0 :                 break;
      75             :             case XML_TOK_STRING:
      76           0 :                 aProperty.Name = INFO_TEXTDELIMITER;
      77           0 :                 break;
      78             :             case XML_TOK_FIELD:
      79           0 :                 aProperty.Name = INFO_FIELDDELIMITER;
      80           0 :                 bFoundField = true;
      81           0 :                 break;
      82             :             case XML_TOK_DECIMAL:
      83           0 :                 aProperty.Name = INFO_DECIMALDELIMITER;
      84           0 :                 break;
      85             :             case XML_TOK_THOUSAND:
      86           0 :                 aProperty.Name = INFO_THOUSANDSDELIMITER;
      87           0 :                 bFoundThousand = true;
      88           0 :                 break;
      89             :             case XML_TOK_ENCODING:
      90           7 :                 aProperty.Name = INFO_CHARSET;
      91           7 :                 bFoundCharset = true;
      92           7 :                 break;
      93             :         }
      94           7 :         if ( !aProperty.Name.isEmpty() )
      95             :         {
      96           7 :             aProperty.Value <<= sValue;
      97           7 :             rImport.addInfo(aProperty);
      98             :         }
      99           7 :     }
     100           7 :     if ( bAutoEnabled )
     101             :     {
     102           0 :         aProperty.Name = INFO_AUTORETRIEVEENABLED;
     103           0 :         aProperty.Value <<= sal_True;
     104           0 :         rImport.addInfo(aProperty);
     105             :     }
     106           7 :     if ( rImport.isNewFormat() )
     107             :     {
     108           7 :         if ( XML_TOK_DELIMITER == _nToken )
     109             :         {
     110           0 :             if ( !bFoundField )
     111             :             {
     112           0 :                 aProperty.Name = INFO_FIELDDELIMITER;
     113           0 :                 aProperty.Value <<= OUString(";");
     114           0 :                 rImport.addInfo(aProperty);
     115             :             }
     116           0 :             if ( !bFoundThousand )
     117             :             {
     118           0 :                 aProperty.Name = INFO_THOUSANDSDELIMITER;
     119           0 :                 aProperty.Value <<= OUString(",");
     120           0 :                 rImport.addInfo(aProperty);
     121             :             }
     122             :         }
     123           7 :         if ( XML_TOK_FONT_CHARSET == _nToken && !bFoundCharset )
     124             :         {
     125           0 :             aProperty.Name = INFO_CHARSET;
     126           0 :             aProperty.Value <<= OUString("utf8");
     127           0 :             rImport.addInfo(aProperty);
     128             :         }
     129           7 :     }
     130           7 : }
     131             : 
     132          14 : OXMLDataSourceInfo::~OXMLDataSourceInfo()
     133             : {
     134             : 
     135          14 : }
     136             : 
     137             : } // namespace dbaxml
     138             : 
     139             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11