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

Generated by: LCOV version 1.10