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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <SwXMLSectionList.hxx>
21 #include <xmloff/xmlictxt.hxx>
22 #include <xmloff/xmlnamespace.hxx>
23 #include <xmloff/xmltoken.hxx>
26 using namespace ::com::sun::star
;
27 using namespace ::xmloff::token
;
31 class SvXMLSectionListContext
: public SvXMLImportContext
34 SwXMLSectionList
& GetImport() { return static_cast<SwXMLSectionList
&>(SvXMLImportContext::GetImport()); }
37 SvXMLSectionListContext(SwXMLSectionList
& rImport
);
39 virtual css::uno::Reference
<css::xml::sax::XFastContextHandler
> SAL_CALL
createFastChildContext(
41 const css::uno::Reference
< css::xml::sax::XFastAttributeList
> & xAttrList
) override
;
44 class SwXMLParentContext
: public SvXMLImportContext
47 SwXMLSectionList
& GetImport() { return static_cast<SwXMLSectionList
&>(SvXMLImportContext::GetImport()); }
50 SwXMLParentContext(SwXMLSectionList
& rImport
)
51 : SvXMLImportContext(rImport
)
55 virtual css::uno::Reference
<XFastContextHandler
> SAL_CALL
createFastChildContext(
56 sal_Int32 Element
, const css::uno::Reference
< css::xml::sax::XFastAttributeList
> & /*xAttrList*/ ) override
58 if (Element
== XML_ELEMENT(OFFICE
, XML_BODY
) ||
59 Element
== XML_ELEMENT(OFFICE_OOO
, XML_BODY
))
61 return new SvXMLSectionListContext(GetImport());
63 if (IsTokenInNamespace(Element
, XML_NAMESPACE_TEXT
) ||
64 IsTokenInNamespace(Element
, XML_NAMESPACE_TEXT_OOO
))
66 auto nToken
= Element
& TOKEN_MASK
;
67 if (nToken
== XML_P
||
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());
78 return new SwXMLParentContext(GetImport());
84 SwXMLSectionList::SwXMLSectionList(const css::uno::Reference
< css::uno::XComponentContext
>& rContext
, std::vector
<OUString
> &rNewSectionList
)
85 : SvXMLImport(rContext
, "")
86 , m_rSectionList(rNewSectionList
)
90 SwXMLSectionList::~SwXMLSectionList()
95 SvXMLImportContext
* SwXMLSectionList::CreateFastContext(
96 sal_Int32
/*Element*/,
97 const css::uno::Reference
< css::xml::sax::XFastAttributeList
> & /*xAttrList*/ )
99 return new SwXMLParentContext(*this);
102 SvXMLSectionListContext::SvXMLSectionListContext( SwXMLSectionList
& rImport
)
103 : SvXMLImportContext ( rImport
)
107 css::uno::Reference
<css::xml::sax::XFastContextHandler
> SvXMLSectionListContext::createFastChildContext(
109 const css::uno::Reference
< css::xml::sax::XFastAttributeList
> & xAttrList
)
111 SvXMLImportContext
*pContext
= nullptr;
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
) )
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
);
127 pContext
= new SvXMLSectionListContext(GetImport());
131 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */