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