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/nmspmap.hxx>
23 #include <xmloff/xmlnmspe.hxx>
26 using namespace ::com::sun::star
;
27 using namespace ::xmloff::token
;
29 class SvXMLSectionListContext
: public SvXMLImportContext
32 SwXMLSectionList
& m_rImport
;
35 SvXMLSectionListContext(SwXMLSectionList
& rImport
,
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
47 SwXMLSectionList
& m_rImport
;
50 SwXMLParentContext(SwXMLSectionList
& rImport
,
52 const OUString
& rLocalName
)
53 : SvXMLImportContext(rImport
, nPrefix
, rLocalName
)
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
);
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
),
100 SwXMLSectionList::~SwXMLSectionList()
105 SvXMLImportContext
*SwXMLSectionList::CreateDocumentContext(
107 const OUString
& rLocalName
,
108 const uno::Reference
<xml::sax::XAttributeList
> & )
110 return new SwXMLParentContext(*this, nPrefix
, rLocalName
);
113 SvXMLSectionListContext::SvXMLSectionListContext(
114 SwXMLSectionList
& rImport
,
116 const OUString
& rLocalName
,
117 const uno::Reference
< xml::sax::XAttributeList
> & ) :
118 SvXMLImportContext ( rImport
, nPrefix
, rLocalName
),
123 SvXMLImportContextRef
SvXMLSectionListContext::CreateChildContext(
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
) ) )
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
);
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
);
152 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */