merge the formfield patch from ooo-build
[ooovba.git] / xmloff / source / text / XMLFootnoteConfigurationImportContext.cxx
blob0087b0fa4999a464e7e311b85c01a3714450f667
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: XMLFootnoteConfigurationImportContext.cxx,v $
10 * $Revision: 1.21 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_xmloff.hxx"
33 #include "XMLFootnoteConfigurationImportContext.hxx"
35 #ifndef _RTL_USTRING
36 #include <rtl/ustring.hxx>
37 #endif
38 #include <rtl/ustrbuf.hxx>
39 #include <tools/debug.hxx>
40 #include <xmloff/nmspmap.hxx>
41 #include "xmlnmspe.hxx"
42 #include <xmloff/xmltoken.hxx>
44 #ifndef _XMLOFF_FAMILIES_HXX
45 #include <xmloff/families.hxx>
46 #endif
47 #include <xmloff/xmluconv.hxx>
48 #include <xmloff/xmlimp.hxx>
49 #include <xmloff/xmlnumi.hxx>
50 #include <com/sun/star/xml/sax/XAttributeList.hpp>
51 #include <com/sun/star/beans/XPropertySet.hpp>
52 #include <com/sun/star/text/XFootnote.hpp>
53 #include <com/sun/star/text/XFootnotesSupplier.hpp>
54 #include <com/sun/star/text/XEndnotesSupplier.hpp>
55 #include <com/sun/star/text/FootnoteNumbering.hpp>
56 #include <com/sun/star/style/NumberingType.hpp>
59 using ::rtl::OUString;
60 using ::rtl::OUStringBuffer;
62 using namespace ::com::sun::star::text;
63 using namespace ::com::sun::star::beans;
64 using namespace ::com::sun::star::uno;
65 using namespace ::com::sun::star::style;
66 using namespace ::com::sun::star::xml::sax;
67 using namespace ::xmloff::token;
70 // XMLFootnoteConfigHelper
73 /// local helper class for import of quo-vadis and ergo-sum elements
74 class XMLFootnoteConfigHelper : public SvXMLImportContext
76 OUStringBuffer sBuffer;
77 XMLFootnoteConfigurationImportContext& rConfig;
78 sal_Bool bIsBegin;
80 public:
81 TYPEINFO();
83 XMLFootnoteConfigHelper(
84 SvXMLImport& rImport,
85 sal_uInt16 nPrfx,
86 const OUString& rLName,
87 XMLFootnoteConfigurationImportContext& rConfigImport,
88 sal_Bool bBegin);
90 virtual void EndElement();
92 virtual void Characters( const OUString& rChars );
95 TYPEINIT1( XMLFootnoteConfigHelper, SvXMLImportContext );
97 XMLFootnoteConfigHelper::XMLFootnoteConfigHelper(
98 SvXMLImport& rImport,
99 sal_uInt16 nPrfx,
100 const OUString& rLName,
101 XMLFootnoteConfigurationImportContext& rConfigImport,
102 sal_Bool bBegin)
103 : SvXMLImportContext(rImport, nPrfx, rLName)
104 , sBuffer()
105 , rConfig(rConfigImport)
106 , bIsBegin(bBegin)
110 void XMLFootnoteConfigHelper::EndElement()
112 if (bIsBegin)
114 rConfig.SetBeginNotice(sBuffer.makeStringAndClear());
116 else
118 rConfig.SetEndNotice(sBuffer.makeStringAndClear());
120 // rConfig = NULL; // import contexts are ref-counted
123 void XMLFootnoteConfigHelper::Characters( const OUString& rChars )
125 sBuffer.append(rChars);
130 // XMLFootnoteConfigurationImportContext
134 TYPEINIT1( XMLFootnoteConfigurationImportContext, SvXMLStyleContext );
136 XMLFootnoteConfigurationImportContext::XMLFootnoteConfigurationImportContext(
137 SvXMLImport& rImport,
138 sal_uInt16 nPrfx,
139 const OUString& rLocalName,
140 const Reference<XAttributeList> & xAttrList)
141 : SvXMLStyleContext(rImport, nPrfx, rLocalName, xAttrList, XML_STYLE_FAMILY_TEXT_FOOTNOTECONFIG)
142 , sPropertyAnchorCharStyleName(RTL_CONSTASCII_USTRINGPARAM("AnchorCharStyleName"))
143 , sPropertyCharStyleName(RTL_CONSTASCII_USTRINGPARAM("CharStyleName"))
144 , sPropertyNumberingType(RTL_CONSTASCII_USTRINGPARAM("NumberingType"))
145 , sPropertyPageStyleName(RTL_CONSTASCII_USTRINGPARAM("PageStyleName"))
146 , sPropertyParagraphStyleName(RTL_CONSTASCII_USTRINGPARAM("ParaStyleName"))
147 , sPropertyPrefix(RTL_CONSTASCII_USTRINGPARAM("Prefix"))
148 , sPropertyStartAt(RTL_CONSTASCII_USTRINGPARAM("StartAt"))
149 , sPropertySuffix(RTL_CONSTASCII_USTRINGPARAM("Suffix"))
150 , sPropertyPositionEndOfDoc(RTL_CONSTASCII_USTRINGPARAM("PositionEndOfDoc"))
151 , sPropertyFootnoteCounting(RTL_CONSTASCII_USTRINGPARAM("FootnoteCounting"))
152 , sPropertyEndNotice(RTL_CONSTASCII_USTRINGPARAM("EndNotice"))
153 , sPropertyBeginNotice(RTL_CONSTASCII_USTRINGPARAM("BeginNotice"))
154 , sNumFormat(RTL_CONSTASCII_USTRINGPARAM("1"))
155 , sNumSync(RTL_CONSTASCII_USTRINGPARAM("false"))
156 , pAttrTokenMap(NULL)
157 , nOffset(0)
158 , nNumbering(FootnoteNumbering::PER_PAGE)
159 , bPosition(sal_False)
160 , bIsEndnote(sal_False)
162 sal_Int16 nLength = xAttrList->getLength();
163 for(sal_Int16 nAttr = 0; nAttr < nLength; nAttr++)
165 OUString sLocalName;
166 sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
167 GetKeyByAttrName( xAttrList->getNameByIndex(nAttr),
168 &sLocalName );
169 if( XML_NAMESPACE_TEXT == nPrefix && IsXMLToken( sLocalName,
170 XML_NOTE_CLASS ) )
172 const OUString& rValue = xAttrList->getValueByIndex( nAttr );
173 if( IsXMLToken( rValue, XML_ENDNOTE ) )
175 bIsEndnote = sal_True;
176 SetFamily( XML_STYLE_FAMILY_TEXT_FOOTNOTECONFIG );
178 break;
183 XMLFootnoteConfigurationImportContext::~XMLFootnoteConfigurationImportContext()
185 delete pAttrTokenMap;
188 enum XMLFtnConfigToken
190 XML_TOK_FTNCONFIG_CITATION_STYLENAME,
191 XML_TOK_FTNCONFIG_ANCHOR_STYLENAME,
192 XML_TOK_FTNCONFIG_DEFAULT_STYLENAME,
193 XML_TOK_FTNCONFIG_PAGE_STYLENAME,
194 XML_TOK_FTNCONFIG_OFFSET,
195 XML_TOK_FTNCONFIG_NUM_PREFIX,
196 XML_TOK_FTNCONFIG_NUM_SUFFIX,
197 XML_TOK_FTNCONFIG_NUM_FORMAT,
198 XML_TOK_FTNCONFIG_NUM_SYNC,
199 XML_TOK_FTNCONFIG_START_AT,
200 XML_TOK_FTNCONFIG_POSITION
203 static __FAR_DATA SvXMLTokenMapEntry aTextFieldAttrTokenMap[] =
205 { XML_NAMESPACE_TEXT, XML_CITATION_STYLE_NAME, XML_TOK_FTNCONFIG_CITATION_STYLENAME },
206 { XML_NAMESPACE_TEXT, XML_CITATION_BODY_STYLE_NAME, XML_TOK_FTNCONFIG_ANCHOR_STYLENAME },
207 { XML_NAMESPACE_TEXT, XML_DEFAULT_STYLE_NAME, XML_TOK_FTNCONFIG_DEFAULT_STYLENAME },
208 { XML_NAMESPACE_TEXT, XML_MASTER_PAGE_NAME, XML_TOK_FTNCONFIG_PAGE_STYLENAME },
209 { XML_NAMESPACE_TEXT, XML_START_VALUE, XML_TOK_FTNCONFIG_OFFSET },
210 { XML_NAMESPACE_STYLE, XML_NUM_PREFIX, XML_TOK_FTNCONFIG_NUM_PREFIX },
211 { XML_NAMESPACE_STYLE, XML_NUM_SUFFIX, XML_TOK_FTNCONFIG_NUM_SUFFIX },
212 { XML_NAMESPACE_STYLE, XML_NUM_FORMAT, XML_TOK_FTNCONFIG_NUM_FORMAT },
213 { XML_NAMESPACE_STYLE, XML_NUM_LETTER_SYNC, XML_TOK_FTNCONFIG_NUM_SYNC },
214 { XML_NAMESPACE_TEXT, XML_START_NUMBERING_AT, XML_TOK_FTNCONFIG_START_AT},
215 { XML_NAMESPACE_TEXT, XML_FOOTNOTES_POSITION, XML_TOK_FTNCONFIG_POSITION},
217 // for backwards compatibility with SRC630 & earlier
218 { XML_NAMESPACE_TEXT, XML_NUM_PREFIX, XML_TOK_FTNCONFIG_NUM_PREFIX },
219 { XML_NAMESPACE_TEXT, XML_NUM_SUFFIX, XML_TOK_FTNCONFIG_NUM_SUFFIX },
220 { XML_NAMESPACE_TEXT, XML_OFFSET, XML_TOK_FTNCONFIG_OFFSET },
221 XML_TOKEN_MAP_END
224 const SvXMLTokenMap&
225 XMLFootnoteConfigurationImportContext::GetFtnConfigAttrTokenMap()
227 if (NULL == pAttrTokenMap)
229 pAttrTokenMap = new SvXMLTokenMap(aTextFieldAttrTokenMap);
232 return *pAttrTokenMap;
235 static SvXMLEnumMapEntry __READONLY_DATA aFootnoteNumberingMap[] =
237 { XML_PAGE, FootnoteNumbering::PER_PAGE },
238 { XML_CHAPTER, FootnoteNumbering::PER_CHAPTER },
239 { XML_DOCUMENT, FootnoteNumbering::PER_DOCUMENT },
240 { XML_TOKEN_INVALID, 0 },
243 void XMLFootnoteConfigurationImportContext::StartElement(
244 const Reference<XAttributeList> & xAttrList )
246 sal_Int16 nLength = xAttrList->getLength();
247 for(sal_Int16 nAttr = 0; nAttr < nLength; nAttr++)
249 OUString sLocalName;
250 sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
251 GetKeyByAttrName( xAttrList->getNameByIndex(nAttr),
252 &sLocalName );
253 OUString sValue = xAttrList->getValueByIndex(nAttr);
254 switch (GetFtnConfigAttrTokenMap().Get(nPrefix, sLocalName))
256 case XML_TOK_FTNCONFIG_CITATION_STYLENAME:
257 sCitationStyle = sValue;
258 break;
259 case XML_TOK_FTNCONFIG_ANCHOR_STYLENAME:
260 sAnchorStyle = sValue;
261 break;
262 case XML_TOK_FTNCONFIG_DEFAULT_STYLENAME:
263 sDefaultStyle = sValue;
264 break;
265 case XML_TOK_FTNCONFIG_PAGE_STYLENAME:
266 sPageStyle = sValue;
267 break;
268 case XML_TOK_FTNCONFIG_OFFSET:
270 sal_Int32 nTmp;
271 if (SvXMLUnitConverter::convertNumber(nTmp, sValue))
273 nOffset = (sal_uInt16)nTmp;
275 break;
277 case XML_TOK_FTNCONFIG_NUM_PREFIX:
278 sPrefix = sValue;
279 break;
280 case XML_TOK_FTNCONFIG_NUM_SUFFIX:
281 sSuffix = sValue;
282 break;
283 case XML_TOK_FTNCONFIG_NUM_FORMAT:
284 sNumFormat = sValue;
285 break;
286 case XML_TOK_FTNCONFIG_NUM_SYNC:
287 sNumSync = sValue;
288 break;
289 case XML_TOK_FTNCONFIG_START_AT:
291 sal_uInt16 nTmp;
292 if (SvXMLUnitConverter::convertEnum(nTmp, sValue,
293 aFootnoteNumberingMap))
295 nNumbering = nTmp;
297 break;
299 case XML_TOK_FTNCONFIG_POSITION:
300 bPosition = IsXMLToken( sValue, XML_DOCUMENT );
301 break;
302 default:
303 ; // ignore
308 SvXMLImportContext *XMLFootnoteConfigurationImportContext::CreateChildContext(
309 USHORT nPrefix,
310 const OUString& rLocalName,
311 const Reference<XAttributeList> & xAttrList )
313 SvXMLImportContext* pContext = NULL;
315 if (!bIsEndnote)
317 if (XML_NAMESPACE_TEXT == nPrefix)
319 if ( IsXMLToken( rLocalName,
320 XML_FOOTNOTE_CONTINUATION_NOTICE_FORWARD ) )
322 pContext = new XMLFootnoteConfigHelper(GetImport(),
323 nPrefix, rLocalName,
324 *this, sal_False);
326 else if ( IsXMLToken( rLocalName,
327 XML_FOOTNOTE_CONTINUATION_NOTICE_BACKWARD ) )
329 pContext = new XMLFootnoteConfigHelper(GetImport(),
330 nPrefix, rLocalName,
331 *this, sal_True);
333 // else: default context
335 // else: unknown namespace -> default context
337 // else: endnote -> default context
339 if (pContext == NULL)
341 // default: delegate to super class
342 pContext = SvXMLStyleContext::CreateChildContext(nPrefix,
343 rLocalName,
344 xAttrList);
347 return pContext;
351 // --> OD 2005-01-31 #i40597# - rename method <CreateAndInsertLate(..)> to
352 // <Finish(..)>
353 void XMLFootnoteConfigurationImportContext::Finish( sal_Bool bOverwrite )
354 // <--
357 if (bOverwrite)
359 if (bIsEndnote)
361 Reference<XEndnotesSupplier> xSupplier(
362 GetImport().GetModel(), UNO_QUERY);
363 if (xSupplier.is())
365 ProcessSettings(xSupplier->getEndnoteSettings());
368 else
370 Reference<XFootnotesSupplier> xSupplier(
371 GetImport().GetModel(), UNO_QUERY);
372 if (xSupplier.is())
374 ProcessSettings(xSupplier->getFootnoteSettings());
378 // else: ignore (there's only one configuration, so we can only overwrite)
381 void XMLFootnoteConfigurationImportContext::ProcessSettings(
382 const Reference<XPropertySet> & rConfig)
384 Any aAny;
386 if (sCitationStyle.getLength() > 0)
388 aAny <<= GetImport().GetStyleDisplayName(
389 XML_STYLE_FAMILY_TEXT_TEXT, sCitationStyle );
390 rConfig->setPropertyValue(sPropertyCharStyleName, aAny);
393 if (sAnchorStyle.getLength() > 0)
395 aAny <<= GetImport().GetStyleDisplayName(
396 XML_STYLE_FAMILY_TEXT_TEXT, sAnchorStyle );
397 rConfig->setPropertyValue(sPropertyAnchorCharStyleName, aAny);
400 if (sPageStyle.getLength() > 0)
402 aAny <<= GetImport().GetStyleDisplayName(
403 XML_STYLE_FAMILY_MASTER_PAGE, sPageStyle );
404 rConfig->setPropertyValue(sPropertyPageStyleName, aAny);
407 if (sDefaultStyle.getLength() > 0)
409 aAny <<= GetImport().GetStyleDisplayName(
410 XML_STYLE_FAMILY_TEXT_PARAGRAPH, sDefaultStyle );
411 rConfig->setPropertyValue(sPropertyParagraphStyleName, aAny);
414 aAny <<= sPrefix;
415 rConfig->setPropertyValue(sPropertyPrefix, aAny);
417 aAny <<= sSuffix;
418 rConfig->setPropertyValue(sPropertySuffix, aAny);
420 sal_Int16 nNumType = NumberingType::ARABIC;
421 GetImport().GetMM100UnitConverter().convertNumFormat( nNumType, sNumFormat,
422 sNumSync );
423 // #i61399: Corrupt file? It contains "Bullet" as numbering style for footnotes.
424 // Okay, even it seems to be corrupt, we will oversee this and set the style to ARABIC
425 if( NumberingType::CHAR_SPECIAL == nNumType )
426 nNumType = NumberingType::ARABIC;
428 aAny <<= nNumType;
429 rConfig->setPropertyValue(sPropertyNumberingType, aAny);
431 aAny <<= nOffset;
432 rConfig->setPropertyValue(sPropertyStartAt, aAny);
434 if (!bIsEndnote)
436 aAny.setValue(&bPosition, ::getBooleanCppuType());
437 rConfig->setPropertyValue(sPropertyPositionEndOfDoc, aAny);
439 aAny <<= nNumbering;
440 rConfig->setPropertyValue(sPropertyFootnoteCounting, aAny);
442 aAny <<= sEndNotice;
443 rConfig->setPropertyValue(sPropertyEndNotice, aAny);
445 aAny <<= sBeginNotice;
446 rConfig->setPropertyValue(sPropertyBeginNotice, aAny);
450 void XMLFootnoteConfigurationImportContext::SetBeginNotice(
451 OUString sText)
453 sBeginNotice = sText;
456 void XMLFootnoteConfigurationImportContext::SetEndNotice(
457 OUString sText)
459 sEndNotice = sText;