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#include <com/sun/star/beans/XPropertySet.hpp>
22#include <com/sun/star/container/XIndexReplace.hpp>
23#include <xmloff/xmlictxt.hxx>
24#include <xmloff/xmlimp.hxx>
25#include <xmloff/txtimp.hxx>
28#include <xmloff/xmltoken.hxx>
30#include <com/sun/star/uno/Sequence.hxx>
31#include <rtl/ustring.hxx>
32
33
34using namespace ::xmloff::token;
35
36using ::com::sun::star::beans::XPropertySet;
37using ::com::sun::star::uno::Reference;
38using ::com::sun::star::uno::Sequence;
39using ::com::sun::star::uno::Any;
40using ::com::sun::star::container::XIndexReplace;
41using ::com::sun::star::xml::sax::XAttributeList;
42
43
44
46 SvXMLImport& rImport, Reference<XPropertySet> & rPropSet)
47 : SvXMLImportContext(rImport)
48 , rTOCPropertySet(rPropSet)
49 , nOutlineLevel(0)
50{
51}
52
54{
55}
56
58 sal_Int32 /*nElement*/,
59 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
60{
61 // find text:outline-level attribute
62 for( auto& aIter : sax_fastparser::castToFastAttributeList(xAttrList) )
63 {
64 if ( aIter.getToken() == XML_ELEMENT(TEXT, XML_OUTLINE_LEVEL) )
65 {
66 sal_Int32 nTmp;
68 nTmp, aIter.toView(), 1,
69 GetImport().GetTextImport()->GetChapterNumbering()->
70 getCount()))
71 {
72 // API numbers 0..9, we number 1..10
73 nOutlineLevel = nTmp-1;
74 }
75 break;
76 }
77 }
78}
79
81{
82 // if valid...
83 if (nOutlineLevel < 0)
84 return;
85
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++)
91 {
92 aStyleNamesSequenceRange[i] = GetImport().GetStyleDisplayName(
94 aStyleNames[i] );
95 }
96
97 // get index replace
98 Any aAny = rTOCPropertySet->getPropertyValue("LevelParagraphStyles");
99 Reference<XIndexReplace> xIndexReplace;
100 aAny >>= xIndexReplace;
101
102 // set style names
103 xIndexReplace->replaceByIndex(nOutlineLevel, Any(aStyleNamesSequence));
104}
105
106css::uno::Reference< css::xml::sax::XFastContextHandler > XMLIndexTOCStylesContext::createFastChildContext(
107 sal_Int32 nElement,
108 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
109{
110 // check for index-source-style
111 if ( nElement == XML_ELEMENT(TEXT, XML_INDEX_SOURCE_STYLE) )
112 {
113 // find text:style-name attribute and record in aStyleNames
114 for( auto& aIter : sax_fastparser::castToFastAttributeList(xAttrList) )
115 {
116 if ( aIter.getToken() == XML_ELEMENT(TEXT, XML_STYLE_NAME) )
117 {
118 aStyleNames.push_back(aIter.toString());
119 break;
120 }
121 }
122 }
123
124 // always return default context; we already got the interesting info
125 return new SvXMLImportContext(GetImport());
126}
127
128/* 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
TEXT
#define XML_ELEMENT(prefix, name)
Definition: xmlimp.hxx:98