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 .
24 * This file implements XMLTextParagraphExport methods to export
27 * - footnote configuration elements
28 * - endnote configuration elements
30 #include <tools/debug.hxx>
31 #include <rtl/ustrbuf.hxx>
32 #include <com/sun/star/lang/XServiceInfo.hpp>
33 #include <com/sun/star/beans/XPropertySet.hpp>
34 #include <com/sun/star/beans/XPropertyState.hpp>
35 #include <com/sun/star/text/XTextDocument.hpp>
36 #include <com/sun/star/text/XText.hpp>
37 #include <com/sun/star/text/XTextContent.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/container/XNameReplace.hpp>
43 #include <sax/tools/converter.hxx>
44 #include <xmloff/xmltoken.hxx>
45 #include <xmloff/xmlnmspe.hxx>
46 #include <xmloff/xmlnumfe.hxx>
47 #include <xmloff/xmluconv.hxx>
48 #include <xmloff/nmspmap.hxx>
49 #include <xmloff/xmlexp.hxx>
50 #include <xmloff/families.hxx>
51 #include <xmloff/xmlnume.hxx>
52 #include "XMLTextCharStyleNamesElementExport.hxx"
53 #include <xmloff/XMLEventExport.hxx>
54 #include <xmloff/txtparae.hxx>
57 using namespace ::com::sun::star
;
58 using namespace ::com::sun::star::uno
;
59 using namespace ::com::sun::star::lang
;
60 using namespace ::com::sun::star::beans
;
61 using namespace ::com::sun::star::text
;
62 using namespace ::com::sun::star::container
;
63 using namespace ::xmloff::token
;
66 void XMLTextParagraphExport::exportTextFootnote(
67 const Reference
<XPropertySet
> & rPropSet
,
68 const OUString
& rText
,
69 bool bAutoStyles
, bool bIsProgress
)
71 // get footnote and associated text
73 aAny
= rPropSet
->getPropertyValue(sFootnote
);
74 Reference
<XFootnote
> xFootnote
;
76 Reference
<XText
> xText(xFootnote
, UNO_QUERY
);
79 Reference
<XServiceInfo
> xServiceInfo( xFootnote
, UNO_QUERY
);
80 bool bIsEndnote
= xServiceInfo
->supportsService(sTextEndnoteService
);
84 // handle formatting of citation mark
85 Add( XML_STYLE_FAMILY_TEXT_TEXT
, rPropSet
);
87 // handle formatting within footnote
88 exportTextFootnoteHelper(xFootnote
, xText
, rText
,
89 bAutoStyles
, bIsEndnote
, bIsProgress
);
93 // create span (for citation mark) if necessary; footnote content
94 // wil be handled via exportTextFootnoteHelper, exportText
96 bool bIsUICharStyle
= false;
97 bool bHasAutoStyle
= false;
99 OUString sStyle
= FindTextStyleAndHyperlink( rPropSet
, bHasHyperlink
,
100 bIsUICharStyle
, bHasAutoStyle
);
102 // export hyperlink (if we have one)
103 Reference
< XPropertySetInfo
> xPropSetInfo
;
106 Reference
<XPropertyState
> xPropState( rPropSet
, UNO_QUERY
);
107 xPropSetInfo
= rPropSet
->getPropertySetInfo();
109 addHyperlinkAttributes( rPropSet
, xPropState
, xPropSetInfo
);
111 SvXMLElementExport
aHyperlink( GetExport(), bHasHyperlink
,
112 XML_NAMESPACE_TEXT
, XML_A
,
117 // export events (if supported)
118 OUString
sHyperLinkEvents("HyperLinkEvents");
119 if (xPropSetInfo
->hasPropertyByName(sHyperLinkEvents
))
121 Any a
= rPropSet
->getPropertyValue(sHyperLinkEvents
);
122 Reference
<XNameReplace
> xName
;
124 GetExport().GetEventExport().Export(xName
, false);
129 XMLTextCharStyleNamesElementExport
aCharStylesExport(
130 GetExport(), bIsUICharStyle
&&
131 aCharStyleNamesPropInfoCache
.hasProperty(
132 rPropSet
), bHasAutoStyle
,
133 rPropSet
, sCharStyleNames
);
134 if( !sStyle
.isEmpty() )
136 GetExport().AddAttribute( XML_NAMESPACE_TEXT
, XML_STYLE_NAME
,
137 GetExport().EncodeStyleName( sStyle
) );
138 SvXMLElementExport
aElem( GetExport(), XML_NAMESPACE_TEXT
,
139 XML_SPAN
, false, false );
140 exportTextFootnoteHelper(xFootnote
, xText
, rText
,
141 bAutoStyles
, bIsEndnote
, bIsProgress
);
145 exportTextFootnoteHelper(xFootnote
, xText
, rText
,
146 bAutoStyles
, bIsEndnote
, bIsProgress
);
153 void XMLTextParagraphExport::exportTextFootnoteHelper(
154 const Reference
<XFootnote
> & rFootnote
,
155 const Reference
<XText
> & rText
,
156 const OUString
& rTextString
,
163 exportText(rText
, bAutoStyles
, bIsProgress
, true );
167 // export reference Id (for reference fields)
168 Reference
<XPropertySet
> xPropSet(rFootnote
, UNO_QUERY
);
169 Any aAny
= xPropSet
->getPropertyValue(sReferenceId
);
170 sal_Int32 nNumber
= 0;
173 aBuf
.appendAscii("ftn");
174 aBuf
.append(nNumber
);
175 GetExport().AddAttribute(XML_NAMESPACE_TEXT
, XML_ID
,
176 aBuf
.makeStringAndClear());
177 GetExport().AddAttribute(XML_NAMESPACE_TEXT
, XML_NOTE_CLASS
,
178 GetXMLToken( bIsEndnote
? XML_ENDNOTE
181 SvXMLElementExport
aNote(GetExport(), XML_NAMESPACE_TEXT
,
182 XML_NOTE
, false, false);
184 // handle label vs. automatic numbering
185 OUString sLabel
= rFootnote
->getLabel();
186 if (!sLabel
.isEmpty())
188 GetExport().AddAttribute(XML_NAMESPACE_TEXT
, XML_LABEL
,
191 // else: automatic numbering -> no attribute
193 SvXMLElementExport
aCite(GetExport(), XML_NAMESPACE_TEXT
,
194 XML_NOTE_CITATION
, false, false);
195 GetExport().Characters(rTextString
);
199 SvXMLElementExport
aBody(GetExport(), XML_NAMESPACE_TEXT
,
200 XML_NOTE_BODY
, false, false);
201 exportText(rText
, bAutoStyles
, bIsProgress
, true );
207 void XMLTextParagraphExport::exportTextFootnoteConfiguration()
210 Reference
<XFootnotesSupplier
> aFootnotesSupplier(GetExport().GetModel(),
212 Reference
<XPropertySet
> aFootnoteConfiguration(
213 aFootnotesSupplier
->getFootnoteSettings());
214 exportTextFootnoteConfigurationHelper(aFootnoteConfiguration
, false);
217 Reference
<XEndnotesSupplier
> aEndnotesSupplier(GetExport().GetModel(),
219 Reference
<XPropertySet
> aEndnoteConfiguration(
220 aEndnotesSupplier
->getEndnoteSettings());
221 exportTextFootnoteConfigurationHelper(aEndnoteConfiguration
, true);
225 static void lcl_exportString(
226 SvXMLExport
& rExport
,
227 const Reference
<XPropertySet
> & rPropSet
,
228 const OUString
& sProperty
,
230 enum XMLTokenEnum eElement
,
234 DBG_ASSERT( eElement
!= XML_TOKEN_INVALID
, "need element token");
236 Any aAny
= rPropSet
->getPropertyValue(sProperty
);
239 if (!bOmitIfEmpty
|| !sTmp
.isEmpty())
242 sTmp
= rExport
.EncodeStyleName( sTmp
);
243 rExport
.AddAttribute(nPrefix
, eElement
, sTmp
);
247 void XMLTextParagraphExport::exportTextFootnoteConfigurationHelper(
248 const Reference
<XPropertySet
> & rFootnoteConfig
,
251 GetExport().AddAttribute(XML_NAMESPACE_TEXT
, XML_NOTE_CLASS
,
252 GetXMLToken( bIsEndnote
? XML_ENDNOTE
254 // default/paragraph style
255 lcl_exportString( GetExport(), rFootnoteConfig
,
257 XML_NAMESPACE_TEXT
, XML_DEFAULT_STYLE_NAME
,
261 lcl_exportString( GetExport(), rFootnoteConfig
,
263 XML_NAMESPACE_TEXT
, XML_CITATION_STYLE_NAME
,
266 // citation body style
267 lcl_exportString( GetExport(), rFootnoteConfig
,
268 sAnchorCharStyleName
,
269 XML_NAMESPACE_TEXT
, XML_CITATION_BODY_STYLE_NAME
,
273 lcl_exportString( GetExport(), rFootnoteConfig
,
275 XML_NAMESPACE_TEXT
, XML_MASTER_PAGE_NAME
,
279 lcl_exportString( GetExport(), rFootnoteConfig
, sPrefix
,
280 XML_NAMESPACE_STYLE
, XML_NUM_PREFIX
, false, true);
283 lcl_exportString( GetExport(), rFootnoteConfig
, sSuffix
,
284 XML_NAMESPACE_STYLE
, XML_NUM_SUFFIX
, false, true);
291 OUStringBuffer sBuffer
;
292 aAny
= rFootnoteConfig
->getPropertyValue(sNumberingType
);
293 sal_Int16 nNumbering
= 0;
295 GetExport().GetMM100UnitConverter().convertNumFormat( sBuffer
, nNumbering
);
296 GetExport().AddAttribute(XML_NAMESPACE_STYLE
, XML_NUM_FORMAT
,
297 sBuffer
.makeStringAndClear() );
298 SvXMLUnitConverter::convertNumLetterSync( sBuffer
, nNumbering
);
299 if (!sBuffer
.isEmpty() )
301 GetExport().AddAttribute(XML_NAMESPACE_STYLE
, XML_NUM_LETTER_SYNC
,
302 sBuffer
.makeStringAndClear());
305 // StartAt / start-value
306 aAny
= rFootnoteConfig
->getPropertyValue(sStartAt
);
307 sal_Int16 nOffset
= 0;
309 ::sax::Converter::convertNumber(sBuffer
, (sal_Int32
)nOffset
);
310 GetExport().AddAttribute(XML_NAMESPACE_TEXT
, XML_START_VALUE
,
311 sBuffer
.makeStringAndClear());
313 // some properties are for footnotes only
316 // footnotes position
317 aAny
= rFootnoteConfig
->getPropertyValue(
319 GetExport().AddAttribute(XML_NAMESPACE_TEXT
, XML_FOOTNOTES_POSITION
,
320 ( (*static_cast<sal_Bool
const *>(aAny
.getValue())) ?
321 XML_DOCUMENT
: XML_PAGE
) );
323 aAny
= rFootnoteConfig
->getPropertyValue(sFootnoteCounting
);
326 enum XMLTokenEnum eElement
;
329 case FootnoteNumbering::PER_PAGE
:
332 case FootnoteNumbering::PER_CHAPTER
:
333 eElement
= XML_CHAPTER
;
335 case FootnoteNumbering::PER_DOCUMENT
:
337 eElement
= XML_DOCUMENT
;
340 GetExport().AddAttribute(XML_NAMESPACE_TEXT
,
341 XML_START_NUMBERING_AT
, eElement
);
345 SvXMLElementExport
aFootnoteConfigElement(
346 GetExport(), XML_NAMESPACE_TEXT
,
347 XML_NOTES_CONFIGURATION
,
350 // two element for footnote content
355 // end notice / quo vadis
356 aAny
= rFootnoteConfig
->getPropertyValue(sEndNotice
);
361 SvXMLElementExport
aElem(GetExport(), XML_NAMESPACE_TEXT
,
362 XML_FOOTNOTE_CONTINUATION_NOTICE_FORWARD
,
364 GetExport().Characters(sTmp
);
367 // begin notice / ergo sum
368 aAny
= rFootnoteConfig
->getPropertyValue(sBeginNotice
);
373 SvXMLElementExport
aElem(GetExport(), XML_NAMESPACE_TEXT
,
374 XML_FOOTNOTE_CONTINUATION_NOTICE_BACKWARD
,
376 GetExport().Characters(sTmp
);
381 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */