LCOV - code coverage report
Current view: top level - xmloff/source/script - xmlbasici.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 32 66 48.5 %
Date: 2014-11-03 Functions: 5 14 35.7 %
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 "xmlbasici.hxx"
      21             : #include <xmloff/attrlist.hxx>
      22             : #include <xmloff/nmspmap.hxx>
      23             : #include <xmloff/xmlimp.hxx>
      24             : #include <com/sun/star/document/XMLOasisBasicImporter.hpp>
      25             : #include <comphelper/processfactory.hxx>
      26             : 
      27             : using namespace ::com::sun::star;
      28             : using namespace ::com::sun::star::uno;
      29             : 
      30             : // XMLBasicImportContext
      31             : 
      32           2 : XMLBasicImportContext::XMLBasicImportContext( SvXMLImport& rImport, sal_uInt16 nPrfx, const OUString& rLName,
      33             :         const Reference< frame::XModel >& rxModel )
      34             :     :SvXMLImportContext( rImport, nPrfx, rLName )
      35           2 :     ,m_xModel( rxModel )
      36             : {
      37           2 :     Reference< uno::XComponentContext > xContext = GetImport().GetComponentContext();
      38           2 :     m_xHandler = document::XMLOasisBasicImporter::create( xContext );
      39             : 
      40           4 :     Reference< lang::XComponent > xComp( m_xModel, UNO_QUERY );
      41           4 :     m_xHandler->setTargetDocument( xComp );
      42           2 : }
      43             : 
      44           4 : XMLBasicImportContext::~XMLBasicImportContext()
      45             : {
      46           4 : }
      47             : 
      48           0 : SvXMLImportContext* XMLBasicImportContext::CreateChildContext(
      49             :     sal_uInt16 nPrefix, const OUString& rLocalName,
      50             :     const Reference< xml::sax::XAttributeList >& )
      51             : {
      52           0 :     SvXMLImportContext* pContext = 0;
      53             : 
      54           0 :     if ( m_xHandler.is() )
      55           0 :         pContext = new XMLBasicImportChildContext( GetImport(), nPrefix, rLocalName,
      56           0 :                           Reference<xml::sax::XDocumentHandler>(m_xHandler, UNO_QUERY_THROW) );
      57             : 
      58           0 :     if ( !pContext )
      59           0 :         pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
      60             : 
      61           0 :     return pContext;
      62             : }
      63             : 
      64           2 : void XMLBasicImportContext::StartElement(
      65             :     const Reference< xml::sax::XAttributeList >& rxAttrList )
      66             : {
      67           2 :     if ( m_xHandler.is() )
      68             :     {
      69           2 :         m_xHandler->startDocument();
      70             : 
      71             :         // copy namespace declarations
      72           2 :         SvXMLAttributeList* pAttrList = new SvXMLAttributeList( rxAttrList );
      73           2 :         Reference< xml::sax::XAttributeList > xAttrList( pAttrList );
      74           2 :         const SvXMLNamespaceMap& rNamespaceMap = GetImport().GetNamespaceMap();
      75           2 :         sal_uInt16 nPos = rNamespaceMap.GetFirstKey();
      76          78 :         while ( nPos != USHRT_MAX )
      77             :         {
      78          74 :             OUString aAttrName( rNamespaceMap.GetAttrNameByKey( nPos ) );
      79          74 :             if ( xAttrList->getValueByName( aAttrName ).isEmpty() )
      80          70 :                 pAttrList->AddAttribute( aAttrName, rNamespaceMap.GetNameByKey( nPos ) );
      81          74 :             nPos = rNamespaceMap.GetNextKey( nPos );
      82          74 :         }
      83             : 
      84           2 :         m_xHandler->startElement(
      85           4 :             GetImport().GetNamespaceMap().GetQNameByKey( GetPrefix(), GetLocalName() ),
      86           6 :             xAttrList );
      87             :     }
      88           2 : }
      89             : 
      90           2 : void XMLBasicImportContext::EndElement()
      91             : {
      92           2 :     if ( m_xHandler.is() )
      93             :     {
      94           2 :         m_xHandler->endElement(
      95           2 :             GetImport().GetNamespaceMap().GetQNameByKey( GetPrefix(), GetLocalName() ) );
      96           2 :         m_xHandler->endDocument();
      97             :     }
      98           2 : }
      99             : 
     100           0 : void XMLBasicImportContext::Characters( const OUString& rChars )
     101             : {
     102           0 :     if ( m_xHandler.is() )
     103           0 :         m_xHandler->characters( rChars );
     104           0 : }
     105             : 
     106             : // XMLBasicImportChildContext
     107             : 
     108           0 : XMLBasicImportChildContext::XMLBasicImportChildContext( SvXMLImport& rImport, sal_uInt16 nPrfx, const OUString& rLName,
     109             :         const Reference< xml::sax::XDocumentHandler >& rxHandler )
     110             :     :SvXMLImportContext( rImport, nPrfx, rLName )
     111           0 :     ,m_xHandler( rxHandler )
     112             : {
     113           0 : }
     114             : 
     115           0 : XMLBasicImportChildContext::~XMLBasicImportChildContext()
     116             : {
     117           0 : }
     118             : 
     119           0 : SvXMLImportContext* XMLBasicImportChildContext::CreateChildContext(
     120             :     sal_uInt16 nPrefix, const OUString& rLocalName,
     121             :     const Reference< xml::sax::XAttributeList >& )
     122             : {
     123           0 :     return new XMLBasicImportChildContext( GetImport(), nPrefix, rLocalName, m_xHandler );
     124             : }
     125             : 
     126           0 : void XMLBasicImportChildContext::StartElement(
     127             :     const Reference< xml::sax::XAttributeList >& xAttrList )
     128             : {
     129           0 :     if ( m_xHandler.is() )
     130             :     {
     131           0 :         m_xHandler->startElement(
     132           0 :             GetImport().GetNamespaceMap().GetQNameByKey( GetPrefix(), GetLocalName() ),
     133           0 :             xAttrList );
     134             :     }
     135           0 : }
     136             : 
     137           0 : void XMLBasicImportChildContext::EndElement()
     138             : {
     139           0 :     if ( m_xHandler.is() )
     140             :     {
     141           0 :         m_xHandler->endElement(
     142           0 :             GetImport().GetNamespaceMap().GetQNameByKey( GetPrefix(), GetLocalName() ) );
     143             :     }
     144           0 : }
     145             : 
     146           0 : void XMLBasicImportChildContext::Characters( const OUString& rChars )
     147             : {
     148           0 :     if ( m_xHandler.is() )
     149           0 :         m_xHandler->characters( rChars );
     150           0 : }
     151             : 
     152             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10