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
18namespace sw {
19
20void
21ToxLinkProcessor::StartNewLink(sal_Int32 startPosition, const OUString& characterStyle)
22{
23 SAL_INFO_IF(m_oStartedLink, "sw.core", "ToxLinkProcessor: LS without LE");
24 m_oStartedLink.emplace(startPosition, characterStyle);
25}
26
27void ToxLinkProcessor::CloseLink(sal_Int32 endPosition, const OUString& url, bool bRelative)
28{
29 if (!m_oStartedLink)
30 {
31 SAL_INFO("sw.core", "ToxLinkProcessor: LE without LS");
32 return;
33 }
34
35 if (url.isEmpty()) {
36 return;
37 }
38
39 OUString uri;
40 if (bRelative)
41 {
42 // url contains '|' which must be encoded; also in some cases contains
43 // arbitrary strings that need to be encoded
44 assert(url[0] == '#'); // all links are internal
45 uri = "#"
46 + rtl::Uri::encode(url.copy(1), rtl_UriCharClassUricNoSlash,
47 rtl_UriEncodeIgnoreEscapes, RTL_TEXTENCODING_UTF8);
48 }
49 else
50 {
51 uri = url;
52 }
53
54 std::unique_ptr<ClosedLink> pClosedLink(
55 new ClosedLink(uri, m_oStartedLink->mStartPosition, endPosition));
56
57 const OUString& characterStyle = m_oStartedLink->mCharacterStyle;
58 sal_uInt16 poolId = ObtainPoolId(characterStyle);
59 pClosedLink->mINetFormat.SetVisitedFormatAndId(characterStyle, poolId);
60 pClosedLink->mINetFormat.SetINetFormatAndId(characterStyle, poolId);
61
62 m_ClosedLinks.push_back(std::move(pClosedLink));
63 m_oStartedLink.reset();
64}
65
66sal_uInt16
67ToxLinkProcessor::ObtainPoolId(const OUString& characterStyle) const
68{
69 if (characterStyle.isEmpty()) {
70 return USHRT_MAX;
71 }
72 else {
74 }
75}
76
77
78void
80{
81 for (auto const& clink : m_ClosedLinks)
82 {
83 node.InsertItem(clink->mINetFormat, clink->mStartTextPos, clink->mEndTextPos);
84 }
85}
86
87}
88
89/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static SW_DLLPUBLIC sal_uInt16 GetPoolIdFromUIName(const OUString &rName, SwGetPoolIdFromName)
SwTextNode is a paragraph in the document model.
Definition: ndtxt.hxx:112
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:1305
std::optional< StartedLink > m_oStartedLink
void StartNewLink(sal_Int32 startPosition, const OUString &characterStyle)
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
void CloseLink(sal_Int32 endPosition, const OUString &url, bool bRelative)
Close a link which has been found during processing.
void InsertLinkAttributes(SwTextNode &node)
Insert the found links as attributes to a text node.
#define SAL_INFO_IF(condition, area, stream)
#define SAL_INFO(area, stream)
Dialog to specify the properties of date form field.