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
)
83 , rConfig(rConfigImport
)
88 void XMLFootnoteConfigHelper::endFastElement(sal_Int32
)
92 rConfig
.SetBeginNotice(sBuffer
.makeStringAndClear());
96 rConfig
.SetEndNotice(sBuffer
.makeStringAndClear());
98 // rConfig = NULL; // import contexts are ref-counted
101 void XMLFootnoteConfigHelper::characters( const OUString
& rChars
)
103 sBuffer
.append(rChars
);
107 // XMLFootnoteConfigurationImportContext
109 constexpr OUStringLiteral
gsPropertyAnchorCharStyleName(u
"AnchorCharStyleName");
110 constexpr OUStringLiteral
gsPropertyCharStyleName(u
"CharStyleName");
111 constexpr OUStringLiteral
gsPropertyNumberingType(u
"NumberingType");
112 constexpr OUStringLiteral
gsPropertyPageStyleName(u
"PageStyleName");
113 constexpr OUStringLiteral
gsPropertyParagraphStyleName(u
"ParaStyleName");
114 constexpr OUStringLiteral
gsPropertyPrefix(u
"Prefix");
115 constexpr OUStringLiteral
gsPropertyStartAt(u
"StartAt");
116 constexpr OUStringLiteral
gsPropertySuffix(u
"Suffix");
117 constexpr OUStringLiteral
gsPropertyPositionEndOfDoc(u
"PositionEndOfDoc");
118 constexpr OUStringLiteral
gsPropertyFootnoteCounting(u
"FootnoteCounting");
119 constexpr OUStringLiteral
gsPropertyEndNotice(u
"EndNotice");
120 constexpr OUStringLiteral
gsPropertyBeginNotice(u
"BeginNotice");
122 XMLFootnoteConfigurationImportContext::XMLFootnoteConfigurationImportContext(
123 SvXMLImport
& rImport
,
124 sal_Int32
/*nElement*/,
125 const Reference
<XFastAttributeList
> & xAttrList
)
126 : SvXMLStyleContext(rImport
, XmlStyleFamily::TEXT_FOOTNOTECONFIG
)
130 , nNumbering(FootnoteNumbering::PER_PAGE
)
134 for (auto &aIter
: sax_fastparser::castToFastAttributeList( xAttrList
))
136 if( aIter
.getToken() == XML_ELEMENT(TEXT
, XML_NOTE_CLASS
) )
138 if( IsXMLToken(aIter
, XML_ENDNOTE
) )
141 SetFamily( XmlStyleFamily::TEXT_FOOTNOTECONFIG
);
148 XMLFootnoteConfigurationImportContext::~XMLFootnoteConfigurationImportContext()
152 SvXMLEnumMapEntry
<sal_Int16
> const aFootnoteNumberingMap
[] =
154 { XML_PAGE
, FootnoteNumbering::PER_PAGE
},
155 { XML_CHAPTER
, FootnoteNumbering::PER_CHAPTER
},
156 { XML_DOCUMENT
, FootnoteNumbering::PER_DOCUMENT
},
157 { XML_TOKEN_INVALID
, 0 },
160 void XMLFootnoteConfigurationImportContext::SetAttribute( sal_Int32 nElement
,
161 const OUString
& rValue
)
165 case XML_ELEMENT(TEXT
, XML_CITATION_STYLE_NAME
):
166 sCitationStyle
= rValue
;
168 case XML_ELEMENT(TEXT
, XML_CITATION_BODY_STYLE_NAME
):
169 sAnchorStyle
= rValue
;
171 case XML_ELEMENT(TEXT
, XML_DEFAULT_STYLE_NAME
):
172 sDefaultStyle
= rValue
;
174 case XML_ELEMENT(TEXT
, XML_MASTER_PAGE_NAME
):
177 case XML_ELEMENT(TEXT
, XML_START_VALUE
):
178 case XML_ELEMENT(TEXT
, XML_OFFSET
): // for backwards compatibility with SRC630 & earlier
181 if (::sax::Converter::convertNumber(nTmp
, rValue
))
183 nOffset
= static_cast<sal_uInt16
>(nTmp
);
187 case XML_ELEMENT(STYLE
, XML_NUM_PREFIX
):
188 case XML_ELEMENT(TEXT
, XML_NUM_PREFIX
): // for backwards compatibility with SRC630 & earlier
191 case XML_ELEMENT(STYLE
, XML_NUM_SUFFIX
):
192 case XML_ELEMENT(TEXT
, XML_NUM_SUFFIX
): // for backwards compatibility with SRC630 & earlier
195 case XML_ELEMENT(STYLE
, XML_NUM_FORMAT
):
198 case XML_ELEMENT(STYLE
, XML_NUM_LETTER_SYNC
):
201 case XML_ELEMENT(TEXT
, XML_START_NUMBERING_AT
):
203 (void)SvXMLUnitConverter::convertEnum(nNumbering
, rValue
,
204 aFootnoteNumberingMap
);
207 case XML_ELEMENT(TEXT
, XML_FOOTNOTES_POSITION
):
208 bPosition
= IsXMLToken( rValue
, XML_DOCUMENT
);
215 css::uno::Reference
< css::xml::sax::XFastContextHandler
> XMLFootnoteConfigurationImportContext::createFastChildContext(
217 const css::uno::Reference
< css::xml::sax::XFastAttributeList
>& )
219 css::uno::Reference
< css::xml::sax::XFastContextHandler
> xContext
;
226 case XML_ELEMENT(TEXT
, XML_FOOTNOTE_CONTINUATION_NOTICE_FORWARD
):
227 xContext
= new XMLFootnoteConfigHelper(GetImport(), *this, false);
229 case XML_ELEMENT(TEXT
, XML_FOOTNOTE_CONTINUATION_NOTICE_BACKWARD
):
230 xContext
= new XMLFootnoteConfigHelper(GetImport(), *this, true);
237 // Rename method <CreateAndInsertLate(..)> to <Finish(..)> (#i40597#)
238 void XMLFootnoteConfigurationImportContext::Finish( bool bOverwrite
)
246 Reference
<XEndnotesSupplier
> xSupplier(
247 GetImport().GetModel(), UNO_QUERY
);
250 ProcessSettings(xSupplier
->getEndnoteSettings());
255 Reference
<XFootnotesSupplier
> xSupplier(
256 GetImport().GetModel(), UNO_QUERY
);
259 ProcessSettings(xSupplier
->getFootnoteSettings());
262 // else: ignore (there's only one configuration, so we can only overwrite)
265 void XMLFootnoteConfigurationImportContext::ProcessSettings(
266 const Reference
<XPropertySet
> & rConfig
)
270 if (!sCitationStyle
.isEmpty())
272 aAny
<<= GetImport().GetStyleDisplayName(
273 XmlStyleFamily::TEXT_TEXT
, sCitationStyle
);
274 rConfig
->setPropertyValue(gsPropertyCharStyleName
, aAny
);
277 if (!sAnchorStyle
.isEmpty())
279 aAny
<<= GetImport().GetStyleDisplayName(
280 XmlStyleFamily::TEXT_TEXT
, sAnchorStyle
);
281 rConfig
->setPropertyValue(gsPropertyAnchorCharStyleName
, aAny
);
284 if (!sPageStyle
.isEmpty())
286 aAny
<<= GetImport().GetStyleDisplayName(
287 XmlStyleFamily::MASTER_PAGE
, sPageStyle
);
288 rConfig
->setPropertyValue(gsPropertyPageStyleName
, aAny
);
291 if (!sDefaultStyle
.isEmpty())
293 aAny
<<= GetImport().GetStyleDisplayName(
294 XmlStyleFamily::TEXT_PARAGRAPH
, sDefaultStyle
);
295 rConfig
->setPropertyValue(gsPropertyParagraphStyleName
, aAny
);
298 rConfig
->setPropertyValue(gsPropertyPrefix
, Any(sPrefix
));
300 rConfig
->setPropertyValue(gsPropertySuffix
, Any(sSuffix
));
302 sal_Int16 nNumType
= NumberingType::ARABIC
;
303 GetImport().GetMM100UnitConverter().convertNumFormat( nNumType
, sNumFormat
,
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
;
310 rConfig
->setPropertyValue(gsPropertyNumberingType
, Any(nNumType
));
312 rConfig
->setPropertyValue(gsPropertyStartAt
, Any(nOffset
));
316 rConfig
->setPropertyValue(gsPropertyPositionEndOfDoc
, Any(bPosition
));
317 rConfig
->setPropertyValue(gsPropertyFootnoteCounting
, Any(nNumbering
));
318 rConfig
->setPropertyValue(gsPropertyEndNotice
, Any(sEndNotice
));
319 rConfig
->setPropertyValue(gsPropertyBeginNotice
, Any(sBeginNotice
));
323 void XMLFootnoteConfigurationImportContext::SetBeginNotice(
324 const OUString
& sText
)
326 sBeginNotice
= sText
;
329 void XMLFootnoteConfigurationImportContext::SetEndNotice(
330 const OUString
& sText
)
335 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */