LibreOffice Module xmloff (master) 1
XMLIndexSourceBaseContext.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>
24#include <xmloff/xmlictxt.hxx>
25#include <xmloff/xmlimp.hxx>
28#include <xmloff/xmltoken.hxx>
30#include <rtl/ustring.hxx>
31#include <sal/log.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::Any;
39
40
42 SvXMLImport& rImport,
43 Reference<XPropertySet> & rPropSet,
44 UseStyles const eUseStyles)
45: SvXMLImportContext(rImport)
46, m_UseStyles(eUseStyles)
47, bChapterIndex(false)
48, bRelativeTabs(true)
49, rIndexPropertySet(rPropSet)
50{
51}
52
54{
55}
56
58 sal_Int32 /*nElement*/,
59 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
60{
61 // process attributes
62 for( auto& aIter : sax_fastparser::castToFastAttributeList(xAttrList) )
63 ProcessAttribute(aIter);
64}
65
67{
68 switch (aIter.getToken())
69 {
71 if ( IsXMLToken( aIter, XML_CHAPTER ) )
72 {
73 bChapterIndex = true;
74 }
75 break;
76
78 {
79 bool bTmp(false);
80 if (::sax::Converter::convertBool(bTmp, aIter.toView()))
81 {
82 bRelativeTabs = bTmp;
83 }
84 break;
85 }
86
87 default:
88 // unknown attribute -> ignore
89 XMLOFF_WARN_UNKNOWN("xmloff", aIter);
90 break;
91 }
92}
93
95{
96 rIndexPropertySet->setPropertyValue("IsRelativeTabstops", css::uno::Any(bRelativeTabs));
97 rIndexPropertySet->setPropertyValue("CreateFromChapter", css::uno::Any(bChapterIndex));
98}
99
100css::uno::Reference< css::xml::sax::XFastContextHandler > XMLIndexSourceBaseContext::createFastChildContext(
101 sal_Int32 nElement,
102 const css::uno::Reference<css::xml::sax::XFastAttributeList>& xAttrList)
103{
104 SvXMLImportContextRef xContext;
105
106 if (nElement == XML_ELEMENT(TEXT, XML_INDEX_TITLE_TEMPLATE) )
107 {
110 }
111 else if (m_UseStyles == UseStyles::Level
113 {
114 xContext = new XMLIndexTOCStylesContext(GetImport(),
116 }
118 && (nElement == XML_ELEMENT(LO_EXT, XML_INDEX_SOURCE_STYLE)
119 || nElement == XML_ELEMENT(TEXT, XML_INDEX_SOURCE_STYLE)))
120 {
121 OUString const styleName(xmloff::GetIndexSourceStyleName(xAttrList));
122 if (!styleName.isEmpty())
123 {
124 OUString const convertedStyleName(GetImport().GetStyleDisplayName(
126 rIndexPropertySet->setPropertyValue("CreateFromParagraphStyle", css::uno::Any(convertedStyleName));
127 }
128 }
129
130 // else: unknown namespace -> ignore
131
132 return xContext;
133}
134
135/* 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
virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList) 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 ...
css::uno::Reference< css::beans::XPropertySet > & rIndexPropertySet
tab stops relative to margin or indent?
bool bRelativeTabs
chapter-wise or document index?
virtual void SAL_CALL startFastElement(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList) override
virtual ~XMLIndexSourceBaseContext() override
XMLIndexSourceBaseContext(SvXMLImport &rImport, css::uno::Reference< css::beans::XPropertySet > &rPropSet, UseStyles eUseStyles)
virtual void ProcessAttribute(const sax_fastparser::FastAttributeList::FastAttributeIter &aIter)
Import <test:index-source-styles> elements and their children.
static bool convertBool(bool &rBool, std::u16string_view rString)
FastAttributeList & castToFastAttributeList(const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
Handling of tokens in XML:
@ XML_RELATIVE_TAB_STOP_POSITION
Definition: xmltoken.hxx:1623
@ XML_INDEX_SOURCE_STYLES
Definition: xmltoken.hxx:1100
@ XML_INDEX_TITLE_TEMPLATE
Definition: xmltoken.hxx:1102
@ XML_INDEX_SOURCE_STYLE
Definition: xmltoken.hxx:1099
bool IsXMLToken(std::u16string_view rString, enum XMLTokenEnum eToken)
compare eToken to the string
Definition: xmltoken.cxx:3597
OUString GetIndexSourceStyleName(css::uno::Reference< css::xml::sax::XFastAttributeList > const &xAttrList)
TEXT
#define XMLOFF_WARN_UNKNOWN(area, rIter)
Definition: xmlictxt.hxx:114
#define XML_ELEMENT(prefix, name)
Definition: xmlimp.hxx:97