1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
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(
69 XMLTextParagraphExport
& rParaExp
)
71 , rParaExport(rParaExp
)
72 , bHeadingDummiesExported( false )
77 void XMLSectionExport::ExportSectionStart(
78 const Reference
<XTextSection
> & rSection
,
81 Reference
<XPropertySet
> xPropertySet(rSection
, UNO_QUERY
);
83 // always export section (auto) style
86 // get PropertySet and add section style
87 GetParaExport().Add( XmlStyleFamily::TEXT_SECTION
, xPropertySet
);
91 // always export section style
92 GetExport().AddAttribute(XML_NAMESPACE_TEXT
, XML_STYLE_NAME
,
94 XmlStyleFamily::TEXT_SECTION
,
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
))
107 ExportIndexStart(xIndex
);
111 // we are an index header
112 ExportIndexHeaderStart(rSection
);
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
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
;
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
)
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.
179 void XMLSectionExport::ExportSectionEnd(
180 const Reference
<XTextSection
> & rSection
,
183 // no end section for styles
187 enum XMLTokenEnum eElement
= XML_TOKEN_INVALID
;
189 // export index or regular section end
190 Reference
<XDocumentIndex
> xIndex
;
191 if (GetIndex(rSection
, xIndex
))
195 // index end: close index body element
196 GetExport().EndElement( XML_NAMESPACE_TEXT
, XML_INDEX_BODY
,
198 GetExport().IgnorableWhitespace();
200 switch (MapSectionType(xIndex
->getServiceName()))
202 case TEXT_SECTION_TYPE_TOC
:
203 eElement
= XML_TABLE_OF_CONTENT
;
206 case TEXT_SECTION_TYPE_ILLUSTRATION
:
207 eElement
= XML_ILLUSTRATION_INDEX
;
210 case TEXT_SECTION_TYPE_ALPHABETICAL
:
211 eElement
= XML_ALPHABETICAL_INDEX
;
214 case TEXT_SECTION_TYPE_TABLE
:
215 eElement
= XML_TABLE_INDEX
;
218 case TEXT_SECTION_TYPE_OBJECT
:
219 eElement
= XML_OBJECT_INDEX
;
222 case TEXT_SECTION_TYPE_USER
:
223 eElement
= XML_USER_INDEX
;
226 case TEXT_SECTION_TYPE_BIBLIOGRAPHY
:
227 eElement
= XML_BIBLIOGRAPHY
;
231 OSL_FAIL("unknown index type");
232 // default: skip index!
238 eElement
= XML_INDEX_TITLE
;
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();
257 OSL_FAIL("Need element name!");
259 // else: autostyles -> ignore
262 void XMLSectionExport::ExportIndexStart(
263 const Reference
<XDocumentIndex
> & rIndex
)
266 Reference
<XPropertySet
> xPropertySet(rIndex
, UNO_QUERY
);
268 switch (MapSectionType(rIndex
->getServiceName()))
270 case TEXT_SECTION_TYPE_TOC
:
271 ExportTableOfContentStart(xPropertySet
);
274 case TEXT_SECTION_TYPE_ILLUSTRATION
:
275 ExportIllustrationIndexStart(xPropertySet
);
278 case TEXT_SECTION_TYPE_ALPHABETICAL
:
279 ExportAlphabeticalIndexStart(xPropertySet
);
282 case TEXT_SECTION_TYPE_TABLE
:
283 ExportTableIndexStart(xPropertySet
);
286 case TEXT_SECTION_TYPE_OBJECT
:
287 ExportObjectIndexStart(xPropertySet
);
290 case TEXT_SECTION_TYPE_USER
:
291 ExportUserIndexStart(xPropertySet
);
294 case TEXT_SECTION_TYPE_BIBLIOGRAPHY
:
295 ExportBibliographyStart(xPropertySet
);
300 OSL_FAIL("unknown index type");
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.
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");
363 enum XMLTokenEnum eDisplay
= XML_TOKEN_INVALID
;
364 if (!sCond
.isEmpty())
367 GetExport().GetNamespaceMap().GetQNameByKey( XML_NAMESPACE_OOOW
,
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
,
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");
415 GetExport().IgnorableWhitespace();
416 GetExport().StartElement( XML_NAMESPACE_TEXT
, XML_SECTION
, true );
419 // unfortunately, we have to test all relevant strings for non-zero length
420 aAny
= xPropSet
->getPropertyValue("FileLink");
421 SectionFileLink 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
,
450 SvXMLElementExport
aElem(GetExport(),
451 XML_NAMESPACE_TEXT
, XML_SECTION_SOURCE
,
456 // check for DDE first
457 if (xPropSet
->getPropertySetInfo()->hasPropertyByName("DDECommandFile"))
460 // unfortunately, we have to test all relevant strings for
462 aAny
= xPropSet
->getPropertyValue("DDECommandFile");
463 OUString sApplication
;
464 aAny
>>= sApplication
;
465 aAny
= xPropSet
->getPropertyValue("DDECommandType");
468 aAny
= xPropSet
->getPropertyValue("DDECommandElement");
472 if ( !sApplication
.isEmpty() ||
476 GetExport().AddAttribute(XML_NAMESPACE_OFFICE
,
477 XML_DDE_APPLICATION
, sApplication
);
478 GetExport().AddAttribute(XML_NAMESPACE_OFFICE
, XML_DDE_TOPIC
,
480 GetExport().AddAttribute(XML_NAMESPACE_OFFICE
, XML_DDE_ITEM
,
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
,
516 OUString::number(nLevel
));
520 ExportBoolean(rPropertySet
, "CreateFromOutline",
521 XML_USE_OUTLINE_LEVEL
, true);
524 ExportBoolean(rPropertySet
, "CreateFromMarks",
525 XML_USE_INDEX_MARKS
, true);
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");
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
,
619 ExportBoolean(rPropertySet
, "UseAlphabeticalSeparators",
620 XML_ALPHABETICAL_SEPARATORS
, false);
621 ExportBoolean(rPropertySet
, "UseCombinedEntries", XML_COMBINE_ENTRIES
,
623 ExportBoolean(rPropertySet
, "UseDash", XML_COMBINE_ENTRIES_WITH_DASH
,
625 ExportBoolean(rPropertySet
, "UseKeyAsEntry", XML_USE_KEYS_AS_ENTRIES
,
627 ExportBoolean(rPropertySet
, "UsePP", XML_COMBINE_ENTRIES_WITH_PP
,
629 ExportBoolean(rPropertySet
, "UseUpperCase", XML_CAPITALIZE_ENTRIES
,
631 ExportBoolean(rPropertySet
, "IsCommaSeparated", XML_COMMA_SEPARATED
,
635 aAny
= rPropertySet
->getPropertyValue("SortAlgorithm");
638 if (!sAlgorithm
.isEmpty())
640 GetExport().AddAttribute( XML_NAMESPACE_TEXT
, XML_SORT_ALGORITHM
,
645 aAny
= rPropertySet
->getPropertyValue("Locale");
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
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" );
683 GetExport().AddAttribute(XML_NAMESPACE_TEXT
, XML_INDEX_NAME
,
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
);
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
)
749 OSL_ENSURE(eType
>= TEXT_SECTION_TYPE_TOC
, "illegal index type");
750 OSL_ENSURE(eType
<= TEXT_SECTION_TYPE_BIBLIOGRAPHY
, "illegal index type");
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
,
775 // the index source element (all indices)
776 SvXMLElementExport
aElem(GetExport(),
779 aTypeSourceElementNameMap
[
780 eType
- TEXT_SECTION_TYPE_TOC
]),
783 // scope for title template (all indices)
786 aAny
= rPropertySet
->getPropertyValue("ParaStyleHeading");
789 GetExport().AddAttribute(XML_NAMESPACE_TEXT
,
791 GetExport().EncodeStyleName( sStyleName
));
794 SvXMLElementExport
aHeaderTemplate(GetExport(),
796 XML_INDEX_TITLE_TEMPLATE
,
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
++)
817 Sequence
<PropertyValues
> aTemplateSequence
;
818 aAny
= xLevelTemplates
->getByIndex(i
);
819 aAny
>>= aTemplateSequence
;
821 // export the sequence (abort export if an error occurred; #91214#)
823 ExportIndexTemplate(eType
, i
, rPropertySet
, aTemplateSequence
);
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");
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
)
879 Any aAny
= rPropertySet
->getPropertyValue("CreateFromLabels");
880 if (! *o3tl::doAccess
<bool>(aAny
))
882 GetExport().AddAttribute(XML_NAMESPACE_TEXT
,
883 XML_USE_CAPTION
, XML_FALSE
);
887 aAny
= rPropertySet
->getPropertyValue("LabelCategory");
888 OUString sSequenceName
;
889 aAny
>>= sSequenceName
;
890 GetExport().AddAttribute(XML_NAMESPACE_TEXT
,
891 XML_CAPTION_SEQUENCE_NAME
,
895 aAny
= rPropertySet
->getPropertyValue("LabelDisplayType");
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
,
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 static const char* aLevelStylePropNameTOCMap
[] =
934 { nullptr, "ParaStyleLevel1", "ParaStyleLevel2", "ParaStyleLevel3",
935 "ParaStyleLevel4", "ParaStyleLevel5", "ParaStyleLevel6",
936 "ParaStyleLevel7", "ParaStyleLevel8", "ParaStyleLevel9",
937 "ParaStyleLevel10", nullptr };
938 static const char* aLevelStylePropNameTableMap
[] =
939 { nullptr, "ParaStyleLevel1", nullptr };
940 static const char* aLevelStylePropNameAlphaMap
[] =
941 { nullptr, "ParaStyleSeparator", "ParaStyleLevel1", "ParaStyleLevel2",
942 "ParaStyleLevel3", nullptr };
943 static const char* aLevelStylePropNameBibliographyMap
[] =
944 // TODO: replace with real property names, when available
945 { nullptr, "ParaStyleLevel1", "ParaStyleLevel1", "ParaStyleLevel1",
946 "ParaStyleLevel1", "ParaStyleLevel1", "ParaStyleLevel1",
947 "ParaStyleLevel1", "ParaStyleLevel1", "ParaStyleLevel1",
948 "ParaStyleLevel1", "ParaStyleLevel1", "ParaStyleLevel1",
949 "ParaStyleLevel1", "ParaStyleLevel1", "ParaStyleLevel1",
950 "ParaStyleLevel1", "ParaStyleLevel1", "ParaStyleLevel1",
951 "ParaStyleLevel1", "ParaStyleLevel1", "ParaStyleLevel1",
955 static const char** 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#
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 char* pPropName(
1031 aTypeLevelStylePropNameMap
[eType
-TEXT_SECTION_TYPE_TOC
][nOutlineLevel
]);
1032 OSL_ENSURE(nullptr != pPropName
, "can't find property name");
1033 if (nullptr != pPropName
)
1035 Any aAny
= rPropertySet
->getPropertyValue(
1036 OUString::createFromAscii(pPropName
));
1037 OUString sParaStyleName
;
1038 aAny
>>= sParaStyleName
;
1039 GetExport().AddAttribute(XML_NAMESPACE_TEXT
,
1041 GetExport().EncodeStyleName( sParaStyleName
));
1045 const XMLTokenEnum
eElementName(
1046 aTypeElementNameMap
[eType
- TEXT_SECTION_TYPE_TOC
]);
1047 SvXMLElementExport
aLevelTemplate(GetExport(),
1049 GetXMLToken(eElementName
),
1053 for(auto& rValue
: rValues
)
1055 ExportIndexTemplateElement(
1066 enum TemplateTypeEnum
1068 TOK_TTYPE_ENTRY_NUMBER
,
1069 TOK_TTYPE_ENTRY_TEXT
,
1072 TOK_TTYPE_PAGE_NUMBER
,
1073 TOK_TTYPE_CHAPTER_INFO
,
1074 TOK_TTYPE_HYPERLINK_START
,
1075 TOK_TTYPE_HYPERLINK_END
,
1076 TOK_TTYPE_BIBLIOGRAPHY
,
1080 enum TemplateParamEnum
1082 TOK_TPARAM_TOKEN_TYPE
,
1083 TOK_TPARAM_CHAR_STYLE
,
1084 TOK_TPARAM_TAB_RIGHT_ALIGNED
,
1085 TOK_TPARAM_TAB_POSITION
,
1086 TOK_TPARAM_TAB_WITH_TAB
, // #i21237#
1087 TOK_TPARAM_TAB_FILL_CHAR
,
1089 TOK_TPARAM_CHAPTER_FORMAT
,
1090 TOK_TPARAM_CHAPTER_LEVEL
,//i53420
1091 TOK_TPARAM_BIBLIOGRAPHY_DATA
1096 SvXMLEnumStringMapEntry
<TemplateTypeEnum
> const aTemplateTypeMap
[] =
1098 ENUM_STRING_MAP_ENTRY( "TokenEntryNumber", TOK_TTYPE_ENTRY_NUMBER
),
1099 ENUM_STRING_MAP_ENTRY( "TokenEntryText", TOK_TTYPE_ENTRY_TEXT
),
1100 ENUM_STRING_MAP_ENTRY( "TokenTabStop", TOK_TTYPE_TAB_STOP
),
1101 ENUM_STRING_MAP_ENTRY( "TokenText", TOK_TTYPE_TEXT
),
1102 ENUM_STRING_MAP_ENTRY( "TokenPageNumber", TOK_TTYPE_PAGE_NUMBER
),
1103 ENUM_STRING_MAP_ENTRY( "TokenChapterInfo", TOK_TTYPE_CHAPTER_INFO
),
1104 ENUM_STRING_MAP_ENTRY( "TokenHyperlinkStart", TOK_TTYPE_HYPERLINK_START
),
1105 ENUM_STRING_MAP_ENTRY( "TokenHyperlinkEnd", TOK_TTYPE_HYPERLINK_END
),
1106 ENUM_STRING_MAP_ENTRY( "TokenBibliographyDataField", TOK_TTYPE_BIBLIOGRAPHY
),
1107 { nullptr, 0, TemplateTypeEnum(0)}
1110 SvXMLEnumStringMapEntry
<TemplateParamEnum
> const aTemplateParamMap
[] =
1112 ENUM_STRING_MAP_ENTRY( "TokenType", TOK_TPARAM_TOKEN_TYPE
),
1113 ENUM_STRING_MAP_ENTRY( "CharacterStyleName", TOK_TPARAM_CHAR_STYLE
),
1114 ENUM_STRING_MAP_ENTRY( "TabStopRightAligned", TOK_TPARAM_TAB_RIGHT_ALIGNED
),
1115 ENUM_STRING_MAP_ENTRY( "TabStopPosition", TOK_TPARAM_TAB_POSITION
),
1116 ENUM_STRING_MAP_ENTRY( "TabStopFillCharacter", TOK_TPARAM_TAB_FILL_CHAR
),
1118 ENUM_STRING_MAP_ENTRY( "WithTab", TOK_TPARAM_TAB_WITH_TAB
),
1119 ENUM_STRING_MAP_ENTRY( "Text", TOK_TPARAM_TEXT
),
1120 ENUM_STRING_MAP_ENTRY( "ChapterFormat", TOK_TPARAM_CHAPTER_FORMAT
),
1121 ENUM_STRING_MAP_ENTRY( "ChapterLevel", TOK_TPARAM_CHAPTER_LEVEL
),//i53420
1122 ENUM_STRING_MAP_ENTRY( "BibliographyDataField", TOK_TPARAM_BIBLIOGRAPHY_DATA
),
1123 { nullptr, 0, TemplateParamEnum(0)}
1126 SvXMLEnumMapEntry
<sal_Int16
> const aBibliographyDataFieldMap
[] =
1128 { XML_ADDRESS
, BibliographyDataField::ADDRESS
},
1129 { XML_ANNOTE
, BibliographyDataField::ANNOTE
},
1130 { XML_AUTHOR
, BibliographyDataField::AUTHOR
},
1131 { XML_BIBLIOGRAPHY_TYPE
, BibliographyDataField::BIBILIOGRAPHIC_TYPE
},
1132 { XML_BOOKTITLE
, BibliographyDataField::BOOKTITLE
},
1133 { XML_CHAPTER
, BibliographyDataField::CHAPTER
},
1134 { XML_CUSTOM1
, BibliographyDataField::CUSTOM1
},
1135 { XML_CUSTOM2
, BibliographyDataField::CUSTOM2
},
1136 { XML_CUSTOM3
, BibliographyDataField::CUSTOM3
},
1137 { XML_CUSTOM4
, BibliographyDataField::CUSTOM4
},
1138 { XML_CUSTOM5
, BibliographyDataField::CUSTOM5
},
1139 { XML_EDITION
, BibliographyDataField::EDITION
},
1140 { XML_EDITOR
, BibliographyDataField::EDITOR
},
1141 { XML_HOWPUBLISHED
, BibliographyDataField::HOWPUBLISHED
},
1142 { XML_IDENTIFIER
, BibliographyDataField::IDENTIFIER
},
1143 { XML_INSTITUTION
, BibliographyDataField::INSTITUTION
},
1144 { XML_ISBN
, BibliographyDataField::ISBN
},
1145 { XML_JOURNAL
, BibliographyDataField::JOURNAL
},
1146 { XML_MONTH
, BibliographyDataField::MONTH
},
1147 { XML_NOTE
, BibliographyDataField::NOTE
},
1148 { XML_NUMBER
, BibliographyDataField::NUMBER
},
1149 { XML_ORGANIZATIONS
, BibliographyDataField::ORGANIZATIONS
},
1150 { XML_PAGES
, BibliographyDataField::PAGES
},
1151 { XML_PUBLISHER
, BibliographyDataField::PUBLISHER
},
1152 { XML_REPORT_TYPE
, BibliographyDataField::REPORT_TYPE
},
1153 { XML_SCHOOL
, BibliographyDataField::SCHOOL
},
1154 { XML_SERIES
, BibliographyDataField::SERIES
},
1155 { XML_TITLE
, BibliographyDataField::TITLE
},
1156 { XML_URL
, BibliographyDataField::URL
},
1157 { XML_VOLUME
, BibliographyDataField::VOLUME
},
1158 { XML_YEAR
, BibliographyDataField::YEAR
},
1159 { XML_TOKEN_INVALID
, 0 }
1162 void XMLSectionExport::ExportIndexTemplateElement(
1163 SectionTypeEnum eType
, //i90246
1164 const Sequence
<PropertyValue
> & rValues
)
1166 // variables for template values
1169 OUString sCharStyle
;
1170 bool bCharStyleOK
= false;
1174 bool bTextOK
= false;
1177 bool bRightAligned
= false;
1180 sal_Int32 nTabPosition
= 0;
1181 bool bTabPositionOK
= false;
1185 bool bFillCharOK
= false;
1188 sal_Int16 nChapterFormat
= 0;
1189 bool bChapterFormatOK
= false;
1191 // outline max level
1192 sal_Int16 nLevel
= 0;
1193 bool bLevelOK
= false;
1195 // Bibliography Data
1196 sal_Int16 nBibliographyData
= 0;
1197 bool bBibliographyDataOK
= false;
1199 // With Tab Stop #i21237#
1200 bool bWithTabStop
= false;
1201 bool bWithTabStopOK
= false;
1203 //i90246, the ODF version being written to is:
1204 const SvtSaveOptions::ODFSaneDefaultVersion aODFVersion
= rExport
.getSaneDefaultVersion();
1205 //the above version cannot be used for old OOo (OOo 1.0) formats!
1208 enum TemplateTypeEnum nTokenType
= TOK_TTYPE_INVALID
;
1210 for(const auto& rValue
: rValues
)
1212 TemplateParamEnum nToken
;
1213 if ( SvXMLUnitConverter::convertEnum( nToken
, rValue
.Name
,
1214 aTemplateParamMap
) )
1216 // Only use direct and default values.
1217 // Wrong. no property states, so ignore.
1218 // if ( (beans::PropertyState_DIRECT_VALUE == rValues[i].State) ||
1219 // (beans::PropertyState_DEFAULT_VALUE == rValues[i].State) )
1223 case TOK_TPARAM_TOKEN_TYPE
:
1226 rValue
.Value
>>= sVal
;
1227 SvXMLUnitConverter::convertEnum( nTokenType
, sVal
, aTemplateTypeMap
);
1231 case TOK_TPARAM_CHAR_STYLE
:
1232 // only valid, if not empty
1233 rValue
.Value
>>= sCharStyle
;
1234 bCharStyleOK
= !sCharStyle
.isEmpty();
1237 case TOK_TPARAM_TEXT
:
1238 rValue
.Value
>>= sText
;
1242 case TOK_TPARAM_TAB_RIGHT_ALIGNED
:
1244 *o3tl::doAccess
<bool>(rValue
.Value
);
1247 case TOK_TPARAM_TAB_POSITION
:
1248 rValue
.Value
>>= nTabPosition
;
1249 bTabPositionOK
= true;
1253 case TOK_TPARAM_TAB_WITH_TAB
:
1254 bWithTabStop
= *o3tl::doAccess
<bool>(rValue
.Value
);
1255 bWithTabStopOK
= true;
1258 case TOK_TPARAM_TAB_FILL_CHAR
:
1259 rValue
.Value
>>= sFillChar
;
1263 case TOK_TPARAM_CHAPTER_FORMAT
:
1264 rValue
.Value
>>= nChapterFormat
;
1265 bChapterFormatOK
= true;
1268 case TOK_TPARAM_CHAPTER_LEVEL
:
1269 rValue
.Value
>>= nLevel
;
1272 case TOK_TPARAM_BIBLIOGRAPHY_DATA
:
1273 rValue
.Value
>>= nBibliographyData
;
1274 bBibliographyDataOK
= true;
1280 // convert type to token (and check validity) ...
1281 XMLTokenEnum
eElement(XML_TOKEN_INVALID
);
1282 sal_uInt16
nNamespace(XML_NAMESPACE_TEXT
);
1285 case TOK_TTYPE_ENTRY_TEXT
:
1286 eElement
= XML_INDEX_ENTRY_TEXT
;
1288 case TOK_TTYPE_TAB_STOP
:
1290 if ( bRightAligned
|| bTabPositionOK
|| bFillCharOK
)
1292 eElement
= XML_INDEX_ENTRY_TAB_STOP
;
1295 case TOK_TTYPE_TEXT
:
1299 eElement
= XML_INDEX_ENTRY_SPAN
;
1302 case TOK_TTYPE_PAGE_NUMBER
:
1303 eElement
= XML_INDEX_ENTRY_PAGE_NUMBER
;
1305 case TOK_TTYPE_CHAPTER_INFO
: // keyword index
1306 eElement
= XML_INDEX_ENTRY_CHAPTER
;
1308 case TOK_TTYPE_ENTRY_NUMBER
: // table of content
1309 eElement
= XML_INDEX_ENTRY_CHAPTER
;
1311 case TOK_TTYPE_HYPERLINK_START
:
1312 eElement
= XML_INDEX_ENTRY_LINK_START
;
1314 case TOK_TTYPE_HYPERLINK_END
:
1315 eElement
= XML_INDEX_ENTRY_LINK_END
;
1317 case TOK_TTYPE_BIBLIOGRAPHY
:
1318 if (bBibliographyDataOK
)
1320 eElement
= XML_INDEX_ENTRY_BIBLIOGRAPHY
;
1324 ; // unknown/unimplemented template
1328 if (eType
!= TEXT_SECTION_TYPE_TOC
)
1332 case TOK_TTYPE_HYPERLINK_START
:
1333 case TOK_TTYPE_HYPERLINK_END
:
1334 if (SvtSaveOptions::ODFSVER_012
< aODFVersion
)
1336 assert(eType
== TEXT_SECTION_TYPE_ILLUSTRATION
1337 || eType
== TEXT_SECTION_TYPE_OBJECT
1338 || eType
== TEXT_SECTION_TYPE_TABLE
1339 || eType
== TEXT_SECTION_TYPE_USER
);
1340 // ODF 1.3 OFFICE-3941
1341 nNamespace
= (SvtSaveOptions::ODFSVER_013
<= aODFVersion
)
1342 ? XML_NAMESPACE_TEXT
1343 : XML_NAMESPACE_LO_EXT
;
1347 eElement
= XML_TOKEN_INVALID
; // not allowed in ODF <= 1.2
1356 //check the ODF version being exported
1357 if (aODFVersion
== SvtSaveOptions::ODFSVER_011
1358 || aODFVersion
== SvtSaveOptions::ODFSVER_010
)
1361 if (TOK_TTYPE_CHAPTER_INFO
== nTokenType
)
1363 //if we are emitting for ODF 1.1 or 1.0, this information can be used for alphabetical index only
1364 //it's not permitted in other indexes
1365 if (eType
!= TEXT_SECTION_TYPE_ALPHABETICAL
)
1367 eElement
= XML_TOKEN_INVALID
; //not permitted, invalidate the element
1369 else //maps format for 1.1 & 1.0
1371 // a few word here: OOo up to 2.4 uses the field chapter info in Alphabetical index
1372 // in a way different from the ODF 1.1/1.0 specification:
1374 // ODF1.1/1.0 OOo display in chapter info ODF1.2
1375 // (used in alphabetical index only
1377 // number chapter number without pre/postfix plain-number
1378 // number-and-name chapter number without pre/postfix plus title plain-number-and-name
1380 // with issue i89791 the reading of ODF 1.1 and 1.0 was corrected
1381 // this one corrects the writing back from ODF 1.2 to ODF 1.1/1.0
1382 // unfortunately if there is another application which interprets correctly ODF1.1/1.0,
1383 // the resulting alphabetical index will be rendered wrong by OOo 2.4 version
1385 switch( nChapterFormat
)
1387 case ChapterFormat::DIGIT
:
1388 nChapterFormat
= ChapterFormat::NUMBER
;
1390 case ChapterFormat::NO_PREFIX_SUFFIX
:
1391 nChapterFormat
= ChapterFormat::NAME_NUMBER
;
1396 else if (TOK_TTYPE_ENTRY_NUMBER
== nTokenType
)
1398 //in case of ODF 1.1 or 1.0 the only allowed number format is "number"
1400 // The only expected 'foreign' nChapterFormat is
1401 // ' ChapterFormat::DIGIT', forced to 'none, since the
1402 // 'value allowed in ODF 1.1 and 1.0 is 'number' the default
1403 // this can be obtained by simply disabling the chapter format
1404 bChapterFormatOK
= false;
1408 // ... and write Element
1409 if (eElement
== XML_TOKEN_INVALID
)
1412 // character style (for most templates)
1417 case TOK_TTYPE_ENTRY_TEXT
:
1418 case TOK_TTYPE_TEXT
:
1419 case TOK_TTYPE_PAGE_NUMBER
:
1420 case TOK_TTYPE_ENTRY_NUMBER
:
1421 case TOK_TTYPE_HYPERLINK_START
:
1422 case TOK_TTYPE_HYPERLINK_END
:
1423 case TOK_TTYPE_BIBLIOGRAPHY
:
1424 case TOK_TTYPE_CHAPTER_INFO
:
1425 case TOK_TTYPE_TAB_STOP
:
1426 GetExport().AddAttribute(XML_NAMESPACE_TEXT
,
1428 GetExport().EncodeStyleName( sCharStyle
) );
1431 ; // nothing: no character style
1437 if (TOK_TTYPE_TAB_STOP
== nTokenType
)
1440 GetExport().AddAttribute(XML_NAMESPACE_STYLE
, XML_TYPE
,
1441 bRightAligned
? XML_RIGHT
: XML_LEFT
);
1443 if (bTabPositionOK
&& (! bRightAligned
))
1445 // position for left tabs (convert to measure)
1446 OUStringBuffer sBuf
;
1447 GetExport().GetMM100UnitConverter().convertMeasureToXML(sBuf
,
1449 GetExport().AddAttribute(XML_NAMESPACE_STYLE
,
1451 sBuf
.makeStringAndClear());
1454 // fill char ("leader char")
1455 if (bFillCharOK
&& !sFillChar
.isEmpty())
1457 GetExport().AddAttribute(XML_NAMESPACE_STYLE
,
1458 XML_LEADER_CHAR
, sFillChar
);
1462 if (bWithTabStopOK
&& ! bWithTabStop
)
1464 GetExport().AddAttribute(XML_NAMESPACE_STYLE
,
1470 // bibliography data
1471 if (TOK_TTYPE_BIBLIOGRAPHY
== nTokenType
)
1473 OSL_ENSURE(bBibliographyDataOK
, "need bibl data");
1474 OUStringBuffer sBuf
;
1475 if (SvXMLUnitConverter::convertEnum( sBuf
, nBibliographyData
,
1476 aBibliographyDataFieldMap
) )
1478 GetExport().AddAttribute(XML_NAMESPACE_TEXT
,
1479 XML_BIBLIOGRAPHY_DATA_FIELD
,
1480 sBuf
.makeStringAndClear());
1485 if (TOK_TTYPE_CHAPTER_INFO
== nTokenType
)
1487 OSL_ENSURE(bChapterFormatOK
, "need chapter info");
1488 GetExport().AddAttribute(
1489 XML_NAMESPACE_TEXT
, XML_DISPLAY
,
1490 XMLTextFieldExport::MapChapterDisplayFormat(nChapterFormat
));
1493 GetExport().AddAttribute(XML_NAMESPACE_TEXT
, XML_OUTLINE_LEVEL
,
1494 OUString::number(nLevel
));
1498 if (TOK_TTYPE_ENTRY_NUMBER
== nTokenType
)
1500 if (bChapterFormatOK
)
1501 GetExport().AddAttribute(
1502 XML_NAMESPACE_TEXT
, XML_DISPLAY
,
1503 XMLTextFieldExport::MapChapterDisplayFormat(nChapterFormat
));
1506 GetExport().AddAttribute(XML_NAMESPACE_TEXT
, XML_OUTLINE_LEVEL
,
1507 OUString::number(nLevel
));
1510 SvXMLElementExport
aTemplateElement(GetExport(), nNamespace
,
1511 GetXMLToken(eElement
),
1515 // entry text or span element: write text
1516 if (TOK_TTYPE_TEXT
== nTokenType
)
1518 GetExport().Characters(sText
);
1522 void XMLSectionExport::ExportLevelParagraphStyles(
1523 Reference
<XIndexReplace
> const & xLevelParagraphStyles
)
1525 // iterate over levels
1526 sal_Int32 nPLevelCount
= xLevelParagraphStyles
->getCount();
1527 for(sal_Int32 nLevel
= 0; nLevel
< nPLevelCount
; nLevel
++)
1529 Any aAny
= xLevelParagraphStyles
->getByIndex(nLevel
);
1530 Sequence
<OUString
> aStyleNames
;
1531 aAny
>>= aStyleNames
;
1533 // export only if at least one style is contained
1534 if (aStyleNames
.hasElements())
1536 // level attribute; we count 1..10; API 0..9
1537 sal_Int32 nLevelPlusOne
= nLevel
+ 1;
1538 GetExport().AddAttribute(XML_NAMESPACE_TEXT
,
1540 OUString::number(nLevelPlusOne
));
1542 // source styles element
1543 SvXMLElementExport
aParaStyles(GetExport(),
1545 XML_INDEX_SOURCE_STYLES
,
1548 // iterate over styles in this level
1549 for(const auto& rStyleName
: std::as_const(aStyleNames
))
1551 // stylename attribute
1552 GetExport().AddAttribute(XML_NAMESPACE_TEXT
,
1554 GetExport().EncodeStyleName(rStyleName
) );
1557 SvXMLElementExport
aParaStyle(GetExport(),
1559 XML_INDEX_SOURCE_STYLE
,
1566 void XMLSectionExport::ExportBoolean(
1567 const Reference
<XPropertySet
> & rPropSet
,
1568 const OUString
& sPropertyName
,
1569 enum XMLTokenEnum eAttributeName
,
1573 OSL_ENSURE(eAttributeName
!= XML_TOKEN_INVALID
, "Need attribute name");
1575 Any aAny
= rPropSet
->getPropertyValue(sPropertyName
);
1576 bool bTmp
= *o3tl::doAccess
<bool>(aAny
);
1578 // value = value ^ bInvert
1579 // omit if value == default
1580 if ( (bTmp
!= bInvert
) != bDefault
)
1582 // export non-default value (since default is omitted)
1583 GetExport().AddAttribute(XML_NAMESPACE_TEXT
,
1585 bDefault
? XML_FALSE
: XML_TRUE
);
1589 void XMLSectionExport::ExportBibliographyConfiguration(SvXMLExport
& rExport
)
1591 // first: get field master (via text field supplier)
1592 Reference
<XTextFieldsSupplier
> xTextFieldsSupp( rExport
.GetModel(),
1594 if ( !xTextFieldsSupp
.is() )
1597 static constexpr OUString
sFieldMaster_Bibliography(u
"com.sun.star.text.FieldMaster.Bibliography"_ustr
);
1599 // get bibliography field master
1600 Reference
<XNameAccess
> xMasters
=
1601 xTextFieldsSupp
->getTextFieldMasters();
1602 if ( !xMasters
->hasByName(sFieldMaster_Bibliography
) )
1606 xMasters
->getByName(sFieldMaster_Bibliography
);
1607 Reference
<XPropertySet
> xPropSet
;
1610 OSL_ENSURE( xPropSet
.is(), "field master must have XPropSet" );
1614 aAny
= xPropSet
->getPropertyValue("BracketBefore");
1616 rExport
.AddAttribute(XML_NAMESPACE_TEXT
, XML_PREFIX
, sTmp
);
1618 aAny
= xPropSet
->getPropertyValue("BracketAfter");
1620 rExport
.AddAttribute(XML_NAMESPACE_TEXT
, XML_SUFFIX
, sTmp
);
1622 aAny
= xPropSet
->getPropertyValue("IsNumberEntries");
1623 if (*o3tl::doAccess
<bool>(aAny
))
1625 rExport
.AddAttribute(XML_NAMESPACE_TEXT
,
1626 XML_NUMBERED_ENTRIES
, XML_TRUE
);
1629 aAny
= xPropSet
->getPropertyValue("IsSortByPosition");
1630 if (! *o3tl::doAccess
<bool>(aAny
))
1632 rExport
.AddAttribute(XML_NAMESPACE_TEXT
,
1633 XML_SORT_BY_POSITION
, XML_FALSE
);
1637 aAny
= xPropSet
->getPropertyValue("SortAlgorithm");
1638 OUString sAlgorithm
;
1639 aAny
>>= sAlgorithm
;
1640 if( !sAlgorithm
.isEmpty() )
1642 rExport
.AddAttribute( XML_NAMESPACE_TEXT
,
1643 XML_SORT_ALGORITHM
, sAlgorithm
);
1647 aAny
= xPropSet
->getPropertyValue("Locale");
1650 rExport
.AddLanguageTagAttributes( XML_NAMESPACE_FO
, XML_NAMESPACE_STYLE
, aLocale
, true);
1652 // configuration element
1653 SvXMLElementExport
aElement(rExport
, XML_NAMESPACE_TEXT
,
1654 XML_BIBLIOGRAPHY_CONFIGURATION
,
1658 aAny
= xPropSet
->getPropertyValue("SortKeys");
1659 Sequence
<Sequence
<PropertyValue
> > aKeys
;
1661 for(const Sequence
<PropertyValue
> & rKey
: std::as_const(aKeys
))
1663 for(const PropertyValue
& rValue
: rKey
)
1665 if (rValue
.Name
== "SortKey")
1668 rValue
.Value
>>= nKey
;
1669 OUStringBuffer sBuf
;
1670 if (SvXMLUnitConverter::convertEnum( sBuf
, nKey
,
1671 aBibliographyDataFieldMap
) )
1673 rExport
.AddAttribute(XML_NAMESPACE_TEXT
, XML_KEY
,
1674 sBuf
.makeStringAndClear());
1677 else if (rValue
.Name
== "IsSortAscending")
1679 bool bTmp
= *o3tl::doAccess
<bool>(rValue
.Value
);
1680 rExport
.AddAttribute(XML_NAMESPACE_TEXT
,
1682 bTmp
? XML_TRUE
: XML_FALSE
);
1686 SvXMLElementExport
aKeyElem(rExport
,
1687 XML_NAMESPACE_TEXT
, XML_SORT_KEY
,
1693 bool XMLSectionExport::IsMuteSection(
1694 const Reference
<XTextSection
> & rSection
) const
1698 // a section is mute if
1700 // 2) the SaveLinkedSections flag (at the export) is false
1701 // 3) the IsGlobalDocumentSection property is true
1702 // 4) it is not an Index
1704 if ( (!rExport
.IsSaveLinkedSections()) && rSection
.is() )
1706 // walk the section chain and set bRet if any is linked
1707 for(Reference
<XTextSection
> aSection(rSection
);
1709 aSection
= aSection
->getParentSection())
1711 // check if it is a global document section (linked or index)
1712 Reference
<XPropertySet
> xPropSet(aSection
, UNO_QUERY
);
1715 Any aAny
= xPropSet
->getPropertyValue("IsGlobalDocumentSection");
1717 if ( *o3tl::doAccess
<bool>(aAny
) )
1719 Reference
<XDocumentIndex
> xIndex
;
1720 if (! GetIndex(rSection
, xIndex
))
1724 // early out if result is known
1729 // section has no properties: ignore
1732 // else: no section, or always save sections: default (false)
1737 bool XMLSectionExport::IsMuteSection(
1738 const Reference
<XTextContent
> & rSection
,
1739 bool bDefault
) const
1741 // default: like default argument
1742 bool bRet
= bDefault
;
1744 Reference
<XPropertySet
> xPropSet(rSection
->getAnchor(), UNO_QUERY
);
1747 if (xPropSet
->getPropertySetInfo()->hasPropertyByName("TextSection"))
1749 Any aAny
= xPropSet
->getPropertyValue("TextSection");
1750 Reference
<XTextSection
> xSection
;
1753 bRet
= IsMuteSection(xSection
);
1755 // else: return default
1757 // else: return default
1762 bool XMLSectionExport::IsInSection(
1763 const Reference
<XTextSection
> & rEnclosingSection
,
1764 const Reference
<XTextContent
> & rContent
,
1767 // default: like default argument
1768 bool bRet
= bDefault
;
1769 OSL_ENSURE(rEnclosingSection
.is(), "enclosing section expected");
1771 Reference
<XPropertySet
> xPropSet(rContent
, UNO_QUERY
);
1774 if (xPropSet
->getPropertySetInfo()->hasPropertyByName("TextSection"))
1776 Any aAny
= xPropSet
->getPropertyValue("TextSection");
1777 Reference
<XTextSection
> xSection
;
1780 // now walk chain of text sections (if we have one)
1785 bRet
= (rEnclosingSection
== xSection
);
1786 xSection
= xSection
->getParentSection();
1788 while (!bRet
&& xSection
.is());
1791 bRet
= false; // no section -> can't be inside
1793 // else: no TextSection property -> return default
1795 // else: no XPropertySet -> return default
1801 void XMLSectionExport::ExportMasterDocHeadingDummies()
1803 if( bHeadingDummiesExported
)
1806 Reference
< XChapterNumberingSupplier
> xCNSupplier( rExport
.GetModel(),
1809 Reference
< XIndexReplace
> xChapterNumbering
;
1810 if( xCNSupplier
.is() )
1811 xChapterNumbering
= xCNSupplier
->getChapterNumberingRules();
1813 if( !xChapterNumbering
.is() )
1816 sal_Int32 nCount
= xChapterNumbering
->getCount();
1817 for( sal_Int32 nLevel
= 0; nLevel
< nCount
; nLevel
++ )
1820 Sequence
<PropertyValue
> aProperties
;
1821 xChapterNumbering
->getByIndex( nLevel
) >>= aProperties
;
1822 auto pProp
= std::find_if(std::cbegin(aProperties
), std::cend(aProperties
),
1823 [](const PropertyValue
& rProp
) { return rProp
.Name
== "HeadingStyleName"; });
1824 if (pProp
!= std::cend(aProperties
))
1825 pProp
->Value
>>= sStyle
;
1827 if( !sStyle
.isEmpty() )
1829 GetExport().AddAttribute( XML_NAMESPACE_TEXT
, XML_STYLE_NAME
,
1830 GetExport().EncodeStyleName( sStyle
) );
1832 GetExport().AddAttribute( XML_NAMESPACE_TEXT
, XML_LEVEL
,
1833 OUString::number( nLevel
+ 1 ) );
1834 SvXMLElementExport
aElem( GetExport(), XML_NAMESPACE_TEXT
, XML_H
,
1839 bHeadingDummiesExported
= true;
1842 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */