LibreOffice Module xmloff (master)  1
XMLTextFrameHyperlinkContext.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  * Licensed to the Apache Software Foundation (ASF) under one or more
12  * contributor license agreements. See the NOTICE file distributed
13  * with this work for additional information regarding copyright
14  * ownership. The ASF licenses this file to you under the Apache
15  * License, Version 2.0 (the "License"); you may not use this file
16  * except in compliance with the License. You may obtain a copy of
17  * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 #include <sax/tools/converter.hxx>
21 
22 #include <xmloff/xmlimp.hxx>
23 #include <xmloff/nmspmap.hxx>
24 #include <xmloff/xmlnmspe.hxx>
25 #include <xmloff/xmltoken.hxx>
26 #include "XMLTextFrameContext.hxx"
28 
29 using namespace ::com::sun::star::uno;
30 using namespace ::com::sun::star::text;
31 using namespace ::com::sun::star::xml::sax;
32 using namespace ::com::sun::star::beans;
33 using namespace ::xmloff::token;
34 
36 
37 
39  SvXMLImport& rImport,
40  sal_uInt16 nPrfx, const OUString& rLName,
41  const Reference< XAttributeList > & xAttrList,
42  TextContentAnchorType eATyp ) :
43  SvXMLImportContext( rImport, nPrfx, rLName ),
44  eDefaultAnchorType( eATyp ),
45  bMap( false )
46 {
47  OUString sShow;
48  const SvXMLTokenMap& rTokenMap =
49  GetImport().GetTextImport()->GetTextHyperlinkAttrTokenMap();
50 
51  sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
52  for( sal_Int16 i=0; i < nAttrCount; i++ )
53  {
54  const OUString& rAttrName = xAttrList->getNameByIndex( i );
55  const OUString& rValue = xAttrList->getValueByIndex( i );
56 
57  OUString aLocalName;
58  sal_uInt16 nPrefix =
60  &aLocalName );
61  switch( rTokenMap.Get( nPrefix, aLocalName ) )
62  {
64  sHRef = GetImport().GetAbsoluteReference( rValue );
65  break;
67  sName = rValue;
68  break;
71  break;
73  sShow = rValue;
74  break;
76  {
77  bool bTmp(false);
78  if (::sax::Converter::convertBool( bTmp, rValue ))
79  {
80  bMap = bTmp;
81  }
82  }
83  break;
84  }
85  }
86 
87  if( !sShow.isEmpty() && sTargetFrameName.isEmpty() )
88  {
89  if( IsXMLToken( sShow, XML_NEW ) )
90  sTargetFrameName = "_blank";
91  else if( IsXMLToken( sShow, XML_REPLACE ) )
92  sTargetFrameName = "_self";
93  }
94 }
95 
97 {
98 }
99 
101 {
102 }
103 
105  sal_uInt16 nPrefix,
106  const OUString& rLocalName,
107  const Reference< XAttributeList > & xAttrList )
108 {
109  SvXMLImportContext *pContext = nullptr;
110  XMLTextFrameContext *pTextFrameContext = nullptr;
111 
112  if( XML_NAMESPACE_DRAW == nPrefix )
113  {
114  if( IsXMLToken( rLocalName, XML_FRAME ) )
115  pTextFrameContext = new XMLTextFrameContext( GetImport(), nPrefix,
116  rLocalName, xAttrList,
118  }
119 
120  if( pTextFrameContext )
121  {
122  pTextFrameContext->SetHyperlink( sHRef, sName, sTargetFrameName, bMap );
123  pContext = pTextFrameContext;
124  xFrameContext = pContext;
125  }
126 
127  return pContext;
128 }
129 
130 
131 TextContentAnchorType XMLTextFrameHyperlinkContext::GetAnchorType() const
132 {
133  if( xFrameContext.is() )
134  {
135  SvXMLImportContext *pContext = xFrameContext.get();
136  return dynamic_cast<XMLTextFrameContext&>(*pContext).GetAnchorType();
137  }
138  else
139  return eDefaultAnchorType;
140 
141 }
142 
143 Reference < XTextContent > XMLTextFrameHyperlinkContext::GetTextContent() const
144 {
145  Reference <XTextContent > xTxt;
146  if( xFrameContext.is() )
147  {
148  SvXMLImportContext *pContext = xFrameContext.get();
149  xTxt = dynamic_cast<XMLTextFrameContext&>(*pContext).GetTextContent();
150  }
151 
152  return xTxt;
153 }
154 
155 // Frame "to character": anchor moves from first to last char after saving (#i33242#)
156 Reference < drawing::XShape > XMLTextFrameHyperlinkContext::GetShape() const
157 {
158  Reference < drawing::XShape > xShape;
159  if( xFrameContext.is() )
160  {
161  SvXMLImportContext *pContext = xFrameContext.get();
162  xShape = dynamic_cast<XMLTextFrameContext&>(*pContext).GetShape();
163  }
164 
165  return xShape;
166 }
167 
168 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool IsXMLToken(const OUString &rString, enum XMLTokenEnum eToken)
compare eToken to the string
Definition: xmltoken.cxx:3422
virtual void EndElement() override
EndElement is called before a context will be destructed, but after an elements context has been pars...
static bool convertBool(bool &rBool, const OUString &rString)
SvXMLImport & GetImport()
Definition: xmlictxt.hxx:62
SvXMLNamespaceMap & GetNamespaceMap()
Definition: xmlimp.hxx:397
rtl::Reference< XMLTextImportHelper > const & GetTextImport()
Definition: xmlimp.hxx:594
sal_uInt16 GetKeyByAttrName(const OUString &rAttrName, OUString *pPrefix, OUString *pLocalName, OUString *pNamespace) const
Definition: nmspmap.cxx:437
void SetHyperlink(const OUString &rHRef, const OUString &rName, const OUString &rTargetFrameName, bool bMap)
XMLTextFrameHyperlinkContext(SvXMLImport &rImport, sal_uInt16 nPrfx, const OUString &rLName, const css::uno::Reference< css::xml::sax::XAttributeList > &xAttrList, css::text::TextContentAnchorType eDefaultAnchorType)
css::uno::Reference< css::text::XTextContent > GetTextContent() const
css::uno::Any const & rValue
Definition: ImageStyle.hxx:38
css::text::TextContentAnchorType GetAnchorType() const
constexpr sal_uInt16 XML_NAMESPACE_DRAW
Definition: xmlnmspe.hxx:33
css::uno::Reference< css::drawing::XShape > GetShape() const
int i
css::uno::Reference< css::text::XTextContent > GetTextContent() const
sal_uInt16 Get(sal_uInt16 nPrefix, const OUString &rLName) const
Definition: xmltkmap.cxx:93
This class deliberately does not support XWeak, to improve performance when loading large documents...
Definition: xmlictxt.hxx:44
OUString GetAbsoluteReference(const OUString &rValue) const
Definition: xmlimp.cxx:1686
SvXMLImportContextRef CreateChildContext(sal_uInt16 nPrefix, const OUString &rLocalName, const css::uno::Reference< css::xml::sax::XAttributeList > &xAttrList) override
Create a children element context.
Handling of tokens in XML:
css::text::TextContentAnchorType GetAnchorType() const
css::text::TextContentAnchorType eDefaultAnchorType
css::uno::Reference< css::drawing::XShape > GetShape() const