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

Generated by: LCOV version 1.11