LibreOffice Module xmloff (master) 1
XMLIndexTOCStylesContext.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
21
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>
30#include <xmloff/xmltoken.hxx>
32#include <com/sun/star/uno/Sequence.hxx>
33#include <rtl/ustring.hxx>
34
35
36using namespace ::xmloff::token;
37
38using ::com::sun::star::beans::XPropertySet;
39using ::com::sun::star::uno::Reference;
40using ::com::sun::star::uno::Sequence;
41using ::com::sun::star::uno::Any;
42using ::com::sun::star::container::XIndexReplace;
43
44
45
47 SvXMLImport& rImport, Reference<XPropertySet> & rPropSet)
48 : SvXMLImportContext(rImport)
49 , rTOCPropertySet(rPropSet)
50 , nOutlineLevel(0)
51{
52}
53
55{
56}
57
59 sal_Int32 /*nElement*/,
60 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
61{
62 // find text:outline-level attribute
63 for( auto& aIter : sax_fastparser::castToFastAttributeList(xAttrList) )
64 {
65 if ( aIter.getToken() == XML_ELEMENT(TEXT, XML_OUTLINE_LEVEL) )
66 {
67 sal_Int32 nTmp;
69 nTmp, aIter.toView(), 1,
70 GetImport().GetTextImport()->GetChapterNumbering()->
71 getCount()))
72 {
73 // API numbers 0..9, we number 1..10
74 nOutlineLevel = nTmp-1;
75 }
76 break;
77 }
78 }
79}
80
82{
83 // if valid...
84 if (nOutlineLevel < 0)
85 return;
86
87 // copy vector into sequence
88 const sal_Int32 nCount = aStyleNames.size();
89 Sequence<OUString> aStyleNamesSequence(nCount);
90 auto aStyleNamesSequenceRange = asNonConstRange(aStyleNamesSequence);
91 for(sal_Int32 i = 0; i < nCount; i++)
92 {
93 aStyleNamesSequenceRange[i] = GetImport().GetStyleDisplayName(
95 aStyleNames[i] );
96 }
97
98 // get index replace
99 Any aAny = rTOCPropertySet->getPropertyValue("LevelParagraphStyles");
100 Reference<XIndexReplace> xIndexReplace;
101 aAny >>= xIndexReplace;
102
103 // set style names
104 xIndexReplace->replaceByIndex(nOutlineLevel, Any(aStyleNamesSequence));
105}
106
107namespace xmloff {
108
110 css::uno::Reference<css::xml::sax::XFastAttributeList> const& xAttrList)
111{
112 for (auto& rIter : sax_fastparser::castToFastAttributeList(xAttrList))
113 {
114 if (rIter.getToken() == XML_ELEMENT(TEXT, XML_STYLE_NAME))
115 {
116 return rIter.toString();
117 }
118 }
119 return OUString();
120}
121
122} // namespace xmloff
123
124css::uno::Reference< css::xml::sax::XFastContextHandler > XMLIndexTOCStylesContext::createFastChildContext(
125 sal_Int32 nElement,
126 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
127{
128 // check for index-source-style
129 if ( nElement == XML_ELEMENT(TEXT, XML_INDEX_SOURCE_STYLE) )
130 {
131 // find text:style-name attribute and record in aStyleNames
132 OUString const styleName(xmloff::GetIndexSourceStyleName(xAttrList));
133 if (!styleName.isEmpty())
134 {
135 aStyleNames.emplace_back(styleName);
136 }
137 }
138
139 // always return default context; we already got the interesting info
140 return new SvXMLImportContext(GetImport());
141}
142
143/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
This class deliberately does not support XWeak, to improve performance when loading large documents.
Definition: xmlictxt.hxx:48
SvXMLImport & GetImport()
Definition: xmlictxt.hxx:60
SvXMLImportContext(SvXMLImport &rImport)
A contexts constructor does anything that is required if an element starts.
Definition: xmlictxt.cxx:30
::std::vector< OUString > aStyleNames
style names for this level
virtual ~XMLIndexTOCStylesContext() override
virtual void SAL_CALL endFastElement(sal_Int32 nElement) override
endFastElement is called before a context will be destructed, but after an elements context has been ...
virtual void SAL_CALL startFastElement(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList) override
XMLIndexTOCStylesContext(SvXMLImport &rImport, css::uno::Reference< css::beans::XPropertySet > &rPropSet)
sal_Int32 nOutlineLevel
outline level
css::uno::Reference< css::beans::XPropertySet > & rTOCPropertySet
XPropertySet of the index.
virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList) override
static bool convertNumber(sal_Int32 &rValue, std::u16string_view aString, sal_Int32 nMin=SAL_MIN_INT32, sal_Int32 nMax=SAL_MAX_INT32)
int nCount
int i
FastAttributeList & castToFastAttributeList(const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
Handling of tokens in XML:
@ XML_INDEX_SOURCE_STYLE
Definition: xmltoken.hxx:1099
OUString GetIndexSourceStyleName(css::uno::Reference< css::xml::sax::XFastAttributeList > const &xAttrList)
TEXT
#define XML_ELEMENT(prefix, name)
Definition: xmlimp.hxx:97