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/nmspmap.hxx>
29 #include <xmloff/xmlnmspe.hxx>
30 #include <xmloff/xmltoken.hxx>
32 #include <xmloff/families.hxx>
33 #include <xmloff/xmluconv.hxx>
34 #include <xmloff/xmlimp.hxx>
35 #include <xmloff/xmlnumi.hxx>
36 #include <com/sun/star/xml/sax/XAttributeList.hpp>
37 #include <com/sun/star/beans/XPropertySet.hpp>
38 #include <com/sun/star/text/XFootnote.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>
46 using namespace ::com::sun::star::text
;
47 using namespace ::com::sun::star::beans
;
48 using namespace ::com::sun::star::uno
;
49 using namespace ::com::sun::star::style
;
50 using namespace ::com::sun::star::xml::sax
;
51 using namespace ::xmloff::token
;
54 // 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
;
67 XMLFootnoteConfigHelper(
70 const OUString
& rLName
,
71 XMLFootnoteConfigurationImportContext
& rConfigImport
,
74 virtual void EndElement() SAL_OVERRIDE
;
76 virtual void Characters( const OUString
& rChars
) SAL_OVERRIDE
;
79 TYPEINIT1( XMLFootnoteConfigHelper
, SvXMLImportContext
);
81 XMLFootnoteConfigHelper::XMLFootnoteConfigHelper(
84 const OUString
& rLName
,
85 XMLFootnoteConfigurationImportContext
& rConfigImport
,
87 : SvXMLImportContext(rImport
, nPrfx
, rLName
)
89 , rConfig(rConfigImport
)
94 void XMLFootnoteConfigHelper::EndElement()
98 rConfig
.SetBeginNotice(sBuffer
.makeStringAndClear());
102 rConfig
.SetEndNotice(sBuffer
.makeStringAndClear());
104 // rConfig = NULL; // import contexts are ref-counted
107 void XMLFootnoteConfigHelper::Characters( const OUString
& rChars
)
109 sBuffer
.append(rChars
);
114 // XMLFootnoteConfigurationImportContext
118 TYPEINIT1( XMLFootnoteConfigurationImportContext
, SvXMLStyleContext
);
120 XMLFootnoteConfigurationImportContext::XMLFootnoteConfigurationImportContext(
121 SvXMLImport
& rImport
,
123 const OUString
& rLocalName
,
124 const Reference
<XAttributeList
> & xAttrList
)
125 : SvXMLStyleContext(rImport
, nPrfx
, rLocalName
, xAttrList
, XML_STYLE_FAMILY_TEXT_FOOTNOTECONFIG
)
126 , sPropertyAnchorCharStyleName("AnchorCharStyleName")
127 , sPropertyCharStyleName("CharStyleName")
128 , sPropertyNumberingType("NumberingType")
129 , sPropertyPageStyleName("PageStyleName")
130 , sPropertyParagraphStyleName("ParaStyleName")
131 , sPropertyPrefix("Prefix")
132 , sPropertyStartAt("StartAt")
133 , sPropertySuffix("Suffix")
134 , sPropertyPositionEndOfDoc("PositionEndOfDoc")
135 , sPropertyFootnoteCounting("FootnoteCounting")
136 , sPropertyEndNotice("EndNotice")
137 , sPropertyBeginNotice("BeginNotice")
140 , pAttrTokenMap(NULL
)
142 , nNumbering(FootnoteNumbering::PER_PAGE
)
146 sal_Int16 nLength
= xAttrList
->getLength();
147 for(sal_Int16 nAttr
= 0; nAttr
< nLength
; nAttr
++)
150 sal_uInt16 nPrefix
= GetImport().GetNamespaceMap().
151 GetKeyByAttrName( xAttrList
->getNameByIndex(nAttr
),
153 if( XML_NAMESPACE_TEXT
== nPrefix
&& IsXMLToken( sLocalName
,
156 const OUString
& rValue
= xAttrList
->getValueByIndex( nAttr
);
157 if( IsXMLToken( rValue
, XML_ENDNOTE
) )
160 SetFamily( XML_STYLE_FAMILY_TEXT_FOOTNOTECONFIG
);
167 XMLFootnoteConfigurationImportContext::~XMLFootnoteConfigurationImportContext()
169 delete pAttrTokenMap
;
172 enum XMLFtnConfigToken
174 XML_TOK_FTNCONFIG_CITATION_STYLENAME
,
175 XML_TOK_FTNCONFIG_ANCHOR_STYLENAME
,
176 XML_TOK_FTNCONFIG_DEFAULT_STYLENAME
,
177 XML_TOK_FTNCONFIG_PAGE_STYLENAME
,
178 XML_TOK_FTNCONFIG_OFFSET
,
179 XML_TOK_FTNCONFIG_NUM_PREFIX
,
180 XML_TOK_FTNCONFIG_NUM_SUFFIX
,
181 XML_TOK_FTNCONFIG_NUM_FORMAT
,
182 XML_TOK_FTNCONFIG_NUM_SYNC
,
183 XML_TOK_FTNCONFIG_START_AT
,
184 XML_TOK_FTNCONFIG_POSITION
187 static const SvXMLTokenMapEntry aTextFieldAttrTokenMap
[] =
189 { XML_NAMESPACE_TEXT
, XML_CITATION_STYLE_NAME
, XML_TOK_FTNCONFIG_CITATION_STYLENAME
},
190 { XML_NAMESPACE_TEXT
, XML_CITATION_BODY_STYLE_NAME
, XML_TOK_FTNCONFIG_ANCHOR_STYLENAME
},
191 { XML_NAMESPACE_TEXT
, XML_DEFAULT_STYLE_NAME
, XML_TOK_FTNCONFIG_DEFAULT_STYLENAME
},
192 { XML_NAMESPACE_TEXT
, XML_MASTER_PAGE_NAME
, XML_TOK_FTNCONFIG_PAGE_STYLENAME
},
193 { XML_NAMESPACE_TEXT
, XML_START_VALUE
, XML_TOK_FTNCONFIG_OFFSET
},
194 { XML_NAMESPACE_STYLE
, XML_NUM_PREFIX
, XML_TOK_FTNCONFIG_NUM_PREFIX
},
195 { XML_NAMESPACE_STYLE
, XML_NUM_SUFFIX
, XML_TOK_FTNCONFIG_NUM_SUFFIX
},
196 { XML_NAMESPACE_STYLE
, XML_NUM_FORMAT
, XML_TOK_FTNCONFIG_NUM_FORMAT
},
197 { XML_NAMESPACE_STYLE
, XML_NUM_LETTER_SYNC
, XML_TOK_FTNCONFIG_NUM_SYNC
},
198 { XML_NAMESPACE_TEXT
, XML_START_NUMBERING_AT
, XML_TOK_FTNCONFIG_START_AT
},
199 { XML_NAMESPACE_TEXT
, XML_FOOTNOTES_POSITION
, XML_TOK_FTNCONFIG_POSITION
},
201 // for backwards compatibility with SRC630 & earlier
202 { XML_NAMESPACE_TEXT
, XML_NUM_PREFIX
, XML_TOK_FTNCONFIG_NUM_PREFIX
},
203 { XML_NAMESPACE_TEXT
, XML_NUM_SUFFIX
, XML_TOK_FTNCONFIG_NUM_SUFFIX
},
204 { XML_NAMESPACE_TEXT
, XML_OFFSET
, XML_TOK_FTNCONFIG_OFFSET
},
209 XMLFootnoteConfigurationImportContext::GetFtnConfigAttrTokenMap()
211 if (NULL
== pAttrTokenMap
)
213 pAttrTokenMap
= new SvXMLTokenMap(aTextFieldAttrTokenMap
);
216 return *pAttrTokenMap
;
219 static SvXMLEnumMapEntry
const aFootnoteNumberingMap
[] =
221 { XML_PAGE
, FootnoteNumbering::PER_PAGE
},
222 { XML_CHAPTER
, FootnoteNumbering::PER_CHAPTER
},
223 { XML_DOCUMENT
, FootnoteNumbering::PER_DOCUMENT
},
224 { XML_TOKEN_INVALID
, 0 },
227 void XMLFootnoteConfigurationImportContext::StartElement(
228 const Reference
<XAttributeList
> & xAttrList
)
230 sal_Int16 nLength
= xAttrList
->getLength();
231 for(sal_Int16 nAttr
= 0; nAttr
< nLength
; nAttr
++)
234 sal_uInt16 nPrefix
= GetImport().GetNamespaceMap().
235 GetKeyByAttrName( xAttrList
->getNameByIndex(nAttr
),
237 OUString sValue
= xAttrList
->getValueByIndex(nAttr
);
238 switch (GetFtnConfigAttrTokenMap().Get(nPrefix
, sLocalName
))
240 case XML_TOK_FTNCONFIG_CITATION_STYLENAME
:
241 sCitationStyle
= sValue
;
243 case XML_TOK_FTNCONFIG_ANCHOR_STYLENAME
:
244 sAnchorStyle
= sValue
;
246 case XML_TOK_FTNCONFIG_DEFAULT_STYLENAME
:
247 sDefaultStyle
= sValue
;
249 case XML_TOK_FTNCONFIG_PAGE_STYLENAME
:
252 case XML_TOK_FTNCONFIG_OFFSET
:
255 if (::sax::Converter::convertNumber(nTmp
, sValue
))
257 nOffset
= (sal_uInt16
)nTmp
;
261 case XML_TOK_FTNCONFIG_NUM_PREFIX
:
264 case XML_TOK_FTNCONFIG_NUM_SUFFIX
:
267 case XML_TOK_FTNCONFIG_NUM_FORMAT
:
270 case XML_TOK_FTNCONFIG_NUM_SYNC
:
273 case XML_TOK_FTNCONFIG_START_AT
:
276 if (SvXMLUnitConverter::convertEnum(nTmp
, sValue
,
277 aFootnoteNumberingMap
))
283 case XML_TOK_FTNCONFIG_POSITION
:
284 bPosition
= IsXMLToken( sValue
, XML_DOCUMENT
);
292 SvXMLImportContext
*XMLFootnoteConfigurationImportContext::CreateChildContext(
294 const OUString
& rLocalName
,
295 const Reference
<XAttributeList
> & xAttrList
)
297 SvXMLImportContext
* pContext
= NULL
;
301 if (XML_NAMESPACE_TEXT
== nPrefix
)
303 if ( IsXMLToken( rLocalName
,
304 XML_FOOTNOTE_CONTINUATION_NOTICE_FORWARD
) )
306 pContext
= new XMLFootnoteConfigHelper(GetImport(),
310 else if ( IsXMLToken( rLocalName
,
311 XML_FOOTNOTE_CONTINUATION_NOTICE_BACKWARD
) )
313 pContext
= new XMLFootnoteConfigHelper(GetImport(),
317 // else: default context
319 // else: unknown namespace -> default context
321 // else: endnote -> default context
323 if (pContext
== NULL
)
325 // default: delegate to super class
326 pContext
= SvXMLStyleContext::CreateChildContext(nPrefix
,
334 // Rename method <CreateAndInsertLate(..)> to <Finish(..)> (#i40597#)
335 void XMLFootnoteConfigurationImportContext::Finish( bool bOverwrite
)
342 Reference
<XEndnotesSupplier
> xSupplier(
343 GetImport().GetModel(), UNO_QUERY
);
346 ProcessSettings(xSupplier
->getEndnoteSettings());
351 Reference
<XFootnotesSupplier
> xSupplier(
352 GetImport().GetModel(), UNO_QUERY
);
355 ProcessSettings(xSupplier
->getFootnoteSettings());
359 // else: ignore (there's only one configuration, so we can only overwrite)
362 void XMLFootnoteConfigurationImportContext::ProcessSettings(
363 const Reference
<XPropertySet
> & rConfig
)
367 if (!sCitationStyle
.isEmpty())
369 aAny
<<= GetImport().GetStyleDisplayName(
370 XML_STYLE_FAMILY_TEXT_TEXT
, sCitationStyle
);
371 rConfig
->setPropertyValue(sPropertyCharStyleName
, aAny
);
374 if (!sAnchorStyle
.isEmpty())
376 aAny
<<= GetImport().GetStyleDisplayName(
377 XML_STYLE_FAMILY_TEXT_TEXT
, sAnchorStyle
);
378 rConfig
->setPropertyValue(sPropertyAnchorCharStyleName
, aAny
);
381 if (!sPageStyle
.isEmpty())
383 aAny
<<= GetImport().GetStyleDisplayName(
384 XML_STYLE_FAMILY_MASTER_PAGE
, sPageStyle
);
385 rConfig
->setPropertyValue(sPropertyPageStyleName
, aAny
);
388 if (!sDefaultStyle
.isEmpty())
390 aAny
<<= GetImport().GetStyleDisplayName(
391 XML_STYLE_FAMILY_TEXT_PARAGRAPH
, sDefaultStyle
);
392 rConfig
->setPropertyValue(sPropertyParagraphStyleName
, aAny
);
396 rConfig
->setPropertyValue(sPropertyPrefix
, aAny
);
399 rConfig
->setPropertyValue(sPropertySuffix
, aAny
);
401 sal_Int16 nNumType
= NumberingType::ARABIC
;
402 GetImport().GetMM100UnitConverter().convertNumFormat( nNumType
, sNumFormat
,
404 // #i61399: Corrupt file? It contains "Bullet" as numbering style for footnotes.
405 // Okay, even it seems to be corrupt, we will oversee this and set the style to ARABIC
406 if( NumberingType::CHAR_SPECIAL
== nNumType
)
407 nNumType
= NumberingType::ARABIC
;
410 rConfig
->setPropertyValue(sPropertyNumberingType
, aAny
);
413 rConfig
->setPropertyValue(sPropertyStartAt
, aAny
);
417 aAny
.setValue(&bPosition
, cppu::UnoType
<bool>::get());
418 rConfig
->setPropertyValue(sPropertyPositionEndOfDoc
, aAny
);
421 rConfig
->setPropertyValue(sPropertyFootnoteCounting
, aAny
);
424 rConfig
->setPropertyValue(sPropertyEndNotice
, aAny
);
426 aAny
<<= sBeginNotice
;
427 rConfig
->setPropertyValue(sPropertyBeginNotice
, aAny
);
431 void XMLFootnoteConfigurationImportContext::SetBeginNotice(
432 const OUString
& sText
)
434 sBeginNotice
= sText
;
437 void XMLFootnoteConfigurationImportContext::SetEndNotice(
438 const OUString
& sText
)
443 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */