Line data Source code
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 : #ifndef SW_TOXLINKPROCESSOR_HXX_
11 : #define SW_TOXLINKPROCESSOR_HXX_
12 :
13 : #include "fmtinfmt.hxx"
14 : #include "rtl/ustring.hxx"
15 :
16 : #include <boost/ptr_container/ptr_vector.hpp>
17 :
18 : class SwTxtNode;
19 :
20 : class ToxLinkProcessorTest;
21 :
22 : namespace sw {
23 :
24 : /** A helper class for ToxTextGenerator.
25 : * It collects information about encountered link tokens and allows access in a processed form.
26 : */
27 : class SW_DLLPUBLIC ToxLinkProcessor {
28 : public:
29 20 : ToxLinkProcessor() {}
30 32 : virtual ~ToxLinkProcessor() {}
31 :
32 : void
33 : StartNewLink(sal_Int32 startPosition, const OUString& characterStyle);
34 :
35 : /** Close a link which has been found during processing.
36 : *
37 : * @throw std::runtime_error If there are no open links.
38 : */
39 : void
40 : CloseLink(sal_Int32 endPosition, const OUString& url);
41 :
42 : /** Insert the found links as attributes to a text node */
43 : void
44 : InsertLinkAttributes(SwTxtNode& node);
45 :
46 : private:
47 : /** Obtain the pool id which belongs to a character style.
48 : *
49 : * @internal
50 : * This method is overridden in the unittests. You should not override it yourself.
51 : */
52 : virtual sal_uInt16
53 : ObtainPoolId(const OUString& characterStyle) const;
54 :
55 : /** Information about a started link */
56 54 : struct StartedLink {
57 18 : StartedLink(sal_Int32 startPosition, const OUString& characterStyle) :
58 18 : mStartPosition(startPosition), mCharacterStyle(characterStyle) {
59 18 : }
60 : sal_Int32 mStartPosition;
61 : OUString mCharacterStyle;
62 : };
63 :
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.
66 : */
67 18 : struct ClosedLink {
68 18 : ClosedLink(const OUString& url, sal_Int32 startPosition, sal_Int32 endPosition) :
69 18 : mINetFmt(url, OUString()), mStartTextPos(endPosition), mEndTextPos(startPosition) {
70 18 : }
71 : SwFmtINetFmt mINetFmt;
72 : sal_Int32 mStartTextPos;
73 : sal_Int32 mEndTextPos;
74 : };
75 :
76 : boost::ptr_vector<ClosedLink> mClosedLinks;
77 :
78 : boost::ptr_vector<StartedLink> mStartedLinks;
79 :
80 : friend class ::ToxLinkProcessorTest;
81 : };
82 :
83 : }
84 :
85 : #endif /* SW_TOXLINKPROCESSOR_HXX_ */
86 :
87 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|