Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : :
31 : : /** @#file
32 : : *
33 : : * This file implements XMLTextParagraphExport methods to export
34 : : * - footnotes
35 : : * - endnotes
36 : : * - footnote configuration elements
37 : : * - endnote configuration elements
38 : : */
39 : : #include <tools/debug.hxx>
40 : : #include <rtl/ustrbuf.hxx>
41 : : #include <com/sun/star/lang/XServiceInfo.hpp>
42 : : #include <com/sun/star/beans/XPropertySet.hpp>
43 : : #include <com/sun/star/beans/XPropertyState.hpp>
44 : : #include <com/sun/star/text/XTextDocument.hpp>
45 : : #include <com/sun/star/text/XText.hpp>
46 : : #include <com/sun/star/text/XTextContent.hpp>
47 : : #include <com/sun/star/text/XFootnote.hpp>
48 : : #include <com/sun/star/text/XFootnotesSupplier.hpp>
49 : : #include <com/sun/star/text/XEndnotesSupplier.hpp>
50 : : #include <com/sun/star/text/FootnoteNumbering.hpp>
51 : : #include <com/sun/star/container/XNameReplace.hpp>
52 : : #include <sax/tools/converter.hxx>
53 : : #include <xmloff/xmltoken.hxx>
54 : : #include "xmloff/xmlnmspe.hxx"
55 : : #include <xmloff/xmlnumfe.hxx>
56 : : #include <xmloff/xmluconv.hxx>
57 : : #include <xmloff/nmspmap.hxx>
58 : : #include <xmloff/xmlexp.hxx>
59 : : #include <xmloff/families.hxx>
60 : : #include <xmloff/xmlnume.hxx>
61 : : #include "XMLTextCharStyleNamesElementExport.hxx"
62 : : #include <xmloff/XMLEventExport.hxx>
63 : : #include <xmloff/txtparae.hxx>
64 : :
65 : : using ::rtl::OUString;
66 : : using ::rtl::OUStringBuffer;
67 : :
68 : : using namespace ::com::sun::star;
69 : : using namespace ::com::sun::star::uno;
70 : : using namespace ::com::sun::star::lang;
71 : : using namespace ::com::sun::star::beans;
72 : : using namespace ::com::sun::star::text;
73 : : using namespace ::com::sun::star::container;
74 : : using namespace ::xmloff::token;
75 : :
76 : :
77 : 0 : void XMLTextParagraphExport::exportTextFootnote(
78 : : const Reference<XPropertySet> & rPropSet,
79 : : const OUString& rText,
80 : : sal_Bool bAutoStyles, sal_Bool bIsProgress )
81 : : {
82 : : // get footnote and associated text
83 : 0 : Any aAny;
84 [ # # ][ # # ]: 0 : aAny = rPropSet->getPropertyValue(sFootnote);
85 : 0 : Reference<XFootnote> xFootnote;
86 [ # # ]: 0 : aAny >>= xFootnote;
87 [ # # ]: 0 : Reference<XText> xText(xFootnote, UNO_QUERY);
88 : :
89 : : // are we an endnote?
90 [ # # ]: 0 : Reference<XServiceInfo> xServiceInfo( xFootnote, UNO_QUERY );
91 [ # # ][ # # ]: 0 : sal_Bool bIsEndnote = xServiceInfo->supportsService(sTextEndnoteService);
92 : :
93 [ # # ]: 0 : if (bAutoStyles)
94 : : {
95 : : // handle formatting of citation mark
96 [ # # ]: 0 : Add( XML_STYLE_FAMILY_TEXT_TEXT, rPropSet );
97 : :
98 : : // handle formatting within footnote
99 : : exportTextFootnoteHelper(xFootnote, xText, rText,
100 [ # # ]: 0 : bAutoStyles, bIsEndnote, bIsProgress );
101 : : }
102 : : else
103 : : {
104 : : // create span (for citation mark) if necessary; footnote content
105 : : // wil be handled via exportTextFootnoteHelper, exportText
106 : : sal_Bool bHasHyperlink;
107 : 0 : sal_Bool bIsUICharStyle = sal_False;
108 : 0 : sal_Bool bHasAutoStyle = sal_False;
109 : :
110 : : OUString sStyle = FindTextStyleAndHyperlink( rPropSet, bHasHyperlink,
111 [ # # ]: 0 : bIsUICharStyle, bHasAutoStyle );
112 : :
113 : : // export hyperlink (if we have one)
114 : 0 : Reference < XPropertySetInfo > xPropSetInfo;
115 [ # # ]: 0 : if( bHasHyperlink )
116 : : {
117 [ # # ]: 0 : Reference<XPropertyState> xPropState( rPropSet, UNO_QUERY );
118 [ # # ][ # # ]: 0 : xPropSetInfo = rPropSet->getPropertySetInfo();
[ # # ]
119 : : bHasHyperlink =
120 [ # # ]: 0 : addHyperlinkAttributes( rPropSet, xPropState, xPropSetInfo );
121 : : }
122 : 0 : SvXMLElementExport aHyperlink( GetExport(), bHasHyperlink,
123 : : XML_NAMESPACE_TEXT, XML_A,
124 [ # # ]: 0 : sal_False, sal_False );
125 : :
126 [ # # ]: 0 : if( bHasHyperlink )
127 : : {
128 : : // export events (if supported)
129 : : OUString sHyperLinkEvents(RTL_CONSTASCII_USTRINGPARAM(
130 [ # # ]: 0 : "HyperLinkEvents"));
131 [ # # ][ # # ]: 0 : if (xPropSetInfo->hasPropertyByName(sHyperLinkEvents))
[ # # ]
132 : : {
133 [ # # ][ # # ]: 0 : Any a = rPropSet->getPropertyValue(sHyperLinkEvents);
134 : 0 : Reference<XNameReplace> xName;
135 [ # # ]: 0 : a >>= xName;
136 [ # # ][ # # ]: 0 : GetExport().GetEventExport().Export(xName, sal_False);
137 : 0 : }
138 : : }
139 : :
140 : : {
141 : : XMLTextCharStyleNamesElementExport aCharStylesExport(
142 : 0 : GetExport(), bIsUICharStyle &&
143 : : aCharStyleNamesPropInfoCache.hasProperty(
144 [ # # ]: 0 : rPropSet ), bHasAutoStyle,
145 [ # # ][ # # ]: 0 : rPropSet, sCharStyleNames );
[ # # ]
146 [ # # ]: 0 : if( !sStyle.isEmpty() )
147 : : {
148 : 0 : GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_STYLE_NAME,
149 [ # # # # ]: 0 : GetExport().EncodeStyleName( sStyle ) );
150 : 0 : SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_TEXT,
151 [ # # ]: 0 : XML_SPAN, sal_False, sal_False );
152 : : exportTextFootnoteHelper(xFootnote, xText, rText,
153 [ # # ][ # # ]: 0 : bAutoStyles, bIsEndnote, bIsProgress );
154 : : }
155 : : else
156 : : {
157 : : exportTextFootnoteHelper(xFootnote, xText, rText,
158 [ # # ]: 0 : bAutoStyles, bIsEndnote, bIsProgress );
159 [ # # ]: 0 : }
160 [ # # ]: 0 : }
161 : 0 : }
162 : 0 : }
163 : :
164 : :
165 : 0 : void XMLTextParagraphExport::exportTextFootnoteHelper(
166 : : const Reference<XFootnote> & rFootnote,
167 : : const Reference<XText> & rText,
168 : : const OUString& rTextString,
169 : : sal_Bool bAutoStyles,
170 : : sal_Bool bIsEndnote,
171 : : sal_Bool bIsProgress )
172 : : {
173 [ # # ]: 0 : if (bAutoStyles)
174 : : {
175 : 0 : exportText(rText, bAutoStyles, bIsProgress, sal_True );
176 : : }
177 : : else
178 : : {
179 : : // export reference Id (for reference fields)
180 [ # # ]: 0 : Reference<XPropertySet> xPropSet(rFootnote, UNO_QUERY);
181 [ # # ][ # # ]: 0 : Any aAny = xPropSet->getPropertyValue(sReferenceId);
182 : 0 : sal_Int32 nNumber = 0;
183 : 0 : aAny >>= nNumber;
184 : 0 : OUStringBuffer aBuf;
185 [ # # ]: 0 : aBuf.appendAscii("ftn");
186 [ # # ]: 0 : aBuf.append(nNumber);
187 : 0 : GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_ID,
188 [ # # # # ]: 0 : aBuf.makeStringAndClear());
189 : 0 : GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_NOTE_CLASS,
190 : : GetXMLToken( bIsEndnote ? XML_ENDNOTE
191 [ # # # # ]: 0 : : XML_FOOTNOTE ) );
[ # # ]
192 : :
193 : 0 : SvXMLElementExport aNote(GetExport(), XML_NAMESPACE_TEXT,
194 [ # # ]: 0 : XML_NOTE, sal_False, sal_False);
195 : : {
196 : : // handle label vs. automatic numbering
197 [ # # ][ # # ]: 0 : OUString sLabel = rFootnote->getLabel();
198 [ # # ]: 0 : if (!sLabel.isEmpty())
199 : : {
200 : 0 : GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_LABEL,
201 [ # # ]: 0 : sLabel);
202 : : }
203 : : // else: automatic numbering -> no attribute
204 : :
205 : 0 : SvXMLElementExport aCite(GetExport(), XML_NAMESPACE_TEXT,
206 [ # # ]: 0 : XML_NOTE_CITATION, sal_False, sal_False);
207 [ # # ][ # # ]: 0 : GetExport().Characters(rTextString);
208 : : }
209 : :
210 : : {
211 : 0 : SvXMLElementExport aBody(GetExport(), XML_NAMESPACE_TEXT,
212 [ # # ]: 0 : XML_NOTE_BODY, sal_False, sal_False);
213 [ # # ][ # # ]: 0 : exportText(rText, bAutoStyles, bIsProgress, sal_True );
214 [ # # ]: 0 : }
215 : : }
216 : 0 : }
217 : :
218 : :
219 : 19 : void XMLTextParagraphExport::exportTextFootnoteConfiguration()
220 : : {
221 : : // footnote settings
222 : 19 : Reference<XFootnotesSupplier> aFootnotesSupplier(GetExport().GetModel(),
223 [ + - ]: 19 : UNO_QUERY);
224 : : Reference<XPropertySet> aFootnoteConfiguration(
225 [ + - ][ + - ]: 19 : aFootnotesSupplier->getFootnoteSettings());
226 [ + - ]: 19 : exportTextFootnoteConfigurationHelper(aFootnoteConfiguration, sal_False);
227 : :
228 : : // endnote settings
229 : 19 : Reference<XEndnotesSupplier> aEndnotesSupplier(GetExport().GetModel(),
230 [ + - ]: 19 : UNO_QUERY);
231 : : Reference<XPropertySet> aEndnoteConfiguration(
232 [ + - ][ + - ]: 19 : aEndnotesSupplier->getEndnoteSettings());
233 [ + - ]: 19 : exportTextFootnoteConfigurationHelper(aEndnoteConfiguration, sal_True);
234 : 19 : }
235 : :
236 : :
237 : 228 : void lcl_exportString(
238 : : SvXMLExport& rExport,
239 : : const Reference<XPropertySet> & rPropSet,
240 : : const OUString& sProperty,
241 : : sal_uInt16 nPrefix,
242 : : enum XMLTokenEnum eElement,
243 : : sal_Bool bEncodeName,
244 : : sal_Bool bOmitIfEmpty)
245 : : {
246 : : DBG_ASSERT( eElement != XML_TOKEN_INVALID, "need element token");
247 : :
248 [ + - ][ + - ]: 228 : Any aAny = rPropSet->getPropertyValue(sProperty);
249 : 228 : OUString sTmp;
250 : 228 : aAny >>= sTmp;
251 [ - + ][ - + ]: 228 : if (!bOmitIfEmpty || !sTmp.isEmpty())
[ + - ]
252 : : {
253 [ # # ]: 0 : if( bEncodeName )
254 [ # # ]: 0 : sTmp = rExport.EncodeStyleName( sTmp );
255 [ # # ]: 0 : rExport.AddAttribute(nPrefix, eElement, sTmp);
256 : 228 : }
257 : 228 : }
258 : :
259 : 38 : void XMLTextParagraphExport::exportTextFootnoteConfigurationHelper(
260 : : const Reference<XPropertySet> & rFootnoteConfig,
261 : : sal_Bool bIsEndnote)
262 : : {
263 : 38 : GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_NOTE_CLASS,
264 : : GetXMLToken( bIsEndnote ? XML_ENDNOTE
265 [ + + ]: 76 : : XML_FOOTNOTE ) );
[ + - + - ]
266 : : // default/paragraph style
267 : 38 : lcl_exportString( GetExport(), rFootnoteConfig,
268 : : sParaStyleName,
269 : : XML_NAMESPACE_TEXT, XML_DEFAULT_STYLE_NAME,
270 [ + - ]: 38 : sal_True, sal_True);
271 : :
272 : : // citation style
273 : 38 : lcl_exportString( GetExport(), rFootnoteConfig,
274 : : sCharStyleName,
275 : : XML_NAMESPACE_TEXT, XML_CITATION_STYLE_NAME,
276 [ + - ]: 38 : sal_True, sal_True);
277 : :
278 : : // citation body style
279 : 38 : lcl_exportString( GetExport(), rFootnoteConfig,
280 : : sAnchorCharStyleName,
281 : : XML_NAMESPACE_TEXT, XML_CITATION_BODY_STYLE_NAME,
282 [ + - ]: 38 : sal_True, sal_True);
283 : :
284 : : // page style
285 : 38 : lcl_exportString( GetExport(), rFootnoteConfig,
286 : : sPageStyleName,
287 : : XML_NAMESPACE_TEXT, XML_MASTER_PAGE_NAME,
288 [ + - ]: 38 : sal_True, sal_True );
289 : :
290 : : // prefix
291 : 38 : lcl_exportString( GetExport(), rFootnoteConfig, sPrefix,
292 [ + - ]: 38 : XML_NAMESPACE_STYLE, XML_NUM_PREFIX, sal_False, sal_True);
293 : :
294 : : // suffix
295 : 38 : lcl_exportString( GetExport(), rFootnoteConfig, sSuffix,
296 [ + - ]: 38 : XML_NAMESPACE_STYLE, XML_NUM_SUFFIX, sal_False, sal_True);
297 : :
298 : :
299 : :
300 : 38 : Any aAny;
301 : :
302 : : // numbering style
303 : 38 : OUStringBuffer sBuffer;
304 [ + - ][ + - ]: 38 : aAny = rFootnoteConfig->getPropertyValue(sNumberingType);
305 : 38 : sal_Int16 nNumbering = 0;
306 : 38 : aAny >>= nNumbering;
307 [ + - ]: 38 : GetExport().GetMM100UnitConverter().convertNumFormat( sBuffer, nNumbering);
308 : 38 : GetExport().AddAttribute(XML_NAMESPACE_STYLE, XML_NUM_FORMAT,
309 [ + - + - ]: 76 : sBuffer.makeStringAndClear() );
310 [ + - ]: 38 : GetExport().GetMM100UnitConverter().convertNumLetterSync( sBuffer, nNumbering);
311 [ - + ]: 38 : if (sBuffer.getLength() )
312 : : {
313 : 0 : GetExport().AddAttribute(XML_NAMESPACE_STYLE, XML_NUM_LETTER_SYNC,
314 [ # # # # ]: 0 : sBuffer.makeStringAndClear());
315 : : }
316 : :
317 : : // StartAt / start-value
318 [ + - ][ + - ]: 38 : aAny = rFootnoteConfig->getPropertyValue(sStartAt);
319 : 38 : sal_Int16 nOffset = 0;
320 : 38 : aAny >>= nOffset;
321 [ + - ]: 38 : ::sax::Converter::convertNumber(sBuffer, (sal_Int32)nOffset);
322 : 38 : GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_START_VALUE,
323 [ + - + - ]: 76 : sBuffer.makeStringAndClear());
324 : :
325 : : // some properties are for footnotes only
326 [ + + ]: 38 : if (!bIsEndnote)
327 : : {
328 : : // footnotes position
329 [ + - ]: 19 : aAny = rFootnoteConfig->getPropertyValue(
330 [ + - ]: 19 : sPositionEndOfDoc);
331 : 19 : GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_FOOTNOTES_POSITION,
332 : 19 : ( (*(sal_Bool *)aAny.getValue()) ?
333 [ + - ][ - + ]: 38 : XML_DOCUMENT : XML_PAGE ) );
334 : :
335 [ + - ][ + - ]: 19 : aAny = rFootnoteConfig->getPropertyValue(sFootnoteCounting);
336 : 19 : sal_Int16 nTmp = 0;
337 : 19 : aAny >>= nTmp;
338 : : enum XMLTokenEnum eElement;
339 [ - - + ]: 19 : switch (nTmp)
340 : : {
341 : : case FootnoteNumbering::PER_PAGE:
342 : 0 : eElement = XML_PAGE;
343 : 0 : break;
344 : : case FootnoteNumbering::PER_CHAPTER:
345 : 0 : eElement = XML_CHAPTER;
346 : 0 : break;
347 : : case FootnoteNumbering::PER_DOCUMENT:
348 : : default:
349 : 19 : eElement = XML_DOCUMENT;
350 : 19 : break;
351 : : }
352 : 19 : GetExport().AddAttribute(XML_NAMESPACE_TEXT,
353 [ + - ]: 19 : XML_START_NUMBERING_AT, eElement);
354 : : }
355 : :
356 : : // element
357 : : SvXMLElementExport aFootnoteConfigElement(
358 : 38 : GetExport(), XML_NAMESPACE_TEXT,
359 : : XML_NOTES_CONFIGURATION,
360 [ + - ]: 38 : sal_True, sal_True);
361 : :
362 : : // two element for footnote content
363 [ + + ]: 38 : if (!bIsEndnote)
364 : : {
365 : 19 : OUString sTmp;
366 : :
367 : : // end notice / quo vadis
368 [ + - ][ + - ]: 19 : aAny = rFootnoteConfig->getPropertyValue(sEndNotice);
369 : 19 : aAny >>= sTmp;
370 : :
371 [ - + ]: 19 : if (!sTmp.isEmpty())
372 : : {
373 : 0 : SvXMLElementExport aElem(GetExport(), XML_NAMESPACE_TEXT,
374 : : XML_FOOTNOTE_CONTINUATION_NOTICE_FORWARD,
375 [ # # ]: 0 : sal_True, sal_False);
376 [ # # ][ # # ]: 0 : GetExport().Characters(sTmp);
377 : : }
378 : :
379 : : // begin notice / ergo sum
380 [ + - ][ + - ]: 19 : aAny = rFootnoteConfig->getPropertyValue(sBeginNotice);
381 : 19 : aAny >>= sTmp;
382 : :
383 [ - + ]: 19 : if (!sTmp.isEmpty())
384 : : {
385 : 0 : SvXMLElementExport aElem(GetExport(), XML_NAMESPACE_TEXT,
386 : : XML_FOOTNOTE_CONTINUATION_NOTICE_BACKWARD,
387 [ # # ]: 0 : sal_True, sal_False);
388 [ # # ][ # # ]: 0 : GetExport().Characters(sTmp);
389 : 19 : }
390 [ + - ]: 38 : }
391 : 38 : }
392 : :
393 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|