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 <sal/log.hxx>
21 #include <sax/tools/converter.hxx>
22 
23 #include <xmloff/xmlimp.hxx>
24 #include <xmloff/namespacemap.hxx>
25 #include <xmloff/xmlnamespace.hxx>
26 #include <xmloff/xmltoken.hxx>
27 #include "XMLTextFrameContext.hxx"
29 
30 using namespace ::com::sun::star::uno;
31 using namespace ::com::sun::star::text;
32 using namespace ::com::sun::star::xml::sax;
33 using namespace ::com::sun::star::beans;
34 using namespace ::xmloff::token;
35 
37 
38 
40  SvXMLImport& rImport,
41  sal_Int32 /*nElement*/,
42  const Reference< XFastAttributeList > & xAttrList,
43  TextContentAnchorType eATyp ) :
44  SvXMLImportContext( rImport ),
45  eDefaultAnchorType( eATyp ),
46  bMap( false )
47 {
48  OUString sShow;
49 
50  for( auto& aIter : sax_fastparser::castToFastAttributeList(xAttrList) )
51  {
52  switch( aIter.getToken() )
53  {
54  case XML_ELEMENT(XLINK, XML_HREF):
55  sHRef = GetImport().GetAbsoluteReference( aIter.toString() );
56  break;
58  sName = aIter.toString();
59  break;
61  sTargetFrameName = aIter.toString();
62  break;
63  case XML_ELEMENT(XLINK, XML_SHOW):
64  sShow = aIter.toString();
65  break;
67  {
68  bool bTmp(false);
69  if (::sax::Converter::convertBool( bTmp, aIter.toView() ))
70  {
71  bMap = bTmp;
72  }
73  }
74  break;
75  default:
76  XMLOFF_WARN_UNKNOWN("xmloff", aIter);
77  }
78  }
79 
80  if( !sShow.isEmpty() && sTargetFrameName.isEmpty() )
81  {
82  if( IsXMLToken( sShow, XML_NEW ) )
83  sTargetFrameName = "_blank";
84  else if( IsXMLToken( sShow, XML_REPLACE ) )
85  sTargetFrameName = "_self";
86  }
87 }
88 
90 {
91 }
92 
93 css::uno::Reference< css::xml::sax::XFastContextHandler > XMLTextFrameHyperlinkContext::createFastChildContext(
94  sal_Int32 nElement,
95  const css::uno::Reference< css::xml::sax::XFastAttributeList>& xAttrList )
96 {
97  SvXMLImportContext *pContext = nullptr;
98  XMLTextFrameContext *pTextFrameContext = nullptr;
99 
100  if( nElement == XML_ELEMENT(DRAW, XML_FRAME) )
101  {
102  pTextFrameContext = new XMLTextFrameContext( GetImport(),
103  xAttrList,
105  pTextFrameContext->SetHyperlink( sHRef, sName, sTargetFrameName, bMap );
106  pContext = pTextFrameContext;
107  xFrameContext = pContext;
108  }
109 
110  if (!pContext)
111  XMLOFF_WARN_UNKNOWN_ELEMENT("xmloff", nElement);
112 
113  return pContext;
114 }
115 
116 
117 TextContentAnchorType XMLTextFrameHyperlinkContext::GetAnchorType() const
118 {
119  if( xFrameContext.is() )
120  {
121  SvXMLImportContext *pContext = xFrameContext.get();
122  return dynamic_cast<XMLTextFrameContext&>(*pContext).GetAnchorType();
123  }
124  else
125  return eDefaultAnchorType;
126 
127 }
128 
129 Reference < XTextContent > XMLTextFrameHyperlinkContext::GetTextContent() const
130 {
131  Reference <XTextContent > xTxt;
132  if( xFrameContext.is() )
133  {
134  SvXMLImportContext *pContext = xFrameContext.get();
135  xTxt = dynamic_cast<XMLTextFrameContext&>(*pContext).GetTextContent();
136  }
137 
138  return xTxt;
139 }
140 
141 // Frame "to character": anchor moves from first to last char after saving (#i33242#)
142 Reference < drawing::XShape > XMLTextFrameHyperlinkContext::GetShape() const
143 {
144  Reference < drawing::XShape > xShape;
145  if( xFrameContext.is() )
146  {
147  SvXMLImportContext *pContext = xFrameContext.get();
148  xShape = dynamic_cast<XMLTextFrameContext&>(*pContext).GetShape();
149  }
150 
151  return xShape;
152 }
153 
154 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SvXMLImport & GetImport()
Definition: xmlictxt.hxx:60
bool IsXMLToken(std::u16string_view rString, enum XMLTokenEnum eToken)
compare eToken to the string
Definition: xmltoken.cxx:3480
FastAttributeList & castToFastAttributeList(const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
void SetHyperlink(const OUString &rHRef, const OUString &rName, const OUString &rTargetFrameName, bool bMap)
css::uno::Reference< css::text::XTextContent > GetTextContent() const
DRAW
#define XMLOFF_WARN_UNKNOWN(area, rIter)
Definition: xmlictxt.hxx:114
virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &AttrList) override
css::text::TextContentAnchorType GetAnchorType() const
css::uno::Reference< css::drawing::XShape > GetShape() const
css::uno::Reference< css::text::XTextContent > GetTextContent() const
static bool convertBool(bool &rBool, std::u16string_view rString)
This class deliberately does not support XWeak, to improve performance when loading large documents...
Definition: xmlictxt.hxx:45
OUString GetAbsoluteReference(const OUString &rValue) const
Definition: xmlimp.cxx:1601
Handling of tokens in XML:
#define XML_ELEMENT(prefix, name)
Definition: xmlimp.hxx:96
css::text::TextContentAnchorType GetAnchorType() const
css::text::TextContentAnchorType eDefaultAnchorType
#define XMLOFF_WARN_UNKNOWN_ELEMENT(area, token)
Definition: xmlictxt.hxx:120
css::uno::Reference< css::drawing::XShape > GetShape() const
XMLTextFrameHyperlinkContext(SvXMLImport &rImport, sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList, css::text::TextContentAnchorType eDefaultAnchorType)