LCOV - code coverage report
Current view: top level - oox/source/drawingml - hyperlinkcontext.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 32 67 47.8 %
Date: 2015-06-13 12:38:46 Functions: 5 6 83.3 %
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 "hyperlinkcontext.hxx"
      21             : 
      22             : #include <com/sun/star/xml/sax/XFastContextHandler.hpp>
      23             : 
      24             : #include <osl/diagnose.h>
      25             : #include "oox/helper/propertymap.hxx"
      26             : #include "oox/core/relations.hxx"
      27             : #include "oox/core/xmlfilterbase.hxx"
      28             : #include "drawingml/embeddedwavaudiofile.hxx"
      29             : 
      30             : using namespace ::oox::core;
      31             : using namespace ::com::sun::star::uno;
      32             : using namespace ::com::sun::star::xml::sax;
      33             : 
      34             : namespace oox {
      35             : namespace drawingml {
      36             : 
      37           5 : HyperLinkContext::HyperLinkContext( ContextHandler2Helper& rParent,
      38             :         const AttributeList& rAttribs, PropertyMap& aProperties )
      39             :     : ContextHandler2( rParent )
      40           5 :     , maProperties(aProperties)
      41             : {
      42          10 :     OUString sURL, sHref;
      43          10 :     OUString aRelId = rAttribs.getString( R_TOKEN( id ) ).get();
      44           5 :     if ( !aRelId.isEmpty() )
      45             :     {
      46             :         OSL_TRACE("OOX: URI rId %s", OUStringToOString (aRelId, RTL_TEXTENCODING_UTF8).pData->buffer);
      47           3 :         sHref = getRelations().getExternalTargetFromRelId( aRelId );
      48           3 :         if( !sHref.isEmpty() )
      49             :         {
      50             :             OSL_TRACE("OOX: URI href %s", OUStringToOString (sHref, RTL_TEXTENCODING_UTF8).pData->buffer);
      51           1 :             sURL = getFilter().getAbsoluteUrl( sHref );
      52             :         }
      53             :         else
      54             :         {
      55             :             // not sure if we also need to set sHref to the internal target
      56           2 :             sURL = getRelations().getInternalTargetFromRelId( aRelId );
      57             :         }
      58             :     }
      59          10 :     OUString sTooltip = rAttribs.getString( R_TOKEN( tooltip ) ).get();
      60           5 :     if ( !sTooltip.isEmpty() )
      61           0 :         maProperties.setProperty(PROP_Representation, sTooltip);
      62          10 :     OUString sFrame = rAttribs.getString( R_TOKEN( tgtFrame ) ).get();
      63           5 :     if( !sFrame.isEmpty() )
      64           0 :         maProperties.setProperty(PROP_TargetFrame, sFrame);
      65          10 :     OUString aAction = rAttribs.getString( XML_action ).get();
      66           5 :     if ( !aAction.isEmpty() )
      67             :     {
      68             :         // reserved values of the unrestricted string aAction:
      69             :         // ppaction://customshow?id=SHOW_ID             // custom presentation
      70             :         // ppaction://hlinkfile                         // external file via r:id
      71             :         // ppaction://hlinkpres?slideindex=SLIDE_NUM    // external presentation via r:id
      72             :         // ppaction://hlinkshowjump?jump=endshow
      73             :         // ppaction://hlinkshowjump?jump=firstslide
      74             :         // ppaction://hlinkshowjump?jump=lastslide
      75             :         // ppaction://hlinkshowjump?jump=lastslideviewed
      76             :         // ppaction://hlinkshowjump?jump=nextslide
      77             :         // ppaction://hlinkshowjump?jump=previousslide
      78             :         // ppaction://hlinksldjump
      79             :         // ppaction://macro?name=MACRO_NAME
      80             :         // ppaction://program
      81             : 
      82           2 :         const OUString sPPAction( "ppaction://" );
      83           2 :         if ( aAction.matchIgnoreAsciiCase( sPPAction, 0 ) )
      84             :         {
      85           2 :             OUString aPPAct( aAction.copy( sPPAction.getLength() ) );
      86           2 :             sal_Int32 nIndex = aPPAct.indexOf( '?', 0 );
      87           4 :             OUString aPPAction( nIndex > 0 ? aPPAct.copy( 0, nIndex ) : aPPAct );
      88             : 
      89           4 :             const OUString sHlinkshowjump( "hlinkshowjump" );
      90           4 :             const OUString sHlinksldjump( "hlinksldjump" );
      91           2 :             if ( aPPAction.match( sHlinkshowjump ) )
      92             :             {
      93           0 :                 const OUString sJump( "jump=" );
      94           0 :                 if ( aPPAct.match( sJump, nIndex + 1 ) )
      95             :                 {
      96           0 :                     OUString aDestination( aPPAct.copy( nIndex + 1 + sJump.getLength() ) );
      97           0 :                     sURL = sURL.concat( "#action?jump=" );
      98           0 :                     sURL = sURL.concat( aDestination );
      99           0 :                 }
     100             :             }
     101           2 :             else if ( aPPAction.match( sHlinksldjump ) )
     102             :             {
     103           0 :                 sURL.clear();
     104             : 
     105           0 :                 sal_Int32 nIndex2 = 0;
     106           0 :                 while ( nIndex2 < sHref.getLength() )
     107             :                 {
     108           0 :                     sal_Unicode nChar = sHref[ nIndex2 ];
     109           0 :                     if ( ( nChar >= '0' ) && ( nChar <= '9' ) )
     110           0 :                         break;
     111           0 :                     nIndex2++;
     112             :                 }
     113           0 :                 if ( nIndex2 && ( nIndex2 != sHref.getLength() ) )
     114             :                 {
     115           0 :                     sal_Int32 nLength = 1;
     116           0 :                     while( ( nIndex2 + nLength ) < sHref.getLength() )
     117             :                     {
     118           0 :                         sal_Unicode nChar = sHref[ nIndex2 + nLength ];
     119           0 :                         if ( ( nChar < '0' ) || ( nChar > '9' ) )
     120             :                             break;
     121           0 :                         nLength++;
     122             :                     }
     123           0 :                     sal_Int32 nPageNumber = sHref.copy( nIndex2, nLength ).toInt32();
     124           0 :                     if ( nPageNumber )
     125             :                     {
     126           0 :                         const OUString sSlide( "slide" );
     127           0 :                         const OUString sNotesSlide( "notesSlide" );
     128           0 :                         const OUString aSlideType( sHref.copy( 0, nIndex2 ) );
     129           0 :                         if ( aSlideType.match( sSlide ) )
     130           0 :                             sURL = "#Slide " + OUString::number( nPageNumber );
     131           0 :                         else if ( aSlideType.match( sNotesSlide ) )
     132           0 :                             sURL = "#Notes " + OUString::number( nPageNumber );
     133             : //                      else: todo for other types such as notesMaster or slideMaster as they can't be referenced easily
     134             :                     }
     135             :                 }
     136           2 :             }
     137           2 :         }
     138             :     }
     139           5 :     if ( !sURL.isEmpty() )
     140           8 :         maProperties.setProperty(PROP_URL, sURL);
     141             : 
     142             :     // TODO unhandled
     143             :     // XML_invalidUrl
     144             :     // XML_history
     145             :     // XML_highlightClick
     146             :     // XML_endSnd
     147           5 : }
     148             : 
     149          10 : HyperLinkContext::~HyperLinkContext()
     150             : {
     151          10 : }
     152             : 
     153           0 : ContextHandlerRef HyperLinkContext::onCreateContext(
     154             :         ::sal_Int32 aElement, const AttributeList&  )
     155             : {
     156           0 :     switch( aElement )
     157             :     {
     158             :     case A_TOKEN( extLst ):
     159           0 :         return 0;
     160             :     case A_TOKEN( snd ):
     161             :         // TODO use getEmbeddedWAVAudioFile() here
     162           0 :         break;
     163             :     }
     164             : 
     165           0 :     return this;
     166             : }
     167             : 
     168             : } // namespace drawingml
     169         246 : } // namespace oox
     170             : 
     171             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11