LCOV - code coverage report
Current view: top level - xmloff/source/chart - XMLSymbolImageContext.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 29 44 65.9 %
Date: 2014-11-03 Functions: 5 11 45.5 %
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 "XMLSymbolImageContext.hxx"
      21             : #include <xmloff/xmltoken.hxx>
      22             : #include <xmloff/xmltkmap.hxx>
      23             : #include <xmloff/xmlnmspe.hxx>
      24             : #include <xmloff/xmlimp.hxx>
      25             : #include <xmloff/nmspmap.hxx>
      26             : #include <xmloff/XMLBase64ImportContext.hxx>
      27             : #include <com/sun/star/io/XOutputStream.hpp>
      28             : 
      29           0 : TYPEINIT1( XMLSymbolImageContext, XMLElementPropertyContext );
      30             : 
      31             : using namespace ::com::sun::star;
      32             : 
      33             : enum SvXMLTokenMapAttrs
      34             : {
      35             :     XML_TOK_SYMBOL_IMAGE_HREF,
      36             :     XML_TOK_SYMBOL_IMAGE_TYPE,
      37             :     XML_TOK_SYMBOL_IMAGE_ACTUATE,
      38             :     XML_TOK_SYMBOL_IMAGE_SHOW,
      39             :     XML_TOK_SYMBOL_IMAGE_END = XML_TOK_UNKNOWN
      40             : };
      41             : 
      42             : static const SvXMLTokenMapEntry aSymbolImageAttrTokenMap[] =
      43             : {
      44             :     { XML_NAMESPACE_XLINK,  ::xmloff::token::XML_HREF,     XML_TOK_SYMBOL_IMAGE_HREF    },
      45             :     { XML_NAMESPACE_XLINK,  ::xmloff::token::XML_TYPE,     XML_TOK_SYMBOL_IMAGE_TYPE    },
      46             :     { XML_NAMESPACE_XLINK,  ::xmloff::token::XML_ACTUATE,  XML_TOK_SYMBOL_IMAGE_ACTUATE },
      47             :     { XML_NAMESPACE_XLINK,  ::xmloff::token::XML_SHOW,     XML_TOK_SYMBOL_IMAGE_SHOW },
      48             :     XML_TOKEN_MAP_END
      49             : };
      50             : 
      51          16 : XMLSymbolImageContext::XMLSymbolImageContext(
      52             :     SvXMLImport& rImport, sal_uInt16 nPrfx,
      53             :     const OUString& rLName,
      54             :     const XMLPropertyState& rProp,
      55             :     ::std::vector< XMLPropertyState > &rProps ) :
      56             :         XMLElementPropertyContext(
      57          16 :             rImport, nPrfx, rLName, rProp, rProps )
      58             : {
      59          16 : }
      60             : 
      61          32 : XMLSymbolImageContext::~XMLSymbolImageContext()
      62          32 : {}
      63             : 
      64          16 : void XMLSymbolImageContext::StartElement( const uno::Reference< xml::sax::XAttributeList >& xAttrList )
      65             : {
      66          16 :     SvXMLTokenMap aTokenMap( aSymbolImageAttrTokenMap );
      67          32 :     OUString aLocalName;
      68             : 
      69          16 :     sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
      70          64 :     for( sal_Int16 i = 0; i < nAttrCount; i++ )
      71             :     {
      72          48 :         const OUString& rAttrName = xAttrList->getNameByIndex( i );
      73             :         sal_uInt16 nPrefix =
      74          48 :             GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName,
      75          48 :                                                             &aLocalName );
      76          96 :         const OUString& rValue = xAttrList->getValueByIndex( i );
      77             : 
      78          48 :         switch( aTokenMap.Get( nPrefix, aLocalName ) )
      79             :         {
      80             :             case XML_TOK_SYMBOL_IMAGE_HREF:
      81          16 :                 msURL = rValue;
      82          16 :                 break;
      83             :             case XML_TOK_SYMBOL_IMAGE_ACTUATE:
      84             :             case XML_TOK_SYMBOL_IMAGE_TYPE:
      85             :             case XML_TOK_SYMBOL_IMAGE_SHOW:
      86             :                 // these values are currently not interpreted
      87             :                 // it is always assumed 'actuate=onLoad', 'type=simple', 'show=embed'
      88          32 :                 break;
      89             :         }
      90          64 :     }
      91          16 : }
      92             : 
      93           0 : SvXMLImportContext* XMLSymbolImageContext::CreateChildContext(
      94             :     sal_uInt16 nPrefix, const OUString& rLocalName,
      95             :     const uno::Reference< xml::sax::XAttributeList > & xAttrList )
      96             : {
      97           0 :     SvXMLImportContext* pContext = NULL;
      98           0 :     if( xmloff::token::IsXMLToken( rLocalName,
      99             :                                    xmloff::token::XML_BINARY_DATA ) )
     100             :     {
     101           0 :         if( msURL.isEmpty() && ! mxBase64Stream.is() )
     102             :         {
     103           0 :             mxBase64Stream = GetImport().GetStreamForGraphicObjectURLFromBase64();
     104           0 :             if( mxBase64Stream.is() )
     105           0 :                 pContext = new XMLBase64ImportContext( GetImport(), nPrefix,
     106             :                                                        rLocalName, xAttrList,
     107           0 :                                                        mxBase64Stream );
     108             :         }
     109             :     }
     110           0 :     if( ! pContext )
     111             :     {
     112           0 :         pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
     113             :     }
     114             : 
     115           0 :     return pContext;
     116             : }
     117             : 
     118          16 : void XMLSymbolImageContext::EndElement()
     119             : {
     120          16 :     OUString sResolvedURL;
     121             : 
     122          16 :     if( !msURL.isEmpty() )
     123             :     {
     124          16 :         sResolvedURL = GetImport().ResolveGraphicObjectURL( msURL, false );
     125             :     }
     126           0 :     else if( mxBase64Stream.is() )
     127             :     {
     128           0 :         sResolvedURL = GetImport().ResolveGraphicObjectURLFromBase64( mxBase64Stream );
     129           0 :         mxBase64Stream = 0;
     130             :     }
     131             : 
     132          16 :     if( !sResolvedURL.isEmpty())
     133             :     {
     134             :         // aProp is a member of XMLElementPropertyContext
     135          16 :         aProp.maValue <<= sResolvedURL;
     136          16 :         SetInsert( true );
     137             :     }
     138             : 
     139          16 :     XMLElementPropertyContext::EndElement();
     140          16 : }
     141             : 
     142             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10