LibreOffice Module oox (master)  1
hyperlinkcontext.cxx
Go to the documentation of this file.
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 
26 #include <oox/core/relations.hxx>
28 #include <oox/token/namespaces.hxx>
29 #include <oox/token/properties.hxx>
30 #include <oox/token/tokens.hxx>
31 
32 using namespace ::oox::core;
33 using namespace ::com::sun::star::uno;
34 using namespace ::com::sun::star::xml::sax;
35 
36 namespace oox::drawingml {
37 
39  const AttributeList& rAttribs, PropertyMap& aProperties )
40  : ContextHandler2( rParent )
41  , maProperties(aProperties)
42 {
43  OUString sURL, sHref;
44  OUString aRelId = rAttribs.getString( R_TOKEN( id ) ).get();
45  if ( !aRelId.isEmpty() )
46  {
47  sHref = getRelations().getExternalTargetFromRelId( aRelId );
48  if( !sHref.isEmpty() )
49  {
50  sURL = getFilter().getAbsoluteUrl( sHref );
51  }
52  else
53  {
54  // not sure if we also need to set sHref to the internal target
55  sURL = getRelations().getInternalTargetFromRelId( aRelId );
56  }
57  }
58  OUString sTooltip = rAttribs.getString( R_TOKEN( tooltip ) ).get();
59  if ( !sTooltip.isEmpty() )
60  maProperties.setProperty(PROP_Representation, sTooltip);
61  OUString sFrame = rAttribs.getString( R_TOKEN( tgtFrame ) ).get();
62  if( !sFrame.isEmpty() )
63  maProperties.setProperty(PROP_TargetFrame, sFrame);
64  OUString aAction = rAttribs.getString( XML_action ).get();
65  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  static const OUStringLiteral sPPAction( u"ppaction://" );
82  if ( aAction.matchIgnoreAsciiCase( sPPAction ) )
83  {
84  OUString aPPAct( aAction.copy( sPPAction.getLength() ) );
85  sal_Int32 nIndex = aPPAct.indexOf( '?' );
86  OUString aPPAction( nIndex > 0 ? aPPAct.copy( 0, nIndex ) : aPPAct );
87 
88  if ( aPPAction.match( "hlinkshowjump" ) )
89  {
90  static const OUStringLiteral sJump( u"jump=" );
91  if ( aPPAct.match( sJump, nIndex + 1 ) )
92  {
93  OUString aDestination( aPPAct.copy( nIndex + 1 + sJump.getLength() ) );
94  sURL += "#action?jump=" + aDestination;
95  }
96  }
97  else if ( aPPAction.match( "hlinksldjump" ) )
98  {
99  sHref = sURL;
100 
101  sal_Int32 nIndex2 = 0;
102  while ( nIndex2 < sHref.getLength() )
103  {
104  sal_Unicode nChar = sHref[ nIndex2 ];
105  if ( ( nChar >= '0' ) && ( nChar <= '9' ) )
106  break;
107  nIndex2++;
108  }
109  if ( nIndex2 && ( nIndex2 != sHref.getLength() ) )
110  {
111  sal_Int32 nLength = 1;
112  while( ( nIndex2 + nLength ) < sHref.getLength() )
113  {
114  sal_Unicode nChar = sHref[ nIndex2 + nLength ];
115  if ( ( nChar < '0' ) || ( nChar > '9' ) )
116  break;
117  nLength++;
118  }
119  sal_Int32 nPageNumber = sHref.copy( nIndex2, nLength ).toInt32();
120  if ( nPageNumber )
121  {
122  const OUString aSlideType( sHref.copy( 0, nIndex2 ) );
123  if ( aSlideType.match( "slide" ) )
124  sURL = "#Slide " + OUString::number( nPageNumber );
125  else if ( aSlideType.match( "notesSlide" ) )
126  sURL = "#Notes " + OUString::number( nPageNumber );
127 // else: todo for other types such as notesMaster or slideMaster as they can't be referenced easily
128  }
129  }
130  }
131  }
132  }
133  if ( !sURL.isEmpty() )
134  maProperties.setProperty(PROP_URL, sURL);
135 
136  // TODO unhandled
137  // XML_invalidUrl
138  // XML_history
139  // XML_highlightClick
140  // XML_endSnd
141 }
142 
144 {
145 }
146 
148  ::sal_Int32 aElement, const AttributeList& )
149 {
150  switch( aElement )
151  {
152  case A_TOKEN( extLst ):
153  maProperties.setProperty(PROP_CharColor, XML_fillcolor);
154  break;
155  case A_TOKEN( snd ):
156  // TODO use getEmbeddedWAVAudioFile() here
157  break;
158  }
159 
160  return this;
161 }
162 
163 } // namespace oox::drawingml
164 
165 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
OUString getInternalTargetFromRelId(const OUString &rRelId) const
Returns the internal target of the relation with the passed relation identifier.
Definition: relations.cxx:90
sal_Int32 nIndex
A helper that maps property identifiers to property values.
Definition: propertymap.hxx:52
virtual ::oox::core::ContextHandlerRef onCreateContext(::sal_Int32 Element, const ::oox::AttributeList &rAttribs) override
constexpr OUStringLiteral sFrame
OUString getExternalTargetFromRelId(const OUString &rRelId) const
Returns the external target of the relation with the passed relation identifier.
Definition: relations.cxx:84
bool setProperty(sal_Int32 nPropId, Type &&rValue)
Sets the specified property to the passed value.
Definition: propertymap.hxx:70
OptValue< OUString > getString(sal_Int32 nAttrToken) const
Returns the string value of the specified attribute.
sal_uInt16 sal_Unicode
const Type & get() const
Definition: helper.hxx:185
SvGenericNameContainerMapImpl maProperties
const Relations & getRelations() const
Returns the relations of the current fragment.
float u
Provides access to attribute values of an element.
XmlFilterBase & getFilter() const
Returns the filter instance.
HyperLinkContext(::oox::core::ContextHandler2Helper const &rParent, const ::oox::AttributeList &rAttribs, PropertyMap &aProperties)
OUString getAbsoluteUrl(const OUString &rUrl) const
Returns an absolute URL for the passed relative or absolute URL.
Definition: filterbase.cxx:265
sal_Int32 nLength
Helper class that provides a context stack.