Version 6.1.0.2, tag libreoffice-6.1.0.2
[LibreOffice.git] / sw / source / core / swg / SwXMLSectionList.cxx
blob1ac8c1d083f10d2ed414acb57708634e451cfee8
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/nmspmap.hxx>
23 #include <xmloff/xmlnmspe.hxx>
24 #include <vector>
26 using namespace ::com::sun::star;
27 using namespace ::xmloff::token;
29 class SvXMLSectionListContext : public SvXMLImportContext
31 private:
32 SwXMLSectionList & m_rImport;
34 public:
35 SvXMLSectionListContext(SwXMLSectionList& rImport,
36 sal_uInt16 nPrefix,
37 const OUString& rLocalName,
38 const uno::Reference<xml::sax::XAttributeList> & xAttrList);
39 virtual SvXMLImportContextRef CreateChildContext(sal_uInt16 nPrefix,
40 const OUString& rLocalName,
41 const uno::Reference<xml::sax::XAttributeList> & xAttrList) override;
44 class SwXMLParentContext : public SvXMLImportContext
46 private:
47 SwXMLSectionList & m_rImport;
49 public:
50 SwXMLParentContext(SwXMLSectionList& rImport,
51 sal_uInt16 nPrefix,
52 const OUString& rLocalName)
53 : SvXMLImportContext(rImport, nPrefix, rLocalName)
54 , m_rImport(rImport)
58 virtual SvXMLImportContextRef CreateChildContext(sal_uInt16 nPrefix,
59 const OUString& rLocalName,
60 const uno::Reference<xml::sax::XAttributeList> & xAttrList) override
62 if ((nPrefix == XML_NAMESPACE_OFFICE && IsXMLToken(rLocalName, XML_BODY)) ||
63 (nPrefix == XML_NAMESPACE_TEXT &&
64 ( IsXMLToken(rLocalName, XML_P)
65 || IsXMLToken(rLocalName, XML_H)
66 || IsXMLToken(rLocalName, XML_A)
67 || IsXMLToken(rLocalName, XML_SPAN)
68 || IsXMLToken(rLocalName, XML_SECTION)
69 || IsXMLToken(rLocalName, XML_INDEX_BODY)
70 || IsXMLToken(rLocalName, XML_INDEX_TITLE)
71 || IsXMLToken(rLocalName, XML_INSERTION)
72 || IsXMLToken(rLocalName, XML_DELETION))))
74 return new SvXMLSectionListContext(m_rImport, nPrefix, rLocalName, xAttrList);
76 else
78 return new SwXMLParentContext(m_rImport, nPrefix, rLocalName);
84 SwXMLSectionList::SwXMLSectionList(
85 const uno::Reference< uno::XComponentContext >& rContext,
86 std::vector<OUString> &rNewSectionList)
87 : SvXMLImport(rContext, "")
88 , m_rSectionList(rNewSectionList)
90 // TODO: verify if these should match the same-name constants
91 // in xmloff/source/core/xmlimp.cxx ("_office" and "_office")
92 GetNamespaceMap().Add( "_ooffice",
93 GetXMLToken(XML_N_OFFICE_OOO),
94 XML_NAMESPACE_OFFICE );
95 GetNamespaceMap().Add( "_otext",
96 GetXMLToken(XML_N_TEXT_OOO),
97 XML_NAMESPACE_TEXT );
100 SwXMLSectionList::~SwXMLSectionList()
101 throw()
105 SvXMLImportContext *SwXMLSectionList::CreateDocumentContext(
106 sal_uInt16 nPrefix,
107 const OUString& rLocalName,
108 const uno::Reference<xml::sax::XAttributeList> & )
110 return new SwXMLParentContext(*this, nPrefix, rLocalName);
113 SvXMLSectionListContext::SvXMLSectionListContext(
114 SwXMLSectionList& rImport,
115 sal_uInt16 nPrefix,
116 const OUString& rLocalName,
117 const uno::Reference< xml::sax::XAttributeList > & ) :
118 SvXMLImportContext ( rImport, nPrefix, rLocalName ),
119 m_rImport(rImport)
123 SvXMLImportContextRef SvXMLSectionListContext::CreateChildContext(
124 sal_uInt16 nPrefix,
125 const OUString& rLocalName,
126 const uno::Reference< xml::sax::XAttributeList > & xAttrList )
128 SvXMLImportContext *pContext = nullptr;
130 if (nPrefix == XML_NAMESPACE_TEXT && ( IsXMLToken ( rLocalName, XML_SECTION ) ||
131 IsXMLToken ( rLocalName, XML_BOOKMARK) ) )
133 OUString sName;
134 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
136 for (sal_Int16 i=0; i < nAttrCount; i++)
138 const OUString& rAttrName = xAttrList->getNameByIndex( i );
139 OUString aLocalName;
140 sal_uInt16 nPrefx = m_rImport.GetNamespaceMap().GetKeyByAttrName(rAttrName, &aLocalName);
141 if (XML_NAMESPACE_TEXT == nPrefx && IsXMLToken ( aLocalName, XML_NAME ) )
142 sName = xAttrList->getValueByIndex( i );
144 if ( !sName.isEmpty() )
145 m_rImport.m_rSectionList.push_back(sName);
148 pContext = new SvXMLSectionListContext(m_rImport, nPrefix, rLocalName, xAttrList);
149 return pContext;
152 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */