LCOV - code coverage report
Current view: top level - xmloff/source/script - xmlbasici.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 32 66 48.5 %
Date: 2015-06-13 12:38:46 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           1 : XMLBasicImportContext::XMLBasicImportContext( SvXMLImport& rImport, sal_uInt16 nPrfx, const OUString& rLName,
      33             :         const Reference< frame::XModel >& rxModel )
      34             :     :SvXMLImportContext( rImport, nPrfx, rLName )
      35           1 :     ,m_xModel( rxModel )
      36             : {
      37           1 :     Reference< uno::XComponentContext > xContext = GetImport().GetComponentContext();
      38           1 :     m_xHandler = document::XMLOasisBasicImporter::create( xContext );
      39             : 
      40           2 :     Reference< lang::XComponent > xComp( m_xModel, UNO_QUERY );
      41           2 :     m_xHandler->setTargetDocument( xComp );
      42           1 : }
      43             : 
      44           2 : XMLBasicImportContext::~XMLBasicImportContext()
      45             : {
      46           2 : }
      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           1 : void XMLBasicImportContext::StartElement(
      65             :     const Reference< xml::sax::XAttributeList >& rxAttrList )
      66             : {
      67           1 :     if ( m_xHandler.is() )
      68             :     {
      69           1 :         m_xHandler->startDocument();
      70             : 
      71             :         // copy namespace declarations
      72           1 :         SvXMLAttributeList* pAttrList = new SvXMLAttributeList( rxAttrList );
      73           1 :         Reference< xml::sax::XAttributeList > xAttrList( pAttrList );
      74           1 :         const SvXMLNamespaceMap& rNamespaceMap = GetImport().GetNamespaceMap();
      75           1 :         sal_uInt16 nPos = rNamespaceMap.GetFirstKey();
      76          39 :         while ( nPos != USHRT_MAX )
      77             :         {
      78          37 :             OUString aAttrName( rNamespaceMap.GetAttrNameByKey( nPos ) );
      79          37 :             if ( xAttrList->getValueByName( aAttrName ).isEmpty() )
      80          35 :                 pAttrList->AddAttribute( aAttrName, rNamespaceMap.GetNameByKey( nPos ) );
      81          37 :             nPos = rNamespaceMap.GetNextKey( nPos );
      82          37 :         }
      83             : 
      84           1 :         m_xHandler->startElement(
      85           2 :             GetImport().GetNamespaceMap().GetQNameByKey( GetPrefix(), GetLocalName() ),
      86           3 :             xAttrList );
      87             :     }
      88           1 : }
      89             : 
      90           1 : void XMLBasicImportContext::EndElement()
      91             : {
      92           1 :     if ( m_xHandler.is() )
      93             :     {
      94           1 :         m_xHandler->endElement(
      95           1 :             GetImport().GetNamespaceMap().GetQNameByKey( GetPrefix(), GetLocalName() ) );
      96           1 :         m_xHandler->endDocument();
      97             :     }
      98           1 : }
      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.11