1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
10 #ifndef SW_TOXLINKPROCESSOR_HXX_
11 #define SW_TOXLINKPROCESSOR_HXX_
13 #include "fmtinfmt.hxx"
14 #include "rtl/ustring.hxx"
16 #include <boost/ptr_container/ptr_vector.hpp>
20 class ToxLinkProcessorTest
;
24 /** A helper class for ToxTextGenerator.
25 * It collects information about encountered link tokens and allows access in a processed form.
27 class ToxLinkProcessor
{
30 virtual ~ToxLinkProcessor() {}
33 StartNewLink(sal_Int32 startPosition
, const OUString
& characterStyle
);
35 /** Close a link which has been found during processing.
37 * @throw std::runtime_error If there are no open links.
40 CloseLink(sal_Int32 endPosition
, const OUString
& url
);
42 /** Insert the found links as attributes to a text node */
44 InsertLinkAttributes(SwTextNode
& node
);
47 /** Obtain the pool id which belongs to a character style.
50 * This method is overridden in the unittests. You should not override it yourself.
53 ObtainPoolId(const OUString
& characterStyle
) const;
55 /** Information about a started link */
57 StartedLink(sal_Int32 startPosition
, const OUString
& characterStyle
) :
58 mStartPosition(startPosition
), mCharacterStyle(characterStyle
) {
60 sal_Int32 mStartPosition
;
61 OUString mCharacterStyle
;
64 /** A link that has been encountered while parsing a tox.
65 * A link is closed if it has both a start and an end token.
68 ClosedLink(const OUString
& url
, sal_Int32 startPosition
, sal_Int32 endPosition
) :
69 mINetFormat(url
, OUString()), mStartTextPos(endPosition
), mEndTextPos(startPosition
) {
71 SwFormatINetFormat mINetFormat
;
72 sal_Int32 mStartTextPos
;
73 sal_Int32 mEndTextPos
;
76 boost::ptr_vector
<ClosedLink
> mClosedLinks
;
78 boost::ptr_vector
<StartedLink
> mStartedLinks
;
80 friend class ::ToxLinkProcessorTest
;
85 #endif /* SW_TOXLINKPROCESSOR_HXX_ */
87 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */