LCOV - code coverage report
Current view: top level - dbaccess/source/filter/xml - xmlComponent.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 41 42 97.6 %
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 "xmlComponent.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 <com/sun/star/beans/PropertyValue.hpp>
      28             : #include <com/sun/star/container/XNameContainer.hpp>
      29             : #include <tools/debug.hxx>
      30             : #include <tools/diagnose_ex.h>
      31             : 
      32             : namespace dbaxml
      33             : {
      34             :     using namespace ::com::sun::star::uno;
      35             :     using namespace ::com::sun::star::beans;
      36             :     using namespace ::com::sun::star::container;
      37             :     using namespace ::com::sun::star::xml::sax;
      38             : 
      39           8 : OXMLComponent::OXMLComponent( ODBFilter& rImport
      40             :                 ,sal_uInt16 nPrfx
      41             :                 ,const OUString& _sLocalName
      42             :                 ,const Reference< XAttributeList > & _xAttrList
      43             :                 ,const Reference< XNameAccess >& _xParentContainer
      44             :                 ,const OUString& _sComponentServiceName
      45             :                 ) :
      46             :     SvXMLImportContext( rImport, nPrfx, _sLocalName )
      47           8 :     ,m_bAsTemplate(false)
      48             : {
      49             : 
      50             :     OSL_ENSURE(_xAttrList.is(),"Attribute list is NULL!");
      51           8 :     const SvXMLNamespaceMap& rMap = rImport.GetNamespaceMap();
      52           8 :     const SvXMLTokenMap& rTokenMap = rImport.GetComponentElemTokenMap();
      53             : 
      54           8 :     sal_Int16 nLength = (_xAttrList.is()) ? _xAttrList->getLength() : 0;
      55           8 :     static const OUString s_sTRUE = ::xmloff::token::GetXMLToken(XML_TRUE);
      56          32 :     for(sal_Int16 i = 0; i < nLength; ++i)
      57             :     {
      58          24 :         OUString sLocalName;
      59          48 :         OUString sAttrName = _xAttrList->getNameByIndex( i );
      60          24 :         sal_uInt16 nPrefix = rMap.GetKeyByAttrName( sAttrName,&sLocalName );
      61          48 :         OUString sValue = _xAttrList->getValueByIndex( i );
      62             : 
      63          24 :         switch( rTokenMap.Get( nPrefix, sLocalName ) )
      64             :         {
      65             :             case XML_TOK_HREF:
      66           8 :                 m_sHREF = sValue;
      67           8 :                 break;
      68             :             case XML_TOK_COMPONENT_NAME:
      69           8 :                 m_sName = sValue;
      70             :                 // sanitize the name. Previously, we allowed to create forms/reports/queries which contain
      71             :                 // a / in their name, which nowadays is forbidden. To not lose such objects if they're contained
      72             :                 // in older files, we replace the slash with something less offending.
      73           8 :                 m_sName = m_sName.replace( '/', '_' );
      74           8 :                 break;
      75             :             case XML_TOK_AS_TEMPLATE:
      76           8 :                 m_bAsTemplate = sValue == s_sTRUE;
      77           8 :                 break;
      78             :         }
      79          24 :     }
      80           8 :     if ( !m_sHREF.isEmpty() && !m_sName.isEmpty() && _xParentContainer.is() )
      81             :     {
      82           8 :         Sequence< Any > aArguments(3);
      83          16 :         PropertyValue aValue;
      84             :         // set as folder
      85           8 :         aValue.Name = PROPERTY_NAME;
      86           8 :         aValue.Value <<= m_sName;
      87           8 :         aArguments[0] <<= aValue;
      88             : 
      89           8 :         aValue.Name = PROPERTY_PERSISTENT_NAME;
      90           8 :         sal_Int32 nIndex = m_sHREF.lastIndexOf('/')+1;
      91           8 :         aValue.Value <<= m_sHREF.getToken(0,'/',nIndex);
      92           8 :         aArguments[1] <<= aValue;
      93             : 
      94           8 :         aValue.Name = PROPERTY_AS_TEMPLATE;
      95           8 :         aValue.Value <<= m_bAsTemplate;
      96           8 :         aArguments[2] <<= aValue;
      97             : 
      98             :         try
      99             :         {
     100           8 :             Reference< XMultiServiceFactory > xORB( _xParentContainer, UNO_QUERY_THROW );
     101          16 :             Reference< XInterface > xComponent( xORB->createInstanceWithArguments( _sComponentServiceName, aArguments ) );
     102          16 :             Reference< XNameContainer > xNameContainer( _xParentContainer, UNO_QUERY_THROW );
     103          16 :             xNameContainer->insertByName( m_sName, makeAny( xComponent ) );
     104             :         }
     105           0 :         catch(Exception&)
     106             :         {
     107             :             DBG_UNHANDLED_EXCEPTION();
     108           8 :         }
     109             :     }
     110           8 : }
     111             : 
     112          16 : OXMLComponent::~OXMLComponent()
     113             : {
     114             : 
     115          16 : }
     116             : 
     117             : } // namespace dbaxml
     118             : 
     119             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11