tdf#154285 Check upper bound of arguments in SbRtl_Minute function
[LibreOffice.git] / xmloff / source / text / XMLIndexTOCStylesContext.cxx
blob7f6eb6f6a18070f85e6217b4c05639cd2e029af1
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 "XMLIndexTOCStylesContext.hxx"
22 #include "XMLIndexSourceBaseContext.hxx"
23 #include <com/sun/star/beans/XPropertySet.hpp>
24 #include <com/sun/star/container/XIndexReplace.hpp>
25 #include <xmloff/xmlictxt.hxx>
26 #include <xmloff/xmlimp.hxx>
27 #include <xmloff/txtimp.hxx>
28 #include <xmloff/xmlnamespace.hxx>
29 #include <xmloff/xmltoken.hxx>
30 #include <sax/tools/converter.hxx>
31 #include <com/sun/star/uno/Sequence.hxx>
32 #include <rtl/ustring.hxx>
35 using namespace ::xmloff::token;
37 using ::com::sun::star::beans::XPropertySet;
38 using ::com::sun::star::uno::Reference;
39 using ::com::sun::star::uno::Sequence;
40 using ::com::sun::star::uno::Any;
41 using ::com::sun::star::container::XIndexReplace;
45 XMLIndexTOCStylesContext::XMLIndexTOCStylesContext(
46 SvXMLImport& rImport, Reference<XPropertySet> & rPropSet)
47 : SvXMLImportContext(rImport)
48 , rTOCPropertySet(rPropSet)
49 , nOutlineLevel(0)
53 XMLIndexTOCStylesContext::~XMLIndexTOCStylesContext()
57 void XMLIndexTOCStylesContext::startFastElement(
58 sal_Int32 /*nElement*/,
59 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
61 // find text:outline-level attribute
62 for( auto& aIter : sax_fastparser::castToFastAttributeList(xAttrList) )
64 if ( aIter.getToken() == XML_ELEMENT(TEXT, XML_OUTLINE_LEVEL) )
66 sal_Int32 nTmp;
67 if (::sax::Converter::convertNumber(
68 nTmp, aIter.toView(), 1,
69 GetImport().GetTextImport()->GetChapterNumbering()->
70 getCount()))
72 // API numbers 0..9, we number 1..10
73 nOutlineLevel = nTmp-1;
75 break;
80 void XMLIndexTOCStylesContext::endFastElement(sal_Int32 )
82 // if valid...
83 if (nOutlineLevel < 0)
84 return;
86 // copy vector into sequence
87 const sal_Int32 nCount = aStyleNames.size();
88 Sequence<OUString> aStyleNamesSequence(nCount);
89 auto aStyleNamesSequenceRange = asNonConstRange(aStyleNamesSequence);
90 for(sal_Int32 i = 0; i < nCount; i++)
92 aStyleNamesSequenceRange[i] = GetImport().GetStyleDisplayName(
93 XmlStyleFamily::TEXT_PARAGRAPH,
94 aStyleNames[i] );
97 // get index replace
98 Any aAny = rTOCPropertySet->getPropertyValue(u"LevelParagraphStyles"_ustr);
99 Reference<XIndexReplace> xIndexReplace;
100 aAny >>= xIndexReplace;
102 // set style names
103 xIndexReplace->replaceByIndex(nOutlineLevel, Any(aStyleNamesSequence));
106 namespace xmloff {
108 OUString GetIndexSourceStyleName(
109 css::uno::Reference<css::xml::sax::XFastAttributeList> const& xAttrList)
111 for (auto& rIter : sax_fastparser::castToFastAttributeList(xAttrList))
113 if (rIter.getToken() == XML_ELEMENT(TEXT, XML_STYLE_NAME))
115 return rIter.toString();
118 return OUString();
121 } // namespace xmloff
123 css::uno::Reference< css::xml::sax::XFastContextHandler > XMLIndexTOCStylesContext::createFastChildContext(
124 sal_Int32 nElement,
125 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
127 // check for index-source-style
128 if ( nElement == XML_ELEMENT(TEXT, XML_INDEX_SOURCE_STYLE) )
130 // find text:style-name attribute and record in aStyleNames
131 OUString const styleName(xmloff::GetIndexSourceStyleName(xAttrList));
132 if (!styleName.isEmpty())
134 aStyleNames.emplace_back(styleName);
138 // always return default context; we already got the interesting info
139 return new SvXMLImportContext(GetImport());
142 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */