1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_xmloff.hxx" 30 #include <xmloff/xmlimp.hxx> 31 #include <xmloff/nmspmap.hxx> 32 #include "xmloff/xmlnmspe.hxx" 33 #include <xmloff/xmltoken.hxx> 34 #include <xmloff/xmluconv.hxx> 35 #include "XMLTextFrameContext.hxx" 36 #include "XMLTextFrameHyperlinkContext.hxx" 37 38 // OD 2004-04-21 #i26791# 39 #include <txtparaimphint.hxx> 40 41 using ::rtl::OUString; 42 using ::rtl::OUStringBuffer; 43 44 using namespace ::com::sun::star::uno; 45 using namespace ::com::sun::star::text; 46 using namespace ::com::sun::star::xml::sax; 47 using namespace ::com::sun::star::beans; 48 using namespace ::xmloff::token; 49 50 TYPEINIT1( XMLTextFrameHyperlinkContext, SvXMLImportContext ); 51 52 XMLTextFrameHyperlinkContext::XMLTextFrameHyperlinkContext( 53 SvXMLImport& rImport, 54 sal_uInt16 nPrfx, const OUString& rLName, 55 const Reference< XAttributeList > & xAttrList, 56 TextContentAnchorType eATyp ) : 57 SvXMLImportContext( rImport, nPrfx, rLName ), 58 eDefaultAnchorType( eATyp ), 59 bMap( sal_False ) 60 { 61 OUString sShow; 62 const SvXMLTokenMap& rTokenMap = 63 GetImport().GetTextImport()->GetTextHyperlinkAttrTokenMap(); 64 65 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0; 66 for( sal_Int16 i=0; i < nAttrCount; i++ ) 67 { 68 const OUString& rAttrName = xAttrList->getNameByIndex( i ); 69 const OUString& rValue = xAttrList->getValueByIndex( i ); 70 71 OUString aLocalName; 72 sal_uInt16 nPrefix = 73 GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName, 74 &aLocalName ); 75 switch( rTokenMap.Get( nPrefix, aLocalName ) ) 76 { 77 case XML_TOK_TEXT_HYPERLINK_HREF: 78 sHRef = GetImport().GetAbsoluteReference( rValue ); 79 break; 80 case XML_TOK_TEXT_HYPERLINK_NAME: 81 sName = rValue; 82 break; 83 case XML_TOK_TEXT_HYPERLINK_TARGET_FRAME: 84 sTargetFrameName = rValue; 85 break; 86 case XML_TOK_TEXT_HYPERLINK_SHOW: 87 sShow = rValue; 88 break; 89 case XML_TOK_TEXT_HYPERLINK_SERVER_MAP: 90 { 91 sal_Bool bTmp; 92 if( rImport.GetMM100UnitConverter().convertBool( bTmp, 93 rValue ) ) 94 { 95 bMap = bTmp; 96 } 97 } 98 break; 99 } 100 } 101 102 if( sShow.getLength() && !sTargetFrameName.getLength() ) 103 { 104 if( IsXMLToken( sShow, XML_NEW ) ) 105 sTargetFrameName = 106 OUString( RTL_CONSTASCII_USTRINGPARAM("_blank" ) ); 107 else if( IsXMLToken( sShow, XML_REPLACE ) ) 108 sTargetFrameName = 109 OUString( RTL_CONSTASCII_USTRINGPARAM("_self" ) ); 110 } 111 } 112 113 XMLTextFrameHyperlinkContext::~XMLTextFrameHyperlinkContext() 114 { 115 } 116 117 void XMLTextFrameHyperlinkContext::EndElement() 118 { 119 } 120 121 SvXMLImportContext *XMLTextFrameHyperlinkContext::CreateChildContext( 122 sal_uInt16 nPrefix, 123 const OUString& rLocalName, 124 const Reference< XAttributeList > & xAttrList ) 125 { 126 SvXMLImportContext *pContext = 0; 127 XMLTextFrameContext *pTextFrameContext = 0; 128 129 if( XML_NAMESPACE_DRAW == nPrefix ) 130 { 131 if( IsXMLToken( rLocalName, XML_FRAME ) ) 132 pTextFrameContext = new XMLTextFrameContext( GetImport(), nPrefix, 133 rLocalName, xAttrList, 134 eDefaultAnchorType ); 135 } 136 137 if( pTextFrameContext ) 138 { 139 pTextFrameContext->SetHyperlink( sHRef, sName, sTargetFrameName, bMap ); 140 pContext = pTextFrameContext; 141 xFrameContext = pContext; 142 } 143 else 144 pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName ); 145 146 return pContext; 147 } 148 149 150 TextContentAnchorType XMLTextFrameHyperlinkContext::GetAnchorType() const 151 { 152 if( xFrameContext.Is() ) 153 { 154 SvXMLImportContext *pContext = &xFrameContext; 155 return PTR_CAST( XMLTextFrameContext, pContext ) ->GetAnchorType(); 156 } 157 else 158 return eDefaultAnchorType; 159 160 } 161 162 Reference < XTextContent > XMLTextFrameHyperlinkContext::GetTextContent() const 163 { 164 Reference <XTextContent > xTxt; 165 if( xFrameContext.Is() ) 166 { 167 SvXMLImportContext *pContext = &xFrameContext; 168 xTxt = PTR_CAST( XMLTextFrameContext, pContext )->GetTextContent(); 169 } 170 171 return xTxt; 172 } 173 174 // --> OD 2004-08-24 #33242# 175 Reference < drawing::XShape > XMLTextFrameHyperlinkContext::GetShape() const 176 { 177 Reference < drawing::XShape > xShape; 178 if( xFrameContext.Is() ) 179 { 180 SvXMLImportContext *pContext = &xFrameContext; 181 xShape = PTR_CAST( XMLTextFrameContext, pContext )->GetShape(); 182 } 183 184 return xShape; 185 } 186 // <-- 187 188 189