LCOV - code coverage report
Current view: top level - dbaccess/source/filter/xml - xmlFileBasedDatabase.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 40 47 85.1 %
Date: 2012-08-25 Functions: 3 3 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 49 104 47.1 %

           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 "xmlFileBasedDatabase.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 <comphelper/sequence.hxx>
      30                 :            : #include <svl/filenotation.hxx>
      31                 :            : #include <unotools/pathoptions.hxx>
      32                 :            : #include "dsntypes.hxx"
      33                 :            : namespace dbaxml
      34                 :            : {
      35                 :            :     using namespace ::com::sun::star::uno;
      36                 :            :     using namespace ::com::sun::star::xml::sax;
      37                 :            : DBG_NAME(OXMLFileBasedDatabase)
      38                 :            : 
      39                 :         14 : OXMLFileBasedDatabase::OXMLFileBasedDatabase( ODBFilter& rImport,
      40                 :            :                 sal_uInt16 nPrfx, const ::rtl::OUString& _sLocalName,
      41                 :            :                 const Reference< XAttributeList > & _xAttrList) :
      42                 :         14 :     SvXMLImportContext( rImport, nPrfx, _sLocalName )
      43                 :            : {
      44                 :            :     DBG_CTOR(OXMLFileBasedDatabase,NULL);
      45                 :            : 
      46                 :            :     OSL_ENSURE(_xAttrList.is(),"Attribute list is NULL!");
      47                 :         14 :     const SvXMLNamespaceMap& rMap = rImport.GetNamespaceMap();
      48         [ +  - ]:         14 :     const SvXMLTokenMap& rTokenMap = rImport.GetDataSourceElemTokenMap();
      49                 :            : 
      50         [ +  - ]:         14 :     Reference<XPropertySet> xDataSource = rImport.getDataSource();
      51                 :            : 
      52                 :         14 :     PropertyValue aProperty;
      53                 :            : 
      54 [ +  - ][ +  - ]:         14 :     const sal_Int16 nLength = (xDataSource.is() && _xAttrList.is()) ? _xAttrList->getLength() : 0;
         [ +  - ][ +  - ]
      55                 :         14 :     ::rtl::OUString sLocation,sMediaType,sFileTypeExtension;
      56         [ +  + ]:         42 :     for(sal_Int16 i = 0; i < nLength; ++i)
      57                 :            :     {
      58                 :         28 :         ::rtl::OUString sLocalName;
      59 [ +  - ][ +  - ]:         28 :         const rtl::OUString sAttrName = _xAttrList->getNameByIndex( i );
      60         [ +  - ]:         28 :         const sal_uInt16 nPrefix = rMap.GetKeyByAttrName( sAttrName,&sLocalName );
      61 [ +  - ][ +  - ]:         28 :         const rtl::OUString sValue = _xAttrList->getValueByIndex( i );
      62                 :            : 
      63                 :         28 :         aProperty.Name = ::rtl::OUString();
      64                 :         28 :         aProperty.Value = Any();
      65                 :            : 
      66   [ +  +  -  - ]:         28 :         switch( rTokenMap.Get( nPrefix, sLocalName ) )
                 [ +  - ]
      67                 :            :         {
      68                 :            :             case XML_TOK_DB_HREF:
      69                 :            :                 {
      70         [ +  - ]:         14 :                     SvtPathOptions aPathOptions;
      71 [ +  - ][ +  - ]:         14 :                     rtl::OUString sFileName = aPathOptions.SubstituteVariable(sValue);
         [ +  - ][ +  - ]
                 [ +  - ]
      72         [ +  + ]:         14 :                     if ( sValue == sFileName )
      73                 :            :                     {
      74                 :          2 :                         const sal_Int32 nFileNameLength = sFileName.getLength();
      75 [ +  - ][ +  - ]:          2 :                         if ( ( nFileNameLength > 0 ) && ( sFileName.getStr()[ nFileNameLength - 1 ] == '/' ) )
                 [ +  - ]
      76                 :          2 :                             sFileName = sFileName.copy( 0, nFileNameLength - 1 );
      77                 :            : 
      78 [ +  - ][ +  - ]:          2 :                         sLocation = ::svt::OFileNotation( rImport.GetAbsoluteReference( sFileName ) ).get( ::svt::OFileNotation::N_SYSTEM );
         [ +  - ][ +  - ]
      79                 :            :                     }
      80                 :            : 
      81         [ +  + ]:         14 :                     if ( sLocation.isEmpty() )
      82         [ +  - ]:         14 :                         sLocation = sValue;
      83                 :            :                 }
      84                 :         14 :                 break;
      85                 :            :             case XML_TOK_MEDIA_TYPE:
      86                 :         14 :                 sMediaType = sValue;
      87                 :         14 :                 break;
      88                 :            :             case XML_TOK_EXTENSION:
      89         [ #  # ]:          0 :                 aProperty.Name = INFO_TEXTFILEEXTENSION;
      90                 :          0 :                 sFileTypeExtension = sValue;
      91                 :          0 :                 break;
      92                 :            :         }
      93         [ -  + ]:         28 :         if ( !aProperty.Name.isEmpty() )
      94                 :            :         {
      95         [ #  # ]:          0 :             if ( !aProperty.Value.hasValue() )
      96         [ #  # ]:          0 :                 aProperty.Value <<= sValue;
      97         [ #  # ]:          0 :             rImport.addInfo(aProperty);
      98                 :            :         }
      99                 :         28 :     }
     100 [ +  - ][ +  - ]:         14 :     if ( !(sLocation.isEmpty() || sMediaType.isEmpty()) )
                 [ +  - ]
     101                 :            :     {
     102 [ +  - ][ +  - ]:         14 :         ::dbaccess::ODsnTypeCollection aTypeCollection(rImport.getORB());
     103 [ +  - ][ +  - ]:         14 :         ::rtl::OUString sURL(aTypeCollection.getDatasourcePrefixFromMediaType(sMediaType,sFileTypeExtension));
                 [ +  - ]
     104                 :         14 :         sURL += sLocation;
     105                 :            :         try
     106                 :            :         {
     107 [ +  - ][ +  - ]:         14 :             xDataSource->setPropertyValue(PROPERTY_URL,makeAny(sURL));
         [ +  - ][ #  # ]
                 [ +  - ]
     108                 :            :         }
     109         [ #  # ]:          0 :         catch(const Exception&)
     110                 :            :         {
     111                 :            :             DBG_UNHANDLED_EXCEPTION();
     112         [ +  - ]:         14 :         }
     113                 :         14 :     }
     114                 :         14 : }
     115                 :            : // -----------------------------------------------------------------------------
     116                 :            : 
     117                 :         14 : OXMLFileBasedDatabase::~OXMLFileBasedDatabase()
     118                 :            : {
     119                 :            : 
     120                 :            :     DBG_DTOR(OXMLFileBasedDatabase,NULL);
     121         [ -  + ]:         28 : }
     122                 :            : // -----------------------------------------------------------------------------
     123                 :            : //----------------------------------------------------------------------------
     124                 :            : } // namespace dbaxml
     125                 :            : // -----------------------------------------------------------------------------
     126                 :            : 
     127                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10