Update ooo320-m1
[ooovba.git] / xmloff / source / text / XMLTextFrameHyperlinkContext.cxx
blob9fae363ea53c5b88bb03c56cd45e03956a9e8725
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: XMLTextFrameHyperlinkContext.cxx,v $
10 * $Revision: 1.14 $
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 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_xmloff.hxx"
33 #include <xmloff/xmlimp.hxx>
34 #include <xmloff/nmspmap.hxx>
35 #include "xmlnmspe.hxx"
36 #include <xmloff/xmltoken.hxx>
37 #include <xmloff/xmluconv.hxx>
38 #include "XMLTextFrameContext.hxx"
39 #include "XMLTextFrameHyperlinkContext.hxx"
41 // OD 2004-04-21 #i26791#
42 #include <txtparaimphint.hxx>
44 using ::rtl::OUString;
45 using ::rtl::OUStringBuffer;
47 using namespace ::com::sun::star::uno;
48 using namespace ::com::sun::star::text;
49 using namespace ::com::sun::star::xml::sax;
50 using namespace ::com::sun::star::beans;
51 using namespace ::xmloff::token;
53 TYPEINIT1( XMLTextFrameHyperlinkContext, SvXMLImportContext );
55 XMLTextFrameHyperlinkContext::XMLTextFrameHyperlinkContext(
56 SvXMLImport& rImport,
57 sal_uInt16 nPrfx, const OUString& rLName,
58 const Reference< XAttributeList > & xAttrList,
59 TextContentAnchorType eATyp ) :
60 SvXMLImportContext( rImport, nPrfx, rLName ),
61 eDefaultAnchorType( eATyp ),
62 bMap( sal_False )
64 OUString sShow;
65 const SvXMLTokenMap& rTokenMap =
66 GetImport().GetTextImport()->GetTextHyperlinkAttrTokenMap();
68 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
69 for( sal_Int16 i=0; i < nAttrCount; i++ )
71 const OUString& rAttrName = xAttrList->getNameByIndex( i );
72 const OUString& rValue = xAttrList->getValueByIndex( i );
74 OUString aLocalName;
75 sal_uInt16 nPrefix =
76 GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName,
77 &aLocalName );
78 switch( rTokenMap.Get( nPrefix, aLocalName ) )
80 case XML_TOK_TEXT_HYPERLINK_HREF:
81 sHRef = GetImport().GetAbsoluteReference( rValue );
82 break;
83 case XML_TOK_TEXT_HYPERLINK_NAME:
84 sName = rValue;
85 break;
86 case XML_TOK_TEXT_HYPERLINK_TARGET_FRAME:
87 sTargetFrameName = rValue;
88 break;
89 case XML_TOK_TEXT_HYPERLINK_SHOW:
90 sShow = rValue;
91 break;
92 case XML_TOK_TEXT_HYPERLINK_SERVER_MAP:
94 sal_Bool bTmp;
95 if( rImport.GetMM100UnitConverter().convertBool( bTmp,
96 rValue ) )
98 bMap = bTmp;
101 break;
105 if( sShow.getLength() && !sTargetFrameName.getLength() )
107 if( IsXMLToken( sShow, XML_NEW ) )
108 sTargetFrameName =
109 OUString( RTL_CONSTASCII_USTRINGPARAM("_blank" ) );
110 else if( IsXMLToken( sShow, XML_REPLACE ) )
111 sTargetFrameName =
112 OUString( RTL_CONSTASCII_USTRINGPARAM("_self" ) );
116 XMLTextFrameHyperlinkContext::~XMLTextFrameHyperlinkContext()
120 void XMLTextFrameHyperlinkContext::EndElement()
124 SvXMLImportContext *XMLTextFrameHyperlinkContext::CreateChildContext(
125 sal_uInt16 nPrefix,
126 const OUString& rLocalName,
127 const Reference< XAttributeList > & xAttrList )
129 SvXMLImportContext *pContext = 0;
130 XMLTextFrameContext *pTextFrameContext = 0;
132 if( XML_NAMESPACE_DRAW == nPrefix )
134 if( IsXMLToken( rLocalName, XML_FRAME ) )
135 pTextFrameContext = new XMLTextFrameContext( GetImport(), nPrefix,
136 rLocalName, xAttrList,
137 eDefaultAnchorType );
140 if( pTextFrameContext )
142 pTextFrameContext->SetHyperlink( sHRef, sName, sTargetFrameName, bMap );
143 pContext = pTextFrameContext;
144 xFrameContext = pContext;
146 else
147 pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
149 return pContext;
153 TextContentAnchorType XMLTextFrameHyperlinkContext::GetAnchorType() const
155 if( xFrameContext.Is() )
157 SvXMLImportContext *pContext = &xFrameContext;
158 return PTR_CAST( XMLTextFrameContext, pContext ) ->GetAnchorType();
160 else
161 return eDefaultAnchorType;
165 Reference < XTextContent > XMLTextFrameHyperlinkContext::GetTextContent() const
167 Reference <XTextContent > xTxt;
168 if( xFrameContext.Is() )
170 SvXMLImportContext *pContext = &xFrameContext;
171 xTxt = PTR_CAST( XMLTextFrameContext, pContext )->GetTextContent();
174 return xTxt;
177 // --> OD 2004-08-24 #33242#
178 Reference < drawing::XShape > XMLTextFrameHyperlinkContext::GetShape() const
180 Reference < drawing::XShape > xShape;
181 if( xFrameContext.Is() )
183 SvXMLImportContext *pContext = &xFrameContext;
184 xShape = PTR_CAST( XMLTextFrameContext, pContext )->GetShape();
187 return xShape;
189 // <--