LibreOffice Module xmloff (master) 1
XMLFootnoteConfigurationImportContext.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
20
22
23#include <rtl/ustring.hxx>
24#include <rtl/ustrbuf.hxx>
25
27
30#include <xmloff/xmltoken.hxx>
31#include <xmloff/xmlement.hxx>
32
33#include <xmloff/families.hxx>
34#include <xmloff/xmluconv.hxx>
35#include <xmloff/xmlimp.hxx>
36#include <com/sun/star/frame/XModel.hpp>
37#include <com/sun/star/xml/sax/XAttributeList.hpp>
38#include <com/sun/star/beans/XPropertySet.hpp>
39#include <com/sun/star/text/XFootnotesSupplier.hpp>
40#include <com/sun/star/text/XEndnotesSupplier.hpp>
41#include <com/sun/star/text/FootnoteNumbering.hpp>
42#include <com/sun/star/style/NumberingType.hpp>
43
44
45using namespace ::com::sun::star::text;
46using namespace ::com::sun::star::beans;
47using namespace ::com::sun::star::uno;
48using namespace ::com::sun::star::style;
49using namespace ::com::sun::star::xml::sax;
50using namespace ::xmloff::token;
51
52
53// XMLFootnoteConfigHelper
54
55namespace {
56
58class XMLFootnoteConfigHelper : public SvXMLImportContext
59{
60 OUStringBuffer sBuffer;
62 bool bIsBegin;
63
64public:
65
66 XMLFootnoteConfigHelper(
67 SvXMLImport& rImport,
69 bool bBegin);
70
71 virtual void SAL_CALL endFastElement(sal_Int32 nElement) override;
72
73 virtual void SAL_CALL characters( const OUString& rChars ) override;
74};
75
76}
77
78XMLFootnoteConfigHelper::XMLFootnoteConfigHelper(
79 SvXMLImport& rImport,
81 bool bBegin)
82: SvXMLImportContext(rImport)
83, rConfig(rConfigImport)
84, bIsBegin(bBegin)
85{
86}
87
88void XMLFootnoteConfigHelper::endFastElement(sal_Int32 )
89{
90 if (bIsBegin)
91 {
92 rConfig.SetBeginNotice(sBuffer.makeStringAndClear());
93 }
94 else
95 {
96 rConfig.SetEndNotice(sBuffer.makeStringAndClear());
97 }
98// rConfig = NULL; // import contexts are ref-counted
99}
100
101void XMLFootnoteConfigHelper::characters( const OUString& rChars )
102{
103 sBuffer.append(rChars);
104}
105
106
107// XMLFootnoteConfigurationImportContext
108
109constexpr OUStringLiteral gsPropertyAnchorCharStyleName(u"AnchorCharStyleName");
110constexpr OUStringLiteral gsPropertyCharStyleName(u"CharStyleName");
111constexpr OUStringLiteral gsPropertyNumberingType(u"NumberingType");
112constexpr OUStringLiteral gsPropertyPageStyleName(u"PageStyleName");
113constexpr OUStringLiteral gsPropertyParagraphStyleName(u"ParaStyleName");
114constexpr OUStringLiteral gsPropertyPrefix(u"Prefix");
115constexpr OUStringLiteral gsPropertyStartAt(u"StartAt");
116constexpr OUStringLiteral gsPropertySuffix(u"Suffix");
117constexpr OUStringLiteral gsPropertyPositionEndOfDoc(u"PositionEndOfDoc");
118constexpr OUStringLiteral gsPropertyFootnoteCounting(u"FootnoteCounting");
119constexpr OUStringLiteral gsPropertyEndNotice(u"EndNotice");
120constexpr OUStringLiteral gsPropertyBeginNotice(u"BeginNotice");
121
123 SvXMLImport& rImport,
124 sal_Int32 /*nElement*/,
125 const Reference<XFastAttributeList> & xAttrList)
127, sNumFormat("1")
128, sNumSync("false")
129, nOffset(0)
130, nNumbering(FootnoteNumbering::PER_PAGE)
131, bPosition(false)
132, bIsEndnote(false)
133{
134 for (auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList ))
135 {
136 if( aIter.getToken() == XML_ELEMENT(TEXT, XML_NOTE_CLASS) )
137 {
138 if( IsXMLToken(aIter, XML_ENDNOTE ) )
139 {
140 bIsEndnote = true;
142 }
143 break;
144 }
145 }
146
147}
149{
150}
151
153{
154 { XML_PAGE, FootnoteNumbering::PER_PAGE },
155 { XML_CHAPTER, FootnoteNumbering::PER_CHAPTER },
156 { XML_DOCUMENT, FootnoteNumbering::PER_DOCUMENT },
157 { XML_TOKEN_INVALID, 0 },
158};
159
161 const OUString& rValue )
162{
163 switch (nElement)
164 {
166 sCitationStyle = rValue;
167 break;
169 sAnchorStyle = rValue;
170 break;
172 sDefaultStyle = rValue;
173 break;
175 sPageStyle = rValue;
176 break;
178 case XML_ELEMENT(TEXT, XML_OFFSET): // for backwards compatibility with SRC630 & earlier
179 {
180 sal_Int32 nTmp;
181 if (::sax::Converter::convertNumber(nTmp, rValue))
182 {
183 nOffset = static_cast<sal_uInt16>(nTmp);
184 }
185 break;
186 }
188 case XML_ELEMENT(TEXT, XML_NUM_PREFIX): // for backwards compatibility with SRC630 & earlier
189 sPrefix = rValue;
190 break;
192 case XML_ELEMENT(TEXT, XML_NUM_SUFFIX): // for backwards compatibility with SRC630 & earlier
193 sSuffix = rValue;
194 break;
196 sNumFormat = rValue;
197 break;
199 sNumSync = rValue;
200 break;
202 {
205 break;
206 }
208 bPosition = IsXMLToken( rValue, XML_DOCUMENT );
209 break;
210 default:
211 ; // ignore
212 }
213}
214
215css::uno::Reference< css::xml::sax::XFastContextHandler > XMLFootnoteConfigurationImportContext::createFastChildContext(
216 sal_Int32 nElement,
217 const css::uno::Reference< css::xml::sax::XFastAttributeList >& )
218{
219 css::uno::Reference< css::xml::sax::XFastContextHandler > xContext;
220
221 if (bIsEndnote)
222 return nullptr;
223
224 switch (nElement)
225 {
227 xContext = new XMLFootnoteConfigHelper(GetImport(), *this, false);
228 break;
230 xContext = new XMLFootnoteConfigHelper(GetImport(), *this, true);
231 break;
232 }
233
234 return xContext;
235}
236
237// Rename method <CreateAndInsertLate(..)> to <Finish(..)> (#i40597#)
239{
240
241 if (!bOverwrite)
242 return;
243
244 if (bIsEndnote)
245 {
246 Reference<XEndnotesSupplier> xSupplier(
247 GetImport().GetModel(), UNO_QUERY);
248 if (xSupplier.is())
249 {
250 ProcessSettings(xSupplier->getEndnoteSettings());
251 }
252 }
253 else
254 {
255 Reference<XFootnotesSupplier> xSupplier(
256 GetImport().GetModel(), UNO_QUERY);
257 if (xSupplier.is())
258 {
259 ProcessSettings(xSupplier->getFootnoteSettings());
260 }
261 }
262 // else: ignore (there's only one configuration, so we can only overwrite)
263}
264
266 const Reference<XPropertySet> & rConfig)
267{
268 Any aAny;
269
270 if (!sCitationStyle.isEmpty())
271 {
272 aAny <<= GetImport().GetStyleDisplayName(
274 rConfig->setPropertyValue(gsPropertyCharStyleName, aAny);
275 }
276
277 if (!sAnchorStyle.isEmpty())
278 {
279 aAny <<= GetImport().GetStyleDisplayName(
281 rConfig->setPropertyValue(gsPropertyAnchorCharStyleName, aAny);
282 }
283
284 if (!sPageStyle.isEmpty())
285 {
286 aAny <<= GetImport().GetStyleDisplayName(
288 rConfig->setPropertyValue(gsPropertyPageStyleName, aAny);
289 }
290
291 if (!sDefaultStyle.isEmpty())
292 {
293 aAny <<= GetImport().GetStyleDisplayName(
295 rConfig->setPropertyValue(gsPropertyParagraphStyleName, aAny);
296 }
297
298 rConfig->setPropertyValue(gsPropertyPrefix, Any(sPrefix));
299
300 rConfig->setPropertyValue(gsPropertySuffix, Any(sSuffix));
301
302 sal_Int16 nNumType = NumberingType::ARABIC;
303 GetImport().GetMM100UnitConverter().convertNumFormat( nNumType, sNumFormat,
304 sNumSync );
305 // #i61399: Corrupt file? It contains "Bullet" as numbering style for footnotes.
306 // Okay, even it seems to be corrupt, we will oversee this and set the style to ARABIC
307 if( NumberingType::CHAR_SPECIAL == nNumType )
308 nNumType = NumberingType::ARABIC;
309
310 rConfig->setPropertyValue(gsPropertyNumberingType, Any(nNumType));
311
312 rConfig->setPropertyValue(gsPropertyStartAt, Any(nOffset));
313
314 if (!bIsEndnote)
315 {
316 rConfig->setPropertyValue(gsPropertyPositionEndOfDoc, Any(bPosition));
317 rConfig->setPropertyValue(gsPropertyFootnoteCounting, Any(nNumbering));
318 rConfig->setPropertyValue(gsPropertyEndNotice, Any(sEndNotice));
319 rConfig->setPropertyValue(gsPropertyBeginNotice, Any(sBeginNotice));
320 }
321}
322
324 const OUString& sText)
325{
326 sBeginNotice = sText;
327}
328
330 const OUString& sText)
331{
332 sEndNotice = sText;
333}
334
335/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
constexpr OUStringLiteral gsPropertyNumberingType(u"NumberingType")
constexpr OUStringLiteral gsPropertySuffix(u"Suffix")
constexpr OUStringLiteral gsPropertyPageStyleName(u"PageStyleName")
constexpr OUStringLiteral gsPropertyBeginNotice(u"BeginNotice")
constexpr OUStringLiteral gsPropertyStartAt(u"StartAt")
SvXMLEnumMapEntry< sal_Int16 > const aFootnoteNumberingMap[]
constexpr OUStringLiteral gsPropertyPositionEndOfDoc(u"PositionEndOfDoc")
constexpr OUStringLiteral gsPropertyCharStyleName(u"CharStyleName")
constexpr OUStringLiteral gsPropertyAnchorCharStyleName(u"AnchorCharStyleName")
constexpr OUStringLiteral gsPropertyPrefix(u"Prefix")
constexpr OUStringLiteral gsPropertyParagraphStyleName(u"ParaStyleName")
constexpr OUStringLiteral gsPropertyEndNotice(u"EndNotice")
constexpr OUStringLiteral gsPropertyFootnoteCounting(u"FootnoteCounting")
This class deliberately does not support XWeak, to improve performance when loading large documents.
Definition: xmlictxt.hxx:48
virtual void SAL_CALL endFastElement(sal_Int32 Element) override
endFastElement is called before a context will be destructed, but after an elements context has been ...
Definition: xmlictxt.cxx:40
SvXMLImport & GetImport()
Definition: xmlictxt.hxx:60
virtual void SAL_CALL characters(const OUString &aChars) override
This method is called for all characters that are contained in the current element.
Definition: xmlictxt.cxx:70
void SetFamily(XmlStyleFamily nSet)
Definition: xmlstyle.hxx:63
static bool convertEnum(EnumT &rEnum, std::u16string_view rValue, const SvXMLEnumMapEntry< EnumT > *pMap)
convert string to enum using given enum map, if the enum is not found in the map, this method will re...
Definition: xmluconv.hxx:145
import footnote and endnote configuration elements
virtual void Finish(bool bOverwrite) override
set configuration at document; calls ProcessSettings
void SetEndNotice(const OUString &sText)
for helper class: set end notice
void ProcessSettings(const css::uno::Reference< css::beans::XPropertySet > &rConfig)
set configuration at document
virtual void SetAttribute(sal_Int32 nElement, const OUString &rValue) override
parse attributes
virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &AttrList) override
for footnotes, also parse begin and end notices
XMLFootnoteConfigurationImportContext(SvXMLImport &rImport, sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
void SetBeginNotice(const OUString &sText)
for helper class: set begin notice
static bool convertNumber(sal_Int32 &rValue, std::u16string_view aString, sal_Int32 nMin=SAL_MIN_INT32, sal_Int32 nMax=SAL_MAX_INT32)
XmlStyleFamily
Definition: families.hxx:50
sal_Int16 nNumType
FastAttributeList & castToFastAttributeList(const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
Handling of tokens in XML:
@ XML_DEFAULT_STYLE_NAME
Definition: xmltoken.hxx:654
@ XML_CITATION_BODY_STYLE_NAME
Definition: xmltoken.hxx:440
@ XML_START_NUMBERING_AT
Definition: xmltoken.hxx:1842
@ XML_FOOTNOTE_CONTINUATION_NOTICE_FORWARD
Definition: xmltoken.hxx:920
@ XML_FOOTNOTES_POSITION
Definition: xmltoken.hxx:925
@ XML_FOOTNOTE_CONTINUATION_NOTICE_BACKWARD
Definition: xmltoken.hxx:919
@ XML_CITATION_STYLE_NAME
Definition: xmltoken.hxx:441
bool IsXMLToken(std::u16string_view rString, enum XMLTokenEnum eToken)
compare eToken to the string
Definition: xmltoken.cxx:3597
TEXT
#define XML_ELEMENT(prefix, name)
Definition: xmlimp.hxx:97