replace createFromAscii with OUString literals in XMLSectionExport
[libreoffice.git] / xmloff / source / text / XMLSectionExport.cxx
blob702b5dc047ab6ead829bf5e54e7d55631a96669e
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
20 #include "XMLSectionExport.hxx"
21 #include <o3tl/any.hxx>
22 #include <rtl/ustring.hxx>
23 #include <rtl/ustrbuf.hxx>
24 #include <osl/diagnose.h>
25 #include <com/sun/star/frame/XModel.hpp>
26 #include <com/sun/star/lang/Locale.hpp>
27 #include <com/sun/star/container/XIndexReplace.hpp>
28 #include <com/sun/star/beans/XPropertySet.hpp>
29 #include <com/sun/star/beans/PropertyValue.hpp>
30 #include <com/sun/star/beans/PropertyValues.hpp>
31 #include <com/sun/star/text/XTextSection.hpp>
32 #include <com/sun/star/text/SectionFileLink.hpp>
33 #include <com/sun/star/container/XNamed.hpp>
34 #include <com/sun/star/container/XNameAccess.hpp>
35 #include <com/sun/star/text/XDocumentIndex.hpp>
36 #include <com/sun/star/text/BibliographyDataField.hpp>
37 #include <com/sun/star/text/XTextFieldsSupplier.hpp>
38 #include <com/sun/star/text/XChapterNumberingSupplier.hpp>
39 #include <com/sun/star/text/ChapterFormat.hpp>
41 #include <comphelper/base64.hxx>
43 #include <xmloff/xmltoken.hxx>
44 #include <xmloff/xmlnamespace.hxx>
45 #include <xmloff/families.hxx>
46 #include <xmloff/xmluconv.hxx>
47 #include <xmloff/namespacemap.hxx>
48 #include <xmloff/xmlexp.hxx>
49 #include <xmloff/xmlement.hxx>
50 #include <txtflde.hxx>
53 using namespace ::com::sun::star;
54 using namespace ::com::sun::star::text;
55 using namespace ::com::sun::star::uno;
56 using namespace ::xmloff::token;
58 using ::com::sun::star::beans::XPropertySet;
59 using ::com::sun::star::beans::PropertyValue;
60 using ::com::sun::star::beans::PropertyValues;
61 using ::com::sun::star::container::XIndexReplace;
62 using ::com::sun::star::container::XNameAccess;
63 using ::com::sun::star::container::XNamed;
64 using ::com::sun::star::lang::Locale;
67 XMLSectionExport::XMLSectionExport(
68 SvXMLExport& rExp,
69 XMLTextParagraphExport& rParaExp)
70 : rExport(rExp)
71 , rParaExport(rParaExp)
72 , bHeadingDummiesExported( false )
77 void XMLSectionExport::ExportSectionStart(
78 const Reference<XTextSection> & rSection,
79 bool bAutoStyles)
81 Reference<XPropertySet> xPropertySet(rSection, UNO_QUERY);
83 // always export section (auto) style
84 if (bAutoStyles)
86 // get PropertySet and add section style
87 GetParaExport().Add( XmlStyleFamily::TEXT_SECTION, xPropertySet );
89 else
91 // always export section style
92 GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_STYLE_NAME,
93 GetParaExport().Find(
94 XmlStyleFamily::TEXT_SECTION,
95 xPropertySet, "" ) );
97 // xml:id for RDF metadata
98 GetExport().AddAttributeXmlId(rSection);
100 // export index or regular section
101 Reference<XDocumentIndex> xIndex;
102 if (GetIndex(rSection, xIndex))
104 if (xIndex.is())
106 // we are an index
107 ExportIndexStart(xIndex);
109 else
111 // we are an index header
112 ExportIndexHeaderStart(rSection);
115 else
117 // we are not an index
118 ExportRegularSectionStart(rSection);
123 bool XMLSectionExport::GetIndex(
124 const Reference<XTextSection> & rSection,
125 Reference<XDocumentIndex> & rIndex)
127 // first, reset result
128 bool bRet = false;
129 rIndex = nullptr;
131 // get section Properties
132 Reference<XPropertySet> xSectionPropSet(rSection, UNO_QUERY);
134 // then check if this section happens to be inside an index
135 if (xSectionPropSet->getPropertySetInfo()->
136 hasPropertyByName("DocumentIndex"))
138 Any aAny = xSectionPropSet->getPropertyValue("DocumentIndex");
139 Reference<XDocumentIndex> xDocumentIndex;
140 aAny >>= xDocumentIndex;
142 // OK, are we inside of an index
143 if (xDocumentIndex.is())
145 // is the enclosing index identical with "our" section?
146 Reference<XPropertySet> xIndexPropSet(xDocumentIndex, UNO_QUERY);
147 aAny = xIndexPropSet->getPropertyValue("ContentSection");
148 Reference<XTextSection> xEnclosingSection;
149 aAny >>= xEnclosingSection;
151 // if the enclosing section is "our" section, then we are an index!
152 if (rSection == xEnclosingSection)
154 rIndex = xDocumentIndex;
155 bRet = true;
157 // else: index header or regular section
159 // is the enclosing index identical with the header section?
160 aAny = xIndexPropSet->getPropertyValue("HeaderSection");
161 // now mis-named: contains header section
162 aAny >>= xEnclosingSection;
164 // if the enclosing section is "our" section, then we are an index!
165 if (rSection == xEnclosingSection)
167 bRet = true;
169 // else: regular section
171 // else: we aren't even inside of an index
173 // else: we don't even know what an index is.
175 return bRet;
179 void XMLSectionExport::ExportSectionEnd(
180 const Reference<XTextSection> & rSection,
181 bool bAutoStyles)
183 // no end section for styles
184 if (bAutoStyles)
185 return;
187 enum XMLTokenEnum eElement = XML_TOKEN_INVALID;
189 // export index or regular section end
190 Reference<XDocumentIndex> xIndex;
191 if (GetIndex(rSection, xIndex))
193 if (xIndex.is())
195 // index end: close index body element
196 GetExport().EndElement( XML_NAMESPACE_TEXT, XML_INDEX_BODY,
197 true );
198 GetExport().IgnorableWhitespace();
200 switch (MapSectionType(xIndex->getServiceName()))
202 case TEXT_SECTION_TYPE_TOC:
203 eElement = XML_TABLE_OF_CONTENT;
204 break;
206 case TEXT_SECTION_TYPE_ILLUSTRATION:
207 eElement = XML_ILLUSTRATION_INDEX;
208 break;
210 case TEXT_SECTION_TYPE_ALPHABETICAL:
211 eElement = XML_ALPHABETICAL_INDEX;
212 break;
214 case TEXT_SECTION_TYPE_TABLE:
215 eElement = XML_TABLE_INDEX;
216 break;
218 case TEXT_SECTION_TYPE_OBJECT:
219 eElement = XML_OBJECT_INDEX;
220 break;
222 case TEXT_SECTION_TYPE_USER:
223 eElement = XML_USER_INDEX;
224 break;
226 case TEXT_SECTION_TYPE_BIBLIOGRAPHY:
227 eElement = XML_BIBLIOGRAPHY;
228 break;
230 default:
231 OSL_FAIL("unknown index type");
232 // default: skip index!
233 break;
236 else
238 eElement = XML_INDEX_TITLE;
241 else
243 eElement = XML_SECTION;
246 if (XML_TOKEN_INVALID != eElement)
248 // any old attributes?
249 GetExport().CheckAttrList();
251 // element surrounded by whitespace
252 GetExport().EndElement( XML_NAMESPACE_TEXT, eElement, true);
253 GetExport().IgnorableWhitespace();
255 else
257 OSL_FAIL("Need element name!");
259 // else: autostyles -> ignore
262 void XMLSectionExport::ExportIndexStart(
263 const Reference<XDocumentIndex> & rIndex)
265 // get PropertySet
266 Reference<XPropertySet> xPropertySet(rIndex, UNO_QUERY);
268 switch (MapSectionType(rIndex->getServiceName()))
270 case TEXT_SECTION_TYPE_TOC:
271 ExportTableOfContentStart(xPropertySet);
272 break;
274 case TEXT_SECTION_TYPE_ILLUSTRATION:
275 ExportIllustrationIndexStart(xPropertySet);
276 break;
278 case TEXT_SECTION_TYPE_ALPHABETICAL:
279 ExportAlphabeticalIndexStart(xPropertySet);
280 break;
282 case TEXT_SECTION_TYPE_TABLE:
283 ExportTableIndexStart(xPropertySet);
284 break;
286 case TEXT_SECTION_TYPE_OBJECT:
287 ExportObjectIndexStart(xPropertySet);
288 break;
290 case TEXT_SECTION_TYPE_USER:
291 ExportUserIndexStart(xPropertySet);
292 break;
294 case TEXT_SECTION_TYPE_BIBLIOGRAPHY:
295 ExportBibliographyStart(xPropertySet);
296 break;
298 default:
299 // skip index
300 OSL_FAIL("unknown index type");
301 break;
305 void XMLSectionExport::ExportIndexHeaderStart(
306 const Reference<XTextSection> & rSection)
308 // export name, dammit!
309 Reference<XNamed> xName(rSection, UNO_QUERY);
310 GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_NAME, xName->getName());
311 Reference<XPropertySet> xPropSet(rSection, UNO_QUERY);
312 Any aAny = xPropSet->getPropertyValue("IsProtected");
313 if (*o3tl::doAccess<bool>(aAny))
315 GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_PROTECTED, XML_TRUE);
318 // format already handled -> export only start element
319 GetExport().StartElement( XML_NAMESPACE_TEXT, XML_INDEX_TITLE, true );
320 GetExport().IgnorableWhitespace();
324 SvXMLEnumStringMapEntry<SectionTypeEnum> const aIndexTypeMap[] =
326 ENUM_STRING_MAP_ENTRY( "com.sun.star.text.ContentIndex", TEXT_SECTION_TYPE_TOC ),
327 ENUM_STRING_MAP_ENTRY( "com.sun.star.text.DocumentIndex", TEXT_SECTION_TYPE_ALPHABETICAL ),
328 ENUM_STRING_MAP_ENTRY( "com.sun.star.text.TableIndex", TEXT_SECTION_TYPE_TABLE ),
329 ENUM_STRING_MAP_ENTRY( "com.sun.star.text.ObjectIndex", TEXT_SECTION_TYPE_OBJECT ),
330 ENUM_STRING_MAP_ENTRY( "com.sun.star.text.Bibliography", TEXT_SECTION_TYPE_BIBLIOGRAPHY ),
331 ENUM_STRING_MAP_ENTRY( "com.sun.star.text.UserIndex", TEXT_SECTION_TYPE_USER ),
332 ENUM_STRING_MAP_ENTRY( "com.sun.star.text.IllustrationsIndex", TEXT_SECTION_TYPE_ILLUSTRATION ),
333 { nullptr, 0, SectionTypeEnum(0) }
336 enum SectionTypeEnum XMLSectionExport::MapSectionType(
337 std::u16string_view rServiceName)
339 enum SectionTypeEnum eType = TEXT_SECTION_TYPE_UNKNOWN;
341 SvXMLUnitConverter::convertEnum(eType, rServiceName, aIndexTypeMap);
343 // TODO: index header section types, etc.
345 return eType;
348 void XMLSectionExport::ExportRegularSectionStart(
349 const Reference<XTextSection> & rSection)
351 // style name already handled in ExportSectionStart(...)
353 Reference<XNamed> xName(rSection, UNO_QUERY);
354 GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_NAME, xName->getName());
356 // get XPropertySet for other values
357 Reference<XPropertySet> xPropSet(rSection, UNO_QUERY);
359 // condition and display
360 Any aAny = xPropSet->getPropertyValue("Condition");
361 OUString sCond;
362 aAny >>= sCond;
363 enum XMLTokenEnum eDisplay = XML_TOKEN_INVALID;
364 if (!sCond.isEmpty())
366 OUString sQValue =
367 GetExport().GetNamespaceMap().GetQNameByKey( XML_NAMESPACE_OOOW,
368 sCond, false );
369 GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_CONDITION, sQValue);
370 eDisplay = XML_CONDITION;
372 // #97450# store hidden-status (of conditional sections only)
373 aAny = xPropSet->getPropertyValue("IsCurrentlyVisible");
374 if (! *o3tl::doAccess<bool>(aAny))
376 GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_IS_HIDDEN,
377 XML_TRUE);
380 else
382 eDisplay = XML_NONE;
384 aAny = xPropSet->getPropertyValue("IsVisible");
385 if (! *o3tl::doAccess<bool>(aAny))
387 GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_DISPLAY, eDisplay);
390 // protect + protection key
391 aAny = xPropSet->getPropertyValue("IsProtected");
392 if (*o3tl::doAccess<bool>(aAny))
394 GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_PROTECTED, XML_TRUE);
396 Sequence<sal_Int8> aPassword;
397 xPropSet->getPropertyValue("ProtectionKey") >>= aPassword;
398 if (aPassword.hasElements())
400 OUStringBuffer aBuffer;
401 ::comphelper::Base64::encode(aBuffer, aPassword);
402 // in ODF 1.0/1.1 the algorithm was left unspecified so we can write anything
403 GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_PROTECTION_KEY,
404 aBuffer.makeStringAndClear());
405 if (aPassword.getLength() == 32 && GetExport().getSaneDefaultVersion() >= SvtSaveOptions::ODFSVER_012)
407 // attribute exists in ODF 1.2 or later; default is SHA1 so no need to write that
408 GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_PROTECTION_KEY_DIGEST_ALGORITHM,
409 // write the URL from ODF 1.2, not the W3C one
410 "http://www.w3.org/2000/09/xmldsig#sha256");
414 // export element
415 GetExport().IgnorableWhitespace();
416 GetExport().StartElement( XML_NAMESPACE_TEXT, XML_SECTION, true );
418 // data source
419 // unfortunately, we have to test all relevant strings for non-zero length
420 aAny = xPropSet->getPropertyValue("FileLink");
421 SectionFileLink aFileLink;
422 aAny >>= aFileLink;
424 aAny = xPropSet->getPropertyValue("LinkRegion");
425 OUString sRegionName;
426 aAny >>= sRegionName;
428 if ( !aFileLink.FileURL.isEmpty() ||
429 !aFileLink.FilterName.isEmpty() ||
430 !sRegionName.isEmpty())
432 if (!aFileLink.FileURL.isEmpty())
434 GetExport().AddAttribute(XML_NAMESPACE_XLINK, XML_HREF,
435 GetExport().GetRelativeReference( aFileLink.FileURL) );
438 if (!aFileLink.FilterName.isEmpty())
440 GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_FILTER_NAME,
441 aFileLink.FilterName);
444 if (!sRegionName.isEmpty())
446 GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_SECTION_NAME,
447 sRegionName);
450 SvXMLElementExport aElem(GetExport(),
451 XML_NAMESPACE_TEXT, XML_SECTION_SOURCE,
452 true, true);
454 else
456 // check for DDE first
457 if (xPropSet->getPropertySetInfo()->hasPropertyByName("DDECommandFile"))
459 // data source DDE
460 // unfortunately, we have to test all relevant strings for
461 // non-zero length
462 aAny = xPropSet->getPropertyValue("DDECommandFile");
463 OUString sApplication;
464 aAny >>= sApplication;
465 aAny = xPropSet->getPropertyValue("DDECommandType");
466 OUString sTopic;
467 aAny >>= sTopic;
468 aAny = xPropSet->getPropertyValue("DDECommandElement");
469 OUString sItem;
470 aAny >>= sItem;
472 if ( !sApplication.isEmpty() ||
473 !sTopic.isEmpty() ||
474 !sItem.isEmpty())
476 GetExport().AddAttribute(XML_NAMESPACE_OFFICE,
477 XML_DDE_APPLICATION, sApplication);
478 GetExport().AddAttribute(XML_NAMESPACE_OFFICE, XML_DDE_TOPIC,
479 sTopic);
480 GetExport().AddAttribute(XML_NAMESPACE_OFFICE, XML_DDE_ITEM,
481 sItem);
483 aAny = xPropSet->getPropertyValue("IsAutomaticUpdate");
484 if (*o3tl::doAccess<bool>(aAny))
486 GetExport().AddAttribute(XML_NAMESPACE_OFFICE,
487 XML_AUTOMATIC_UPDATE, XML_TRUE);
490 SvXMLElementExport aElem(GetExport(),
491 XML_NAMESPACE_OFFICE,
492 XML_DDE_SOURCE, true, true);
494 // else: no DDE data source
496 // else: no DDE on this system
500 void XMLSectionExport::ExportTableOfContentStart(
501 const Reference<XPropertySet> & rPropertySet)
503 // export TOC element start
504 ExportBaseIndexStart(XML_TABLE_OF_CONTENT, rPropertySet);
506 // scope for table-of-content-source element
508 // TOC specific index source attributes:
510 // outline-level: 1..10
511 sal_Int16 nLevel = sal_Int16();
512 if( rPropertySet->getPropertyValue("Level") >>= nLevel )
514 GetExport().AddAttribute(XML_NAMESPACE_TEXT,
515 XML_OUTLINE_LEVEL,
516 OUString::number(nLevel));
519 // use outline level
520 ExportBoolean(rPropertySet, "CreateFromOutline",
521 XML_USE_OUTLINE_LEVEL, true);
523 // use index marks
524 ExportBoolean(rPropertySet, "CreateFromMarks",
525 XML_USE_INDEX_MARKS, true);
527 // use level styles
528 ExportBoolean(rPropertySet, "CreateFromLevelParagraphStyles",
529 XML_USE_INDEX_SOURCE_STYLES, false);
531 ExportBaseIndexSource(TEXT_SECTION_TYPE_TOC, rPropertySet);
534 ExportBaseIndexBody(TEXT_SECTION_TYPE_TOC, rPropertySet);
537 void XMLSectionExport::ExportObjectIndexStart(
538 const Reference<XPropertySet> & rPropertySet)
540 // export index start
541 ExportBaseIndexStart(XML_OBJECT_INDEX, rPropertySet);
543 // scope for index source element
545 ExportBoolean(rPropertySet, "CreateFromOtherEmbeddedObjects",
546 XML_USE_OTHER_OBJECTS, false);
547 ExportBoolean(rPropertySet, "CreateFromStarCalc",
548 XML_USE_SPREADSHEET_OBJECTS, false);
549 ExportBoolean(rPropertySet, "CreateFromStarChart",
550 XML_USE_CHART_OBJECTS, false);
551 ExportBoolean(rPropertySet, "CreateFromStarDraw",
552 XML_USE_DRAW_OBJECTS, false);
553 ExportBoolean(rPropertySet, "CreateFromStarMath",
554 XML_USE_MATH_OBJECTS, false);
556 ExportBaseIndexSource(TEXT_SECTION_TYPE_OBJECT, rPropertySet);
559 ExportBaseIndexBody(TEXT_SECTION_TYPE_OBJECT, rPropertySet);
562 void XMLSectionExport::ExportIllustrationIndexStart(
563 const Reference<XPropertySet> & rPropertySet)
565 // export index start
566 ExportBaseIndexStart(XML_ILLUSTRATION_INDEX, rPropertySet);
568 // scope for index source element
570 // export common attributes for illustration and table indices
571 ExportTableAndIllustrationIndexSourceAttributes(rPropertySet);
573 ExportBaseIndexSource(TEXT_SECTION_TYPE_ILLUSTRATION, rPropertySet);
576 ExportBaseIndexBody(TEXT_SECTION_TYPE_ILLUSTRATION, rPropertySet);
579 void XMLSectionExport::ExportTableIndexStart(
580 const Reference<XPropertySet> & rPropertySet)
582 // export index start
583 ExportBaseIndexStart(XML_TABLE_INDEX, rPropertySet);
585 // scope for index source element
587 // export common attributes for illustration and table indices
588 ExportTableAndIllustrationIndexSourceAttributes(rPropertySet);
590 ExportBaseIndexSource(TEXT_SECTION_TYPE_TABLE, rPropertySet);
593 ExportBaseIndexBody(TEXT_SECTION_TYPE_TABLE, rPropertySet);
596 void XMLSectionExport::ExportAlphabeticalIndexStart(
597 const Reference<XPropertySet> & rPropertySet)
599 // export TOC element start
600 ExportBaseIndexStart(XML_ALPHABETICAL_INDEX, rPropertySet);
602 // scope for table-of-content-source element
605 // style name (if present)
606 Any aAny = rPropertySet->getPropertyValue("MainEntryCharacterStyleName");
607 OUString sStyleName;
608 aAny >>= sStyleName;
609 if (!sStyleName.isEmpty())
611 GetExport().AddAttribute(XML_NAMESPACE_TEXT,
612 XML_MAIN_ENTRY_STYLE_NAME,
613 GetExport().EncodeStyleName( sStyleName ));
616 // other (boolean) attributes
617 ExportBoolean(rPropertySet, "IsCaseSensitive", XML_IGNORE_CASE,
618 false, true);
619 ExportBoolean(rPropertySet, "UseAlphabeticalSeparators",
620 XML_ALPHABETICAL_SEPARATORS, false);
621 ExportBoolean(rPropertySet, "UseCombinedEntries", XML_COMBINE_ENTRIES,
622 true);
623 ExportBoolean(rPropertySet, "UseDash", XML_COMBINE_ENTRIES_WITH_DASH,
624 false);
625 ExportBoolean(rPropertySet, "UseKeyAsEntry", XML_USE_KEYS_AS_ENTRIES,
626 false);
627 ExportBoolean(rPropertySet, "UsePP", XML_COMBINE_ENTRIES_WITH_PP,
628 true);
629 ExportBoolean(rPropertySet, "UseUpperCase", XML_CAPITALIZE_ENTRIES,
630 false);
631 ExportBoolean(rPropertySet, "IsCommaSeparated", XML_COMMA_SEPARATED,
632 false);
634 // sort algorithm
635 aAny = rPropertySet->getPropertyValue("SortAlgorithm");
636 OUString sAlgorithm;
637 aAny >>= sAlgorithm;
638 if (!sAlgorithm.isEmpty())
640 GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_SORT_ALGORITHM,
641 sAlgorithm );
644 // locale
645 aAny = rPropertySet->getPropertyValue("Locale");
646 Locale aLocale;
647 aAny >>= aLocale;
648 GetExport().AddLanguageTagAttributes( XML_NAMESPACE_FO, XML_NAMESPACE_STYLE, aLocale, true);
650 ExportBaseIndexSource(TEXT_SECTION_TYPE_ALPHABETICAL, rPropertySet);
653 ExportBaseIndexBody(TEXT_SECTION_TYPE_ALPHABETICAL, rPropertySet);
656 void XMLSectionExport::ExportUserIndexStart(
657 const Reference<XPropertySet> & rPropertySet)
659 // export TOC element start
660 ExportBaseIndexStart(XML_USER_INDEX, rPropertySet);
662 // scope for table-of-content-source element
664 // bool attributes
665 ExportBoolean(rPropertySet, "CreateFromEmbeddedObjects",
666 XML_USE_OBJECTS, false);
667 ExportBoolean(rPropertySet, "CreateFromGraphicObjects",
668 XML_USE_GRAPHICS, false);
669 ExportBoolean(rPropertySet, "CreateFromMarks",
670 XML_USE_INDEX_MARKS, false);
671 ExportBoolean(rPropertySet, "CreateFromTables",
672 XML_USE_TABLES, false);
673 ExportBoolean(rPropertySet, "CreateFromTextFrames",
674 XML_USE_FLOATING_FRAMES, false);
675 ExportBoolean(rPropertySet, "UseLevelFromSource",
676 XML_COPY_OUTLINE_LEVELS, false);
677 ExportBoolean(rPropertySet, "CreateFromLevelParagraphStyles",
678 XML_USE_INDEX_SOURCE_STYLES, false);
680 Any aAny = rPropertySet->getPropertyValue( "UserIndexName" );
681 OUString sIndexName;
682 aAny >>= sIndexName;
683 GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_INDEX_NAME,
684 sIndexName);
686 ExportBaseIndexSource(TEXT_SECTION_TYPE_USER, rPropertySet);
689 ExportBaseIndexBody(TEXT_SECTION_TYPE_USER, rPropertySet);
692 void XMLSectionExport::ExportBibliographyStart(
693 const Reference<XPropertySet> & rPropertySet)
695 // export TOC element start
696 ExportBaseIndexStart(XML_BIBLIOGRAPHY, rPropertySet);
698 // scope for table-of-content-source element
700 // No attributes. Fine.
702 ExportBaseIndexSource(TEXT_SECTION_TYPE_BIBLIOGRAPHY, rPropertySet);
705 ExportBaseIndexBody(TEXT_SECTION_TYPE_BIBLIOGRAPHY, rPropertySet);
709 void XMLSectionExport::ExportBaseIndexStart(
710 XMLTokenEnum eElement,
711 const Reference<XPropertySet> & rPropertySet)
713 // protect + protection key
714 Any aAny = rPropertySet->getPropertyValue("IsProtected");
715 if (*o3tl::doAccess<bool>(aAny))
717 GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_PROTECTED, XML_TRUE);
720 // index name
721 OUString sIndexName;
722 rPropertySet->getPropertyValue("Name") >>= sIndexName;
723 if ( !sIndexName.isEmpty() )
725 GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_NAME, sIndexName);
728 // index Element start
729 GetExport().IgnorableWhitespace();
730 GetExport().StartElement( XML_NAMESPACE_TEXT, eElement, false );
733 const XMLTokenEnum aTypeSourceElementNameMap[] =
735 XML_TABLE_OF_CONTENT_SOURCE, // TOC
736 XML_TABLE_INDEX_SOURCE, // table index
737 XML_ILLUSTRATION_INDEX_SOURCE, // illustration index
738 XML_OBJECT_INDEX_SOURCE, // object index
739 XML_USER_INDEX_SOURCE, // user index
740 XML_ALPHABETICAL_INDEX_SOURCE, // alphabetical index
741 XML_BIBLIOGRAPHY_SOURCE // bibliography
744 void XMLSectionExport::ExportBaseIndexSource(
745 SectionTypeEnum eType,
746 const Reference<XPropertySet> & rPropertySet)
748 // check type
749 OSL_ENSURE(eType >= TEXT_SECTION_TYPE_TOC, "illegal index type");
750 OSL_ENSURE(eType <= TEXT_SECTION_TYPE_BIBLIOGRAPHY, "illegal index type");
752 Any aAny;
754 // common attributes; not supported by bibliography
755 if (eType != TEXT_SECTION_TYPE_BIBLIOGRAPHY)
757 // document or chapter index?
758 aAny = rPropertySet->getPropertyValue("CreateFromChapter");
759 if (*o3tl::doAccess<bool>(aAny))
761 GetExport().AddAttribute(XML_NAMESPACE_TEXT,
762 XML_INDEX_SCOPE, XML_CHAPTER);
765 // tab-stops relative to margin?
766 aAny = rPropertySet->getPropertyValue("IsRelativeTabstops");
767 if (! *o3tl::doAccess<bool>(aAny))
769 GetExport().AddAttribute(XML_NAMESPACE_TEXT,
770 XML_RELATIVE_TAB_STOP_POSITION,
771 XML_FALSE);
775 // the index source element (all indices)
776 SvXMLElementExport aElem(GetExport(),
777 XML_NAMESPACE_TEXT,
778 GetXMLToken(
779 aTypeSourceElementNameMap[
780 eType - TEXT_SECTION_TYPE_TOC]),
781 true, true);
783 // scope for title template (all indices)
785 // header style name
786 aAny = rPropertySet->getPropertyValue("ParaStyleHeading");
787 OUString sStyleName;
788 aAny >>= sStyleName;
789 GetExport().AddAttribute(XML_NAMESPACE_TEXT,
790 XML_STYLE_NAME,
791 GetExport().EncodeStyleName( sStyleName ));
793 // title template
794 SvXMLElementExport aHeaderTemplate(GetExport(),
795 XML_NAMESPACE_TEXT,
796 XML_INDEX_TITLE_TEMPLATE,
797 true, false);
799 // title as element content
800 aAny = rPropertySet->getPropertyValue("Title");
801 OUString sTitleString;
802 aAny >>= sTitleString;
803 GetExport().Characters(sTitleString);
806 // export level templates (all indices)
807 aAny = rPropertySet->getPropertyValue("LevelFormat");
808 Reference<XIndexReplace> xLevelTemplates;
809 aAny >>= xLevelTemplates;
811 // iterate over level formats;
812 // skip element 0 (empty template for title)
813 sal_Int32 nLevelCount = xLevelTemplates->getCount();
814 for(sal_Int32 i = 1; i<nLevelCount; i++)
816 // get sequence
817 Sequence<PropertyValues> aTemplateSequence;
818 aAny = xLevelTemplates->getByIndex(i);
819 aAny >>= aTemplateSequence;
821 // export the sequence (abort export if an error occurred; #91214#)
822 bool bResult =
823 ExportIndexTemplate(eType, i, rPropertySet, aTemplateSequence);
824 if ( !bResult )
825 break;
828 // only TOC and user index:
829 // styles from which to build the index (LevelParagraphStyles)
830 if ( (TEXT_SECTION_TYPE_TOC == eType) ||
831 (TEXT_SECTION_TYPE_USER == eType) )
833 aAny = rPropertySet->getPropertyValue("LevelParagraphStyles");
834 Reference<XIndexReplace> xLevelParagraphStyles;
835 aAny >>= xLevelParagraphStyles;
836 ExportLevelParagraphStyles(xLevelParagraphStyles);
838 else if (TEXT_SECTION_TYPE_ILLUSTRATION == eType
839 || TEXT_SECTION_TYPE_OBJECT == eType
840 || TEXT_SECTION_TYPE_TABLE == eType)
842 Any const any(rPropertySet->getPropertyValue("CreateFromParagraphStyle"));
843 if (any.hasValue() &&
844 (rExport.getSaneDefaultVersion() & SvtSaveOptions::ODFSVER_EXTENDED))
846 OUString const styleName(any.get<OUString>());
847 GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_STYLE_NAME,
848 GetExport().EncodeStyleName(styleName));
850 SvXMLElementExport const e(GetExport(),
851 XML_NAMESPACE_LO_EXT, XML_INDEX_SOURCE_STYLE, true, false);
857 void XMLSectionExport::ExportBaseIndexBody(
858 SectionTypeEnum eType,
859 const Reference<XPropertySet> &)
861 // type not used; checked anyway.
862 OSL_ENSURE(eType >= TEXT_SECTION_TYPE_TOC, "illegal index type");
863 OSL_ENSURE(eType <= TEXT_SECTION_TYPE_BIBLIOGRAPHY, "illegal index type");
865 // export start only
867 // any old attributes?
868 GetExport().CheckAttrList();
870 // start surrounded by whitespace
871 GetExport().IgnorableWhitespace();
872 GetExport().StartElement( XML_NAMESPACE_TEXT, XML_INDEX_BODY, true );
875 void XMLSectionExport::ExportTableAndIllustrationIndexSourceAttributes(
876 const Reference<XPropertySet> & rPropertySet)
878 // use caption
879 Any aAny = rPropertySet->getPropertyValue("CreateFromLabels");
880 if (! *o3tl::doAccess<bool>(aAny))
882 GetExport().AddAttribute(XML_NAMESPACE_TEXT,
883 XML_USE_CAPTION, XML_FALSE);
886 // sequence name
887 aAny = rPropertySet->getPropertyValue("LabelCategory");
888 OUString sSequenceName;
889 aAny >>= sSequenceName;
890 GetExport().AddAttribute(XML_NAMESPACE_TEXT,
891 XML_CAPTION_SEQUENCE_NAME,
892 sSequenceName);
894 // caption format
895 aAny = rPropertySet->getPropertyValue("LabelDisplayType");
896 sal_Int16 nType = 0;
897 aAny >>= nType;
898 GetExport().AddAttribute(XML_NAMESPACE_TEXT,
899 XML_CAPTION_SEQUENCE_FORMAT,
900 XMLTextFieldExport::MapReferenceType(nType));
904 // map index of LevelFormats to attribute value;
905 // level 0 is always the header
906 const XMLTokenEnum aLevelNameTOCMap[] =
907 { XML_TOKEN_INVALID, XML_1, XML_2, XML_3, XML_4, XML_5, XML_6, XML_7,
908 XML_8, XML_9, XML_10, XML_TOKEN_INVALID };
909 const XMLTokenEnum aLevelNameTableMap[] =
910 { XML_TOKEN_INVALID, XML__EMPTY, XML_TOKEN_INVALID };
911 const XMLTokenEnum aLevelNameAlphaMap[] =
912 { XML_TOKEN_INVALID, XML_SEPARATOR, XML_1, XML_2, XML_3, XML_TOKEN_INVALID };
913 const XMLTokenEnum aLevelNameBibliographyMap[] =
914 { XML_TOKEN_INVALID, XML_ARTICLE, XML_BOOK, XML_BOOKLET, XML_CONFERENCE,
915 XML_CUSTOM1, XML_CUSTOM2, XML_CUSTOM3, XML_CUSTOM4,
916 XML_CUSTOM5, XML_EMAIL, XML_INBOOK, XML_INCOLLECTION,
917 XML_INPROCEEDINGS, XML_JOURNAL,
918 XML_MANUAL, XML_MASTERSTHESIS, XML_MISC, XML_PHDTHESIS,
919 XML_PROCEEDINGS, XML_TECHREPORT, XML_UNPUBLISHED, XML_WWW,
920 XML_TOKEN_INVALID };
922 static const XMLTokenEnum* aTypeLevelNameMap[] =
924 aLevelNameTOCMap, // TOC
925 aLevelNameTableMap, // table index
926 aLevelNameTableMap, // illustration index
927 aLevelNameTableMap, // object index
928 aLevelNameTOCMap, // user index
929 aLevelNameAlphaMap, // alphabetical index
930 aLevelNameBibliographyMap // bibliography
933 constexpr OUString aLevelStylePropNameTOCMap[] =
934 { u""_ustr, u"ParaStyleLevel1"_ustr, u"ParaStyleLevel2"_ustr, u"ParaStyleLevel3"_ustr,
935 u"ParaStyleLevel4"_ustr, u"ParaStyleLevel5"_ustr, u"ParaStyleLevel6"_ustr,
936 u"ParaStyleLevel7"_ustr, u"ParaStyleLevel8"_ustr, u"ParaStyleLevel9"_ustr,
937 u"ParaStyleLevel10"_ustr, u""_ustr };
938 constexpr OUString aLevelStylePropNameTableMap[] =
939 { u""_ustr, u"ParaStyleLevel1"_ustr, u""_ustr };
940 constexpr OUString aLevelStylePropNameAlphaMap[] =
941 { u""_ustr, u"ParaStyleSeparator"_ustr, u"ParaStyleLevel1"_ustr, u"ParaStyleLevel2"_ustr,
942 u"ParaStyleLevel3"_ustr, u""_ustr };
943 constexpr OUString aLevelStylePropNameBibliographyMap[] =
944 // TODO: replace with real property names, when available
945 { u""_ustr, u"ParaStyleLevel1"_ustr, u"ParaStyleLevel1"_ustr, u"ParaStyleLevel1"_ustr,
946 u"ParaStyleLevel1"_ustr, u"ParaStyleLevel1"_ustr, u"ParaStyleLevel1"_ustr,
947 u"ParaStyleLevel1"_ustr, u"ParaStyleLevel1"_ustr, u"ParaStyleLevel1"_ustr,
948 u"ParaStyleLevel1"_ustr, u"ParaStyleLevel1"_ustr, u"ParaStyleLevel1"_ustr,
949 u"ParaStyleLevel1"_ustr, u"ParaStyleLevel1"_ustr,u"ParaStyleLevel1"_ustr,
950 u"ParaStyleLevel1"_ustr, u"ParaStyleLevel1"_ustr, u"ParaStyleLevel1"_ustr,
951 u"ParaStyleLevel1"_ustr, u"ParaStyleLevel1"_ustr, u"ParaStyleLevel1"_ustr,
952 u"ParaStyleLevel1"_ustr,
953 u""_ustr };
955 constexpr const OUString* aTypeLevelStylePropNameMap[] =
957 aLevelStylePropNameTOCMap, // TOC
958 aLevelStylePropNameTableMap, // table index
959 aLevelStylePropNameTableMap, // illustration index
960 aLevelStylePropNameTableMap, // object index
961 aLevelStylePropNameTOCMap, // user index
962 aLevelStylePropNameAlphaMap, // alphabetical index
963 aLevelStylePropNameBibliographyMap // bibliography
966 const XMLTokenEnum aTypeLevelAttrMap[] =
968 XML_OUTLINE_LEVEL, // TOC
969 XML_TOKEN_INVALID, // table index
970 XML_TOKEN_INVALID, // illustration index
971 XML_TOKEN_INVALID, // object index
972 XML_OUTLINE_LEVEL, // user index
973 XML_OUTLINE_LEVEL, // alphabetical index
974 XML_BIBLIOGRAPHY_TYPE // bibliography
977 const XMLTokenEnum aTypeElementNameMap[] =
979 XML_TABLE_OF_CONTENT_ENTRY_TEMPLATE, // TOC
980 XML_TABLE_INDEX_ENTRY_TEMPLATE, // table index
981 XML_ILLUSTRATION_INDEX_ENTRY_TEMPLATE, // illustration index
982 XML_OBJECT_INDEX_ENTRY_TEMPLATE, // object index
983 XML_USER_INDEX_ENTRY_TEMPLATE, // user index
984 XML_ALPHABETICAL_INDEX_ENTRY_TEMPLATE, // alphabetical index
985 XML_BIBLIOGRAPHY_ENTRY_TEMPLATE // bibliography
989 bool XMLSectionExport::ExportIndexTemplate(
990 SectionTypeEnum eType,
991 sal_Int32 nOutlineLevel,
992 const Reference<XPropertySet> & rPropertySet,
993 const Sequence<Sequence<PropertyValue> > & rValues)
995 OSL_ENSURE(eType >= TEXT_SECTION_TYPE_TOC, "illegal index type");
996 OSL_ENSURE(eType <= TEXT_SECTION_TYPE_BIBLIOGRAPHY, "illegal index type");
997 OSL_ENSURE(nOutlineLevel >= 0, "illegal outline level");
999 if ( (eType >= TEXT_SECTION_TYPE_TOC) &&
1000 (eType <= TEXT_SECTION_TYPE_BIBLIOGRAPHY) &&
1001 (nOutlineLevel >= 0) )
1003 // get level name and level attribute name from aLevelNameMap;
1004 const XMLTokenEnum eLevelAttrName(
1005 aTypeLevelAttrMap[eType-TEXT_SECTION_TYPE_TOC]);
1006 const XMLTokenEnum eLevelName(
1007 aTypeLevelNameMap[eType-TEXT_SECTION_TYPE_TOC][nOutlineLevel]);
1009 // #92124#: some old documents may be broken, then they have
1010 // too many template levels; we need to recognize this and
1011 // export only as many as is legal for the respective index
1012 // type. To do this, we simply return an error flag, which
1013 // will then abort further template level exports.
1014 OSL_ENSURE(XML_TOKEN_INVALID != eLevelName, "can't find level name");
1015 if ( XML_TOKEN_INVALID == eLevelName )
1017 // output level not found? Then end of templates! #91214#
1018 return false;
1021 // output level name
1022 if ((XML_TOKEN_INVALID != eLevelName) && (XML_TOKEN_INVALID != eLevelAttrName))
1024 GetExport().AddAttribute(XML_NAMESPACE_TEXT,
1025 GetXMLToken(eLevelAttrName),
1026 GetXMLToken(eLevelName));
1029 // paragraph level style name
1030 const OUString pPropName(
1031 aTypeLevelStylePropNameMap[eType-TEXT_SECTION_TYPE_TOC][nOutlineLevel]);
1032 OSL_ENSURE(!pPropName.isEmpty(), "can't find property name");
1033 if (!pPropName.isEmpty())
1035 Any aAny = rPropertySet->getPropertyValue(pPropName);
1036 OUString sParaStyleName;
1037 aAny >>= sParaStyleName;
1038 GetExport().AddAttribute(XML_NAMESPACE_TEXT,
1039 XML_STYLE_NAME,
1040 GetExport().EncodeStyleName( sParaStyleName ));
1043 // template element
1044 const XMLTokenEnum eElementName(
1045 aTypeElementNameMap[eType - TEXT_SECTION_TYPE_TOC]);
1046 SvXMLElementExport aLevelTemplate(GetExport(),
1047 XML_NAMESPACE_TEXT,
1048 GetXMLToken(eElementName),
1049 true, true);
1051 // export sequence
1052 for(auto& rValue : rValues)
1054 ExportIndexTemplateElement(
1055 eType, //i90246
1056 rValue);
1060 return true;
1063 namespace {
1065 enum TemplateTypeEnum
1067 TOK_TTYPE_ENTRY_NUMBER,
1068 TOK_TTYPE_ENTRY_TEXT,
1069 TOK_TTYPE_TAB_STOP,
1070 TOK_TTYPE_TEXT,
1071 TOK_TTYPE_PAGE_NUMBER,
1072 TOK_TTYPE_CHAPTER_INFO,
1073 TOK_TTYPE_HYPERLINK_START,
1074 TOK_TTYPE_HYPERLINK_END,
1075 TOK_TTYPE_BIBLIOGRAPHY,
1076 TOK_TTYPE_INVALID
1079 enum TemplateParamEnum
1081 TOK_TPARAM_TOKEN_TYPE,
1082 TOK_TPARAM_CHAR_STYLE,
1083 TOK_TPARAM_TAB_RIGHT_ALIGNED,
1084 TOK_TPARAM_TAB_POSITION,
1085 TOK_TPARAM_TAB_WITH_TAB, // #i21237#
1086 TOK_TPARAM_TAB_FILL_CHAR,
1087 TOK_TPARAM_TEXT,
1088 TOK_TPARAM_CHAPTER_FORMAT,
1089 TOK_TPARAM_CHAPTER_LEVEL,//i53420
1090 TOK_TPARAM_BIBLIOGRAPHY_DATA
1095 SvXMLEnumStringMapEntry<TemplateTypeEnum> const aTemplateTypeMap[] =
1097 ENUM_STRING_MAP_ENTRY( "TokenEntryNumber", TOK_TTYPE_ENTRY_NUMBER ),
1098 ENUM_STRING_MAP_ENTRY( "TokenEntryText", TOK_TTYPE_ENTRY_TEXT ),
1099 ENUM_STRING_MAP_ENTRY( "TokenTabStop", TOK_TTYPE_TAB_STOP ),
1100 ENUM_STRING_MAP_ENTRY( "TokenText", TOK_TTYPE_TEXT ),
1101 ENUM_STRING_MAP_ENTRY( "TokenPageNumber", TOK_TTYPE_PAGE_NUMBER ),
1102 ENUM_STRING_MAP_ENTRY( "TokenChapterInfo", TOK_TTYPE_CHAPTER_INFO ),
1103 ENUM_STRING_MAP_ENTRY( "TokenHyperlinkStart", TOK_TTYPE_HYPERLINK_START ),
1104 ENUM_STRING_MAP_ENTRY( "TokenHyperlinkEnd", TOK_TTYPE_HYPERLINK_END ),
1105 ENUM_STRING_MAP_ENTRY( "TokenBibliographyDataField", TOK_TTYPE_BIBLIOGRAPHY ),
1106 { nullptr, 0, TemplateTypeEnum(0)}
1109 SvXMLEnumStringMapEntry<TemplateParamEnum> const aTemplateParamMap[] =
1111 ENUM_STRING_MAP_ENTRY( "TokenType", TOK_TPARAM_TOKEN_TYPE ),
1112 ENUM_STRING_MAP_ENTRY( "CharacterStyleName", TOK_TPARAM_CHAR_STYLE ),
1113 ENUM_STRING_MAP_ENTRY( "TabStopRightAligned", TOK_TPARAM_TAB_RIGHT_ALIGNED ),
1114 ENUM_STRING_MAP_ENTRY( "TabStopPosition", TOK_TPARAM_TAB_POSITION ),
1115 ENUM_STRING_MAP_ENTRY( "TabStopFillCharacter", TOK_TPARAM_TAB_FILL_CHAR ),
1116 // #i21237#
1117 ENUM_STRING_MAP_ENTRY( "WithTab", TOK_TPARAM_TAB_WITH_TAB ),
1118 ENUM_STRING_MAP_ENTRY( "Text", TOK_TPARAM_TEXT ),
1119 ENUM_STRING_MAP_ENTRY( "ChapterFormat", TOK_TPARAM_CHAPTER_FORMAT ),
1120 ENUM_STRING_MAP_ENTRY( "ChapterLevel", TOK_TPARAM_CHAPTER_LEVEL ),//i53420
1121 ENUM_STRING_MAP_ENTRY( "BibliographyDataField", TOK_TPARAM_BIBLIOGRAPHY_DATA ),
1122 { nullptr, 0, TemplateParamEnum(0)}
1125 SvXMLEnumMapEntry<sal_Int16> const aBibliographyDataFieldMap[] =
1127 { XML_ADDRESS, BibliographyDataField::ADDRESS },
1128 { XML_ANNOTE, BibliographyDataField::ANNOTE },
1129 { XML_AUTHOR, BibliographyDataField::AUTHOR },
1130 { XML_BIBLIOGRAPHY_TYPE, BibliographyDataField::BIBILIOGRAPHIC_TYPE },
1131 { XML_BOOKTITLE, BibliographyDataField::BOOKTITLE },
1132 { XML_CHAPTER, BibliographyDataField::CHAPTER },
1133 { XML_CUSTOM1, BibliographyDataField::CUSTOM1 },
1134 { XML_CUSTOM2, BibliographyDataField::CUSTOM2 },
1135 { XML_CUSTOM3, BibliographyDataField::CUSTOM3 },
1136 { XML_CUSTOM4, BibliographyDataField::CUSTOM4 },
1137 { XML_CUSTOM5, BibliographyDataField::CUSTOM5 },
1138 { XML_EDITION, BibliographyDataField::EDITION },
1139 { XML_EDITOR, BibliographyDataField::EDITOR },
1140 { XML_HOWPUBLISHED, BibliographyDataField::HOWPUBLISHED },
1141 { XML_IDENTIFIER, BibliographyDataField::IDENTIFIER },
1142 { XML_INSTITUTION, BibliographyDataField::INSTITUTION },
1143 { XML_ISBN, BibliographyDataField::ISBN },
1144 { XML_JOURNAL, BibliographyDataField::JOURNAL },
1145 { XML_MONTH, BibliographyDataField::MONTH },
1146 { XML_NOTE, BibliographyDataField::NOTE },
1147 { XML_NUMBER, BibliographyDataField::NUMBER },
1148 { XML_ORGANIZATIONS, BibliographyDataField::ORGANIZATIONS },
1149 { XML_PAGES, BibliographyDataField::PAGES },
1150 { XML_PUBLISHER, BibliographyDataField::PUBLISHER },
1151 { XML_REPORT_TYPE, BibliographyDataField::REPORT_TYPE },
1152 { XML_SCHOOL, BibliographyDataField::SCHOOL },
1153 { XML_SERIES, BibliographyDataField::SERIES },
1154 { XML_TITLE, BibliographyDataField::TITLE },
1155 { XML_URL, BibliographyDataField::URL },
1156 { XML_VOLUME, BibliographyDataField::VOLUME },
1157 { XML_YEAR, BibliographyDataField::YEAR },
1158 { XML_TOKEN_INVALID, 0 }
1161 void XMLSectionExport::ExportIndexTemplateElement(
1162 SectionTypeEnum eType, //i90246
1163 const Sequence<PropertyValue> & rValues)
1165 // variables for template values
1167 // char style
1168 OUString sCharStyle;
1169 bool bCharStyleOK = false;
1171 // text
1172 OUString sText;
1173 bool bTextOK = false;
1175 // tab position
1176 bool bRightAligned = false;
1178 // tab position
1179 sal_Int32 nTabPosition = 0;
1180 bool bTabPositionOK = false;
1182 // fill character
1183 OUString sFillChar;
1184 bool bFillCharOK = false;
1186 // chapter format
1187 sal_Int16 nChapterFormat = 0;
1188 bool bChapterFormatOK = false;
1190 // outline max level
1191 sal_Int16 nLevel = 0;
1192 bool bLevelOK = false;
1194 // Bibliography Data
1195 sal_Int16 nBibliographyData = 0;
1196 bool bBibliographyDataOK = false;
1198 // With Tab Stop #i21237#
1199 bool bWithTabStop = false;
1200 bool bWithTabStopOK = false;
1202 //i90246, the ODF version being written to is:
1203 const SvtSaveOptions::ODFSaneDefaultVersion aODFVersion = rExport.getSaneDefaultVersion();
1204 //the above version cannot be used for old OOo (OOo 1.0) formats!
1206 // token type
1207 enum TemplateTypeEnum nTokenType = TOK_TTYPE_INVALID;
1209 for(const auto& rValue : rValues)
1211 TemplateParamEnum nToken;
1212 if ( SvXMLUnitConverter::convertEnum( nToken, rValue.Name,
1213 aTemplateParamMap ) )
1215 // Only use direct and default values.
1216 // Wrong. no property states, so ignore.
1217 // if ( (beans::PropertyState_DIRECT_VALUE == rValues[i].State) ||
1218 // (beans::PropertyState_DEFAULT_VALUE == rValues[i].State) )
1220 switch (nToken)
1222 case TOK_TPARAM_TOKEN_TYPE:
1224 OUString sVal;
1225 rValue.Value >>= sVal;
1226 SvXMLUnitConverter::convertEnum( nTokenType, sVal, aTemplateTypeMap);
1227 break;
1230 case TOK_TPARAM_CHAR_STYLE:
1231 // only valid, if not empty
1232 rValue.Value >>= sCharStyle;
1233 bCharStyleOK = !sCharStyle.isEmpty();
1234 break;
1236 case TOK_TPARAM_TEXT:
1237 rValue.Value >>= sText;
1238 bTextOK = true;
1239 break;
1241 case TOK_TPARAM_TAB_RIGHT_ALIGNED:
1242 bRightAligned =
1243 *o3tl::doAccess<bool>(rValue.Value);
1244 break;
1246 case TOK_TPARAM_TAB_POSITION:
1247 rValue.Value >>= nTabPosition;
1248 bTabPositionOK = true;
1249 break;
1251 // #i21237#
1252 case TOK_TPARAM_TAB_WITH_TAB:
1253 bWithTabStop = *o3tl::doAccess<bool>(rValue.Value);
1254 bWithTabStopOK = true;
1255 break;
1257 case TOK_TPARAM_TAB_FILL_CHAR:
1258 rValue.Value >>= sFillChar;
1259 bFillCharOK = true;
1260 break;
1262 case TOK_TPARAM_CHAPTER_FORMAT:
1263 rValue.Value >>= nChapterFormat;
1264 bChapterFormatOK = true;
1265 break;
1266 //---> i53420
1267 case TOK_TPARAM_CHAPTER_LEVEL:
1268 rValue.Value >>= nLevel;
1269 bLevelOK = true;
1270 break;
1271 case TOK_TPARAM_BIBLIOGRAPHY_DATA:
1272 rValue.Value >>= nBibliographyData;
1273 bBibliographyDataOK = true;
1274 break;
1279 // convert type to token (and check validity) ...
1280 XMLTokenEnum eElement(XML_TOKEN_INVALID);
1281 sal_uInt16 nNamespace(XML_NAMESPACE_TEXT);
1282 switch(nTokenType)
1284 case TOK_TTYPE_ENTRY_TEXT:
1285 eElement = XML_INDEX_ENTRY_TEXT;
1286 break;
1287 case TOK_TTYPE_TAB_STOP:
1288 // test validity
1289 if ( bRightAligned || bTabPositionOK || bFillCharOK )
1291 eElement = XML_INDEX_ENTRY_TAB_STOP;
1293 break;
1294 case TOK_TTYPE_TEXT:
1295 // test validity
1296 if (bTextOK)
1298 eElement = XML_INDEX_ENTRY_SPAN;
1300 break;
1301 case TOK_TTYPE_PAGE_NUMBER:
1302 eElement = XML_INDEX_ENTRY_PAGE_NUMBER;
1303 break;
1304 case TOK_TTYPE_CHAPTER_INFO: // keyword index
1305 eElement = XML_INDEX_ENTRY_CHAPTER;
1306 break;
1307 case TOK_TTYPE_ENTRY_NUMBER: // table of content
1308 eElement = XML_INDEX_ENTRY_CHAPTER;
1309 break;
1310 case TOK_TTYPE_HYPERLINK_START:
1311 eElement = XML_INDEX_ENTRY_LINK_START;
1312 break;
1313 case TOK_TTYPE_HYPERLINK_END:
1314 eElement = XML_INDEX_ENTRY_LINK_END;
1315 break;
1316 case TOK_TTYPE_BIBLIOGRAPHY:
1317 if (bBibliographyDataOK)
1319 eElement = XML_INDEX_ENTRY_BIBLIOGRAPHY;
1321 break;
1322 default:
1323 ; // unknown/unimplemented template
1324 break;
1327 if (eType != TEXT_SECTION_TYPE_TOC)
1329 switch (nTokenType)
1331 case TOK_TTYPE_HYPERLINK_START:
1332 case TOK_TTYPE_HYPERLINK_END:
1333 if (SvtSaveOptions::ODFSVER_012 < aODFVersion)
1335 assert(eType == TEXT_SECTION_TYPE_ILLUSTRATION
1336 || eType == TEXT_SECTION_TYPE_OBJECT
1337 || eType == TEXT_SECTION_TYPE_TABLE
1338 || eType == TEXT_SECTION_TYPE_USER);
1339 // ODF 1.3 OFFICE-3941
1340 nNamespace = (SvtSaveOptions::ODFSVER_013 <= aODFVersion)
1341 ? XML_NAMESPACE_TEXT
1342 : XML_NAMESPACE_LO_EXT;
1344 else
1346 eElement = XML_TOKEN_INVALID; // not allowed in ODF <= 1.2
1348 break;
1349 default:
1350 break;
1354 //--->i90246
1355 //check the ODF version being exported
1356 if (aODFVersion == SvtSaveOptions::ODFSVER_011
1357 || aODFVersion == SvtSaveOptions::ODFSVER_010)
1359 bLevelOK = false;
1360 if (TOK_TTYPE_CHAPTER_INFO == nTokenType)
1362 //if we are emitting for ODF 1.1 or 1.0, this information can be used for alphabetical index only
1363 //it's not permitted in other indexes
1364 if (eType != TEXT_SECTION_TYPE_ALPHABETICAL)
1366 eElement = XML_TOKEN_INVALID; //not permitted, invalidate the element
1368 else //maps format for 1.1 & 1.0
1370 // a few word here: OOo up to 2.4 uses the field chapter info in Alphabetical index
1371 // in a way different from the ODF 1.1/1.0 specification:
1373 // ODF1.1/1.0 OOo display in chapter info ODF1.2
1374 // (used in alphabetical index only
1376 // number chapter number without pre/postfix plain-number
1377 // number-and-name chapter number without pre/postfix plus title plain-number-and-name
1379 // with issue i89791 the reading of ODF 1.1 and 1.0 was corrected
1380 // this one corrects the writing back from ODF 1.2 to ODF 1.1/1.0
1381 // unfortunately if there is another application which interprets correctly ODF1.1/1.0,
1382 // the resulting alphabetical index will be rendered wrong by OOo 2.4 version
1384 switch( nChapterFormat )
1386 case ChapterFormat::DIGIT:
1387 nChapterFormat = ChapterFormat::NUMBER;
1388 break;
1389 case ChapterFormat::NO_PREFIX_SUFFIX:
1390 nChapterFormat = ChapterFormat::NAME_NUMBER;
1391 break;
1395 else if (TOK_TTYPE_ENTRY_NUMBER == nTokenType)
1397 //in case of ODF 1.1 or 1.0 the only allowed number format is "number"
1398 //so, force it...
1399 // The only expected 'foreign' nChapterFormat is
1400 // ' ChapterFormat::DIGIT', forced to 'none, since the
1401 // 'value allowed in ODF 1.1 and 1.0 is 'number' the default
1402 // this can be obtained by simply disabling the chapter format
1403 bChapterFormatOK = false;
1407 // ... and write Element
1408 if (eElement == XML_TOKEN_INVALID)
1409 return;
1411 // character style (for most templates)
1412 if (bCharStyleOK)
1414 switch (nTokenType)
1416 case TOK_TTYPE_ENTRY_TEXT:
1417 case TOK_TTYPE_TEXT:
1418 case TOK_TTYPE_PAGE_NUMBER:
1419 case TOK_TTYPE_ENTRY_NUMBER:
1420 case TOK_TTYPE_HYPERLINK_START:
1421 case TOK_TTYPE_HYPERLINK_END:
1422 case TOK_TTYPE_BIBLIOGRAPHY:
1423 case TOK_TTYPE_CHAPTER_INFO:
1424 case TOK_TTYPE_TAB_STOP:
1425 GetExport().AddAttribute(XML_NAMESPACE_TEXT,
1426 XML_STYLE_NAME,
1427 GetExport().EncodeStyleName( sCharStyle) );
1428 break;
1429 default:
1430 ; // nothing: no character style
1431 break;
1435 // tab properties
1436 if (TOK_TTYPE_TAB_STOP == nTokenType)
1438 // tab type
1439 GetExport().AddAttribute(XML_NAMESPACE_STYLE, XML_TYPE,
1440 bRightAligned ? XML_RIGHT : XML_LEFT);
1442 if (bTabPositionOK && (! bRightAligned))
1444 // position for left tabs (convert to measure)
1445 OUStringBuffer sBuf;
1446 GetExport().GetMM100UnitConverter().convertMeasureToXML(sBuf,
1447 nTabPosition);
1448 GetExport().AddAttribute(XML_NAMESPACE_STYLE,
1449 XML_POSITION,
1450 sBuf.makeStringAndClear());
1453 // fill char ("leader char")
1454 if (bFillCharOK && !sFillChar.isEmpty())
1456 GetExport().AddAttribute(XML_NAMESPACE_STYLE,
1457 XML_LEADER_CHAR, sFillChar);
1460 // #i21237#
1461 if (bWithTabStopOK && ! bWithTabStop)
1463 GetExport().AddAttribute(XML_NAMESPACE_STYLE,
1464 XML_WITH_TAB,
1465 XML_FALSE);
1469 // bibliography data
1470 if (TOK_TTYPE_BIBLIOGRAPHY == nTokenType)
1472 OSL_ENSURE(bBibliographyDataOK, "need bibl data");
1473 OUStringBuffer sBuf;
1474 if (SvXMLUnitConverter::convertEnum( sBuf, nBibliographyData,
1475 aBibliographyDataFieldMap ) )
1477 GetExport().AddAttribute(XML_NAMESPACE_TEXT,
1478 XML_BIBLIOGRAPHY_DATA_FIELD,
1479 sBuf.makeStringAndClear());
1483 // chapter info
1484 if (TOK_TTYPE_CHAPTER_INFO == nTokenType)
1486 OSL_ENSURE(bChapterFormatOK, "need chapter info");
1487 GetExport().AddAttribute(
1488 XML_NAMESPACE_TEXT, XML_DISPLAY,
1489 XMLTextFieldExport::MapChapterDisplayFormat(nChapterFormat));
1490 //---> i53420
1491 if (bLevelOK)
1492 GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_OUTLINE_LEVEL,
1493 OUString::number(nLevel));
1496 //--->i53420
1497 if (TOK_TTYPE_ENTRY_NUMBER == nTokenType)
1499 if (bChapterFormatOK)
1500 GetExport().AddAttribute(
1501 XML_NAMESPACE_TEXT, XML_DISPLAY,
1502 XMLTextFieldExport::MapChapterDisplayFormat(nChapterFormat));
1504 if (bLevelOK)
1505 GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_OUTLINE_LEVEL,
1506 OUString::number(nLevel));
1508 // export template
1509 SvXMLElementExport aTemplateElement(GetExport(), nNamespace,
1510 GetXMLToken(eElement),
1511 true, false)
1514 // entry text or span element: write text
1515 if (TOK_TTYPE_TEXT == nTokenType)
1517 GetExport().Characters(sText);
1521 void XMLSectionExport::ExportLevelParagraphStyles(
1522 Reference<XIndexReplace> const & xLevelParagraphStyles)
1524 // iterate over levels
1525 sal_Int32 nPLevelCount = xLevelParagraphStyles->getCount();
1526 for(sal_Int32 nLevel = 0; nLevel < nPLevelCount; nLevel++)
1528 Any aAny = xLevelParagraphStyles->getByIndex(nLevel);
1529 Sequence<OUString> aStyleNames;
1530 aAny >>= aStyleNames;
1532 // export only if at least one style is contained
1533 if (aStyleNames.hasElements())
1535 // level attribute; we count 1..10; API 0..9
1536 sal_Int32 nLevelPlusOne = nLevel + 1;
1537 GetExport().AddAttribute(XML_NAMESPACE_TEXT,
1538 XML_OUTLINE_LEVEL,
1539 OUString::number(nLevelPlusOne));
1541 // source styles element
1542 SvXMLElementExport aParaStyles(GetExport(),
1543 XML_NAMESPACE_TEXT,
1544 XML_INDEX_SOURCE_STYLES,
1545 true, true);
1547 // iterate over styles in this level
1548 for (const auto& rStyleName : aStyleNames)
1550 // stylename attribute
1551 GetExport().AddAttribute(XML_NAMESPACE_TEXT,
1552 XML_STYLE_NAME,
1553 GetExport().EncodeStyleName(rStyleName) );
1555 // element
1556 SvXMLElementExport aParaStyle(GetExport(),
1557 XML_NAMESPACE_TEXT,
1558 XML_INDEX_SOURCE_STYLE,
1559 true, false);
1565 void XMLSectionExport::ExportBoolean(
1566 const Reference<XPropertySet> & rPropSet,
1567 const OUString& sPropertyName,
1568 enum XMLTokenEnum eAttributeName,
1569 bool bDefault,
1570 bool bInvert)
1572 OSL_ENSURE(eAttributeName != XML_TOKEN_INVALID, "Need attribute name");
1574 Any aAny = rPropSet->getPropertyValue(sPropertyName);
1575 bool bTmp = *o3tl::doAccess<bool>(aAny);
1577 // value = value ^ bInvert
1578 // omit if value == default
1579 if ( (bTmp != bInvert) != bDefault )
1581 // export non-default value (since default is omitted)
1582 GetExport().AddAttribute(XML_NAMESPACE_TEXT,
1583 eAttributeName,
1584 bDefault ? XML_FALSE : XML_TRUE);
1588 void XMLSectionExport::ExportBibliographyConfiguration(SvXMLExport& rExport)
1590 // first: get field master (via text field supplier)
1591 Reference<XTextFieldsSupplier> xTextFieldsSupp( rExport.GetModel(),
1592 UNO_QUERY );
1593 if ( !xTextFieldsSupp.is() )
1594 return;
1596 static constexpr OUString sFieldMaster_Bibliography(u"com.sun.star.text.FieldMaster.Bibliography"_ustr);
1598 // get bibliography field master
1599 Reference<XNameAccess> xMasters =
1600 xTextFieldsSupp->getTextFieldMasters();
1601 if ( !xMasters->hasByName(sFieldMaster_Bibliography) )
1602 return;
1604 Any aAny =
1605 xMasters->getByName(sFieldMaster_Bibliography);
1606 Reference<XPropertySet> xPropSet;
1607 aAny >>= xPropSet;
1609 OSL_ENSURE( xPropSet.is(), "field master must have XPropSet" );
1611 OUString sTmp;
1613 aAny = xPropSet->getPropertyValue("BracketBefore");
1614 aAny >>= sTmp;
1615 rExport.AddAttribute(XML_NAMESPACE_TEXT, XML_PREFIX, sTmp);
1617 aAny = xPropSet->getPropertyValue("BracketAfter");
1618 aAny >>= sTmp;
1619 rExport.AddAttribute(XML_NAMESPACE_TEXT, XML_SUFFIX, sTmp);
1621 aAny = xPropSet->getPropertyValue("IsNumberEntries");
1622 if (*o3tl::doAccess<bool>(aAny))
1624 rExport.AddAttribute(XML_NAMESPACE_TEXT,
1625 XML_NUMBERED_ENTRIES, XML_TRUE);
1628 aAny = xPropSet->getPropertyValue("IsSortByPosition");
1629 if (! *o3tl::doAccess<bool>(aAny))
1631 rExport.AddAttribute(XML_NAMESPACE_TEXT,
1632 XML_SORT_BY_POSITION, XML_FALSE);
1635 // sort algorithm
1636 aAny = xPropSet->getPropertyValue("SortAlgorithm");
1637 OUString sAlgorithm;
1638 aAny >>= sAlgorithm;
1639 if( !sAlgorithm.isEmpty() )
1641 rExport.AddAttribute( XML_NAMESPACE_TEXT,
1642 XML_SORT_ALGORITHM, sAlgorithm );
1645 // locale
1646 aAny = xPropSet->getPropertyValue("Locale");
1647 Locale aLocale;
1648 aAny >>= aLocale;
1649 rExport.AddLanguageTagAttributes( XML_NAMESPACE_FO, XML_NAMESPACE_STYLE, aLocale, true);
1651 // configuration element
1652 SvXMLElementExport aElement(rExport, XML_NAMESPACE_TEXT,
1653 XML_BIBLIOGRAPHY_CONFIGURATION,
1654 true, true);
1656 // sort keys
1657 aAny = xPropSet->getPropertyValue("SortKeys");
1658 Sequence<Sequence<PropertyValue> > aKeys;
1659 aAny >>= aKeys;
1660 for (const Sequence<PropertyValue>& rKey : aKeys)
1662 for(const PropertyValue& rValue : rKey)
1664 if (rValue.Name == "SortKey")
1666 sal_Int16 nKey = 0;
1667 rValue.Value >>= nKey;
1668 OUStringBuffer sBuf;
1669 if (SvXMLUnitConverter::convertEnum( sBuf, nKey,
1670 aBibliographyDataFieldMap ) )
1672 rExport.AddAttribute(XML_NAMESPACE_TEXT, XML_KEY,
1673 sBuf.makeStringAndClear());
1676 else if (rValue.Name == "IsSortAscending")
1678 bool bTmp = *o3tl::doAccess<bool>(rValue.Value);
1679 rExport.AddAttribute(XML_NAMESPACE_TEXT,
1680 XML_SORT_ASCENDING,
1681 bTmp ? XML_TRUE : XML_FALSE);
1685 SvXMLElementExport aKeyElem(rExport,
1686 XML_NAMESPACE_TEXT, XML_SORT_KEY,
1687 true, true);
1692 bool XMLSectionExport::IsMuteSection(
1693 const Reference<XTextSection> & rSection) const
1695 bool bRet = false;
1697 // a section is mute if
1698 // 1) it exists
1699 // 2) the SaveLinkedSections flag (at the export) is false
1700 // 3) the IsGlobalDocumentSection property is true
1701 // 4) it is not an Index
1703 if ( (!rExport.IsSaveLinkedSections()) && rSection.is() )
1705 // walk the section chain and set bRet if any is linked
1706 for(Reference<XTextSection> aSection(rSection);
1707 aSection.is();
1708 aSection = aSection->getParentSection())
1710 // check if it is a global document section (linked or index)
1711 Reference<XPropertySet> xPropSet(aSection, UNO_QUERY);
1712 if (xPropSet.is())
1714 Any aAny = xPropSet->getPropertyValue("IsGlobalDocumentSection");
1716 if ( *o3tl::doAccess<bool>(aAny) )
1718 Reference<XDocumentIndex> xIndex;
1719 if (! GetIndex(rSection, xIndex))
1721 bRet = true;
1723 // early out if result is known
1724 break;
1728 // section has no properties: ignore
1731 // else: no section, or always save sections: default (false)
1733 return bRet;
1736 bool XMLSectionExport::IsMuteSection(
1737 const Reference<XTextContent> & rSection,
1738 bool bDefault) const
1740 // default: like default argument
1741 bool bRet = bDefault;
1743 Reference<XPropertySet> xPropSet(rSection->getAnchor(), UNO_QUERY);
1744 if (xPropSet.is())
1746 if (xPropSet->getPropertySetInfo()->hasPropertyByName("TextSection"))
1748 Any aAny = xPropSet->getPropertyValue("TextSection");
1749 Reference<XTextSection> xSection;
1750 aAny >>= xSection;
1752 bRet = IsMuteSection(xSection);
1754 // else: return default
1756 // else: return default
1758 return bRet;
1761 bool XMLSectionExport::IsInSection(
1762 const Reference<XTextSection> & rEnclosingSection,
1763 const Reference<XTextContent> & rContent,
1764 bool bDefault)
1766 // default: like default argument
1767 bool bRet = bDefault;
1768 OSL_ENSURE(rEnclosingSection.is(), "enclosing section expected");
1770 Reference<XPropertySet> xPropSet(rContent, UNO_QUERY);
1771 if (xPropSet.is())
1773 if (xPropSet->getPropertySetInfo()->hasPropertyByName("TextSection"))
1775 Any aAny = xPropSet->getPropertyValue("TextSection");
1776 Reference<XTextSection> xSection;
1777 aAny >>= xSection;
1779 // now walk chain of text sections (if we have one)
1780 if (xSection.is())
1784 bRet = (rEnclosingSection == xSection);
1785 xSection = xSection->getParentSection();
1787 while (!bRet && xSection.is());
1789 else
1790 bRet = false; // no section -> can't be inside
1792 // else: no TextSection property -> return default
1794 // else: no XPropertySet -> return default
1796 return bRet;
1800 void XMLSectionExport::ExportMasterDocHeadingDummies()
1802 if( bHeadingDummiesExported )
1803 return;
1805 Reference< XChapterNumberingSupplier > xCNSupplier( rExport.GetModel(),
1806 UNO_QUERY );
1808 Reference< XIndexReplace > xChapterNumbering;
1809 if( xCNSupplier.is() )
1810 xChapterNumbering = xCNSupplier->getChapterNumberingRules();
1812 if( !xChapterNumbering.is() )
1813 return;
1815 sal_Int32 nCount = xChapterNumbering->getCount();
1816 for( sal_Int32 nLevel = 0; nLevel < nCount; nLevel++ )
1818 OUString sStyle;
1819 Sequence<PropertyValue> aProperties;
1820 xChapterNumbering->getByIndex( nLevel ) >>= aProperties;
1821 auto pProp = std::find_if(std::cbegin(aProperties), std::cend(aProperties),
1822 [](const PropertyValue& rProp) { return rProp.Name == "HeadingStyleName"; });
1823 if (pProp != std::cend(aProperties))
1824 pProp->Value >>= sStyle;
1826 if( !sStyle.isEmpty() )
1828 GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_STYLE_NAME,
1829 GetExport().EncodeStyleName( sStyle ) );
1831 GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_LEVEL,
1832 OUString::number( nLevel + 1 ) );
1833 SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_TEXT, XML_H,
1834 true, false );
1838 bHeadingDummiesExported = true;
1841 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */