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

Generated by: LCOV version 1.10