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 #pragma once
21 
22 #include <xmloff/xmlimp.hxx>
23 #include <xmloff/xmlnamespace.hxx>
24 #include <xmloff/xmltkmap.hxx>
25 #include <com/sun/star/xml/sax/FastToken.hpp>
26 #include <sax/fastattribs.hxx>
27 
28 namespace com::sun::star::xml::sax { class XFastTokenHandler; }
29 
30 using namespace css::xml::sax;
31 using namespace xmloff::token;
32 
33 class SwXMLTextBlocks;
34 class SwXMLBlockListImport final : public SvXMLImport
35 {
36 private:
37     SwXMLTextBlocks &m_rBlockList;
38 
39     // This method is called after the namespace map has been updated, but
40     // before a context for the current element has been pushed.
41     virtual SvXMLImportContext* CreateFastContext( sal_Int32 Element,
42         const css::uno::Reference< css::xml::sax::XFastAttributeList > & xAttrList ) override;
43 
44 public:
45     SwXMLBlockListImport(
46         const css::uno::Reference< css::uno::XComponentContext >& rContext,
47         SwXMLTextBlocks &rBlocks );
48 
getBlockList()49     SwXMLTextBlocks& getBlockList()
50     {
51         return m_rBlockList;
52     }
53     virtual ~SwXMLBlockListImport()
54         noexcept override;
55 };
56 
57 class SwXMLTextBlockImport final : public SvXMLImport
58 {
59     // This method is called after the namespace map has been updated, but
60     // before a context for the current element has been pushed.
61     virtual SvXMLImportContext* CreateFastContext( sal_Int32 Element,
62         const css::uno::Reference< css::xml::sax::XFastAttributeList > & xAttrList ) override;
63 
64 public:
65     bool m_bTextOnly;
66     OUString &m_rText;
67     SwXMLTextBlockImport(
68         const css::uno::Reference< css::uno::XComponentContext >& rContext,
69         OUString &rNewText, bool bNewTextOnly );
70 
71     virtual ~SwXMLTextBlockImport()
72         noexcept override;
73     virtual void SAL_CALL endDocument() override;
74 };
75 
76 enum SwXMLTextBlockToken : sal_Int32
77 {
78     OFFICE_BODY = FastToken::NAMESPACE | XML_NAMESPACE_OFFICE | XML_BODY,
79     OFFICE_TEXT = FastToken::NAMESPACE | XML_NAMESPACE_OFFICE | XML_TEXT,
80     OFFICE_DOCUMENT = FastToken::NAMESPACE | XML_NAMESPACE_OFFICE | XML_DOCUMENT,
81     OFFICE_DOCUMENT_CONTENT = FastToken::NAMESPACE | XML_NAMESPACE_OFFICE | XML_DOCUMENT_CONTENT,
82     TEXT_P = FastToken::NAMESPACE | XML_NAMESPACE_TEXT | XML_P
83 };
84 
85 class SwXMLTextBlockTokenHandler final :
86         public sax_fastparser::FastTokenHandlerBase
87 {
88 public:
89     SwXMLTextBlockTokenHandler();
90     virtual ~SwXMLTextBlockTokenHandler() override;
91 
92     //XFastTokenHandler
93     sal_Int32 SAL_CALL getTokenFromUTF8( const css::uno::Sequence< sal_Int8 >& Identifier ) override;
94     css::uno::Sequence< sal_Int8 > SAL_CALL getUTF8Identifier( sal_Int32 Token ) override;
95 
96     //Much fast direct C++ shortcut to the method that matters
97     virtual sal_Int32 getTokenDirect( const char *pTag, sal_Int32 nLength ) const override;
98 };
99 
100 enum SwXMLBlockListToken : sal_Int32
101 {
102     ABBREVIATED_NAME = FastToken::NAMESPACE | XML_NAMESPACE_BLOCKLIST | XML_ABBREVIATED_NAME,
103     BLOCK = FastToken::NAMESPACE | XML_NAMESPACE_BLOCKLIST | XML_BLOCK,
104     BLOCK_LIST = FastToken::NAMESPACE | XML_NAMESPACE_BLOCKLIST | XML_BLOCK_LIST,
105     LIST_NAME = FastToken::NAMESPACE | XML_NAMESPACE_BLOCKLIST | XML_LIST_NAME,
106     NAME = FastToken::NAMESPACE | XML_NAMESPACE_BLOCKLIST | XML_NAME,
107     PACKAGE_NAME = FastToken::NAMESPACE | XML_NAMESPACE_BLOCKLIST | XML_PACKAGE_NAME,
108     UNFORMATTED_TEXT = FastToken::NAMESPACE | XML_NAMESPACE_BLOCKLIST | XML_UNFORMATTED_TEXT
109 };
110 
111 class SwXMLBlockListTokenHandler final :
112         public sax_fastparser::FastTokenHandlerBase
113 {
114 public:
115     SwXMLBlockListTokenHandler();
116     virtual ~SwXMLBlockListTokenHandler() override;
117 
118     //XFastTokenHandler
119     sal_Int32 SAL_CALL getTokenFromUTF8( const css::uno::Sequence< sal_Int8 >& Identifier ) override;
120     css::uno::Sequence< sal_Int8 > SAL_CALL getUTF8Identifier( sal_Int32 Token ) override;
121 
122     //Much fast direct C++ shortcut to the method that matters
123     virtual sal_Int32 getTokenDirect( const char *pTag, sal_Int32 nLength ) const override;
124 };
125 
126 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
127