LibreOffice Module sw (master)  1
ToxLinkProcessor.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 
10 #include <memory>
11 #include <ToxLinkProcessor.hxx>
12 
13 #include <SwStyleNameMapper.hxx>
14 #include <ndtxt.hxx>
15 #include <sal/log.hxx>
16 #include <rtl/uri.hxx>
17 
18 namespace sw {
19 
20 void
21 ToxLinkProcessor::StartNewLink(sal_Int32 startPosition, const OUString& characterStyle)
22 {
23  SAL_INFO_IF(m_pStartedLink, "sw.core", "ToxLinkProcessor: LS without LE");
24  m_pStartedLink = std::make_unique<StartedLink>(
25  startPosition, characterStyle);
26 }
27 
28 void ToxLinkProcessor::CloseLink(sal_Int32 endPosition, const OUString& url, bool bRelative)
29 {
30  if (m_pStartedLink == nullptr)
31  {
32  SAL_INFO("sw.core", "ToxLinkProcessor: LE without LS");
33  return;
34  }
35 
36  if (url.isEmpty()) {
37  return;
38  }
39 
40  OUString uri;
41  if (bRelative)
42  {
43  // url contains '|' which must be encoded; also in some cases contains
44  // arbitrary strings that need to be encoded
45  assert(url[0] == '#'); // all links are internal
46  uri = "#"
47  + rtl::Uri::encode(url.copy(1), rtl_UriCharClassUricNoSlash,
48  rtl_UriEncodeIgnoreEscapes, RTL_TEXTENCODING_UTF8);
49  }
50  else
51  {
52  uri = url;
53  }
54 
55  std::unique_ptr<ClosedLink> pClosedLink(
56  new ClosedLink(uri, m_pStartedLink->mStartPosition, endPosition));
57 
58  const OUString& characterStyle = m_pStartedLink->mCharacterStyle;
59  sal_uInt16 poolId = ObtainPoolId(characterStyle);
60  pClosedLink->mINetFormat.SetVisitedFormatAndId(characterStyle, poolId);
61  pClosedLink->mINetFormat.SetINetFormatAndId(characterStyle, poolId);
62 
63  m_ClosedLinks.push_back(std::move(pClosedLink));
64  m_pStartedLink.reset();
65 }
66 
67 sal_uInt16
68 ToxLinkProcessor::ObtainPoolId(const OUString& characterStyle) const
69 {
70  if (characterStyle.isEmpty()) {
71  return USHRT_MAX;
72  }
73  else {
75  }
76 }
77 
78 
79 void
81 {
82  for (auto const& clink : m_ClosedLinks)
83  {
84  node.InsertItem(clink->mINetFormat, clink->mStartTextPos, clink->mEndTextPos);
85  }
86 }
87 
88 }
89 
90 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
#define SAL_INFO_IF(condition, area, stream)
Dialog to specify the properties of date form field.
const BorderLinePrimitive2D *pCandidateB assert(pCandidateA)
static SW_DLLPUBLIC sal_uInt16 GetPoolIdFromUIName(const OUString &rName, SwGetPoolIdFromName)
SwTextAttr * InsertItem(SfxPoolItem &rAttr, const sal_Int32 nStart, const sal_Int32 nEnd, const SetAttrMode nMode=SetAttrMode::DEFAULT)
create new text attribute from rAttr and insert it
Definition: thints.cxx:1271
virtual sal_uInt16 ObtainPoolId(const OUString &characterStyle) const
Obtain the pool id which belongs to a character style.
std::vector< std::unique_ptr< ClosedLink > > m_ClosedLinks
std::unique_ptr< StartedLink > m_pStartedLink
void InsertLinkAttributes(SwTextNode &node)
Insert the found links as attributes to a text node.
SwTextNode is a paragraph in the document model.
Definition: ndtxt.hxx:80
const o3tl::enumarray< SvxAdjust, unsigned short > aSvxToUnoAdjust USHRT_MAX
Definition: unosett.cxx:254
#define SAL_INFO(area, stream)
void StartNewLink(sal_Int32 startPosition, const OUString &characterStyle)
void CloseLink(sal_Int32 endPosition, const OUString &url, bool bRelative)
Close a link which has been found during processing.
exports com.sun.star. uri