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;
43using ::com::sun::star::xml::sax::XAttributeList;
44
45
46
48 SvXMLImport& rImport, Reference<XPropertySet> & rPropSet)
49 : SvXMLImportContext(rImport)
50 , rTOCPropertySet(rPropSet)
51 , nOutlineLevel(0)
52{
53}
54
56{
57}
58
60 sal_Int32 /*nElement*/,
61 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
62{
63 // find text:outline-level attribute
64 for( auto& aIter : sax_fastparser::castToFastAttributeList(xAttrList) )
65 {
66 if ( aIter.getToken() == XML_ELEMENT(TEXT, XML_OUTLINE_LEVEL) )
67 {
68 sal_Int32 nTmp;
70 nTmp, aIter.toView(), 1,
71 GetImport().GetTextImport()->GetChapterNumbering()->
72 getCount()))
73 {
74 // API numbers 0..9, we number 1..10
75 nOutlineLevel = nTmp-1;
76 }
77 break;
78 }
79 }
80}
81
83{
84 // if valid...
85 if (nOutlineLevel < 0)
86 return;
87
88 // copy vector into sequence
89 const sal_Int32 nCount = aStyleNames.size();
90 Sequence<OUString> aStyleNamesSequence(nCount);
91 auto aStyleNamesSequenceRange = asNonConstRange(aStyleNamesSequence);
92 for(sal_Int32 i = 0; i < nCount; i++)
93 {
94 aStyleNamesSequenceRange[i] = GetImport().GetStyleDisplayName(
96 aStyleNames[i] );
97 }
98
99 // get index replace
100 Any aAny = rTOCPropertySet->getPropertyValue("LevelParagraphStyles");
101 Reference<XIndexReplace> xIndexReplace;
102 aAny >>= xIndexReplace;
103
104 // set style names
105 xIndexReplace->replaceByIndex(nOutlineLevel, Any(aStyleNamesSequence));
106}
107
108namespace xmloff {
109
111 css::uno::Reference<css::xml::sax::XFastAttributeList> const& xAttrList)
112{
113 for (auto& rIter : sax_fastparser::castToFastAttributeList(xAttrList))
114 {
115 if (rIter.getToken() == XML_ELEMENT(TEXT, XML_STYLE_NAME))
116 {
117 return rIter.toString();
118 }
119 }
120 return OUString();
121}
122
123} // namespace xmloff
124
125css::uno::Reference< css::xml::sax::XFastContextHandler > XMLIndexTOCStylesContext::createFastChildContext(
126 sal_Int32 nElement,
127 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
128{
129 // check for index-source-style
130 if ( nElement == XML_ELEMENT(TEXT, XML_INDEX_SOURCE_STYLE) )
131 {
132 // find text:style-name attribute and record in aStyleNames
133 OUString const styleName(xmloff::GetIndexSourceStyleName(xAttrList));
134 if (!styleName.isEmpty())
135 {
136 aStyleNames.emplace_back(styleName);
137 }
138 }
139
140 // always return default context; we already got the interesting info
141 return new SvXMLImportContext(GetImport());
142}
143
144/* 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:1097
OUString GetIndexSourceStyleName(css::uno::Reference< css::xml::sax::XFastAttributeList > const &xAttrList)
TEXT
#define XML_ELEMENT(prefix, name)
Definition: xmlimp.hxx:97