1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: hyperlinkcontext.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #include "hyperlinkcontext.hxx"
33 #include <rtl/ustring.hxx>
35 #include <com/sun/star/xml/sax/XFastContextHandler.hpp>
37 #include "oox/helper/propertymap.hxx"
38 #include "oox/core/relations.hxx"
39 #include "oox/core/namespaces.hxx"
40 #include "oox/core/xmlfilterbase.hxx"
41 #include "oox/drawingml/embeddedwavaudiofile.hxx"
42 #include "properties.hxx"
45 using ::rtl::OUString
;
46 using namespace ::oox::core
;
47 using namespace ::com::sun::star::uno
;
48 using namespace ::com::sun::star::xml::sax
;
53 HyperLinkContext::HyperLinkContext( ContextHandler
& rParent
,
54 const Reference
< XFastAttributeList
>& xAttributes
, PropertyMap
& aProperties
)
55 : ContextHandler( rParent
)
56 , maProperties(aProperties
)
59 OUString aRelId
= xAttributes
->getOptionalValue( NMSP_RELATIONSHIPS
|XML_id
);
60 if ( aRelId
.getLength() )
62 OSL_TRACE("OOX: URI rId %s", ::rtl::OUStringToOString (aRelId
, RTL_TEXTENCODING_UTF8
).pData
->buffer
);
63 sHref
= getRelations().getExternalTargetFromRelId( aRelId
);
64 if( sHref
.getLength() > 0 )
66 OSL_TRACE("OOX: URI href %s", ::rtl::OUStringToOString (sHref
, RTL_TEXTENCODING_UTF8
).pData
->buffer
);
67 sURL
= getFilter().getAbsoluteUrl( sHref
);
70 OUString sTooltip
= xAttributes
->getOptionalValue( NMSP_RELATIONSHIPS
|XML_tooltip
);
71 if ( sTooltip
.getLength() )
72 maProperties
[ PROP_Representation
] <<= sTooltip
;
73 OUString sFrame
= xAttributes
->getOptionalValue( NMSP_RELATIONSHIPS
|XML_tgtFrame
);
74 if( sFrame
.getLength() )
75 maProperties
[ PROP_TargetFrame
] <<= sFrame
;
76 OUString aAction
= xAttributes
->getOptionalValue( XML_action
);
77 if ( aAction
.getLength() )
79 // reserved values of the unrestricted string aAction:
80 // ppaction://customshow?id=SHOW_ID // custom presentation
81 // ppaction://hlinkfile // external file via r:id
82 // ppaction://hlinkpres?slideindex=SLIDE_NUM // external presentation via r:id
83 // ppaction://hlinkshowjump?jump=endshow
84 // ppaction://hlinkshowjump?jump=firstslide
85 // ppaction://hlinkshowjump?jump=lastslide
86 // ppaction://hlinkshowjump?jump=lastslideviewed
87 // ppaction://hlinkshowjump?jump=nextslide
88 // ppaction://hlinkshowjump?jump=previousslide
89 // ppaction://hlinksldjump
90 // ppaction://macro?name=MACRO_NAME
93 const OUString
sPPAction( CREATE_OUSTRING( "ppaction://" ) );
94 if ( aAction
.matchIgnoreAsciiCase( sPPAction
, 0 ) )
96 OUString
aPPAct( aAction
.copy( sPPAction
.getLength() ) );
97 sal_Int32 nIndex
= aPPAct
.indexOf( '?', 0 );
98 OUString
aPPAction( nIndex
> 0 ? aPPAct
.copy( 0, nIndex
) : aPPAct
);
100 const OUString
sHlinkshowjump( CREATE_OUSTRING( "hlinkshowjump" ) );
101 const OUString
sHlinksldjump( CREATE_OUSTRING( "hlinksldjump" ) );
102 if ( aPPAction
.match( sHlinkshowjump
) )
104 const OUString
sJump( CREATE_OUSTRING( "jump=" ) );
105 if ( aPPAct
.match( sJump
, nIndex
+ 1 ) )
107 OUString
aDestination( aPPAct
.copy( nIndex
+ 1 + sJump
.getLength() ) );
108 sURL
= sURL
.concat( CREATE_OUSTRING( "#action?jump=" ) );
109 sURL
= sURL
.concat( aDestination
);
112 else if ( aPPAction
.match( sHlinksldjump
) )
116 sal_Int32 nIndex2
= 0;
117 while ( nIndex2
< sHref
.getLength() )
119 sal_Unicode nChar
= sHref
[ nIndex2
];
120 if ( ( nChar
>= '0' ) && ( nChar
<= '9' ) )
124 if ( nIndex2
&& ( nIndex2
!= sHref
.getLength() ) )
126 sal_Int32 nLength
= 1;
127 while( ( nIndex2
+ nLength
) < sHref
.getLength() )
129 sal_Unicode nChar
= sHref
[ nIndex2
+ nLength
];
130 if ( ( nChar
< '0' ) || ( nChar
> '9' ) )
134 sal_Int32 nPageNumber
= sHref
.copy( nIndex2
, nLength
).toInt32();
137 const OUString
sSlide( CREATE_OUSTRING( "slide" ) );
138 const OUString
sNotesSlide( CREATE_OUSTRING( "notesSlide" ) );
139 const OUString
aSlideType( sHref
.copy( 0, nIndex2
) );
140 if ( aSlideType
.match( sSlide
) )
141 sURL
= CREATE_OUSTRING( "#Slide " ).concat( rtl::OUString::valueOf( nPageNumber
) );
142 else if ( aSlideType
.match( sNotesSlide
) )
143 sURL
= CREATE_OUSTRING( "#Notes " ).concat( rtl::OUString::valueOf( nPageNumber
) );
144 // else: todo for other types such as notesMaster or slideMaster as they can't be referenced easily
150 if ( sURL
.getLength() )
151 maProperties
[ PROP_URL
] <<= sURL
;
156 // XML_highlightClick
160 HyperLinkContext::~HyperLinkContext()
164 Reference
< XFastContextHandler
> HyperLinkContext::createFastChildContext(
165 ::sal_Int32 aElement
, const Reference
< XFastAttributeList
>& xAttribs
) throw (SAXException
, RuntimeException
)
167 Reference
< XFastContextHandler
> xRet
;
170 case NMSP_DRAWINGML
|XML_extLst
:
172 case NMSP_DRAWINGML
|XML_snd
:
173 EmbeddedWAVAudioFile aAudio
;
174 getEmbeddedWAVAudioFile( getRelations(), xAttribs
, aAudio
);
182 } // namespace drawingml