1*b1cdbd2cSJim Jagielski /**************************************************************
2*b1cdbd2cSJim Jagielski *
3*b1cdbd2cSJim Jagielski * Licensed to the Apache Software Foundation (ASF) under one
4*b1cdbd2cSJim Jagielski * or more contributor license agreements. See the NOTICE file
5*b1cdbd2cSJim Jagielski * distributed with this work for additional information
6*b1cdbd2cSJim Jagielski * regarding copyright ownership. The ASF licenses this file
7*b1cdbd2cSJim Jagielski * to you under the Apache License, Version 2.0 (the
8*b1cdbd2cSJim Jagielski * "License"); you may not use this file except in compliance
9*b1cdbd2cSJim Jagielski * with the License. You may obtain a copy of the License at
10*b1cdbd2cSJim Jagielski *
11*b1cdbd2cSJim Jagielski * http://www.apache.org/licenses/LICENSE-2.0
12*b1cdbd2cSJim Jagielski *
13*b1cdbd2cSJim Jagielski * Unless required by applicable law or agreed to in writing,
14*b1cdbd2cSJim Jagielski * software distributed under the License is distributed on an
15*b1cdbd2cSJim Jagielski * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*b1cdbd2cSJim Jagielski * KIND, either express or implied. See the License for the
17*b1cdbd2cSJim Jagielski * specific language governing permissions and limitations
18*b1cdbd2cSJim Jagielski * under the License.
19*b1cdbd2cSJim Jagielski *
20*b1cdbd2cSJim Jagielski *************************************************************/
21*b1cdbd2cSJim Jagielski
22*b1cdbd2cSJim Jagielski
23*b1cdbd2cSJim Jagielski
24*b1cdbd2cSJim Jagielski #include "hyperlinkcontext.hxx"
25*b1cdbd2cSJim Jagielski
26*b1cdbd2cSJim Jagielski #include <com/sun/star/xml/sax/XFastContextHandler.hpp>
27*b1cdbd2cSJim Jagielski
28*b1cdbd2cSJim Jagielski #include "oox/helper/propertymap.hxx"
29*b1cdbd2cSJim Jagielski #include "oox/core/relations.hxx"
30*b1cdbd2cSJim Jagielski #include "oox/core/xmlfilterbase.hxx"
31*b1cdbd2cSJim Jagielski #include "oox/drawingml/embeddedwavaudiofile.hxx"
32*b1cdbd2cSJim Jagielski
33*b1cdbd2cSJim Jagielski using ::rtl::OUString;
34*b1cdbd2cSJim Jagielski using namespace ::oox::core;
35*b1cdbd2cSJim Jagielski using namespace ::com::sun::star::uno;
36*b1cdbd2cSJim Jagielski using namespace ::com::sun::star::xml::sax;
37*b1cdbd2cSJim Jagielski
38*b1cdbd2cSJim Jagielski namespace oox {
39*b1cdbd2cSJim Jagielski namespace drawingml {
40*b1cdbd2cSJim Jagielski
HyperLinkContext(ContextHandler & rParent,const Reference<XFastAttributeList> & xAttributes,PropertyMap & aProperties)41*b1cdbd2cSJim Jagielski HyperLinkContext::HyperLinkContext( ContextHandler& rParent,
42*b1cdbd2cSJim Jagielski const Reference< XFastAttributeList >& xAttributes, PropertyMap& aProperties )
43*b1cdbd2cSJim Jagielski : ContextHandler( rParent )
44*b1cdbd2cSJim Jagielski , maProperties(aProperties)
45*b1cdbd2cSJim Jagielski {
46*b1cdbd2cSJim Jagielski OUString sURL, sHref;
47*b1cdbd2cSJim Jagielski OUString aRelId = xAttributes->getOptionalValue( R_TOKEN( id ) );
48*b1cdbd2cSJim Jagielski if ( aRelId.getLength() )
49*b1cdbd2cSJim Jagielski {
50*b1cdbd2cSJim Jagielski OSL_TRACE("OOX: URI rId %s", ::rtl::OUStringToOString (aRelId, RTL_TEXTENCODING_UTF8).pData->buffer);
51*b1cdbd2cSJim Jagielski sHref = getRelations().getExternalTargetFromRelId( aRelId );
52*b1cdbd2cSJim Jagielski if( sHref.getLength() > 0 )
53*b1cdbd2cSJim Jagielski {
54*b1cdbd2cSJim Jagielski OSL_TRACE("OOX: URI href %s", ::rtl::OUStringToOString (sHref, RTL_TEXTENCODING_UTF8).pData->buffer);
55*b1cdbd2cSJim Jagielski sURL = getFilter().getAbsoluteUrl( sHref );
56*b1cdbd2cSJim Jagielski }
57*b1cdbd2cSJim Jagielski }
58*b1cdbd2cSJim Jagielski OUString sTooltip = xAttributes->getOptionalValue( R_TOKEN( tooltip ) );
59*b1cdbd2cSJim Jagielski if ( sTooltip.getLength() )
60*b1cdbd2cSJim Jagielski maProperties[ PROP_Representation ] <<= sTooltip;
61*b1cdbd2cSJim Jagielski OUString sFrame = xAttributes->getOptionalValue( R_TOKEN( tgtFrame ) );
62*b1cdbd2cSJim Jagielski if( sFrame.getLength() )
63*b1cdbd2cSJim Jagielski maProperties[ PROP_TargetFrame ] <<= sFrame;
64*b1cdbd2cSJim Jagielski OUString aAction = xAttributes->getOptionalValue( XML_action );
65*b1cdbd2cSJim Jagielski if ( aAction.getLength() )
66*b1cdbd2cSJim Jagielski {
67*b1cdbd2cSJim Jagielski // reserved values of the unrestricted string aAction:
68*b1cdbd2cSJim Jagielski // ppaction://customshow?id=SHOW_ID // custom presentation
69*b1cdbd2cSJim Jagielski // ppaction://hlinkfile // external file via r:id
70*b1cdbd2cSJim Jagielski // ppaction://hlinkpres?slideindex=SLIDE_NUM // external presentation via r:id
71*b1cdbd2cSJim Jagielski // ppaction://hlinkshowjump?jump=endshow
72*b1cdbd2cSJim Jagielski // ppaction://hlinkshowjump?jump=firstslide
73*b1cdbd2cSJim Jagielski // ppaction://hlinkshowjump?jump=lastslide
74*b1cdbd2cSJim Jagielski // ppaction://hlinkshowjump?jump=lastslideviewed
75*b1cdbd2cSJim Jagielski // ppaction://hlinkshowjump?jump=nextslide
76*b1cdbd2cSJim Jagielski // ppaction://hlinkshowjump?jump=previousslide
77*b1cdbd2cSJim Jagielski // ppaction://hlinksldjump
78*b1cdbd2cSJim Jagielski // ppaction://macro?name=MACRO_NAME
79*b1cdbd2cSJim Jagielski // ppaction://program
80*b1cdbd2cSJim Jagielski
81*b1cdbd2cSJim Jagielski const OUString sPPAction( CREATE_OUSTRING( "ppaction://" ) );
82*b1cdbd2cSJim Jagielski if ( aAction.matchIgnoreAsciiCase( sPPAction, 0 ) )
83*b1cdbd2cSJim Jagielski {
84*b1cdbd2cSJim Jagielski OUString aPPAct( aAction.copy( sPPAction.getLength() ) );
85*b1cdbd2cSJim Jagielski sal_Int32 nIndex = aPPAct.indexOf( '?', 0 );
86*b1cdbd2cSJim Jagielski OUString aPPAction( nIndex > 0 ? aPPAct.copy( 0, nIndex ) : aPPAct );
87*b1cdbd2cSJim Jagielski
88*b1cdbd2cSJim Jagielski const OUString sHlinkshowjump( CREATE_OUSTRING( "hlinkshowjump" ) );
89*b1cdbd2cSJim Jagielski const OUString sHlinksldjump( CREATE_OUSTRING( "hlinksldjump" ) );
90*b1cdbd2cSJim Jagielski if ( aPPAction.match( sHlinkshowjump ) )
91*b1cdbd2cSJim Jagielski {
92*b1cdbd2cSJim Jagielski const OUString sJump( CREATE_OUSTRING( "jump=" ) );
93*b1cdbd2cSJim Jagielski if ( aPPAct.match( sJump, nIndex + 1 ) )
94*b1cdbd2cSJim Jagielski {
95*b1cdbd2cSJim Jagielski OUString aDestination( aPPAct.copy( nIndex + 1 + sJump.getLength() ) );
96*b1cdbd2cSJim Jagielski sURL = sURL.concat( CREATE_OUSTRING( "#action?jump=" ) );
97*b1cdbd2cSJim Jagielski sURL = sURL.concat( aDestination );
98*b1cdbd2cSJim Jagielski }
99*b1cdbd2cSJim Jagielski }
100*b1cdbd2cSJim Jagielski else if ( aPPAction.match( sHlinksldjump ) )
101*b1cdbd2cSJim Jagielski {
102*b1cdbd2cSJim Jagielski sURL = OUString();
103*b1cdbd2cSJim Jagielski
104*b1cdbd2cSJim Jagielski sal_Int32 nIndex2 = 0;
105*b1cdbd2cSJim Jagielski while ( nIndex2 < sHref.getLength() )
106*b1cdbd2cSJim Jagielski {
107*b1cdbd2cSJim Jagielski sal_Unicode nChar = sHref[ nIndex2 ];
108*b1cdbd2cSJim Jagielski if ( ( nChar >= '0' ) && ( nChar <= '9' ) )
109*b1cdbd2cSJim Jagielski break;
110*b1cdbd2cSJim Jagielski nIndex2++;
111*b1cdbd2cSJim Jagielski }
112*b1cdbd2cSJim Jagielski if ( nIndex2 && ( nIndex2 != sHref.getLength() ) )
113*b1cdbd2cSJim Jagielski {
114*b1cdbd2cSJim Jagielski sal_Int32 nLength = 1;
115*b1cdbd2cSJim Jagielski while( ( nIndex2 + nLength ) < sHref.getLength() )
116*b1cdbd2cSJim Jagielski {
117*b1cdbd2cSJim Jagielski sal_Unicode nChar = sHref[ nIndex2 + nLength ];
118*b1cdbd2cSJim Jagielski if ( ( nChar < '0' ) || ( nChar > '9' ) )
119*b1cdbd2cSJim Jagielski break;
120*b1cdbd2cSJim Jagielski nLength++;
121*b1cdbd2cSJim Jagielski }
122*b1cdbd2cSJim Jagielski sal_Int32 nPageNumber = sHref.copy( nIndex2, nLength ).toInt32();
123*b1cdbd2cSJim Jagielski if ( nPageNumber )
124*b1cdbd2cSJim Jagielski {
125*b1cdbd2cSJim Jagielski const OUString sSlide( CREATE_OUSTRING( "slide" ) );
126*b1cdbd2cSJim Jagielski const OUString sNotesSlide( CREATE_OUSTRING( "notesSlide" ) );
127*b1cdbd2cSJim Jagielski const OUString aSlideType( sHref.copy( 0, nIndex2 ) );
128*b1cdbd2cSJim Jagielski if ( aSlideType.match( sSlide ) )
129*b1cdbd2cSJim Jagielski sURL = CREATE_OUSTRING( "#Slide " ).concat( rtl::OUString::valueOf( nPageNumber ) );
130*b1cdbd2cSJim Jagielski else if ( aSlideType.match( sNotesSlide ) )
131*b1cdbd2cSJim Jagielski sURL = CREATE_OUSTRING( "#Notes " ).concat( rtl::OUString::valueOf( nPageNumber ) );
132*b1cdbd2cSJim Jagielski // else: todo for other types such as notesMaster or slideMaster as they can't be referenced easily
133*b1cdbd2cSJim Jagielski }
134*b1cdbd2cSJim Jagielski }
135*b1cdbd2cSJim Jagielski }
136*b1cdbd2cSJim Jagielski }
137*b1cdbd2cSJim Jagielski }
138*b1cdbd2cSJim Jagielski if ( sURL.getLength() )
139*b1cdbd2cSJim Jagielski maProperties[ PROP_URL ] <<= sURL;
140*b1cdbd2cSJim Jagielski
141*b1cdbd2cSJim Jagielski // TODO unhandled
142*b1cdbd2cSJim Jagielski // XML_invalidUrl
143*b1cdbd2cSJim Jagielski // XML_history
144*b1cdbd2cSJim Jagielski // XML_highlightClick
145*b1cdbd2cSJim Jagielski // XML_endSnd
146*b1cdbd2cSJim Jagielski }
147*b1cdbd2cSJim Jagielski
~HyperLinkContext()148*b1cdbd2cSJim Jagielski HyperLinkContext::~HyperLinkContext()
149*b1cdbd2cSJim Jagielski {
150*b1cdbd2cSJim Jagielski }
151*b1cdbd2cSJim Jagielski
createFastChildContext(::sal_Int32 aElement,const Reference<XFastAttributeList> & xAttribs)152*b1cdbd2cSJim Jagielski Reference< XFastContextHandler > HyperLinkContext::createFastChildContext(
153*b1cdbd2cSJim Jagielski ::sal_Int32 aElement, const Reference< XFastAttributeList >& xAttribs ) throw (SAXException, RuntimeException)
154*b1cdbd2cSJim Jagielski {
155*b1cdbd2cSJim Jagielski Reference< XFastContextHandler > xRet;
156*b1cdbd2cSJim Jagielski switch( aElement )
157*b1cdbd2cSJim Jagielski {
158*b1cdbd2cSJim Jagielski case A_TOKEN( extLst ):
159*b1cdbd2cSJim Jagielski return xRet;
160*b1cdbd2cSJim Jagielski case A_TOKEN( snd ):
161*b1cdbd2cSJim Jagielski EmbeddedWAVAudioFile aAudio;
162*b1cdbd2cSJim Jagielski getEmbeddedWAVAudioFile( getRelations(), xAttribs, aAudio );
163*b1cdbd2cSJim Jagielski break;
164*b1cdbd2cSJim Jagielski }
165*b1cdbd2cSJim Jagielski if ( !xRet.is() )
166*b1cdbd2cSJim Jagielski xRet.set( this );
167*b1cdbd2cSJim Jagielski return xRet;
168*b1cdbd2cSJim Jagielski }
169*b1cdbd2cSJim Jagielski
170*b1cdbd2cSJim Jagielski } // namespace drawingml
171*b1cdbd2cSJim Jagielski } // namespace oox
172*b1cdbd2cSJim Jagielski
173