LCOV - code coverage report
Current view: top level - libreoffice/xmloff/source/draw - XMLReplacementImageContext.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 31 47 66.0 %
Date: 2012-12-27 Functions: 4 10 40.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 <com/sun/star/beans/XPropertySet.hpp>
      21             : #include <com/sun/star/io/XOutputStream.hpp>
      22             : #include <xmloff/xmlimp.hxx>
      23             : #include <xmloff/xmltoken.hxx>
      24             : #include "xmloff/xmlnmspe.hxx"
      25             : #include <xmloff/nmspmap.hxx>
      26             : #include <xmloff/XMLBase64ImportContext.hxx>
      27             : #include "XMLReplacementImageContext.hxx"
      28             : 
      29             : using ::rtl::OUString;
      30             : using ::com::sun::star::uno::Reference;
      31             : using ::com::sun::star::uno::makeAny;
      32             : using namespace ::com::sun::star::xml::sax;
      33             : using namespace ::com::sun::star::beans;
      34             : 
      35           0 : TYPEINIT1( XMLReplacementImageContext, SvXMLImportContext );
      36             : 
      37           5 : XMLReplacementImageContext::XMLReplacementImageContext(
      38             :         SvXMLImport& rImport,
      39             :         sal_uInt16 nPrfx, const OUString& rLName,
      40             :         const Reference< XAttributeList > & rAttrList,
      41             :         const Reference< XPropertySet > & rPropSet ) :
      42             :     SvXMLImportContext( rImport, nPrfx, rLName ),
      43             :     m_xPropSet( rPropSet ),
      44           5 :     m_sGraphicURL(RTL_CONSTASCII_USTRINGPARAM("GraphicURL"))
      45             : {
      46             :     UniReference < XMLTextImportHelper > xTxtImport =
      47           5 :         GetImport().GetTextImport();
      48             :     const SvXMLTokenMap& rTokenMap =
      49           5 :         xTxtImport->GetTextFrameAttrTokenMap();
      50             : 
      51           5 :     sal_Int16 nAttrCount = rAttrList.is() ? rAttrList->getLength() : 0;
      52          25 :     for( sal_Int16 i=0; i < nAttrCount; i++ )
      53             :     {
      54          20 :         const OUString& rAttrName = rAttrList->getNameByIndex( i );
      55          20 :         const OUString& rValue = rAttrList->getValueByIndex( i );
      56             : 
      57          20 :         OUString aLocalName;
      58             :         sal_uInt16 nPrefix =
      59          20 :             GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName,
      60          20 :                                                             &aLocalName );
      61          20 :         switch( rTokenMap.Get( nPrefix, aLocalName ) )
      62             :         {
      63             :         case XML_TOK_TEXT_FRAME_HREF:
      64           5 :             m_sHRef = rValue;
      65           5 :             break;
      66             :         }
      67          25 :     }
      68           5 : }
      69             : 
      70          10 : XMLReplacementImageContext::~XMLReplacementImageContext()
      71             : {
      72          10 : }
      73             : 
      74           5 : void XMLReplacementImageContext::EndElement()
      75             : {
      76             :     OSL_ENSURE( !m_sHRef.isEmpty() || m_xBase64Stream.is(),
      77             :                 "neither URL nor base64 image data given" );
      78             :     UniReference < XMLTextImportHelper > xTxtImport =
      79           5 :         GetImport().GetTextImport();
      80           5 :     OUString sHRef;
      81           5 :     if( !m_sHRef.isEmpty() )
      82             :     {
      83           5 :         sal_Bool bForceLoad = xTxtImport->IsInsertMode() ||
      84           5 :                               xTxtImport->IsBlockMode() ||
      85           5 :                               xTxtImport->IsStylesOnlyMode() ||
      86          15 :                               xTxtImport->IsOrganizerMode();
      87           5 :         sHRef = GetImport().ResolveGraphicObjectURL( m_sHRef, !bForceLoad );
      88             :     }
      89           0 :     else if( m_xBase64Stream.is() )
      90             :     {
      91           0 :         sHRef = GetImport().ResolveGraphicObjectURLFromBase64( m_xBase64Stream );
      92           0 :         m_xBase64Stream = 0;
      93             :     }
      94             : 
      95             :     Reference < XPropertySetInfo > xPropSetInfo =
      96           5 :         m_xPropSet->getPropertySetInfo();
      97           5 :     if( xPropSetInfo->hasPropertyByName( m_sGraphicURL ) )
      98           1 :         m_xPropSet->setPropertyValue( m_sGraphicURL, makeAny( sHRef ) );
      99           5 : }
     100             : 
     101           0 : SvXMLImportContext *XMLReplacementImageContext::CreateChildContext(
     102             :         sal_uInt16 nPrefix,
     103             :         const OUString& rLocalName,
     104             :         const Reference< XAttributeList > & xAttrList )
     105             : {
     106           0 :     SvXMLImportContext *pContext = 0;
     107             : 
     108           0 :     if( XML_NAMESPACE_OFFICE == nPrefix &&
     109           0 :         IsXMLToken( rLocalName, ::xmloff::token::XML_BINARY_DATA ) &&
     110           0 :         !m_xBase64Stream.is() )
     111             :     {
     112           0 :         m_xBase64Stream = GetImport().GetStreamForGraphicObjectURLFromBase64();
     113           0 :         if( m_xBase64Stream.is() )
     114           0 :             pContext = new XMLBase64ImportContext( GetImport(), nPrefix,
     115             :                                                     rLocalName, xAttrList,
     116           0 :                                                     m_xBase64Stream );
     117             :     }
     118             : 
     119           0 :     if( !pContext )
     120           0 :         pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
     121             : 
     122           0 :     return pContext;
     123             : }
     124             : 
     125             : 
     126             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10