nss: upgrade to release 3.73
[LibreOffice.git] / xmloff / source / text / XMLFootnoteConfigurationImportContext.cxx
blobd4415ff29c0449ad0ba62fb4aec5ec28a7e7d7de
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include <XMLFootnoteConfigurationImportContext.hxx>
23 #include <rtl/ustring.hxx>
24 #include <rtl/ustrbuf.hxx>
26 #include <sax/tools/converter.hxx>
28 #include <xmloff/namespacemap.hxx>
29 #include <xmloff/xmlnamespace.hxx>
30 #include <xmloff/xmltoken.hxx>
31 #include <xmloff/xmlement.hxx>
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>
45 using namespace ::com::sun::star::text;
46 using namespace ::com::sun::star::beans;
47 using namespace ::com::sun::star::uno;
48 using namespace ::com::sun::star::style;
49 using namespace ::com::sun::star::xml::sax;
50 using namespace ::xmloff::token;
53 // XMLFootnoteConfigHelper
55 namespace {
57 /// local helper class for import of quo-vadis and ergo-sum elements
58 class XMLFootnoteConfigHelper : public SvXMLImportContext
60 OUStringBuffer sBuffer;
61 XMLFootnoteConfigurationImportContext& rConfig;
62 bool bIsBegin;
64 public:
66 XMLFootnoteConfigHelper(
67 SvXMLImport& rImport,
68 XMLFootnoteConfigurationImportContext& rConfigImport,
69 bool bBegin);
71 virtual void SAL_CALL endFastElement(sal_Int32 nElement) override;
73 virtual void SAL_CALL characters( const OUString& rChars ) override;
78 XMLFootnoteConfigHelper::XMLFootnoteConfigHelper(
79 SvXMLImport& rImport,
80 XMLFootnoteConfigurationImportContext& rConfigImport,
81 bool bBegin)
82 : SvXMLImportContext(rImport)
83 , sBuffer()
84 , rConfig(rConfigImport)
85 , bIsBegin(bBegin)
89 void XMLFootnoteConfigHelper::endFastElement(sal_Int32 )
91 if (bIsBegin)
93 rConfig.SetBeginNotice(sBuffer.makeStringAndClear());
95 else
97 rConfig.SetEndNotice(sBuffer.makeStringAndClear());
99 // rConfig = NULL; // import contexts are ref-counted
102 void XMLFootnoteConfigHelper::characters( const OUString& rChars )
104 sBuffer.append(rChars);
108 // XMLFootnoteConfigurationImportContext
110 constexpr OUStringLiteral gsPropertyAnchorCharStyleName(u"AnchorCharStyleName");
111 constexpr OUStringLiteral gsPropertyCharStyleName(u"CharStyleName");
112 constexpr OUStringLiteral gsPropertyNumberingType(u"NumberingType");
113 constexpr OUStringLiteral gsPropertyPageStyleName(u"PageStyleName");
114 constexpr OUStringLiteral gsPropertyParagraphStyleName(u"ParaStyleName");
115 constexpr OUStringLiteral gsPropertyPrefix(u"Prefix");
116 constexpr OUStringLiteral gsPropertyStartAt(u"StartAt");
117 constexpr OUStringLiteral gsPropertySuffix(u"Suffix");
118 constexpr OUStringLiteral gsPropertyPositionEndOfDoc(u"PositionEndOfDoc");
119 constexpr OUStringLiteral gsPropertyFootnoteCounting(u"FootnoteCounting");
120 constexpr OUStringLiteral gsPropertyEndNotice(u"EndNotice");
121 constexpr OUStringLiteral gsPropertyBeginNotice(u"BeginNotice");
123 XMLFootnoteConfigurationImportContext::XMLFootnoteConfigurationImportContext(
124 SvXMLImport& rImport,
125 sal_Int32 /*nElement*/,
126 const Reference<XFastAttributeList> & xAttrList)
127 : SvXMLStyleContext(rImport, XmlStyleFamily::TEXT_FOOTNOTECONFIG)
128 , sNumFormat("1")
129 , sNumSync("false")
130 , nOffset(0)
131 , nNumbering(FootnoteNumbering::PER_PAGE)
132 , bPosition(false)
133 , bIsEndnote(false)
135 for (auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList ))
137 if( aIter.getToken() == XML_ELEMENT(TEXT, XML_NOTE_CLASS) )
139 if( IsXMLToken(aIter.toString(), XML_ENDNOTE ) )
141 bIsEndnote = true;
142 SetFamily( XmlStyleFamily::TEXT_FOOTNOTECONFIG );
144 break;
149 XMLFootnoteConfigurationImportContext::~XMLFootnoteConfigurationImportContext()
153 namespace {
155 enum XMLFtnConfigToken
157 XML_TOK_FTNCONFIG_CITATION_STYLENAME,
158 XML_TOK_FTNCONFIG_ANCHOR_STYLENAME,
159 XML_TOK_FTNCONFIG_DEFAULT_STYLENAME,
160 XML_TOK_FTNCONFIG_PAGE_STYLENAME,
161 XML_TOK_FTNCONFIG_OFFSET,
162 XML_TOK_FTNCONFIG_NUM_PREFIX,
163 XML_TOK_FTNCONFIG_NUM_SUFFIX,
164 XML_TOK_FTNCONFIG_NUM_FORMAT,
165 XML_TOK_FTNCONFIG_NUM_SYNC,
166 XML_TOK_FTNCONFIG_START_AT,
167 XML_TOK_FTNCONFIG_POSITION
172 const SvXMLTokenMapEntry aTextFieldAttrTokenMap[] =
174 { XML_NAMESPACE_TEXT, XML_CITATION_STYLE_NAME, XML_TOK_FTNCONFIG_CITATION_STYLENAME },
175 { XML_NAMESPACE_TEXT, XML_CITATION_BODY_STYLE_NAME, XML_TOK_FTNCONFIG_ANCHOR_STYLENAME },
176 { XML_NAMESPACE_TEXT, XML_DEFAULT_STYLE_NAME, XML_TOK_FTNCONFIG_DEFAULT_STYLENAME },
177 { XML_NAMESPACE_TEXT, XML_MASTER_PAGE_NAME, XML_TOK_FTNCONFIG_PAGE_STYLENAME },
178 { XML_NAMESPACE_TEXT, XML_START_VALUE, XML_TOK_FTNCONFIG_OFFSET },
179 { XML_NAMESPACE_STYLE, XML_NUM_PREFIX, XML_TOK_FTNCONFIG_NUM_PREFIX },
180 { XML_NAMESPACE_STYLE, XML_NUM_SUFFIX, XML_TOK_FTNCONFIG_NUM_SUFFIX },
181 { XML_NAMESPACE_STYLE, XML_NUM_FORMAT, XML_TOK_FTNCONFIG_NUM_FORMAT },
182 { XML_NAMESPACE_STYLE, XML_NUM_LETTER_SYNC, XML_TOK_FTNCONFIG_NUM_SYNC },
183 { XML_NAMESPACE_TEXT, XML_START_NUMBERING_AT, XML_TOK_FTNCONFIG_START_AT},
184 { XML_NAMESPACE_TEXT, XML_FOOTNOTES_POSITION, XML_TOK_FTNCONFIG_POSITION},
186 // for backwards compatibility with SRC630 & earlier
187 { XML_NAMESPACE_TEXT, XML_NUM_PREFIX, XML_TOK_FTNCONFIG_NUM_PREFIX },
188 { XML_NAMESPACE_TEXT, XML_NUM_SUFFIX, XML_TOK_FTNCONFIG_NUM_SUFFIX },
189 { XML_NAMESPACE_TEXT, XML_OFFSET, XML_TOK_FTNCONFIG_OFFSET },
190 XML_TOKEN_MAP_END
193 const SvXMLTokenMap&
194 XMLFootnoteConfigurationImportContext::GetFtnConfigAttrTokenMap()
196 if (!pAttrTokenMap)
198 pAttrTokenMap.reset( new SvXMLTokenMap(aTextFieldAttrTokenMap) );
201 return *pAttrTokenMap;
204 SvXMLEnumMapEntry<sal_Int16> const aFootnoteNumberingMap[] =
206 { XML_PAGE, FootnoteNumbering::PER_PAGE },
207 { XML_CHAPTER, FootnoteNumbering::PER_CHAPTER },
208 { XML_DOCUMENT, FootnoteNumbering::PER_DOCUMENT },
209 { XML_TOKEN_INVALID, 0 },
212 void XMLFootnoteConfigurationImportContext::SetAttribute( sal_uInt16 nPrefixKey,
213 const OUString& rLocalName,
214 const OUString& rValue )
216 switch (GetFtnConfigAttrTokenMap().Get(nPrefixKey, rLocalName))
218 case XML_TOK_FTNCONFIG_CITATION_STYLENAME:
219 sCitationStyle = rValue;
220 break;
221 case XML_TOK_FTNCONFIG_ANCHOR_STYLENAME:
222 sAnchorStyle = rValue;
223 break;
224 case XML_TOK_FTNCONFIG_DEFAULT_STYLENAME:
225 sDefaultStyle = rValue;
226 break;
227 case XML_TOK_FTNCONFIG_PAGE_STYLENAME:
228 sPageStyle = rValue;
229 break;
230 case XML_TOK_FTNCONFIG_OFFSET:
232 sal_Int32 nTmp;
233 if (::sax::Converter::convertNumber(nTmp, rValue))
235 nOffset = static_cast<sal_uInt16>(nTmp);
237 break;
239 case XML_TOK_FTNCONFIG_NUM_PREFIX:
240 sPrefix = rValue;
241 break;
242 case XML_TOK_FTNCONFIG_NUM_SUFFIX:
243 sSuffix = rValue;
244 break;
245 case XML_TOK_FTNCONFIG_NUM_FORMAT:
246 sNumFormat = rValue;
247 break;
248 case XML_TOK_FTNCONFIG_NUM_SYNC:
249 sNumSync = rValue;
250 break;
251 case XML_TOK_FTNCONFIG_START_AT:
253 (void)SvXMLUnitConverter::convertEnum(nNumbering, rValue,
254 aFootnoteNumberingMap);
255 break;
257 case XML_TOK_FTNCONFIG_POSITION:
258 bPosition = IsXMLToken( rValue, XML_DOCUMENT );
259 break;
260 default:
261 ; // ignore
265 css::uno::Reference< css::xml::sax::XFastContextHandler > XMLFootnoteConfigurationImportContext::createFastChildContext(
266 sal_Int32 nElement,
267 const css::uno::Reference< css::xml::sax::XFastAttributeList >& )
269 css::uno::Reference< css::xml::sax::XFastContextHandler > xContext;
271 if (bIsEndnote)
272 return nullptr;
274 switch (nElement)
276 case XML_ELEMENT(TEXT, XML_FOOTNOTE_CONTINUATION_NOTICE_FORWARD):
277 xContext = new XMLFootnoteConfigHelper(GetImport(), *this, false);
278 break;
279 case XML_ELEMENT(TEXT, XML_FOOTNOTE_CONTINUATION_NOTICE_BACKWARD):
280 xContext = new XMLFootnoteConfigHelper(GetImport(), *this, true);
281 break;
284 return xContext;
287 // Rename method <CreateAndInsertLate(..)> to <Finish(..)> (#i40597#)
288 void XMLFootnoteConfigurationImportContext::Finish( bool bOverwrite )
291 if (!bOverwrite)
292 return;
294 if (bIsEndnote)
296 Reference<XEndnotesSupplier> xSupplier(
297 GetImport().GetModel(), UNO_QUERY);
298 if (xSupplier.is())
300 ProcessSettings(xSupplier->getEndnoteSettings());
303 else
305 Reference<XFootnotesSupplier> xSupplier(
306 GetImport().GetModel(), UNO_QUERY);
307 if (xSupplier.is())
309 ProcessSettings(xSupplier->getFootnoteSettings());
312 // else: ignore (there's only one configuration, so we can only overwrite)
315 void XMLFootnoteConfigurationImportContext::ProcessSettings(
316 const Reference<XPropertySet> & rConfig)
318 Any aAny;
320 if (!sCitationStyle.isEmpty())
322 aAny <<= GetImport().GetStyleDisplayName(
323 XmlStyleFamily::TEXT_TEXT, sCitationStyle );
324 rConfig->setPropertyValue(gsPropertyCharStyleName, aAny);
327 if (!sAnchorStyle.isEmpty())
329 aAny <<= GetImport().GetStyleDisplayName(
330 XmlStyleFamily::TEXT_TEXT, sAnchorStyle );
331 rConfig->setPropertyValue(gsPropertyAnchorCharStyleName, aAny);
334 if (!sPageStyle.isEmpty())
336 aAny <<= GetImport().GetStyleDisplayName(
337 XmlStyleFamily::MASTER_PAGE, sPageStyle );
338 rConfig->setPropertyValue(gsPropertyPageStyleName, aAny);
341 if (!sDefaultStyle.isEmpty())
343 aAny <<= GetImport().GetStyleDisplayName(
344 XmlStyleFamily::TEXT_PARAGRAPH, sDefaultStyle );
345 rConfig->setPropertyValue(gsPropertyParagraphStyleName, aAny);
348 rConfig->setPropertyValue(gsPropertyPrefix, Any(sPrefix));
350 rConfig->setPropertyValue(gsPropertySuffix, Any(sSuffix));
352 sal_Int16 nNumType = NumberingType::ARABIC;
353 GetImport().GetMM100UnitConverter().convertNumFormat( nNumType, sNumFormat,
354 sNumSync );
355 // #i61399: Corrupt file? It contains "Bullet" as numbering style for footnotes.
356 // Okay, even it seems to be corrupt, we will oversee this and set the style to ARABIC
357 if( NumberingType::CHAR_SPECIAL == nNumType )
358 nNumType = NumberingType::ARABIC;
360 rConfig->setPropertyValue(gsPropertyNumberingType, Any(nNumType));
362 rConfig->setPropertyValue(gsPropertyStartAt, Any(nOffset));
364 if (!bIsEndnote)
366 rConfig->setPropertyValue(gsPropertyPositionEndOfDoc, Any(bPosition));
367 rConfig->setPropertyValue(gsPropertyFootnoteCounting, Any(nNumbering));
368 rConfig->setPropertyValue(gsPropertyEndNotice, Any(sEndNotice));
369 rConfig->setPropertyValue(gsPropertyBeginNotice, Any(sBeginNotice));
373 void XMLFootnoteConfigurationImportContext::SetBeginNotice(
374 const OUString& sText)
376 sBeginNotice = sText;
379 void XMLFootnoteConfigurationImportContext::SetEndNotice(
380 const OUString& sText)
382 sEndNotice = sText;
385 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */