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