LibreOffice Module sw (master) 1
SwXMLSectionList.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 * 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#include <SwXMLSectionList.hxx>
21#include <xmloff/xmlictxt.hxx>
23#include <xmloff/xmltoken.hxx>
24#include <vector>
25
26using namespace ::com::sun::star;
27using namespace ::xmloff::token;
28
29namespace {
30
31class SvXMLSectionListContext : public SvXMLImportContext
32{
33private:
35
36public:
37 SvXMLSectionListContext(SwXMLSectionList& rImport);
38
39 virtual css::uno::Reference<css::xml::sax::XFastContextHandler> SAL_CALL createFastChildContext(
40 sal_Int32 Element,
41 const css::uno::Reference< css::xml::sax::XFastAttributeList > & xAttrList ) override;
42};
43
44class SwXMLParentContext : public SvXMLImportContext
45{
46private:
48
49public:
50 SwXMLParentContext(SwXMLSectionList& rImport)
51 : SvXMLImportContext(rImport)
52 {
53 }
54
55 virtual css::uno::Reference<XFastContextHandler> SAL_CALL createFastChildContext(
56 sal_Int32 Element, const css::uno::Reference< css::xml::sax::XFastAttributeList > & /*xAttrList*/ ) override
57 {
58 if (Element == XML_ELEMENT(OFFICE, XML_BODY) ||
59 Element == XML_ELEMENT(OFFICE_OOO, XML_BODY))
60 {
61 return new SvXMLSectionListContext(GetImport());
62 }
63 if (IsTokenInNamespace(Element, XML_NAMESPACE_TEXT) ||
64 IsTokenInNamespace(Element, XML_NAMESPACE_TEXT_OOO))
65 {
66 auto nToken = Element & TOKEN_MASK;
67 if (nToken == XML_P ||
68 nToken == XML_H ||
69 nToken == XML_A ||
70 nToken == XML_SPAN ||
71 nToken == XML_SECTION ||
72 nToken == XML_INDEX_BODY ||
73 nToken == XML_INDEX_TITLE ||
74 nToken == XML_INSERTION ||
75 nToken == XML_DELETION)
76 return new SvXMLSectionListContext(GetImport());
77 }
78 return new SwXMLParentContext(GetImport());
79 }
80};
81
82}
83
84SwXMLSectionList::SwXMLSectionList(const css::uno::Reference< css::uno::XComponentContext >& rContext, std::vector<OUString> &rNewSectionList)
85: SvXMLImport(rContext, "")
86, m_rSectionList(rNewSectionList)
87{
88}
89
91 noexcept
92{
93}
94
96 sal_Int32 /*Element*/,
97 const css::uno::Reference< css::xml::sax::XFastAttributeList > & /*xAttrList*/ )
98{
99 return new SwXMLParentContext(*this);
100}
101
102SvXMLSectionListContext::SvXMLSectionListContext( SwXMLSectionList& rImport )
103 : SvXMLImportContext ( rImport )
104{
105}
106
107css::uno::Reference<css::xml::sax::XFastContextHandler> SvXMLSectionListContext::createFastChildContext(
108 sal_Int32 Element,
109 const css::uno::Reference< css::xml::sax::XFastAttributeList > & xAttrList )
110{
111 SvXMLImportContext *pContext = nullptr;
112
113 if (Element == XML_ELEMENT(TEXT, XML_SECTION ) ||
114 Element == XML_ELEMENT(TEXT, XML_BOOKMARK) ||
115 Element == XML_ELEMENT(TEXT_OOO, XML_SECTION ) ||
116 Element == XML_ELEMENT(TEXT_OOO, XML_BOOKMARK) )
117 {
118 OUString sName;
119 for (auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList ))
120 if (aIter.getToken() == XML_ELEMENT(TEXT, XML_NAME) ||
121 aIter.getToken() == XML_ELEMENT(TEXT_OOO, XML_NAME))
122 sName = aIter.toString();
123 if ( !sName.isEmpty() )
124 GetImport().m_rSectionList.push_back(sName);
125 }
126
127 pContext = new SvXMLSectionListContext(GetImport());
128 return pContext;
129}
130
131/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SvXMLImport & GetImport()
virtual css::uno::Reference< XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 Element, const css::uno::Reference< css::xml::sax::XFastAttributeList > &Attribs) override
SwXMLSectionList(const css::uno::Reference< css::uno::XComponentContext > &rContext, std::vector< OUString > &rNewSectionList)
virtual ~SwXMLSectionList() noexcept override
virtual SvXMLImportContext * CreateFastContext(sal_Int32 Element, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList) override
OUString sName
FastAttributeList & castToFastAttributeList(const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
DefTokenId nToken
#define XML_ELEMENT(prefix, name)
constexpr bool IsTokenInNamespace(sal_Int32 nToken, sal_uInt16 nNamespacePrefix)
constexpr sal_Int32 TOKEN_MASK