1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: XMLFootnoteConfigurationImportContext.cxx,v $
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"
36 #include <rtl/ustring.hxx>
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>
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
;
83 XMLFootnoteConfigHelper(
86 const OUString
& rLName
,
87 XMLFootnoteConfigurationImportContext
& rConfigImport
,
90 virtual void EndElement();
92 virtual void Characters( const OUString
& rChars
);
95 TYPEINIT1( XMLFootnoteConfigHelper
, SvXMLImportContext
);
97 XMLFootnoteConfigHelper::XMLFootnoteConfigHelper(
100 const OUString
& rLName
,
101 XMLFootnoteConfigurationImportContext
& rConfigImport
,
103 : SvXMLImportContext(rImport
, nPrfx
, rLName
)
105 , rConfig(rConfigImport
)
110 void XMLFootnoteConfigHelper::EndElement()
114 rConfig
.SetBeginNotice(sBuffer
.makeStringAndClear());
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
,
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
)
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
++)
166 sal_uInt16 nPrefix
= GetImport().GetNamespaceMap().
167 GetKeyByAttrName( xAttrList
->getNameByIndex(nAttr
),
169 if( XML_NAMESPACE_TEXT
== nPrefix
&& IsXMLToken( sLocalName
,
172 const OUString
& rValue
= xAttrList
->getValueByIndex( nAttr
);
173 if( IsXMLToken( rValue
, XML_ENDNOTE
) )
175 bIsEndnote
= sal_True
;
176 SetFamily( XML_STYLE_FAMILY_TEXT_FOOTNOTECONFIG
);
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
},
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
++)
250 sal_uInt16 nPrefix
= GetImport().GetNamespaceMap().
251 GetKeyByAttrName( xAttrList
->getNameByIndex(nAttr
),
253 OUString sValue
= xAttrList
->getValueByIndex(nAttr
);
254 switch (GetFtnConfigAttrTokenMap().Get(nPrefix
, sLocalName
))
256 case XML_TOK_FTNCONFIG_CITATION_STYLENAME
:
257 sCitationStyle
= sValue
;
259 case XML_TOK_FTNCONFIG_ANCHOR_STYLENAME
:
260 sAnchorStyle
= sValue
;
262 case XML_TOK_FTNCONFIG_DEFAULT_STYLENAME
:
263 sDefaultStyle
= sValue
;
265 case XML_TOK_FTNCONFIG_PAGE_STYLENAME
:
268 case XML_TOK_FTNCONFIG_OFFSET
:
271 if (SvXMLUnitConverter::convertNumber(nTmp
, sValue
))
273 nOffset
= (sal_uInt16
)nTmp
;
277 case XML_TOK_FTNCONFIG_NUM_PREFIX
:
280 case XML_TOK_FTNCONFIG_NUM_SUFFIX
:
283 case XML_TOK_FTNCONFIG_NUM_FORMAT
:
286 case XML_TOK_FTNCONFIG_NUM_SYNC
:
289 case XML_TOK_FTNCONFIG_START_AT
:
292 if (SvXMLUnitConverter::convertEnum(nTmp
, sValue
,
293 aFootnoteNumberingMap
))
299 case XML_TOK_FTNCONFIG_POSITION
:
300 bPosition
= IsXMLToken( sValue
, XML_DOCUMENT
);
308 SvXMLImportContext
*XMLFootnoteConfigurationImportContext::CreateChildContext(
310 const OUString
& rLocalName
,
311 const Reference
<XAttributeList
> & xAttrList
)
313 SvXMLImportContext
* pContext
= NULL
;
317 if (XML_NAMESPACE_TEXT
== nPrefix
)
319 if ( IsXMLToken( rLocalName
,
320 XML_FOOTNOTE_CONTINUATION_NOTICE_FORWARD
) )
322 pContext
= new XMLFootnoteConfigHelper(GetImport(),
326 else if ( IsXMLToken( rLocalName
,
327 XML_FOOTNOTE_CONTINUATION_NOTICE_BACKWARD
) )
329 pContext
= new XMLFootnoteConfigHelper(GetImport(),
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
,
351 // --> OD 2005-01-31 #i40597# - rename method <CreateAndInsertLate(..)> to
353 void XMLFootnoteConfigurationImportContext::Finish( sal_Bool bOverwrite
)
361 Reference
<XEndnotesSupplier
> xSupplier(
362 GetImport().GetModel(), UNO_QUERY
);
365 ProcessSettings(xSupplier
->getEndnoteSettings());
370 Reference
<XFootnotesSupplier
> xSupplier(
371 GetImport().GetModel(), UNO_QUERY
);
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
)
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
);
415 rConfig
->setPropertyValue(sPropertyPrefix
, aAny
);
418 rConfig
->setPropertyValue(sPropertySuffix
, aAny
);
420 sal_Int16 nNumType
= NumberingType::ARABIC
;
421 GetImport().GetMM100UnitConverter().convertNumFormat( nNumType
, sNumFormat
,
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
;
429 rConfig
->setPropertyValue(sPropertyNumberingType
, aAny
);
432 rConfig
->setPropertyValue(sPropertyStartAt
, aAny
);
436 aAny
.setValue(&bPosition
, ::getBooleanCppuType());
437 rConfig
->setPropertyValue(sPropertyPositionEndOfDoc
, aAny
);
440 rConfig
->setPropertyValue(sPropertyFootnoteCounting
, aAny
);
443 rConfig
->setPropertyValue(sPropertyEndNotice
, aAny
);
445 aAny
<<= sBeginNotice
;
446 rConfig
->setPropertyValue(sPropertyBeginNotice
, aAny
);
450 void XMLFootnoteConfigurationImportContext::SetBeginNotice(
453 sBeginNotice
= sText
;
456 void XMLFootnoteConfigurationImportContext::SetEndNotice(