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