1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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
57 /// local helper class for import of quo-vadis and ergo-sum elements
58 class XMLFootnoteConfigHelper
: public SvXMLImportContext
60 OUStringBuffer sBuffer
;
61 XMLFootnoteConfigurationImportContext
& rConfig
;
66 XMLFootnoteConfigHelper(
68 XMLFootnoteConfigurationImportContext
& rConfigImport
,
71 virtual void SAL_CALL
endFastElement(sal_Int32 nElement
) override
;
73 virtual void SAL_CALL
characters( const OUString
& rChars
) override
;
78 XMLFootnoteConfigHelper::XMLFootnoteConfigHelper(
80 XMLFootnoteConfigurationImportContext
& rConfigImport
,
82 : SvXMLImportContext(rImport
)
84 , rConfig(rConfigImport
)
89 void XMLFootnoteConfigHelper::endFastElement(sal_Int32
)
93 rConfig
.SetBeginNotice(sBuffer
.makeStringAndClear());
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
)
131 , nNumbering(FootnoteNumbering::PER_PAGE
)
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
) )
142 SetFamily( XmlStyleFamily::TEXT_FOOTNOTECONFIG
);
149 XMLFootnoteConfigurationImportContext::~XMLFootnoteConfigurationImportContext()
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
},
194 XMLFootnoteConfigurationImportContext::GetFtnConfigAttrTokenMap()
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
;
221 case XML_TOK_FTNCONFIG_ANCHOR_STYLENAME
:
222 sAnchorStyle
= rValue
;
224 case XML_TOK_FTNCONFIG_DEFAULT_STYLENAME
:
225 sDefaultStyle
= rValue
;
227 case XML_TOK_FTNCONFIG_PAGE_STYLENAME
:
230 case XML_TOK_FTNCONFIG_OFFSET
:
233 if (::sax::Converter::convertNumber(nTmp
, rValue
))
235 nOffset
= static_cast<sal_uInt16
>(nTmp
);
239 case XML_TOK_FTNCONFIG_NUM_PREFIX
:
242 case XML_TOK_FTNCONFIG_NUM_SUFFIX
:
245 case XML_TOK_FTNCONFIG_NUM_FORMAT
:
248 case XML_TOK_FTNCONFIG_NUM_SYNC
:
251 case XML_TOK_FTNCONFIG_START_AT
:
253 (void)SvXMLUnitConverter::convertEnum(nNumbering
, rValue
,
254 aFootnoteNumberingMap
);
257 case XML_TOK_FTNCONFIG_POSITION
:
258 bPosition
= IsXMLToken( rValue
, XML_DOCUMENT
);
265 css::uno::Reference
< css::xml::sax::XFastContextHandler
> XMLFootnoteConfigurationImportContext::createFastChildContext(
267 const css::uno::Reference
< css::xml::sax::XFastAttributeList
>& )
269 css::uno::Reference
< css::xml::sax::XFastContextHandler
> xContext
;
276 case XML_ELEMENT(TEXT
, XML_FOOTNOTE_CONTINUATION_NOTICE_FORWARD
):
277 xContext
= new XMLFootnoteConfigHelper(GetImport(), *this, false);
279 case XML_ELEMENT(TEXT
, XML_FOOTNOTE_CONTINUATION_NOTICE_BACKWARD
):
280 xContext
= new XMLFootnoteConfigHelper(GetImport(), *this, true);
287 // Rename method <CreateAndInsertLate(..)> to <Finish(..)> (#i40597#)
288 void XMLFootnoteConfigurationImportContext::Finish( bool bOverwrite
)
296 Reference
<XEndnotesSupplier
> xSupplier(
297 GetImport().GetModel(), UNO_QUERY
);
300 ProcessSettings(xSupplier
->getEndnoteSettings());
305 Reference
<XFootnotesSupplier
> xSupplier(
306 GetImport().GetModel(), UNO_QUERY
);
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
)
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
,
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
));
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
)
385 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */