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 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 
44 class SwXMLParentContext : public SvXMLImportContext
45 {
46 private:
48 
49 public:
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(TEXT, XML_P) ||
60  Element == XML_ELEMENT(TEXT, XML_H) ||
61  Element == XML_ELEMENT(TEXT, XML_A) ||
62  Element == XML_ELEMENT(TEXT, XML_SPAN) ||
63  Element == XML_ELEMENT(TEXT, XML_SECTION) ||
64  Element == XML_ELEMENT(TEXT, XML_INDEX_BODY) ||
65  Element == XML_ELEMENT(TEXT, XML_INDEX_TITLE) ||
66  Element == XML_ELEMENT(TEXT, XML_INSERTION) ||
67  Element == XML_ELEMENT(TEXT, XML_DELETION))
68  {
69  return new SvXMLSectionListContext(GetImport());
70  }
71  else
72  {
73  return new SwXMLParentContext(GetImport());
74  }
75  }
76 };
77 
78 }
79 
80 SwXMLSectionList::SwXMLSectionList(const css::uno::Reference< css::uno::XComponentContext >& rContext, std::vector<OUString> &rNewSectionList)
81 : SvXMLImport(rContext, "")
82 , m_rSectionList(rNewSectionList)
83 {
84  // TODO: verify if these should match the same-name constants
85  // in xmloff/source/core/xmlimp.cxx ("_office" and "_office")
86  GetNamespaceMap().Add( "_ooffice",
88  XML_NAMESPACE_OFFICE );
89  GetNamespaceMap().Add( "_otext",
91  XML_NAMESPACE_TEXT );
92 }
93 
95  throw()
96 {
97 }
98 
100  sal_Int32 /*Element*/,
101  const css::uno::Reference< css::xml::sax::XFastAttributeList > & /*xAttrList*/ )
102 {
103  return new SwXMLParentContext(*this);
104 }
105 
106 SvXMLSectionListContext::SvXMLSectionListContext( SwXMLSectionList& rImport )
107  : SvXMLImportContext ( rImport )
108 {
109 }
110 
111 css::uno::Reference<css::xml::sax::XFastContextHandler> SvXMLSectionListContext::createFastChildContext(
112  sal_Int32 Element,
113  const css::uno::Reference< css::xml::sax::XFastAttributeList > & xAttrList )
114 {
115  SvXMLImportContext *pContext = nullptr;
116 
117  if (Element == XML_ELEMENT(TEXT, XML_SECTION ) ||
118  Element == XML_ELEMENT(TEXT, XML_BOOKMARK) )
119  {
120  sax_fastparser::FastAttributeList *pAttribList =
122 
123  OUString sName;
124  for (auto &aIter : *pAttribList)
125  if (aIter.getToken() == (XML_NAMESPACE_TEXT | XML_NAME))
126  sName = aIter.toString();
127  if ( !sName.isEmpty() )
128  GetImport().m_rSectionList.push_back(sName);
129  }
130 
131  pContext = new SvXMLSectionListContext(GetImport());
132  return pContext;
133 }
134 
135 /* 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)
XML_NAME
SvXMLImport & GetImport()
XML_N_TEXT_OOO
SvXMLNamespaceMap & GetNamespaceMap()
virtual ~SwXMLSectionList() override
const char * sName
static FastAttributeList * castToFastAttributeList(const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
XML_N_OFFICE_OOO
const OUString & GetXMLToken(enum XMLTokenEnum eToken)
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)
sal_uInt16 Add(const OUString &rPrefix, const OUString &rName, sal_uInt16 nKey=XML_NAMESPACE_UNKNOWN)