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

Generated by: LCOV version 1.10