LCOV - code coverage report
Current view: top level - xmloff/source/draw - XMLReplacementImageContext.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 45 47 95.7 %
Date: 2014-11-03 Functions: 5 10 50.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         102 : 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         102 :     m_sGraphicURL("GraphicURL")
      44             : {
      45             :     rtl::Reference < XMLTextImportHelper > xTxtImport =
      46         102 :         GetImport().GetTextImport();
      47             :     const SvXMLTokenMap& rTokenMap =
      48         102 :         xTxtImport->GetTextFrameAttrTokenMap();
      49             : 
      50         102 :     sal_Int16 nAttrCount = rAttrList.is() ? rAttrList->getLength() : 0;
      51         502 :     for( sal_Int16 i=0; i < nAttrCount; i++ )
      52             :     {
      53         400 :         const OUString& rAttrName = rAttrList->getNameByIndex( i );
      54         800 :         const OUString& rValue = rAttrList->getValueByIndex( i );
      55             : 
      56         800 :         OUString aLocalName;
      57             :         sal_uInt16 nPrefix =
      58         400 :             GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName,
      59         400 :                                                             &aLocalName );
      60         400 :         switch( rTokenMap.Get( nPrefix, aLocalName ) )
      61             :         {
      62             :         case XML_TOK_TEXT_FRAME_HREF:
      63         100 :             m_sHRef = rValue;
      64         100 :             break;
      65             :         }
      66         502 :     }
      67         102 : }
      68             : 
      69         204 : XMLReplacementImageContext::~XMLReplacementImageContext()
      70             : {
      71         204 : }
      72             : 
      73         102 : void XMLReplacementImageContext::EndElement()
      74             : {
      75             :     OSL_ENSURE( !m_sHRef.isEmpty() || m_xBase64Stream.is(),
      76             :                 "neither URL nor base64 image data given" );
      77             :     rtl::Reference < XMLTextImportHelper > xTxtImport =
      78         102 :         GetImport().GetTextImport();
      79         204 :     OUString sHRef;
      80         102 :     if( !m_sHRef.isEmpty() )
      81             :     {
      82         200 :         bool bForceLoad = xTxtImport->IsInsertMode() ||
      83         200 :                               xTxtImport->IsBlockMode() ||
      84         300 :                               xTxtImport->IsStylesOnlyMode() ||
      85         200 :                               xTxtImport->IsOrganizerMode();
      86         100 :         sHRef = GetImport().ResolveGraphicObjectURL( m_sHRef, !bForceLoad );
      87             :     }
      88           2 :     else if( m_xBase64Stream.is() )
      89             :     {
      90           2 :         sHRef = GetImport().ResolveGraphicObjectURLFromBase64( m_xBase64Stream );
      91           2 :         m_xBase64Stream = 0;
      92             :     }
      93             : 
      94             :     Reference < XPropertySetInfo > xPropSetInfo =
      95         204 :         m_xPropSet->getPropertySetInfo();
      96         102 :     if( xPropSetInfo->hasPropertyByName( m_sGraphicURL ) )
      97         122 :         m_xPropSet->setPropertyValue( m_sGraphicURL, makeAny( sHRef ) );
      98         102 : }
      99             : 
     100           2 : SvXMLImportContext *XMLReplacementImageContext::CreateChildContext(
     101             :         sal_uInt16 nPrefix,
     102             :         const OUString& rLocalName,
     103             :         const Reference< XAttributeList > & xAttrList )
     104             : {
     105           2 :     SvXMLImportContext *pContext = 0;
     106             : 
     107           4 :     if( XML_NAMESPACE_OFFICE == nPrefix &&
     108           4 :         IsXMLToken( rLocalName, ::xmloff::token::XML_BINARY_DATA ) &&
     109           2 :         !m_xBase64Stream.is() )
     110             :     {
     111           2 :         m_xBase64Stream = GetImport().GetStreamForGraphicObjectURLFromBase64();
     112           2 :         if( m_xBase64Stream.is() )
     113           2 :             pContext = new XMLBase64ImportContext( GetImport(), nPrefix,
     114             :                                                     rLocalName, xAttrList,
     115           2 :                                                     m_xBase64Stream );
     116             :     }
     117             : 
     118           2 :     if( !pContext )
     119           0 :         pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
     120             : 
     121           2 :     return pContext;
     122             : }
     123             : 
     124             : 
     125             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10