Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include "XMLSectionExport.hxx"
21 : #include <rtl/ustring.hxx>
22 : #include <rtl/ustrbuf.hxx>
23 :
24 : #include <vector>
25 :
26 :
27 : #include <com/sun/star/lang/XServiceInfo.hpp>
28 : #include <com/sun/star/lang/Locale.hpp>
29 : #include <com/sun/star/container/XIndexReplace.hpp>
30 : #include <com/sun/star/beans/XPropertySet.hpp>
31 : #include <com/sun/star/beans/PropertyValue.hpp>
32 : #include <com/sun/star/beans/PropertyValues.hpp>
33 : #include <com/sun/star/beans/PropertyState.hpp>
34 : #include <com/sun/star/text/XText.hpp>
35 : #include <com/sun/star/text/XTextSection.hpp>
36 : #include <com/sun/star/text/SectionFileLink.hpp>
37 : #include <com/sun/star/container/XNamed.hpp>
38 : #include <com/sun/star/container/XNameAccess.hpp>
39 : #include <com/sun/star/text/XDocumentIndex.hpp>
40 : #include <com/sun/star/uno/XInterface.hpp>
41 : #include <com/sun/star/text/BibliographyDataField.hpp>
42 : #include <com/sun/star/text/XTextFieldsSupplier.hpp>
43 : #include <com/sun/star/text/XChapterNumberingSupplier.hpp>
44 : #include <com/sun/star/text/ChapterFormat.hpp> //i90246
45 :
46 : #include <sax/tools/converter.hxx>
47 :
48 : #include <xmloff/xmltoken.hxx>
49 : #include "xmloff/xmlnmspe.hxx"
50 : #include <xmloff/families.hxx>
51 : #include <xmloff/xmluconv.hxx>
52 : #include <xmloff/nmspmap.hxx>
53 : #include <xmloff/xmlexp.hxx>
54 : #include <xmloff/xmltkmap.hxx>
55 : #include "txtflde.hxx"
56 :
57 :
58 :
59 : using namespace ::com::sun::star;
60 : using namespace ::com::sun::star::text;
61 : using namespace ::com::sun::star::uno;
62 : using namespace ::std;
63 : using namespace ::xmloff::token;
64 :
65 : using ::rtl::OUString;
66 : using ::rtl::OUStringBuffer;
67 : using ::com::sun::star::beans::XPropertySet;
68 : using ::com::sun::star::beans::PropertyValue;
69 : using ::com::sun::star::beans::PropertyValues;
70 : using ::com::sun::star::beans::PropertyState;
71 : using ::com::sun::star::container::XIndexReplace;
72 : using ::com::sun::star::container::XNameAccess;
73 : using ::com::sun::star::container::XNamed;
74 : using ::com::sun::star::lang::XServiceInfo;
75 : using ::com::sun::star::lang::Locale;
76 : using ::com::sun::star::uno::XInterface;
77 :
78 :
79 8 : XMLSectionExport::XMLSectionExport(
80 : SvXMLExport& rExp,
81 : XMLTextParagraphExport& rParaExp)
82 : : sCondition(RTL_CONSTASCII_USTRINGPARAM("Condition"))
83 : , sCreateFromChapter(RTL_CONSTASCII_USTRINGPARAM("CreateFromChapter"))
84 : , sCreateFromEmbeddedObjects(RTL_CONSTASCII_USTRINGPARAM("CreateFromEmbeddedObjects"))
85 : , sCreateFromGraphicObjects(RTL_CONSTASCII_USTRINGPARAM("CreateFromGraphicObjects"))
86 : , sCreateFromLabels(RTL_CONSTASCII_USTRINGPARAM("CreateFromLabels"))
87 : , sCreateFromMarks(RTL_CONSTASCII_USTRINGPARAM("CreateFromMarks"))
88 : , sCreateFromOtherEmbeddedObjects(RTL_CONSTASCII_USTRINGPARAM("CreateFromOtherEmbeddedObjects"))
89 : , sCreateFromOutline(RTL_CONSTASCII_USTRINGPARAM("CreateFromOutline"))
90 : , sCreateFromStarCalc(RTL_CONSTASCII_USTRINGPARAM("CreateFromStarCalc"))
91 : , sCreateFromStarChart(RTL_CONSTASCII_USTRINGPARAM("CreateFromStarChart"))
92 : , sCreateFromStarDraw(RTL_CONSTASCII_USTRINGPARAM("CreateFromStarDraw"))
93 : , sCreateFromStarImage(RTL_CONSTASCII_USTRINGPARAM("CreateFromStarImage"))
94 : , sCreateFromStarMath(RTL_CONSTASCII_USTRINGPARAM("CreateFromStarMath"))
95 : , sCreateFromTables(RTL_CONSTASCII_USTRINGPARAM("CreateFromTables"))
96 : , sCreateFromTextFrames(RTL_CONSTASCII_USTRINGPARAM("CreateFromTextFrames"))
97 : , sDdeCommandElement(RTL_CONSTASCII_USTRINGPARAM("DDECommandElement"))
98 : , sDdeCommandFile(RTL_CONSTASCII_USTRINGPARAM("DDECommandFile"))
99 : , sDdeCommandType(RTL_CONSTASCII_USTRINGPARAM("DDECommandType"))
100 : , sFileLink(RTL_CONSTASCII_USTRINGPARAM("FileLink"))
101 : , sIsCaseSensitive(RTL_CONSTASCII_USTRINGPARAM("IsCaseSensitive"))
102 : , sIsProtected(RTL_CONSTASCII_USTRINGPARAM("IsProtected"))
103 : , sIsVisible(RTL_CONSTASCII_USTRINGPARAM("IsVisible"))
104 : , sLabelCategory(RTL_CONSTASCII_USTRINGPARAM("LabelCategory"))
105 : , sLabelDisplayType(RTL_CONSTASCII_USTRINGPARAM("LabelDisplayType"))
106 : , sLevel(RTL_CONSTASCII_USTRINGPARAM("Level"))
107 : , sLevelFormat(RTL_CONSTASCII_USTRINGPARAM("LevelFormat"))
108 : , sLevelParagraphStyles(RTL_CONSTASCII_USTRINGPARAM("LevelParagraphStyles"))
109 : , sLinkRegion(RTL_CONSTASCII_USTRINGPARAM("LinkRegion"))
110 : , sMainEntryCharacterStyleName(RTL_CONSTASCII_USTRINGPARAM("MainEntryCharacterStyleName"))
111 : , sParaStyleHeading(RTL_CONSTASCII_USTRINGPARAM("ParaStyleHeading"))
112 : , sParaStyleLevel(RTL_CONSTASCII_USTRINGPARAM("ParaStyleLevel"))
113 : , sTitle(RTL_CONSTASCII_USTRINGPARAM("Title"))
114 : , sName(RTL_CONSTASCII_USTRINGPARAM("Name"))
115 : , sUseAlphabeticalSeparators(RTL_CONSTASCII_USTRINGPARAM("UseAlphabeticalSeparators"))
116 : , sUseCombinedEntries(RTL_CONSTASCII_USTRINGPARAM("UseCombinedEntries"))
117 : , sUseDash(RTL_CONSTASCII_USTRINGPARAM("UseDash"))
118 : , sUseKeyAsEntry(RTL_CONSTASCII_USTRINGPARAM("UseKeyAsEntry"))
119 : , sUseLevelFromSource(RTL_CONSTASCII_USTRINGPARAM("UseLevelFromSource"))
120 : , sUsePP(RTL_CONSTASCII_USTRINGPARAM("UsePP"))
121 : , sUseUpperCase(RTL_CONSTASCII_USTRINGPARAM("UseUpperCase"))
122 : , sIsCommaSeparated(RTL_CONSTASCII_USTRINGPARAM("IsCommaSeparated"))
123 : , sIsAutomaticUpdate(RTL_CONSTASCII_USTRINGPARAM("IsAutomaticUpdate"))
124 : , sIsRelativeTabstops(RTL_CONSTASCII_USTRINGPARAM("IsRelativeTabstops"))
125 : , sCreateFromLevelParagraphStyles(RTL_CONSTASCII_USTRINGPARAM("CreateFromLevelParagraphStyles"))
126 : , sDocumentIndex(RTL_CONSTASCII_USTRINGPARAM("DocumentIndex"))
127 : , sContentSection(RTL_CONSTASCII_USTRINGPARAM("ContentSection"))
128 : , sHeaderSection(RTL_CONSTASCII_USTRINGPARAM("HeaderSection"))
129 :
130 : , sTextSection(RTL_CONSTASCII_USTRINGPARAM("TextSection"))
131 : , sIsGlobalDocumentSection(RTL_CONSTASCII_USTRINGPARAM("IsGlobalDocumentSection"))
132 : , sProtectionKey(RTL_CONSTASCII_USTRINGPARAM("ProtectionKey"))
133 : , sSortAlgorithm(RTL_CONSTASCII_USTRINGPARAM("SortAlgorithm"))
134 : , sLocale(RTL_CONSTASCII_USTRINGPARAM("Locale"))
135 : , sUserIndexName(RTL_CONSTASCII_USTRINGPARAM("UserIndexName"))
136 :
137 : , sIsCurrentlyVisible(RTL_CONSTASCII_USTRINGPARAM("IsCurrentlyVisible"))
138 : , sHeadingStyleName(RTL_CONSTASCII_USTRINGPARAM("HeadingStyleName"))
139 :
140 : , rExport(rExp)
141 : , rParaExport(rParaExp)
142 8 : , bHeadingDummiesExported( sal_False )
143 : {
144 8 : }
145 :
146 :
147 0 : void XMLSectionExport::ExportSectionStart(
148 : const Reference<XTextSection> & rSection,
149 : sal_Bool bAutoStyles)
150 : {
151 0 : Reference<XPropertySet> xPropertySet(rSection, UNO_QUERY);
152 :
153 : // always export section (auto) style
154 0 : if (bAutoStyles)
155 : {
156 : // get PropertySet and add section style
157 0 : GetParaExport().Add( XML_STYLE_FAMILY_TEXT_SECTION, xPropertySet );
158 : }
159 : else
160 : {
161 : // always export section style
162 0 : GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_STYLE_NAME,
163 0 : GetParaExport().Find(
164 : XML_STYLE_FAMILY_TEXT_SECTION,
165 0 : xPropertySet, sEmpty ) );
166 :
167 : // xml:id for RDF metadata
168 0 : GetExport().AddAttributeXmlId(rSection);
169 :
170 : // export index or regular section
171 0 : Reference<XDocumentIndex> xIndex;
172 0 : if (GetIndex(rSection, xIndex))
173 : {
174 0 : if (xIndex.is())
175 : {
176 : // we are an index
177 0 : ExportIndexStart(xIndex);
178 : }
179 : else
180 : {
181 : // we are an index header
182 0 : ExportIndexHeaderStart(rSection);
183 : }
184 : }
185 : else
186 : {
187 : // we are not an index
188 0 : ExportRegularSectionStart(rSection);
189 0 : }
190 0 : }
191 0 : }
192 :
193 0 : sal_Bool XMLSectionExport::GetIndex(
194 : const Reference<XTextSection> & rSection,
195 : Reference<XDocumentIndex> & rIndex) const
196 : {
197 : // first, reset result
198 0 : sal_Bool bRet = sal_False;
199 0 : rIndex = NULL;
200 :
201 : // get section Properties
202 0 : Reference<XPropertySet> xSectionPropSet(rSection, UNO_QUERY);
203 :
204 : // then check if this section happens to be inside an index
205 0 : if (xSectionPropSet->getPropertySetInfo()->
206 0 : hasPropertyByName(sDocumentIndex))
207 : {
208 0 : Any aAny = xSectionPropSet->getPropertyValue(sDocumentIndex);
209 0 : Reference<XDocumentIndex> xDocumentIndex;
210 0 : aAny >>= xDocumentIndex;
211 :
212 : // OK, are we inside of an index
213 0 : if (xDocumentIndex.is())
214 : {
215 : // is the enclosing index identical with "our" section?
216 0 : Reference<XPropertySet> xIndexPropSet(xDocumentIndex, UNO_QUERY);
217 0 : aAny = xIndexPropSet->getPropertyValue(sContentSection);
218 0 : Reference<XTextSection> xEnclosingSection;
219 0 : aAny >>= xEnclosingSection;
220 :
221 : // if the enclosing section is "our" section, then we are an index!
222 0 : if (rSection == xEnclosingSection)
223 : {
224 0 : rIndex = xDocumentIndex;
225 0 : bRet = sal_True;
226 : }
227 : // else: index header or regular section
228 :
229 : // is the enclosing index identical with the header section?
230 0 : aAny = xIndexPropSet->getPropertyValue(sHeaderSection);
231 : // now mis-named: contains header section
232 0 : aAny >>= xEnclosingSection;
233 :
234 : // if the enclosing section is "our" section, then we are an index!
235 0 : if (rSection == xEnclosingSection)
236 : {
237 0 : bRet = sal_True;
238 0 : }
239 : // else: regular section
240 0 : }
241 : // else: we aren't even inside of an index
242 : }
243 : // else: we don't even know what an index is.
244 :
245 0 : return bRet;
246 : }
247 :
248 :
249 0 : void XMLSectionExport::ExportSectionEnd(
250 : const Reference<XTextSection> & rSection,
251 : sal_Bool bAutoStyles)
252 : {
253 : // no end section for styles
254 0 : if (!bAutoStyles)
255 : {
256 0 : enum XMLTokenEnum eElement = XML_TOKEN_INVALID;
257 :
258 : // export index or regular section end
259 0 : Reference<XDocumentIndex> xIndex;
260 0 : if (GetIndex(rSection, xIndex))
261 : {
262 0 : if (xIndex.is())
263 : {
264 : // index end: close index body element
265 0 : GetExport().EndElement( XML_NAMESPACE_TEXT, XML_INDEX_BODY,
266 0 : sal_True );
267 0 : GetExport().IgnorableWhitespace();
268 :
269 0 : switch (MapSectionType(xIndex->getServiceName()))
270 : {
271 : case TEXT_SECTION_TYPE_TOC:
272 0 : eElement = XML_TABLE_OF_CONTENT;
273 0 : break;
274 :
275 : case TEXT_SECTION_TYPE_ILLUSTRATION:
276 0 : eElement = XML_ILLUSTRATION_INDEX;
277 0 : break;
278 :
279 : case TEXT_SECTION_TYPE_ALPHABETICAL:
280 0 : eElement = XML_ALPHABETICAL_INDEX;
281 0 : break;
282 :
283 : case TEXT_SECTION_TYPE_TABLE:
284 0 : eElement = XML_TABLE_INDEX;
285 0 : break;
286 :
287 : case TEXT_SECTION_TYPE_OBJECT:
288 0 : eElement = XML_OBJECT_INDEX;
289 0 : break;
290 :
291 : case TEXT_SECTION_TYPE_USER:
292 0 : eElement = XML_USER_INDEX;
293 0 : break;
294 :
295 : case TEXT_SECTION_TYPE_BIBLIOGRAPHY:
296 0 : eElement = XML_BIBLIOGRAPHY;
297 0 : break;
298 :
299 : default:
300 : OSL_FAIL("unknown index type");
301 : // default: skip index!
302 0 : break;
303 : }
304 : }
305 : else
306 : {
307 0 : eElement = XML_INDEX_TITLE;
308 : }
309 : }
310 : else
311 : {
312 0 : eElement = XML_SECTION;
313 : }
314 :
315 0 : if (XML_TOKEN_INVALID != eElement)
316 : {
317 : // any old attributes?
318 0 : GetExport().CheckAttrList();
319 :
320 : // element surrounded by whitespace
321 0 : GetExport().EndElement( XML_NAMESPACE_TEXT, eElement, sal_True);
322 0 : GetExport().IgnorableWhitespace();
323 : }
324 : else
325 : {
326 : OSL_FAIL("Need element name!");
327 0 : }
328 : }
329 : // else: autostyles -> ignore
330 0 : }
331 :
332 0 : void XMLSectionExport::ExportIndexStart(
333 : const Reference<XDocumentIndex> & rIndex)
334 : {
335 : // get PropertySet
336 0 : Reference<XPropertySet> xPropertySet(rIndex, UNO_QUERY);
337 :
338 0 : switch (MapSectionType(rIndex->getServiceName()))
339 : {
340 : case TEXT_SECTION_TYPE_TOC:
341 0 : ExportTableOfContentStart(xPropertySet);
342 0 : break;
343 :
344 : case TEXT_SECTION_TYPE_ILLUSTRATION:
345 0 : ExportIllustrationIndexStart(xPropertySet);
346 0 : break;
347 :
348 : case TEXT_SECTION_TYPE_ALPHABETICAL:
349 0 : ExportAlphabeticalIndexStart(xPropertySet);
350 0 : break;
351 :
352 : case TEXT_SECTION_TYPE_TABLE:
353 0 : ExportTableIndexStart(xPropertySet);
354 0 : break;
355 :
356 : case TEXT_SECTION_TYPE_OBJECT:
357 0 : ExportObjectIndexStart(xPropertySet);
358 0 : break;
359 :
360 : case TEXT_SECTION_TYPE_USER:
361 0 : ExportUserIndexStart(xPropertySet);
362 0 : break;
363 :
364 : case TEXT_SECTION_TYPE_BIBLIOGRAPHY:
365 0 : ExportBibliographyStart(xPropertySet);
366 0 : break;
367 :
368 : default:
369 : // skip index
370 : OSL_FAIL("unknown index type");
371 0 : break;
372 0 : }
373 0 : }
374 :
375 0 : void XMLSectionExport::ExportIndexHeaderStart(
376 : const Reference<XTextSection> & rSection)
377 : {
378 : // export name, dammit!
379 0 : Reference<XNamed> xName(rSection, UNO_QUERY);
380 0 : GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_NAME, xName->getName());
381 :
382 : // format already handled -> export only start element
383 0 : GetExport().StartElement( XML_NAMESPACE_TEXT, XML_INDEX_TITLE, sal_True );
384 0 : GetExport().IgnorableWhitespace();
385 0 : }
386 :
387 :
388 : SvXMLEnumStringMapEntry const aIndexTypeMap[] =
389 : {
390 : ENUM_STRING_MAP_ENTRY( "com.sun.star.text.ContentIndex", TEXT_SECTION_TYPE_TOC ),
391 : ENUM_STRING_MAP_ENTRY( "com.sun.star.text.DocumentIndex", TEXT_SECTION_TYPE_ALPHABETICAL ),
392 : ENUM_STRING_MAP_ENTRY( "com.sun.star.text.TableIndex", TEXT_SECTION_TYPE_TABLE ),
393 : ENUM_STRING_MAP_ENTRY( "com.sun.star.text.ObjectIndex", TEXT_SECTION_TYPE_OBJECT ),
394 : ENUM_STRING_MAP_ENTRY( "com.sun.star.text.Bibliography", TEXT_SECTION_TYPE_BIBLIOGRAPHY ),
395 : ENUM_STRING_MAP_ENTRY( "com.sun.star.text.UserIndex", TEXT_SECTION_TYPE_USER ),
396 : ENUM_STRING_MAP_ENTRY( "com.sun.star.text.IllustrationsIndex", TEXT_SECTION_TYPE_ILLUSTRATION ),
397 : ENUM_STRING_MAP_END()
398 : };
399 :
400 0 : enum SectionTypeEnum XMLSectionExport::MapSectionType(
401 : const OUString& rServiceName)
402 : {
403 0 : enum SectionTypeEnum eType = TEXT_SECTION_TYPE_UNKNOWN;
404 :
405 : sal_uInt16 nTmp;
406 0 : if (SvXMLUnitConverter::convertEnum(nTmp, rServiceName, aIndexTypeMap))
407 : {
408 0 : eType = (enum SectionTypeEnum)nTmp;
409 : }
410 :
411 : // TODO: index header section types, etc.
412 :
413 0 : return eType;
414 : }
415 :
416 0 : void XMLSectionExport::ExportRegularSectionStart(
417 : const Reference<XTextSection> & rSection)
418 : {
419 : // style name already handled in ExportSectionStart(...)
420 :
421 0 : Reference<XNamed> xName(rSection, UNO_QUERY);
422 0 : GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_NAME, xName->getName());
423 :
424 : // get XPropertySet for other values
425 0 : Reference<XPropertySet> xPropSet(rSection, UNO_QUERY);
426 0 : Any aAny;
427 :
428 : // condition and display
429 0 : aAny = xPropSet->getPropertyValue(sCondition);
430 0 : OUString sCond;
431 0 : aAny >>= sCond;
432 0 : enum XMLTokenEnum eDisplay = XML_TOKEN_INVALID;
433 0 : if (!sCond.isEmpty())
434 : {
435 : OUString sQValue =
436 0 : GetExport().GetNamespaceMap().GetQNameByKey( XML_NAMESPACE_OOOW,
437 0 : sCond, sal_False );
438 0 : GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_CONDITION, sQValue);
439 0 : eDisplay = XML_CONDITION;
440 :
441 : // #97450# store hidden-status (of conditional sections only)
442 0 : aAny = xPropSet->getPropertyValue(sIsCurrentlyVisible);
443 0 : if (! *(sal_Bool*)aAny.getValue())
444 : {
445 0 : GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_IS_HIDDEN,
446 0 : XML_TRUE);
447 0 : }
448 : }
449 : else
450 : {
451 0 : eDisplay = XML_NONE;
452 : }
453 0 : aAny = xPropSet->getPropertyValue(sIsVisible);
454 0 : if (! *(sal_Bool*)aAny.getValue())
455 : {
456 0 : GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_DISPLAY, eDisplay);
457 : }
458 :
459 : // protect + protection key
460 0 : aAny = xPropSet->getPropertyValue(sIsProtected);
461 0 : if (*(sal_Bool*)aAny.getValue())
462 : {
463 0 : GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_PROTECTED, XML_TRUE);
464 : }
465 0 : Sequence<sal_Int8> aPassword;
466 0 : xPropSet->getPropertyValue(sProtectionKey) >>= aPassword;
467 0 : if (aPassword.getLength() > 0)
468 : {
469 0 : OUStringBuffer aBuffer;
470 0 : ::sax::Converter::encodeBase64(aBuffer, aPassword);
471 0 : GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_PROTECTION_KEY,
472 0 : aBuffer.makeStringAndClear());
473 : }
474 :
475 : // export element
476 0 : GetExport().IgnorableWhitespace();
477 0 : GetExport().StartElement( XML_NAMESPACE_TEXT, XML_SECTION, sal_True );
478 :
479 : // data source
480 : // unfortunately, we have to test all relevant strings for non-zero length
481 0 : aAny = xPropSet->getPropertyValue(sFileLink);
482 0 : SectionFileLink aFileLink;
483 0 : aAny >>= aFileLink;
484 :
485 0 : aAny = xPropSet->getPropertyValue(sLinkRegion);
486 0 : OUString sRegionName;
487 0 : aAny >>= sRegionName;
488 :
489 0 : if ( !aFileLink.FileURL.isEmpty() ||
490 0 : !aFileLink.FilterName.isEmpty() ||
491 0 : !sRegionName.isEmpty())
492 : {
493 0 : if (!aFileLink.FileURL.isEmpty())
494 : {
495 0 : GetExport().AddAttribute(XML_NAMESPACE_XLINK, XML_HREF,
496 0 : GetExport().GetRelativeReference( aFileLink.FileURL) );
497 : }
498 :
499 0 : if (!aFileLink.FilterName.isEmpty())
500 : {
501 0 : GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_FILTER_NAME,
502 0 : aFileLink.FilterName);
503 : }
504 :
505 0 : if (!sRegionName.isEmpty())
506 : {
507 0 : GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_SECTION_NAME,
508 0 : sRegionName);
509 : }
510 :
511 0 : SvXMLElementExport aElem(GetExport(),
512 : XML_NAMESPACE_TEXT, XML_SECTION_SOURCE,
513 0 : sal_True, sal_True);
514 : }
515 : else
516 : {
517 : // check for DDE first
518 0 : if (xPropSet->getPropertySetInfo()->hasPropertyByName(sDdeCommandFile))
519 : {
520 : // data source DDE
521 : // unfortunately, we have to test all relevant strings for
522 : // non-zero length
523 0 : aAny = xPropSet->getPropertyValue(sDdeCommandFile);
524 0 : OUString sApplication;
525 0 : aAny >>= sApplication;
526 0 : aAny = xPropSet->getPropertyValue(sDdeCommandType);
527 0 : OUString sTopic;
528 0 : aAny >>= sTopic;
529 0 : aAny = xPropSet->getPropertyValue(sDdeCommandElement);
530 0 : OUString sItem;
531 0 : aAny >>= sItem;
532 :
533 0 : if ( !sApplication.isEmpty() ||
534 0 : !sTopic.isEmpty() ||
535 0 : !sItem.isEmpty())
536 : {
537 0 : GetExport().AddAttribute(XML_NAMESPACE_OFFICE,
538 0 : XML_DDE_APPLICATION, sApplication);
539 0 : GetExport().AddAttribute(XML_NAMESPACE_OFFICE, XML_DDE_TOPIC,
540 0 : sTopic);
541 0 : GetExport().AddAttribute(XML_NAMESPACE_OFFICE, XML_DDE_ITEM,
542 0 : sItem);
543 :
544 0 : aAny = xPropSet->getPropertyValue(sIsAutomaticUpdate);
545 0 : if (*(sal_Bool*)aAny.getValue())
546 : {
547 0 : GetExport().AddAttribute(XML_NAMESPACE_OFFICE,
548 0 : XML_AUTOMATIC_UPDATE, XML_TRUE);
549 : }
550 :
551 0 : SvXMLElementExport aElem(GetExport(),
552 : XML_NAMESPACE_OFFICE,
553 0 : XML_DDE_SOURCE, sal_True, sal_True);
554 0 : }
555 : // else: no DDE data source
556 : }
557 : // else: no DDE on this system
558 0 : }
559 0 : }
560 :
561 0 : void XMLSectionExport::ExportTableOfContentStart(
562 : const Reference<XPropertySet> & rPropertySet)
563 : {
564 : // export TOC element start
565 0 : ExportBaseIndexStart(XML_TABLE_OF_CONTENT, rPropertySet);
566 :
567 : // scope for table-of-content-source element
568 : {
569 :
570 0 : Any aAny;
571 :
572 : // TOC specific index source attributes:
573 :
574 : // outline-level: 1..10
575 0 : sal_Int16 nLevel = sal_Int16();
576 0 : if( rPropertySet->getPropertyValue(sLevel) >>= nLevel )
577 : {
578 0 : OUStringBuffer sBuffer;
579 0 : ::sax::Converter::convertNumber(sBuffer, (sal_Int32)nLevel);
580 0 : GetExport().AddAttribute(XML_NAMESPACE_TEXT,
581 : XML_OUTLINE_LEVEL,
582 0 : sBuffer.makeStringAndClear());
583 : }
584 :
585 : // use outline level
586 : ExportBoolean(rPropertySet, sCreateFromOutline,
587 0 : XML_USE_OUTLINE_LEVEL, sal_True);
588 :
589 : // use index marks
590 : ExportBoolean(rPropertySet, sCreateFromMarks,
591 0 : XML_USE_INDEX_MARKS, sal_True);
592 :
593 : // use level styles
594 : ExportBoolean(rPropertySet, sCreateFromLevelParagraphStyles,
595 0 : XML_USE_INDEX_SOURCE_STYLES, sal_False);
596 :
597 0 : ExportBaseIndexSource(TEXT_SECTION_TYPE_TOC, rPropertySet);
598 : }
599 :
600 0 : ExportBaseIndexBody(TEXT_SECTION_TYPE_TOC, rPropertySet);
601 0 : }
602 :
603 0 : void XMLSectionExport::ExportObjectIndexStart(
604 : const Reference<XPropertySet> & rPropertySet)
605 : {
606 : // export index start
607 0 : ExportBaseIndexStart(XML_OBJECT_INDEX, rPropertySet);
608 :
609 : // scope for index source element
610 : {
611 : ExportBoolean(rPropertySet, sCreateFromOtherEmbeddedObjects,
612 0 : XML_USE_OTHER_OBJECTS, sal_False);
613 : ExportBoolean(rPropertySet, sCreateFromStarCalc,
614 0 : XML_USE_SPREADSHEET_OBJECTS, sal_False);
615 : ExportBoolean(rPropertySet, sCreateFromStarChart,
616 0 : XML_USE_CHART_OBJECTS, sal_False);
617 : ExportBoolean(rPropertySet, sCreateFromStarDraw,
618 0 : XML_USE_DRAW_OBJECTS, sal_False);
619 : ExportBoolean(rPropertySet, sCreateFromStarMath,
620 0 : XML_USE_MATH_OBJECTS, sal_False);
621 :
622 0 : ExportBaseIndexSource(TEXT_SECTION_TYPE_OBJECT, rPropertySet);
623 : }
624 :
625 0 : ExportBaseIndexBody(TEXT_SECTION_TYPE_OBJECT, rPropertySet);
626 0 : }
627 :
628 0 : void XMLSectionExport::ExportIllustrationIndexStart(
629 : const Reference<XPropertySet> & rPropertySet)
630 : {
631 : // export index start
632 0 : ExportBaseIndexStart(XML_ILLUSTRATION_INDEX, rPropertySet);
633 :
634 : // scope for index source element
635 : {
636 : // export common attributes for illustration and table indices
637 0 : ExportTableAndIllustrationIndexSourceAttributes(rPropertySet);
638 :
639 0 : ExportBaseIndexSource(TEXT_SECTION_TYPE_ILLUSTRATION, rPropertySet);
640 : }
641 :
642 0 : ExportBaseIndexBody(TEXT_SECTION_TYPE_ILLUSTRATION, rPropertySet);
643 0 : }
644 :
645 0 : void XMLSectionExport::ExportTableIndexStart(
646 : const Reference<XPropertySet> & rPropertySet)
647 : {
648 : // export index start
649 0 : ExportBaseIndexStart(XML_TABLE_INDEX, rPropertySet);
650 :
651 : // scope for index source element
652 : {
653 : // export common attributes for illustration and table indices
654 0 : ExportTableAndIllustrationIndexSourceAttributes(rPropertySet);
655 :
656 0 : ExportBaseIndexSource(TEXT_SECTION_TYPE_TABLE, rPropertySet);
657 : }
658 :
659 0 : ExportBaseIndexBody(TEXT_SECTION_TYPE_TABLE, rPropertySet);
660 0 : }
661 :
662 0 : void XMLSectionExport::ExportAlphabeticalIndexStart(
663 : const Reference<XPropertySet> & rPropertySet)
664 : {
665 : // export TOC element start
666 0 : ExportBaseIndexStart(XML_ALPHABETICAL_INDEX, rPropertySet);
667 :
668 : // scope for table-of-content-source element
669 : {
670 :
671 : // style name (if present)
672 0 : Any aAny;
673 0 : aAny = rPropertySet->getPropertyValue(sMainEntryCharacterStyleName);
674 0 : OUString sStyleName;
675 0 : aAny >>= sStyleName;
676 0 : if (!sStyleName.isEmpty())
677 : {
678 0 : GetExport().AddAttribute(XML_NAMESPACE_TEXT,
679 : XML_MAIN_ENTRY_STYLE_NAME,
680 0 : GetExport().EncodeStyleName( sStyleName ));
681 : }
682 :
683 : // other (boolean) attributes
684 : ExportBoolean(rPropertySet, sIsCaseSensitive, XML_IGNORE_CASE,
685 0 : sal_False, sal_True);
686 : ExportBoolean(rPropertySet, sUseAlphabeticalSeparators,
687 0 : XML_ALPHABETICAL_SEPARATORS, sal_False);
688 : ExportBoolean(rPropertySet, sUseCombinedEntries, XML_COMBINE_ENTRIES,
689 0 : sal_True);
690 : ExportBoolean(rPropertySet, sUseDash, XML_COMBINE_ENTRIES_WITH_DASH,
691 0 : sal_False);
692 : ExportBoolean(rPropertySet, sUseKeyAsEntry, XML_USE_KEYS_AS_ENTRIES,
693 0 : sal_False);
694 : ExportBoolean(rPropertySet, sUsePP, XML_COMBINE_ENTRIES_WITH_PP,
695 0 : sal_True);
696 : ExportBoolean(rPropertySet, sUseUpperCase, XML_CAPITALIZE_ENTRIES,
697 0 : sal_False);
698 : ExportBoolean(rPropertySet, sIsCommaSeparated, XML_COMMA_SEPARATED,
699 0 : sal_False);
700 :
701 : // sort algorithm
702 0 : aAny = rPropertySet->getPropertyValue(sSortAlgorithm);
703 0 : OUString sAlgorithm;
704 0 : aAny >>= sAlgorithm;
705 0 : if (!sAlgorithm.isEmpty())
706 : {
707 0 : GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_SORT_ALGORITHM,
708 0 : sAlgorithm );
709 : }
710 :
711 : // locale
712 0 : aAny = rPropertySet->getPropertyValue(sLocale);
713 0 : Locale aLocale;
714 0 : aAny >>= aLocale;
715 0 : GetExport().AddAttribute(XML_NAMESPACE_FO, XML_LANGUAGE,
716 0 : aLocale.Language);
717 0 : GetExport().AddAttribute(XML_NAMESPACE_FO, XML_COUNTRY,
718 0 : aLocale.Country);
719 :
720 0 : ExportBaseIndexSource(TEXT_SECTION_TYPE_ALPHABETICAL, rPropertySet);
721 : }
722 :
723 0 : ExportBaseIndexBody(TEXT_SECTION_TYPE_ALPHABETICAL, rPropertySet);
724 0 : }
725 :
726 0 : void XMLSectionExport::ExportUserIndexStart(
727 : const Reference<XPropertySet> & rPropertySet)
728 : {
729 : // export TOC element start
730 0 : ExportBaseIndexStart(XML_USER_INDEX, rPropertySet);
731 :
732 : // scope for table-of-content-source element
733 : {
734 : // bool attributes
735 : ExportBoolean(rPropertySet, sCreateFromEmbeddedObjects,
736 0 : XML_USE_OBJECTS, sal_False);
737 : ExportBoolean(rPropertySet, sCreateFromGraphicObjects,
738 0 : XML_USE_GRAPHICS, sal_False);
739 : ExportBoolean(rPropertySet, sCreateFromMarks,
740 0 : XML_USE_INDEX_MARKS, sal_False);
741 : ExportBoolean(rPropertySet, sCreateFromTables,
742 0 : XML_USE_TABLES, sal_False);
743 : ExportBoolean(rPropertySet, sCreateFromTextFrames,
744 0 : XML_USE_FLOATING_FRAMES, sal_False);
745 : ExportBoolean(rPropertySet, sUseLevelFromSource,
746 0 : XML_COPY_OUTLINE_LEVELS, sal_False);
747 : ExportBoolean(rPropertySet, sCreateFromLevelParagraphStyles,
748 0 : XML_USE_INDEX_SOURCE_STYLES, sal_False);
749 :
750 0 : Any aAny = rPropertySet->getPropertyValue( sUserIndexName );
751 0 : OUString sIndexName;
752 0 : aAny >>= sIndexName;
753 0 : GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_INDEX_NAME,
754 0 : sIndexName);
755 :
756 0 : ExportBaseIndexSource(TEXT_SECTION_TYPE_USER, rPropertySet);
757 : }
758 :
759 0 : ExportBaseIndexBody(TEXT_SECTION_TYPE_USER, rPropertySet);
760 0 : }
761 :
762 0 : void XMLSectionExport::ExportBibliographyStart(
763 : const Reference<XPropertySet> & rPropertySet)
764 : {
765 : // export TOC element start
766 0 : ExportBaseIndexStart(XML_BIBLIOGRAPHY, rPropertySet);
767 :
768 : // scope for table-of-content-source element
769 : {
770 : // No attributes. Fine.
771 :
772 0 : ExportBaseIndexSource(TEXT_SECTION_TYPE_BIBLIOGRAPHY, rPropertySet);
773 : }
774 :
775 0 : ExportBaseIndexBody(TEXT_SECTION_TYPE_BIBLIOGRAPHY, rPropertySet);
776 0 : }
777 :
778 :
779 0 : void XMLSectionExport::ExportBaseIndexStart(
780 : XMLTokenEnum eElement,
781 : const Reference<XPropertySet> & rPropertySet)
782 : {
783 : // protect + protection key
784 0 : Any aAny = rPropertySet->getPropertyValue(sIsProtected);
785 0 : if (*(sal_Bool*)aAny.getValue())
786 : {
787 0 : GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_PROTECTED, XML_TRUE);
788 : }
789 :
790 : // index name
791 0 : OUString sIndexName;
792 0 : rPropertySet->getPropertyValue(sName) >>= sIndexName;
793 0 : if ( !sIndexName.isEmpty() )
794 : {
795 0 : GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_NAME, sIndexName);
796 : }
797 :
798 : // index Element start
799 0 : GetExport().IgnorableWhitespace();
800 0 : GetExport().StartElement( XML_NAMESPACE_TEXT, eElement, sal_False );
801 0 : }
802 :
803 : static const XMLTokenEnum aTypeSourceElementNameMap[] =
804 : {
805 : XML_TABLE_OF_CONTENT_SOURCE, // TOC
806 : XML_TABLE_INDEX_SOURCE, // table index
807 : XML_ILLUSTRATION_INDEX_SOURCE, // illustration index
808 : XML_OBJECT_INDEX_SOURCE, // object index
809 : XML_USER_INDEX_SOURCE, // user index
810 : XML_ALPHABETICAL_INDEX_SOURCE, // alphabetical index
811 : XML_BIBLIOGRAPHY_SOURCE // bibliography
812 : };
813 :
814 0 : void XMLSectionExport::ExportBaseIndexSource(
815 : SectionTypeEnum eType,
816 : const Reference<XPropertySet> & rPropertySet)
817 : {
818 : // check type
819 : OSL_ENSURE(eType >= TEXT_SECTION_TYPE_TOC, "illegal index type");
820 : OSL_ENSURE(eType <= TEXT_SECTION_TYPE_BIBLIOGRAPHY, "illegal index type");
821 :
822 0 : Any aAny;
823 :
824 : // common attributes; not supported by bibliography
825 0 : if (eType != TEXT_SECTION_TYPE_BIBLIOGRAPHY)
826 : {
827 : // document or chapter index?
828 0 : aAny = rPropertySet->getPropertyValue(sCreateFromChapter);
829 0 : if (*(sal_Bool*)aAny.getValue())
830 : {
831 0 : GetExport().AddAttribute(XML_NAMESPACE_TEXT,
832 0 : XML_INDEX_SCOPE, XML_CHAPTER);
833 : }
834 :
835 : // tab-stops relative to margin?
836 0 : aAny = rPropertySet->getPropertyValue(sIsRelativeTabstops);
837 0 : if (! *(sal_Bool*)aAny.getValue())
838 : {
839 0 : GetExport().AddAttribute(XML_NAMESPACE_TEXT,
840 : XML_RELATIVE_TAB_STOP_POSITION,
841 0 : XML_FALSE);
842 : }
843 : }
844 :
845 : // the index source element (all indices)
846 0 : SvXMLElementExport aElem(GetExport(),
847 : XML_NAMESPACE_TEXT,
848 : GetXMLToken(
849 : aTypeSourceElementNameMap[
850 0 : eType - TEXT_SECTION_TYPE_TOC]),
851 0 : sal_True, sal_True);
852 :
853 : // scope for title template (all indices)
854 : {
855 : // header style name
856 0 : aAny = rPropertySet->getPropertyValue(sParaStyleHeading);
857 0 : OUString sStyleName;
858 0 : aAny >>= sStyleName;
859 0 : GetExport().AddAttribute(XML_NAMESPACE_TEXT,
860 : XML_STYLE_NAME,
861 0 : GetExport().EncodeStyleName( sStyleName ));
862 :
863 : // title template
864 0 : SvXMLElementExport aHeaderTemplate(GetExport(),
865 : XML_NAMESPACE_TEXT,
866 : XML_INDEX_TITLE_TEMPLATE,
867 0 : sal_True, sal_False);
868 :
869 : // title as element content
870 0 : aAny = rPropertySet->getPropertyValue(sTitle);
871 0 : OUString sTitleString;
872 0 : aAny >>= sTitleString;
873 0 : GetExport().Characters(sTitleString);
874 : }
875 :
876 : // export level templates (all indices)
877 0 : aAny = rPropertySet->getPropertyValue(sLevelFormat);
878 0 : Reference<XIndexReplace> xLevelTemplates;
879 0 : aAny >>= xLevelTemplates;
880 :
881 : // iterate over level formats;
882 : // skip element 0 (empty template for title)
883 0 : sal_Int32 nLevelCount = xLevelTemplates->getCount();
884 0 : for(sal_Int32 i = 1; i<nLevelCount; i++)
885 : {
886 : // get sequence
887 0 : Sequence<PropertyValues> aTemplateSequence;
888 0 : aAny = xLevelTemplates->getByIndex(i);
889 0 : aAny >>= aTemplateSequence;
890 :
891 : // export the sequence (abort export if an error occurred; #91214#)
892 : sal_Bool bResult =
893 0 : ExportIndexTemplate(eType, i, rPropertySet, aTemplateSequence);
894 0 : if ( !bResult )
895 : break;
896 0 : }
897 :
898 : // only TOC and user index:
899 : // styles from which to build the index (LevelParagraphStyles)
900 0 : if ( (TEXT_SECTION_TYPE_TOC == eType) ||
901 : (TEXT_SECTION_TYPE_USER == eType) )
902 : {
903 0 : aAny = rPropertySet->getPropertyValue(sLevelParagraphStyles);
904 0 : Reference<XIndexReplace> xLevelParagraphStyles;
905 0 : aAny >>= xLevelParagraphStyles;
906 0 : ExportLevelParagraphStyles(xLevelParagraphStyles);
907 0 : }
908 0 : }
909 :
910 :
911 0 : void XMLSectionExport::ExportBaseIndexBody(
912 : SectionTypeEnum
913 : #if OSL_DEBUG_LEVEL > 0
914 : eType
915 : #endif
916 : ,
917 : const Reference<XPropertySet> &)
918 : {
919 : // type not used; checked anyway.
920 : OSL_ENSURE(eType >= TEXT_SECTION_TYPE_TOC, "illegal index type");
921 : OSL_ENSURE(eType <= TEXT_SECTION_TYPE_BIBLIOGRAPHY, "illegal index type");
922 :
923 : // export start only
924 :
925 : // any old attributes?
926 0 : GetExport().CheckAttrList();
927 :
928 : // start surrounded by whitespace
929 0 : GetExport().IgnorableWhitespace();
930 0 : GetExport().StartElement( XML_NAMESPACE_TEXT, XML_INDEX_BODY, sal_True );
931 0 : }
932 :
933 0 : void XMLSectionExport::ExportTableAndIllustrationIndexSourceAttributes(
934 : const Reference<XPropertySet> & rPropertySet)
935 : {
936 : // use caption
937 0 : Any aAny = rPropertySet->getPropertyValue(sCreateFromLabels);
938 0 : if (! *(sal_Bool*)aAny.getValue())
939 : {
940 0 : GetExport().AddAttribute(XML_NAMESPACE_TEXT,
941 0 : XML_USE_CAPTION, XML_FALSE);
942 : }
943 :
944 : // sequence name
945 0 : aAny = rPropertySet->getPropertyValue(sLabelCategory);
946 0 : OUString sSequenceName;
947 0 : aAny >>= sSequenceName;
948 0 : GetExport().AddAttribute(XML_NAMESPACE_TEXT,
949 : XML_CAPTION_SEQUENCE_NAME,
950 0 : sSequenceName);
951 :
952 : // caption format
953 0 : aAny = rPropertySet->getPropertyValue(sLabelDisplayType);
954 0 : sal_Int16 nType = 0;
955 0 : aAny >>= nType;
956 0 : GetExport().AddAttribute(XML_NAMESPACE_TEXT,
957 : XML_CAPTION_SEQUENCE_FORMAT,
958 0 : XMLTextFieldExport::MapReferenceType(nType));
959 0 : }
960 :
961 :
962 : // map index of LevelFormats to attribute value;
963 : // level 0 is always the header
964 : static const XMLTokenEnum aLevelNameTOCMap[] =
965 : { XML_TOKEN_INVALID, XML_1, XML_2, XML_3, XML_4, XML_5, XML_6, XML_7,
966 : XML_8, XML_9, XML_10, XML_TOKEN_INVALID };
967 : static const XMLTokenEnum aLevelNameTableMap[] =
968 : { XML_TOKEN_INVALID, XML__EMPTY, XML_TOKEN_INVALID };
969 : static const XMLTokenEnum aLevelNameAlphaMap[] =
970 : { XML_TOKEN_INVALID, XML_SEPARATOR, XML_1, XML_2, XML_3, XML_TOKEN_INVALID };
971 : static const XMLTokenEnum aLevelNameBibliographyMap[] =
972 : { XML_TOKEN_INVALID, XML_ARTICLE, XML_BOOK, XML_BOOKLET, XML_CONFERENCE,
973 : XML_CUSTOM1, XML_CUSTOM2, XML_CUSTOM3, XML_CUSTOM4,
974 : XML_CUSTOM5, XML_EMAIL, XML_INBOOK, XML_INCOLLECTION,
975 : XML_INPROCEEDINGS, XML_JOURNAL,
976 : XML_MANUAL, XML_MASTERSTHESIS, XML_MISC, XML_PHDTHESIS,
977 : XML_PROCEEDINGS, XML_TECHREPORT, XML_UNPUBLISHED, XML_WWW,
978 : XML_TOKEN_INVALID };
979 :
980 : static const XMLTokenEnum* aTypeLevelNameMap[] =
981 : {
982 : aLevelNameTOCMap, // TOC
983 : aLevelNameTableMap, // table index
984 : aLevelNameTableMap, // illustration index
985 : aLevelNameTableMap, // object index
986 : aLevelNameTOCMap, // user index
987 : aLevelNameAlphaMap, // alphabetical index
988 : aLevelNameBibliographyMap // bibliography
989 : };
990 :
991 : static const sal_Char* aLevelStylePropNameTOCMap[] =
992 : { NULL, "ParaStyleLevel1", "ParaStyleLevel2", "ParaStyleLevel3",
993 : "ParaStyleLevel4", "ParaStyleLevel5", "ParaStyleLevel6",
994 : "ParaStyleLevel7", "ParaStyleLevel8", "ParaStyleLevel9",
995 : "ParaStyleLevel10", NULL };
996 : static const sal_Char* aLevelStylePropNameTableMap[] =
997 : { NULL, "ParaStyleLevel1", NULL };
998 : static const sal_Char* aLevelStylePropNameAlphaMap[] =
999 : { NULL, "ParaStyleSeparator", "ParaStyleLevel1", "ParaStyleLevel2",
1000 : "ParaStyleLevel3", NULL };
1001 : static const sal_Char* aLevelStylePropNameBibliographyMap[] =
1002 : // TODO: replace with real property names, when available
1003 : { NULL, "ParaStyleLevel1", "ParaStyleLevel1", "ParaStyleLevel1",
1004 : "ParaStyleLevel1", "ParaStyleLevel1", "ParaStyleLevel1",
1005 : "ParaStyleLevel1", "ParaStyleLevel1", "ParaStyleLevel1",
1006 : "ParaStyleLevel1", "ParaStyleLevel1", "ParaStyleLevel1",
1007 : "ParaStyleLevel1", "ParaStyleLevel1", "ParaStyleLevel1",
1008 : "ParaStyleLevel1", "ParaStyleLevel1", "ParaStyleLevel1",
1009 : "ParaStyleLevel1", "ParaStyleLevel1", "ParaStyleLevel1",
1010 : "ParaStyleLevel1",
1011 : NULL };
1012 :
1013 : static const sal_Char** aTypeLevelStylePropNameMap[] =
1014 : {
1015 : aLevelStylePropNameTOCMap, // TOC
1016 : aLevelStylePropNameTableMap, // table index
1017 : aLevelStylePropNameTableMap, // illustration index
1018 : aLevelStylePropNameTableMap, // object index
1019 : aLevelStylePropNameTOCMap, // user index
1020 : aLevelStylePropNameAlphaMap, // alphabetical index
1021 : aLevelStylePropNameBibliographyMap // bibliography
1022 : };
1023 :
1024 : static const XMLTokenEnum aTypeLevelAttrMap[] =
1025 : {
1026 : XML_OUTLINE_LEVEL, // TOC
1027 : XML_TOKEN_INVALID, // table index
1028 : XML_TOKEN_INVALID, // illustration index
1029 : XML_TOKEN_INVALID, // object index
1030 : XML_OUTLINE_LEVEL, // user index
1031 : XML_OUTLINE_LEVEL, // alphabetical index
1032 : XML_BIBLIOGRAPHY_TYPE // bibliography
1033 : };
1034 :
1035 : static const XMLTokenEnum aTypeElementNameMap[] =
1036 : {
1037 : XML_TABLE_OF_CONTENT_ENTRY_TEMPLATE, // TOC
1038 : XML_TABLE_INDEX_ENTRY_TEMPLATE, // table index
1039 : XML_ILLUSTRATION_INDEX_ENTRY_TEMPLATE, // illustration index
1040 : XML_OBJECT_INDEX_ENTRY_TEMPLATE, // object index
1041 : XML_USER_INDEX_ENTRY_TEMPLATE, // user index
1042 : XML_ALPHABETICAL_INDEX_ENTRY_TEMPLATE, // alphabetical index
1043 : XML_BIBLIOGRAPHY_ENTRY_TEMPLATE // bibliography
1044 : };
1045 :
1046 :
1047 0 : sal_Bool XMLSectionExport::ExportIndexTemplate(
1048 : SectionTypeEnum eType,
1049 : sal_Int32 nOutlineLevel,
1050 : const Reference<XPropertySet> & rPropertySet,
1051 : Sequence<Sequence<PropertyValue> > & rValues)
1052 : {
1053 : OSL_ENSURE(eType >= TEXT_SECTION_TYPE_TOC, "illegal index type");
1054 : OSL_ENSURE(eType <= TEXT_SECTION_TYPE_BIBLIOGRAPHY, "illegal index type");
1055 : OSL_ENSURE(nOutlineLevel >= 0, "illegal outline level");
1056 :
1057 0 : if ( (eType >= TEXT_SECTION_TYPE_TOC) &&
1058 : (eType <= TEXT_SECTION_TYPE_BIBLIOGRAPHY) &&
1059 : (nOutlineLevel >= 0) )
1060 : {
1061 : // get level name and level attribute name from aLevelNameMap;
1062 : const XMLTokenEnum eLevelAttrName(
1063 0 : aTypeLevelAttrMap[eType-TEXT_SECTION_TYPE_TOC]);
1064 : const XMLTokenEnum eLevelName(
1065 0 : aTypeLevelNameMap[eType-TEXT_SECTION_TYPE_TOC][nOutlineLevel]);
1066 :
1067 : // #92124#: some old documents may be broken, then they have
1068 : // too many template levels; we need to recognize this and
1069 : // export only as many as is legal for the respective index
1070 : // type. To do this, we simply return an error flag, which
1071 : // will then abort further template level exports.
1072 : OSL_ENSURE(XML_TOKEN_INVALID != eLevelName, "can't find level name");
1073 0 : if ( XML_TOKEN_INVALID == eLevelName )
1074 : {
1075 : // output level not found? Then end of templates! #91214#
1076 0 : return sal_False;
1077 : }
1078 :
1079 : // output level name
1080 0 : if ((XML_TOKEN_INVALID != eLevelName) && (XML_TOKEN_INVALID != eLevelAttrName))
1081 : {
1082 0 : GetExport().AddAttribute(XML_NAMESPACE_TEXT,
1083 0 : GetXMLToken(eLevelAttrName),
1084 0 : GetXMLToken(eLevelName));
1085 : }
1086 :
1087 : // paragraph level style name
1088 : const sal_Char* pPropName(
1089 0 : aTypeLevelStylePropNameMap[eType-TEXT_SECTION_TYPE_TOC][nOutlineLevel]);
1090 : OSL_ENSURE(NULL != pPropName, "can't find property name");
1091 0 : if (NULL != pPropName)
1092 : {
1093 0 : Any aAny = rPropertySet->getPropertyValue(
1094 0 : OUString::createFromAscii(pPropName));
1095 0 : OUString sParaStyleName;
1096 0 : aAny >>= sParaStyleName;
1097 0 : GetExport().AddAttribute(XML_NAMESPACE_TEXT,
1098 : XML_STYLE_NAME,
1099 0 : GetExport().EncodeStyleName( sParaStyleName ));
1100 : }
1101 :
1102 : // template element
1103 : const XMLTokenEnum eElementName(
1104 0 : aTypeElementNameMap[eType - TEXT_SECTION_TYPE_TOC]);
1105 0 : SvXMLElementExport aLevelTemplate(GetExport(),
1106 : XML_NAMESPACE_TEXT,
1107 0 : GetXMLToken(eElementName),
1108 0 : sal_True, sal_True);
1109 :
1110 : // export sequence
1111 0 : sal_Int32 nTemplateCount = rValues.getLength();
1112 0 : for(sal_Int32 nTemplateNo = 0;
1113 : nTemplateNo < nTemplateCount;
1114 : nTemplateNo++)
1115 : {
1116 : ExportIndexTemplateElement(
1117 : eType, //i90246
1118 0 : rValues[nTemplateNo]);
1119 0 : }
1120 : }
1121 :
1122 0 : return sal_True;
1123 : }
1124 :
1125 :
1126 : enum TemplateTypeEnum
1127 : {
1128 : TOK_TTYPE_ENTRY_NUMBER,
1129 : TOK_TTYPE_ENTRY_TEXT,
1130 : TOK_TTYPE_TAB_STOP,
1131 : TOK_TTYPE_TEXT,
1132 : TOK_TTYPE_PAGE_NUMBER,
1133 : TOK_TTYPE_CHAPTER_INFO,
1134 : TOK_TTYPE_HYPERLINK_START,
1135 : TOK_TTYPE_HYPERLINK_END,
1136 : TOK_TTYPE_BIBLIOGRAPHY,
1137 : TOK_TTYPE_INVALID
1138 : };
1139 :
1140 : enum TemplateParamEnum
1141 : {
1142 : TOK_TPARAM_TOKEN_TYPE,
1143 : TOK_TPARAM_CHAR_STYLE,
1144 : TOK_TPARAM_TAB_RIGHT_ALIGNED,
1145 : TOK_TPARAM_TAB_POSITION,
1146 : TOK_TPARAM_TAB_WITH_TAB, // #i21237#
1147 : TOK_TPARAM_TAB_FILL_CHAR,
1148 : TOK_TPARAM_TEXT,
1149 : TOK_TPARAM_CHAPTER_FORMAT,
1150 : TOK_TPARAM_CHAPTER_LEVEL,//i53420
1151 : TOK_TPARAM_BIBLIOGRAPHY_DATA
1152 : };
1153 :
1154 : SvXMLEnumStringMapEntry const aTemplateTypeMap[] =
1155 : {
1156 : ENUM_STRING_MAP_ENTRY( "TokenEntryNumber", TOK_TTYPE_ENTRY_NUMBER ),
1157 : ENUM_STRING_MAP_ENTRY( "TokenEntryText", TOK_TTYPE_ENTRY_TEXT ),
1158 : ENUM_STRING_MAP_ENTRY( "TokenTabStop", TOK_TTYPE_TAB_STOP ),
1159 : ENUM_STRING_MAP_ENTRY( "TokenText", TOK_TTYPE_TEXT ),
1160 : ENUM_STRING_MAP_ENTRY( "TokenPageNumber", TOK_TTYPE_PAGE_NUMBER ),
1161 : ENUM_STRING_MAP_ENTRY( "TokenChapterInfo", TOK_TTYPE_CHAPTER_INFO ),
1162 : ENUM_STRING_MAP_ENTRY( "TokenHyperlinkStart", TOK_TTYPE_HYPERLINK_START ),
1163 : ENUM_STRING_MAP_ENTRY( "TokenHyperlinkEnd", TOK_TTYPE_HYPERLINK_END ),
1164 : ENUM_STRING_MAP_ENTRY( "TokenBibliographyDataField", TOK_TTYPE_BIBLIOGRAPHY ),
1165 : ENUM_STRING_MAP_END()
1166 : };
1167 :
1168 : SvXMLEnumStringMapEntry const aTemplateParamMap[] =
1169 : {
1170 : ENUM_STRING_MAP_ENTRY( "TokenType", TOK_TPARAM_TOKEN_TYPE ),
1171 : ENUM_STRING_MAP_ENTRY( "CharacterStyleName", TOK_TPARAM_CHAR_STYLE ),
1172 : ENUM_STRING_MAP_ENTRY( "TabStopRightAligned", TOK_TPARAM_TAB_RIGHT_ALIGNED ),
1173 : ENUM_STRING_MAP_ENTRY( "TabStopPosition", TOK_TPARAM_TAB_POSITION ),
1174 : ENUM_STRING_MAP_ENTRY( "TabStopFillCharacter", TOK_TPARAM_TAB_FILL_CHAR ),
1175 : // #i21237#
1176 : ENUM_STRING_MAP_ENTRY( "WithTab", TOK_TPARAM_TAB_WITH_TAB ),
1177 : ENUM_STRING_MAP_ENTRY( "Text", TOK_TPARAM_TEXT ),
1178 : ENUM_STRING_MAP_ENTRY( "ChapterFormat", TOK_TPARAM_CHAPTER_FORMAT ),
1179 : ENUM_STRING_MAP_ENTRY( "ChapterLevel", TOK_TPARAM_CHAPTER_LEVEL ),//i53420
1180 : ENUM_STRING_MAP_ENTRY( "BibliographyDataField", TOK_TPARAM_BIBLIOGRAPHY_DATA ),
1181 : ENUM_STRING_MAP_END()
1182 : };
1183 :
1184 : SvXMLEnumMapEntry const aBibliographyDataFieldMap[] =
1185 : {
1186 : { XML_ADDRESS, BibliographyDataField::ADDRESS },
1187 : { XML_ANNOTE, BibliographyDataField::ANNOTE },
1188 : { XML_AUTHOR, BibliographyDataField::AUTHOR },
1189 : { XML_BIBLIOGRAPHY_TYPE, BibliographyDataField::BIBILIOGRAPHIC_TYPE },
1190 : { XML_BOOKTITLE, BibliographyDataField::BOOKTITLE },
1191 : { XML_CHAPTER, BibliographyDataField::CHAPTER },
1192 : { XML_CUSTOM1, BibliographyDataField::CUSTOM1 },
1193 : { XML_CUSTOM2, BibliographyDataField::CUSTOM2 },
1194 : { XML_CUSTOM3, BibliographyDataField::CUSTOM3 },
1195 : { XML_CUSTOM4, BibliographyDataField::CUSTOM4 },
1196 : { XML_CUSTOM5, BibliographyDataField::CUSTOM5 },
1197 : { XML_EDITION, BibliographyDataField::EDITION },
1198 : { XML_EDITOR, BibliographyDataField::EDITOR },
1199 : { XML_HOWPUBLISHED, BibliographyDataField::HOWPUBLISHED },
1200 : { XML_IDENTIFIER, BibliographyDataField::IDENTIFIER },
1201 : { XML_INSTITUTION, BibliographyDataField::INSTITUTION },
1202 : { XML_ISBN, BibliographyDataField::ISBN },
1203 : { XML_JOURNAL, BibliographyDataField::JOURNAL },
1204 : { XML_MONTH, BibliographyDataField::MONTH },
1205 : { XML_NOTE, BibliographyDataField::NOTE },
1206 : { XML_NUMBER, BibliographyDataField::NUMBER },
1207 : { XML_ORGANIZATIONS, BibliographyDataField::ORGANIZATIONS },
1208 : { XML_PAGES, BibliographyDataField::PAGES },
1209 : { XML_PUBLISHER, BibliographyDataField::PUBLISHER },
1210 : { XML_REPORT_TYPE, BibliographyDataField::REPORT_TYPE },
1211 : { XML_SCHOOL, BibliographyDataField::SCHOOL },
1212 : { XML_SERIES, BibliographyDataField::SERIES },
1213 : { XML_TITLE, BibliographyDataField::TITLE },
1214 : { XML_URL, BibliographyDataField::URL },
1215 : { XML_VOLUME, BibliographyDataField::VOLUME },
1216 : { XML_YEAR, BibliographyDataField::YEAR },
1217 : { XML_TOKEN_INVALID, 0 }
1218 : };
1219 :
1220 0 : void XMLSectionExport::ExportIndexTemplateElement(
1221 : SectionTypeEnum eType, //i90246
1222 : Sequence<PropertyValue> & rValues)
1223 : {
1224 : // variables for template values
1225 :
1226 : // char style
1227 0 : OUString sCharStyle;
1228 0 : sal_Bool bCharStyleOK = sal_False;
1229 :
1230 : // text
1231 0 : OUString sText;
1232 0 : sal_Bool bTextOK = sal_False;
1233 :
1234 : // tab position
1235 0 : sal_Bool bRightAligned = sal_False;
1236 :
1237 : // tab position
1238 0 : sal_Int32 nTabPosition = 0;
1239 0 : sal_Bool bTabPositionOK = sal_False;
1240 :
1241 : // fill character
1242 0 : OUString sFillChar;
1243 0 : sal_Bool bFillCharOK = sal_False;
1244 :
1245 : // chapter format
1246 0 : sal_Int16 nChapterFormat = 0;
1247 0 : sal_Bool bChapterFormatOK = sal_False;
1248 :
1249 : // outline max level
1250 0 : sal_Int16 nLevel = 0;
1251 0 : sal_Bool bLevelOK = sal_False;
1252 :
1253 : // Bibliography Data
1254 0 : sal_Int16 nBibliographyData = 0;
1255 0 : sal_Bool bBibliographyDataOK = sal_False;
1256 :
1257 : // With Tab Stop #i21237#
1258 0 : sal_Bool bWithTabStop = sal_False;
1259 0 : sal_Bool bWithTabStopOK = sal_False;
1260 :
1261 : //i90246, the ODF version being written to is:
1262 0 : const SvtSaveOptions::ODFDefaultVersion aODFVersion = rExport.getDefaultVersion();
1263 : //the above version cannot be used for old OOo (OOo 1.0) formats!
1264 :
1265 : // token type
1266 0 : enum TemplateTypeEnum nTokenType = TOK_TTYPE_INVALID;
1267 :
1268 0 : sal_Int32 nCount = rValues.getLength();
1269 0 : for(sal_Int32 i = 0; i<nCount; i++)
1270 : {
1271 : sal_uInt16 nToken;
1272 0 : if ( SvXMLUnitConverter::convertEnum( nToken, rValues[i].Name,
1273 0 : aTemplateParamMap ) )
1274 : {
1275 : // Only use direct and default values.
1276 : // Wrong. no property states, so ignore.
1277 : // if ( (beans::PropertyState_DIRECT_VALUE == rValues[i].State) ||
1278 : // (beans::PropertyState_DEFAULT_VALUE == rValues[i].State) )
1279 :
1280 0 : switch (nToken)
1281 : {
1282 : case TOK_TPARAM_TOKEN_TYPE:
1283 : {
1284 : sal_uInt16 nTmp;
1285 0 : OUString sVal;
1286 0 : rValues[i].Value >>= sVal;
1287 0 : if (SvXMLUnitConverter::convertEnum( nTmp, sVal,
1288 0 : aTemplateTypeMap))
1289 : {
1290 0 : nTokenType = (enum TemplateTypeEnum)nTmp;
1291 : }
1292 0 : break;
1293 : }
1294 :
1295 : case TOK_TPARAM_CHAR_STYLE:
1296 : // only valid, if not empty
1297 0 : rValues[i].Value >>= sCharStyle;
1298 0 : bCharStyleOK = !sCharStyle.isEmpty();
1299 0 : break;
1300 :
1301 : case TOK_TPARAM_TEXT:
1302 0 : rValues[i].Value >>= sText;
1303 0 : bTextOK = sal_True;
1304 0 : break;
1305 :
1306 : case TOK_TPARAM_TAB_RIGHT_ALIGNED:
1307 : bRightAligned =
1308 0 : *(sal_Bool *)rValues[i].Value.getValue();
1309 0 : break;
1310 :
1311 : case TOK_TPARAM_TAB_POSITION:
1312 0 : rValues[i].Value >>= nTabPosition;
1313 0 : bTabPositionOK = sal_True;
1314 0 : break;
1315 :
1316 : // #i21237#
1317 : case TOK_TPARAM_TAB_WITH_TAB:
1318 0 : bWithTabStop = *(sal_Bool *)rValues[i].Value.getValue();
1319 0 : bWithTabStopOK = sal_True;
1320 0 : break;
1321 :
1322 : case TOK_TPARAM_TAB_FILL_CHAR:
1323 0 : rValues[i].Value >>= sFillChar;
1324 0 : bFillCharOK = sal_True;
1325 0 : break;
1326 :
1327 : case TOK_TPARAM_CHAPTER_FORMAT:
1328 0 : rValues[i].Value >>= nChapterFormat;
1329 0 : bChapterFormatOK = sal_True;
1330 0 : break;
1331 : //---> i53420
1332 : case TOK_TPARAM_CHAPTER_LEVEL:
1333 0 : rValues[i].Value >>= nLevel;
1334 0 : bLevelOK = sal_True;
1335 0 : break;
1336 : case TOK_TPARAM_BIBLIOGRAPHY_DATA:
1337 0 : rValues[i].Value >>= nBibliographyData;
1338 0 : bBibliographyDataOK = sal_True;
1339 0 : break;
1340 : }
1341 : }
1342 : }
1343 :
1344 : // convert type to token (and check validity) ...
1345 0 : XMLTokenEnum eElement(XML_TOKEN_INVALID);
1346 0 : switch(nTokenType)
1347 : {
1348 : case TOK_TTYPE_ENTRY_TEXT:
1349 0 : eElement = XML_INDEX_ENTRY_TEXT;
1350 0 : break;
1351 : case TOK_TTYPE_TAB_STOP:
1352 : // test validity
1353 0 : if ( bRightAligned || bTabPositionOK || bFillCharOK )
1354 : {
1355 0 : eElement = XML_INDEX_ENTRY_TAB_STOP;
1356 : }
1357 0 : break;
1358 : case TOK_TTYPE_TEXT:
1359 : // test validity
1360 0 : if (bTextOK)
1361 : {
1362 0 : eElement = XML_INDEX_ENTRY_SPAN;
1363 : }
1364 0 : break;
1365 : case TOK_TTYPE_PAGE_NUMBER:
1366 0 : eElement = XML_INDEX_ENTRY_PAGE_NUMBER;
1367 0 : break;
1368 : case TOK_TTYPE_CHAPTER_INFO: // keyword index
1369 0 : eElement = XML_INDEX_ENTRY_CHAPTER;
1370 0 : break;
1371 : case TOK_TTYPE_ENTRY_NUMBER: // table of content
1372 0 : eElement = XML_INDEX_ENTRY_CHAPTER;
1373 0 : break;
1374 : case TOK_TTYPE_HYPERLINK_START:
1375 0 : eElement = XML_INDEX_ENTRY_LINK_START;
1376 0 : break;
1377 : case TOK_TTYPE_HYPERLINK_END:
1378 0 : eElement = XML_INDEX_ENTRY_LINK_END;
1379 0 : break;
1380 : case TOK_TTYPE_BIBLIOGRAPHY:
1381 0 : if (bBibliographyDataOK)
1382 : {
1383 0 : eElement = XML_INDEX_ENTRY_BIBLIOGRAPHY;
1384 : }
1385 0 : break;
1386 : default:
1387 : ; // unknown/unimplemented template
1388 0 : break;
1389 : }
1390 :
1391 : //--->i90246
1392 : //check the ODF version being exported
1393 0 : if( aODFVersion == SvtSaveOptions::ODFVER_011
1394 : || aODFVersion == SvtSaveOptions::ODFVER_010)
1395 : {
1396 0 : bLevelOK = sal_False;
1397 0 : if (TOK_TTYPE_CHAPTER_INFO == nTokenType)
1398 : {
1399 : //if we are emitting for ODF 1.1 or 1.0, this information can be used for alphabetical index only
1400 : //it's not permitted in other indexes
1401 0 : if (eType != TEXT_SECTION_TYPE_ALPHABETICAL)
1402 : {
1403 0 : eElement = XML_TOKEN_INVALID; //not permitted, invalidate the element
1404 : }
1405 : else //maps format for 1.1 & 1.0
1406 : {
1407 : // a few word here: OOo up to 2.4 uses the field chapter info in Alphabetical index
1408 : // in a way different from the ODF 1.1/1.0 specification:
1409 : //
1410 : // ODF1.1/1.0 OOo display in chapter info ODF1.2
1411 : // (used in alphabetical index only
1412 : //
1413 : // number chapter number without pre/postfix plain-number
1414 : // number-and-name chapter number without pre/postfix plus title plain-number-and-name
1415 : //
1416 : // with issue i89791 the reading of ODF 1.1 and 1.0 was corrected
1417 : // this one corrects the writing back from ODF 1.2 to ODF 1.1/1.0
1418 : // unfortunately if there is another application which interprets correctly ODF1.1/1.0,
1419 : // the resulting alphabetical index will be rendered wrong by OOo 2.4 version
1420 : //
1421 0 : switch( nChapterFormat )
1422 : {
1423 : case ChapterFormat::DIGIT:
1424 0 : nChapterFormat = ChapterFormat::NUMBER;
1425 0 : break;
1426 : case ChapterFormat::NO_PREFIX_SUFFIX:
1427 0 : nChapterFormat = ChapterFormat::NAME_NUMBER;
1428 0 : break;
1429 : }
1430 : }
1431 : }
1432 0 : else if (TOK_TTYPE_ENTRY_NUMBER == nTokenType)
1433 : {
1434 : //in case of ODF 1.1 or 1.0 the only allowed number format is "number"
1435 : //so, force it...
1436 : // The only expected 'foreign' nChapterFormat is
1437 : // ' ChapterFormat::DIGIT', forced to 'none, since the
1438 : // 'value allowed in ODF 1.1 and 1.0 is 'number' the default
1439 : // this can be obtained by simply disabling the chapter format
1440 0 : bChapterFormatOK = sal_False;
1441 : }
1442 : }
1443 :
1444 : // ... and write Element
1445 0 : if (eElement != XML_TOKEN_INVALID)
1446 : {
1447 : // character style (for most templates)
1448 0 : if (bCharStyleOK)
1449 : {
1450 0 : switch (nTokenType)
1451 : {
1452 : case TOK_TTYPE_ENTRY_TEXT:
1453 : case TOK_TTYPE_TEXT:
1454 : case TOK_TTYPE_PAGE_NUMBER:
1455 : case TOK_TTYPE_ENTRY_NUMBER:
1456 : case TOK_TTYPE_HYPERLINK_START:
1457 : case TOK_TTYPE_HYPERLINK_END:
1458 : case TOK_TTYPE_BIBLIOGRAPHY:
1459 : case TOK_TTYPE_CHAPTER_INFO:
1460 : case TOK_TTYPE_TAB_STOP:
1461 0 : GetExport().AddAttribute(XML_NAMESPACE_TEXT,
1462 : XML_STYLE_NAME,
1463 0 : GetExport().EncodeStyleName( sCharStyle) );
1464 0 : break;
1465 : default:
1466 : ; // nothing: no character style
1467 0 : break;
1468 : }
1469 : }
1470 :
1471 : // tab properties
1472 0 : if (TOK_TTYPE_TAB_STOP == nTokenType)
1473 : {
1474 : // tab type
1475 0 : GetExport().AddAttribute(XML_NAMESPACE_STYLE, XML_TYPE,
1476 0 : bRightAligned ? XML_RIGHT : XML_LEFT);
1477 :
1478 0 : if (bTabPositionOK && (! bRightAligned))
1479 : {
1480 : // position for left tabs (convert to measure)
1481 0 : OUStringBuffer sBuf;
1482 0 : GetExport().GetMM100UnitConverter().convertMeasureToXML(sBuf,
1483 0 : nTabPosition);
1484 0 : GetExport().AddAttribute(XML_NAMESPACE_STYLE,
1485 : XML_POSITION,
1486 0 : sBuf.makeStringAndClear());
1487 : }
1488 :
1489 : // fill char ("leader char")
1490 0 : if (bFillCharOK && !sFillChar.isEmpty())
1491 : {
1492 0 : GetExport().AddAttribute(XML_NAMESPACE_STYLE,
1493 0 : XML_LEADER_CHAR, sFillChar);
1494 : }
1495 :
1496 : // #i21237#
1497 0 : if (bWithTabStopOK && ! bWithTabStop)
1498 : {
1499 0 : GetExport().AddAttribute(XML_NAMESPACE_STYLE,
1500 : XML_WITH_TAB,
1501 0 : XML_FALSE);
1502 : }
1503 : }
1504 :
1505 : // bibliography data
1506 0 : if (TOK_TTYPE_BIBLIOGRAPHY == nTokenType)
1507 : {
1508 : OSL_ENSURE(bBibliographyDataOK, "need bibl data");
1509 0 : OUStringBuffer sBuf;
1510 0 : if (SvXMLUnitConverter::convertEnum( sBuf, nBibliographyData,
1511 0 : aBibliographyDataFieldMap ) )
1512 : {
1513 0 : GetExport().AddAttribute(XML_NAMESPACE_TEXT,
1514 : XML_BIBLIOGRAPHY_DATA_FIELD,
1515 0 : sBuf.makeStringAndClear());
1516 0 : }
1517 : }
1518 :
1519 : // chapter info
1520 0 : if (TOK_TTYPE_CHAPTER_INFO == nTokenType)
1521 : {
1522 : OSL_ENSURE(bChapterFormatOK, "need chapter info");
1523 0 : GetExport().AddAttribute(
1524 : XML_NAMESPACE_TEXT, XML_DISPLAY,
1525 0 : XMLTextFieldExport::MapChapterDisplayFormat(nChapterFormat));
1526 : //---> i53420
1527 0 : if (bLevelOK)
1528 0 : GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_OUTLINE_LEVEL,
1529 0 : OUString::valueOf((sal_Int32)nLevel));
1530 : }
1531 :
1532 : //--->i53420
1533 0 : if (TOK_TTYPE_ENTRY_NUMBER == nTokenType)
1534 : {
1535 0 : if (bChapterFormatOK)
1536 0 : GetExport().AddAttribute(
1537 : XML_NAMESPACE_TEXT, XML_DISPLAY,
1538 0 : XMLTextFieldExport::MapChapterDisplayFormat(nChapterFormat));
1539 :
1540 0 : if (bLevelOK)
1541 0 : GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_OUTLINE_LEVEL,
1542 0 : OUString::valueOf((sal_Int32)nLevel));
1543 : }
1544 : // export template
1545 0 : SvXMLElementExport aTemplateElement(GetExport(), XML_NAMESPACE_TEXT,
1546 0 : GetXMLToken(eElement),
1547 0 : sal_True, sal_False)
1548 : ;
1549 :
1550 : // entry text or span element: write text
1551 0 : if (TOK_TTYPE_TEXT == nTokenType)
1552 : {
1553 0 : GetExport().Characters(sText);
1554 0 : }
1555 0 : }
1556 0 : }
1557 :
1558 0 : void XMLSectionExport::ExportLevelParagraphStyles(
1559 : Reference<XIndexReplace> & xLevelParagraphStyles)
1560 : {
1561 : // iterate over levels
1562 0 : sal_Int32 nPLevelCount = xLevelParagraphStyles->getCount();
1563 0 : for(sal_Int32 nLevel = 0; nLevel < nPLevelCount; nLevel++)
1564 : {
1565 0 : Any aAny = xLevelParagraphStyles->getByIndex(nLevel);
1566 0 : Sequence<OUString> aStyleNames;
1567 0 : aAny >>= aStyleNames;
1568 :
1569 : // export only if at least one style is contained
1570 0 : sal_Int32 nNamesCount = aStyleNames.getLength();
1571 0 : if (nNamesCount > 0)
1572 : {
1573 : // level attribute; we count 1..10; API 0..9
1574 0 : OUStringBuffer sBuf;
1575 0 : sal_Int32 nLevelPlusOne = nLevel + 1;
1576 0 : ::sax::Converter::convertNumber(sBuf, nLevelPlusOne);
1577 0 : GetExport().AddAttribute(XML_NAMESPACE_TEXT,
1578 : XML_OUTLINE_LEVEL,
1579 0 : sBuf.makeStringAndClear());
1580 :
1581 : // source styles element
1582 0 : SvXMLElementExport aParaStyles(GetExport(),
1583 : XML_NAMESPACE_TEXT,
1584 : XML_INDEX_SOURCE_STYLES,
1585 0 : sal_True, sal_True);
1586 :
1587 : // iterate over styles in this level
1588 0 : for(sal_Int32 nName = 0; nName < nNamesCount; nName++)
1589 : {
1590 : // stylename attribute
1591 0 : GetExport().AddAttribute(XML_NAMESPACE_TEXT,
1592 : XML_STYLE_NAME,
1593 0 : GetExport().EncodeStyleName( aStyleNames[nName]) );
1594 :
1595 : // element
1596 0 : SvXMLElementExport aParaStyle(GetExport(),
1597 : XML_NAMESPACE_TEXT,
1598 : XML_INDEX_SOURCE_STYLE,
1599 0 : sal_True, sal_False);
1600 0 : }
1601 : }
1602 0 : }
1603 0 : }
1604 :
1605 0 : void XMLSectionExport::ExportBoolean(
1606 : const Reference<XPropertySet> & rPropSet,
1607 : const OUString& sPropertyName,
1608 : enum XMLTokenEnum eAttributeName,
1609 : sal_Bool bDefault,
1610 : sal_Bool bInvert)
1611 : {
1612 : OSL_ENSURE(eAttributeName != XML_TOKEN_INVALID, "Need attribute name");
1613 :
1614 0 : Any aAny = rPropSet->getPropertyValue(sPropertyName);
1615 0 : sal_Bool bTmp = *(sal_Bool*)aAny.getValue();
1616 :
1617 : // value = value ^ bInvert
1618 : // omit if value == default
1619 : // negate forces sal_Bool to 0/1, making them comparable
1620 0 : if ((!(bTmp ^ bInvert)) != (!bDefault))
1621 : {
1622 : // export non-default value (since default is omitted)
1623 0 : GetExport().AddAttribute(XML_NAMESPACE_TEXT,
1624 : eAttributeName,
1625 0 : bDefault ? XML_FALSE : XML_TRUE);
1626 0 : }
1627 0 : }
1628 :
1629 : const sal_Char sAPI_FieldMaster_Bibliography[] =
1630 : "com.sun.star.text.FieldMaster.Bibliography";
1631 : const sal_Char sAPI_SortKey[] = "SortKey";
1632 : const sal_Char sAPI_IsSortAscending[] = "IsSortAscending";
1633 :
1634 2 : void XMLSectionExport::ExportBibliographyConfiguration(SvXMLExport& rExport)
1635 : {
1636 : // first: get field master (via text field supplier)
1637 2 : Reference<XTextFieldsSupplier> xTextFieldsSupp( rExport.GetModel(),
1638 2 : UNO_QUERY );
1639 2 : if ( xTextFieldsSupp.is() )
1640 : {
1641 : const OUString sFieldMaster_Bibliography(
1642 2 : RTL_CONSTASCII_USTRINGPARAM(sAPI_FieldMaster_Bibliography));
1643 :
1644 : // get bibliography field master
1645 : Reference<XNameAccess> xMasters =
1646 2 : xTextFieldsSupp->getTextFieldMasters();
1647 2 : if ( xMasters->hasByName(sFieldMaster_Bibliography) )
1648 : {
1649 : Any aAny =
1650 0 : xMasters->getByName(sFieldMaster_Bibliography);
1651 0 : Reference<XPropertySet> xPropSet;
1652 0 : aAny >>= xPropSet;
1653 :
1654 : OSL_ENSURE( xPropSet.is(), "field master must have XPropSet" );
1655 :
1656 : const OUString sBracketBefore(
1657 0 : RTL_CONSTASCII_USTRINGPARAM("BracketBefore"));
1658 : const OUString sBracketAfter(
1659 0 : RTL_CONSTASCII_USTRINGPARAM("BracketAfter"));
1660 : const OUString sIsNumberEntries(
1661 0 : RTL_CONSTASCII_USTRINGPARAM("IsNumberEntries"));
1662 : const OUString sIsSortByPosition(
1663 0 : RTL_CONSTASCII_USTRINGPARAM("IsSortByPosition"));
1664 : const OUString sSortKeys(
1665 0 : RTL_CONSTASCII_USTRINGPARAM("SortKeys"));
1666 : const OUString sSortAlgorithm(
1667 0 : RTL_CONSTASCII_USTRINGPARAM("SortAlgorithm"));
1668 : const OUString sLocale(
1669 0 : RTL_CONSTASCII_USTRINGPARAM("Locale"));
1670 :
1671 0 : OUString sTmp;
1672 :
1673 0 : aAny = xPropSet->getPropertyValue(sBracketBefore);
1674 0 : aAny >>= sTmp;
1675 0 : rExport.AddAttribute(XML_NAMESPACE_TEXT, XML_PREFIX, sTmp);
1676 :
1677 0 : aAny = xPropSet->getPropertyValue(sBracketAfter);
1678 0 : aAny >>= sTmp;
1679 0 : rExport.AddAttribute(XML_NAMESPACE_TEXT, XML_SUFFIX, sTmp);
1680 :
1681 0 : aAny = xPropSet->getPropertyValue(sIsNumberEntries);
1682 0 : if (*(sal_Bool*)aAny.getValue())
1683 : {
1684 : rExport.AddAttribute(XML_NAMESPACE_TEXT,
1685 0 : XML_NUMBERED_ENTRIES, XML_TRUE);
1686 : }
1687 :
1688 0 : aAny = xPropSet->getPropertyValue(sIsSortByPosition);
1689 0 : if (! *(sal_Bool*)aAny.getValue())
1690 : {
1691 : rExport.AddAttribute(XML_NAMESPACE_TEXT,
1692 0 : XML_SORT_BY_POSITION, XML_FALSE);
1693 : }
1694 :
1695 : // sort algorithm
1696 0 : aAny = xPropSet->getPropertyValue(sSortAlgorithm);
1697 0 : OUString sAlgorithm;
1698 0 : aAny >>= sAlgorithm;
1699 0 : if( !sAlgorithm.isEmpty() )
1700 : {
1701 : rExport.AddAttribute( XML_NAMESPACE_TEXT,
1702 0 : XML_SORT_ALGORITHM, sAlgorithm );
1703 : }
1704 :
1705 : // locale
1706 0 : aAny = xPropSet->getPropertyValue(sLocale);
1707 0 : Locale aLocale;
1708 0 : aAny >>= aLocale;
1709 : rExport.AddAttribute(XML_NAMESPACE_FO, XML_LANGUAGE,
1710 0 : aLocale.Language);
1711 : rExport.AddAttribute(XML_NAMESPACE_FO, XML_COUNTRY,
1712 0 : aLocale.Country);
1713 :
1714 : // configuration element
1715 : SvXMLElementExport aElement(rExport, XML_NAMESPACE_TEXT,
1716 : XML_BIBLIOGRAPHY_CONFIGURATION,
1717 0 : sal_True, sal_True);
1718 :
1719 : // sort keys
1720 0 : aAny = xPropSet->getPropertyValue(sSortKeys);
1721 0 : Sequence<Sequence<PropertyValue> > aKeys;
1722 0 : aAny >>= aKeys;
1723 0 : sal_Int32 nKeysCount = aKeys.getLength();
1724 0 : for(sal_Int32 nKeys = 0; nKeys < nKeysCount; nKeys++)
1725 : {
1726 0 : Sequence<PropertyValue> & rKey = aKeys[nKeys];
1727 :
1728 0 : sal_Int32 nKeyCount = rKey.getLength();
1729 0 : for(sal_Int32 nPropertyKey = 0; nPropertyKey < nKeyCount; nPropertyKey++)
1730 : {
1731 0 : PropertyValue& rValue = rKey[nPropertyKey];
1732 :
1733 0 : if (rValue.Name.equalsAsciiL(sAPI_SortKey,
1734 0 : sizeof(sAPI_SortKey)-1))
1735 : {
1736 0 : sal_Int16 nKey = 0;
1737 0 : rValue.Value >>= nKey;
1738 0 : OUStringBuffer sBuf;
1739 0 : if (SvXMLUnitConverter::convertEnum( sBuf, nKey,
1740 0 : aBibliographyDataFieldMap ) )
1741 : {
1742 : rExport.AddAttribute(XML_NAMESPACE_TEXT, XML_KEY,
1743 0 : sBuf.makeStringAndClear());
1744 0 : }
1745 : }
1746 0 : else if (rValue.Name.equalsAsciiL(sAPI_IsSortAscending,
1747 0 : sizeof(sAPI_IsSortAscending)-1))
1748 : {
1749 0 : sal_Bool bTmp = *(sal_Bool*)rValue.Value.getValue();
1750 : rExport.AddAttribute(XML_NAMESPACE_TEXT,
1751 : XML_SORT_ASCENDING,
1752 0 : bTmp ? XML_TRUE : XML_FALSE);
1753 : }
1754 : }
1755 :
1756 : SvXMLElementExport aKeyElem(rExport,
1757 : XML_NAMESPACE_TEXT, XML_SORT_KEY,
1758 0 : sal_True, sal_True);
1759 0 : }
1760 2 : }
1761 2 : }
1762 2 : }
1763 :
1764 :
1765 92 : sal_Bool XMLSectionExport::IsMuteSection(
1766 : const Reference<XTextSection> & rSection) const
1767 : {
1768 92 : sal_Bool bRet = sal_False;
1769 :
1770 : // a section is mute if
1771 : // 1) it exists
1772 : // 2) the SaveLinkedSections flag (at the export) is false
1773 : // 3) the IsGlobalDocumentSection property is true
1774 : // 4) it is not an Index
1775 :
1776 92 : if ( (!rExport.IsSaveLinkedSections()) && rSection.is() )
1777 : {
1778 : // walk the section chain and set bRet if any is linked
1779 0 : for(Reference<XTextSection> aSection(rSection);
1780 0 : aSection.is();
1781 0 : aSection = aSection->getParentSection())
1782 : {
1783 : // check if it is a global document section (linked or index)
1784 0 : Reference<XPropertySet> xPropSet(aSection, UNO_QUERY);
1785 0 : if (xPropSet.is())
1786 : {
1787 0 : Any aAny = xPropSet->getPropertyValue(sIsGlobalDocumentSection);
1788 :
1789 0 : if ( *(sal_Bool*)aAny.getValue() )
1790 : {
1791 0 : Reference<XDocumentIndex> xIndex;
1792 0 : if (! GetIndex(rSection, xIndex))
1793 : {
1794 0 : bRet = sal_True;
1795 :
1796 : // early out if result is known
1797 : break;
1798 0 : }
1799 0 : }
1800 : }
1801 : // section has no properties: ignore
1802 0 : }
1803 : }
1804 : // else: no section, or always save sections: default (false)
1805 :
1806 92 : return bRet;
1807 : }
1808 :
1809 0 : sal_Bool XMLSectionExport::IsMuteSection(
1810 : const Reference<XTextContent> & rSection,
1811 : sal_Bool bDefault) const
1812 : {
1813 : // default: like default argument
1814 0 : sal_Bool bRet = bDefault;
1815 :
1816 0 : Reference<XPropertySet> xPropSet(rSection->getAnchor(), UNO_QUERY);
1817 0 : if (xPropSet.is())
1818 : {
1819 0 : if (xPropSet->getPropertySetInfo()->hasPropertyByName(sTextSection))
1820 : {
1821 0 : Any aAny = xPropSet->getPropertyValue(sTextSection);
1822 0 : Reference<XTextSection> xSection;
1823 0 : aAny >>= xSection;
1824 :
1825 0 : bRet = IsMuteSection(xSection);
1826 : }
1827 : // else: return default
1828 : }
1829 : // else: return default
1830 :
1831 0 : return bRet;
1832 : }
1833 :
1834 0 : sal_Bool XMLSectionExport::IsInSection(
1835 : const Reference<XTextSection> & rEnclosingSection,
1836 : const Reference<XTextContent> & rContent,
1837 : sal_Bool bDefault)
1838 : {
1839 : // default: like default argument
1840 0 : sal_Bool bRet = bDefault;
1841 : OSL_ENSURE(rEnclosingSection.is(), "enclosing section expected");
1842 :
1843 0 : Reference<XPropertySet> xPropSet(rContent, UNO_QUERY);
1844 0 : if (xPropSet.is())
1845 : {
1846 0 : if (xPropSet->getPropertySetInfo()->hasPropertyByName(sTextSection))
1847 : {
1848 0 : Any aAny = xPropSet->getPropertyValue(sTextSection);
1849 0 : Reference<XTextSection> xSection;
1850 0 : aAny >>= xSection;
1851 :
1852 : // now walk chain of text sections (if we have one)
1853 0 : if (xSection.is())
1854 : {
1855 0 : do
1856 : {
1857 0 : bRet = (rEnclosingSection == xSection);
1858 0 : xSection = xSection->getParentSection();
1859 : }
1860 0 : while (!bRet && xSection.is());
1861 : }
1862 : else
1863 0 : bRet = sal_False; // no section -> can't be inside
1864 : }
1865 : // else: no TextSection property -> return default
1866 : }
1867 : // else: no XPropertySet -> return default
1868 :
1869 0 : return bRet;
1870 : }
1871 :
1872 :
1873 0 : void XMLSectionExport::ExportMasterDocHeadingDummies()
1874 : {
1875 0 : if( bHeadingDummiesExported )
1876 : return;
1877 :
1878 0 : Reference< XChapterNumberingSupplier > xCNSupplier( rExport.GetModel(),
1879 0 : UNO_QUERY );
1880 :
1881 0 : Reference< XIndexReplace > xChapterNumbering;
1882 0 : if( xCNSupplier.is() )
1883 0 : xChapterNumbering = xCNSupplier->getChapterNumberingRules();
1884 :
1885 0 : if( !xChapterNumbering.is() )
1886 : return;
1887 :
1888 0 : sal_Int32 nCount = xChapterNumbering->getCount();
1889 0 : for( sal_Int32 nLevel = 0; nLevel < nCount; nLevel++ )
1890 : {
1891 0 : OUString sStyle;
1892 0 : Sequence<PropertyValue> aProperties;
1893 0 : xChapterNumbering->getByIndex( nLevel ) >>= aProperties;
1894 0 : for( sal_Int32 i = 0; i < aProperties.getLength(); i++ )
1895 : {
1896 0 : if( aProperties[i].Name == sHeadingStyleName )
1897 : {
1898 0 : aProperties[i].Value >>= sStyle;
1899 0 : break;
1900 : }
1901 : }
1902 0 : if( !sStyle.isEmpty() )
1903 : {
1904 0 : GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_STYLE_NAME,
1905 0 : GetExport().EncodeStyleName( sStyle ) );
1906 :
1907 0 : OUStringBuffer sTmp;
1908 0 : sTmp.append( nLevel + 1 );
1909 0 : GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_LEVEL,
1910 0 : sTmp.makeStringAndClear() );
1911 0 : SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_TEXT, XML_H,
1912 0 : sal_True, sal_False );
1913 : }
1914 0 : }
1915 :
1916 0 : bHeadingDummiesExported = sal_True;
1917 : }
1918 :
1919 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|