LCOV - code coverage report
Current view: top level - dbaccess/source/filter/xml - xmlHierarchyCollection.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 16 55 29.1 %
Date: 2015-06-13 12:38:46 Functions: 5 6 83.3 %
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 "xmlHierarchyCollection.hxx"
      21             : #include "xmlComponent.hxx"
      22             : #include "xmlQuery.hxx"
      23             : #include "xmlColumn.hxx"
      24             : #include "xmlfilter.hxx"
      25             : #include <xmloff/xmltoken.hxx>
      26             : #include <xmloff/xmlnmspe.hxx>
      27             : #include <xmloff/nmspmap.hxx>
      28             : #include "xmlEnums.hxx"
      29             : #include "xmlstrings.hrc"
      30             : #include <com/sun/star/beans/PropertyValue.hpp>
      31             : #include <com/sun/star/container/XNameContainer.hpp>
      32             : #include <tools/debug.hxx>
      33             : 
      34             : namespace dbaxml
      35             : {
      36             :     using namespace ::com::sun::star::uno;
      37             :     using namespace ::com::sun::star::beans;
      38             :     using namespace ::com::sun::star::container;
      39             :     using namespace ::com::sun::star::xml::sax;
      40             : 
      41           0 : OXMLHierarchyCollection::OXMLHierarchyCollection( ODBFilter& rImport
      42             :                 ,sal_uInt16 nPrfx
      43             :                 ,const OUString& _sLocalName
      44             :                 ,const Reference< XAttributeList > & _xAttrList
      45             :                 ,const Reference< XNameAccess >& _xParentContainer
      46             :                 ,const OUString& _sCollectionServiceName
      47             :                 ,const OUString& _sComponentServiceName) :
      48             :     SvXMLImportContext( rImport, nPrfx, _sLocalName )
      49             :     ,m_xParentContainer(_xParentContainer)
      50             :     ,m_sCollectionServiceName(_sCollectionServiceName)
      51           0 :     ,m_sComponentServiceName(_sComponentServiceName)
      52             : {
      53             : 
      54           0 :     const SvXMLNamespaceMap& rMap = rImport.GetNamespaceMap();
      55           0 :     const SvXMLTokenMap& rTokenMap = rImport.GetComponentElemTokenMap();
      56             : 
      57           0 :     sal_Int16 nLength = (_xAttrList.is()) ? _xAttrList->getLength() : 0;
      58           0 :     for(sal_Int16 i = 0; i < nLength; ++i)
      59             :     {
      60           0 :         OUString sLocalName;
      61           0 :         OUString sAttrName = _xAttrList->getNameByIndex( i );
      62           0 :         sal_uInt16 nPrefix = rMap.GetKeyByAttrName( sAttrName,&sLocalName );
      63           0 :         OUString sValue = _xAttrList->getValueByIndex( i );
      64             : 
      65           0 :         switch( rTokenMap.Get( nPrefix, sLocalName ) )
      66             :         {
      67             :             case XML_TOK_COMPONENT_NAME:
      68           0 :                 m_sName = sValue;
      69           0 :                 break;
      70             :         }
      71           0 :     }
      72           0 :     if ( !m_sName.isEmpty() && _xParentContainer.is() )
      73             :     {
      74             :         try
      75             :         {
      76           0 :             Sequence< Any > aArguments(2);
      77           0 :             PropertyValue aValue;
      78             :             // set as folder
      79           0 :             aValue.Name = "Name";
      80           0 :             aValue.Value <<= m_sName;
      81           0 :             aArguments[0] <<= aValue;
      82             :             //parent
      83           0 :             aValue.Name = "Parent";
      84           0 :             aValue.Value <<= _xParentContainer;
      85           0 :             aArguments[1] <<= aValue;
      86             : 
      87           0 :             Reference<XMultiServiceFactory> xORB(_xParentContainer,UNO_QUERY);
      88           0 :             if ( xORB.is() )
      89             :             {
      90           0 :                 m_xContainer.set(xORB->createInstanceWithArguments(_sCollectionServiceName,aArguments),UNO_QUERY);
      91           0 :                 Reference<XNameContainer> xNameContainer(_xParentContainer,UNO_QUERY);
      92           0 :                 if ( xNameContainer.is() && !xNameContainer->hasByName(m_sName) )
      93           0 :                     xNameContainer->insertByName(m_sName,makeAny(m_xContainer));
      94           0 :             }
      95             :         }
      96           0 :         catch(Exception&)
      97             :         {
      98             :             OSL_FAIL("OXMLHierarchyCollection::OXMLHierarchyCollection -> exception catched");
      99             :         }
     100             :     }
     101           0 : }
     102             : 
     103           8 : OXMLHierarchyCollection::OXMLHierarchyCollection( ODBFilter& rImport
     104             :                 ,sal_uInt16 nPrfx
     105             :                 ,const OUString& _sLocalName
     106             :                 ,const Reference< XNameAccess >& _xContainer
     107             :                 ,const Reference< XPropertySet >& _xTable
     108             :             ) :
     109             :     SvXMLImportContext( rImport, nPrfx, _sLocalName )
     110             :     ,m_xContainer(_xContainer)
     111           8 :     ,m_xTable(_xTable)
     112             : {
     113           8 : }
     114             : 
     115          16 : OXMLHierarchyCollection::~OXMLHierarchyCollection()
     116             : {
     117             : 
     118          16 : }
     119             : 
     120         213 : SvXMLImportContext* OXMLHierarchyCollection::CreateChildContext(
     121             :         sal_uInt16 nPrefix,
     122             :         const OUString& rLocalName,
     123             :         const Reference< XAttributeList > & xAttrList )
     124             : {
     125         213 :     SvXMLImportContext *pContext = 0;
     126         213 :     const SvXMLTokenMap&    rTokenMap   = GetOwnImport().GetDocumentsElemTokenMap();
     127             : 
     128         213 :     switch( rTokenMap.Get( nPrefix, rLocalName ) )
     129             :     {
     130             :         case XML_TOK_COMPONENT:
     131           0 :             GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
     132           0 :             pContext = new OXMLComponent( GetOwnImport(), nPrefix, rLocalName,xAttrList,m_xContainer,m_sComponentServiceName );
     133           0 :             break;
     134             :         case XML_TOK_COLUMN:
     135         213 :             GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
     136         213 :             pContext = new OXMLColumn( GetOwnImport(), nPrefix, rLocalName,xAttrList,m_xContainer,m_xTable);
     137         213 :             break;
     138             :         case XML_TOK_COMPONENT_COLLECTION:
     139           0 :             GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
     140           0 :             pContext = new OXMLHierarchyCollection( GetOwnImport(), nPrefix, rLocalName,xAttrList,m_xContainer,m_sCollectionServiceName,m_sComponentServiceName);
     141           0 :             break;
     142             :     }
     143             : 
     144         213 :     if( !pContext )
     145           0 :         pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
     146             : 
     147         213 :     return pContext;
     148             : }
     149             : 
     150         639 : ODBFilter& OXMLHierarchyCollection::GetOwnImport()
     151             : {
     152         639 :     return static_cast<ODBFilter&>(GetImport());
     153             : }
     154             : 
     155             : } // namespace dbaxml
     156             : 
     157             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11