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 <rtl/ustring.hxx>
22 #include <rtl/ustrbuf.hxx>
27 #include <com/sun/star/lang/XServiceInfo.hpp>
28 #include <com/sun/star/lang/Locale.hpp>
29 #include <com/sun/star/container/XIndexReplace.hpp>
30 #include <com/sun/star/beans/XPropertySet.hpp>
31 #include <com/sun/star/beans/PropertyValue.hpp>
32 #include <com/sun/star/beans/PropertyValues.hpp>
33 #include <com/sun/star/beans/PropertyState.hpp>
34 #include <com/sun/star/text/XText.hpp>
35 #include <com/sun/star/text/XTextSection.hpp>
36 #include <com/sun/star/text/SectionFileLink.hpp>
37 #include <com/sun/star/container/XNamed.hpp>
38 #include <com/sun/star/container/XNameAccess.hpp>
39 #include <com/sun/star/text/XDocumentIndex.hpp>
40 #include <com/sun/star/uno/XInterface.hpp>
41 #include <com/sun/star/text/BibliographyDataField.hpp>
42 #include <com/sun/star/text/XTextFieldsSupplier.hpp>
43 #include <com/sun/star/text/XChapterNumberingSupplier.hpp>
44 #include <com/sun/star/text/ChapterFormat.hpp> //i90246
46 #include <sax/tools/converter.hxx>
48 #include <xmloff/xmltoken.hxx>
49 #include "xmloff/xmlnmspe.hxx"
50 #include <xmloff/families.hxx>
51 #include <xmloff/xmluconv.hxx>
52 #include <xmloff/nmspmap.hxx>
53 #include <xmloff/xmlexp.hxx>
54 #include <xmloff/xmltkmap.hxx>
55 #include "txtflde.hxx"
59 using namespace ::com::sun::star
;
60 using namespace ::com::sun::star::text
;
61 using namespace ::com::sun::star::uno
;
62 using namespace ::std
;
63 using namespace ::xmloff::token
;
65 using ::com::sun::star::beans::XPropertySet
;
66 using ::com::sun::star::beans::PropertyValue
;
67 using ::com::sun::star::beans::PropertyValues
;
68 using ::com::sun::star::beans::PropertyState
;
69 using ::com::sun::star::container::XIndexReplace
;
70 using ::com::sun::star::container::XNameAccess
;
71 using ::com::sun::star::container::XNamed
;
72 using ::com::sun::star::lang::XServiceInfo
;
73 using ::com::sun::star::lang::Locale
;
74 using ::com::sun::star::uno::XInterface
;
77 XMLSectionExport::XMLSectionExport(
79 XMLTextParagraphExport
& rParaExp
)
80 : sCondition("Condition")
81 , sCreateFromChapter("CreateFromChapter")
82 , sCreateFromEmbeddedObjects("CreateFromEmbeddedObjects")
83 , sCreateFromGraphicObjects("CreateFromGraphicObjects")
84 , sCreateFromLabels("CreateFromLabels")
85 , sCreateFromMarks("CreateFromMarks")
86 , sCreateFromOtherEmbeddedObjects("CreateFromOtherEmbeddedObjects")
87 , sCreateFromOutline("CreateFromOutline")
88 , sCreateFromStarCalc("CreateFromStarCalc")
89 , sCreateFromStarChart("CreateFromStarChart")
90 , sCreateFromStarDraw("CreateFromStarDraw")
91 , sCreateFromStarImage("CreateFromStarImage")
92 , sCreateFromStarMath("CreateFromStarMath")
93 , sCreateFromTables("CreateFromTables")
94 , sCreateFromTextFrames("CreateFromTextFrames")
95 , sDdeCommandElement("DDECommandElement")
96 , sDdeCommandFile("DDECommandFile")
97 , sDdeCommandType("DDECommandType")
98 , sFileLink("FileLink")
99 , sIsCaseSensitive("IsCaseSensitive")
100 , sIsProtected("IsProtected")
101 , sIsVisible("IsVisible")
102 , sLabelCategory("LabelCategory")
103 , sLabelDisplayType("LabelDisplayType")
105 , sLevelFormat("LevelFormat")
106 , sLevelParagraphStyles("LevelParagraphStyles")
107 , sLinkRegion("LinkRegion")
108 , sMainEntryCharacterStyleName("MainEntryCharacterStyleName")
109 , sParaStyleHeading("ParaStyleHeading")
110 , sParaStyleLevel("ParaStyleLevel")
113 , sUseAlphabeticalSeparators("UseAlphabeticalSeparators")
114 , sUseCombinedEntries("UseCombinedEntries")
115 , sUseDash("UseDash")
116 , sUseKeyAsEntry("UseKeyAsEntry")
117 , sUseLevelFromSource("UseLevelFromSource")
119 , sUseUpperCase("UseUpperCase")
120 , sIsCommaSeparated("IsCommaSeparated")
121 , sIsAutomaticUpdate("IsAutomaticUpdate")
122 , sIsRelativeTabstops("IsRelativeTabstops")
123 , sCreateFromLevelParagraphStyles("CreateFromLevelParagraphStyles")
124 , sDocumentIndex("DocumentIndex")
125 , sContentSection("ContentSection")
126 , sHeaderSection("HeaderSection")
128 , sTextSection("TextSection")
129 , sIsGlobalDocumentSection("IsGlobalDocumentSection")
130 , sProtectionKey("ProtectionKey")
131 , sSortAlgorithm("SortAlgorithm")
133 , sUserIndexName("UserIndexName")
135 , sIsCurrentlyVisible("IsCurrentlyVisible")
136 , sHeadingStyleName("HeadingStyleName")
139 , rParaExport(rParaExp
)
140 , bHeadingDummiesExported( sal_False
)
145 void XMLSectionExport::ExportSectionStart(
146 const Reference
<XTextSection
> & rSection
,
147 sal_Bool bAutoStyles
)
149 Reference
<XPropertySet
> xPropertySet(rSection
, UNO_QUERY
);
151 // always export section (auto) style
154 // get PropertySet and add section style
155 GetParaExport().Add( XML_STYLE_FAMILY_TEXT_SECTION
, xPropertySet
);
159 // always export section style
160 GetExport().AddAttribute(XML_NAMESPACE_TEXT
, XML_STYLE_NAME
,
161 GetParaExport().Find(
162 XML_STYLE_FAMILY_TEXT_SECTION
,
163 xPropertySet
, sEmpty
) );
165 // xml:id for RDF metadata
166 GetExport().AddAttributeXmlId(rSection
);
168 // export index or regular section
169 Reference
<XDocumentIndex
> xIndex
;
170 if (GetIndex(rSection
, xIndex
))
175 ExportIndexStart(xIndex
);
179 // we are an index header
180 ExportIndexHeaderStart(rSection
);
185 // we are not an index
186 ExportRegularSectionStart(rSection
);
191 sal_Bool
XMLSectionExport::GetIndex(
192 const Reference
<XTextSection
> & rSection
,
193 Reference
<XDocumentIndex
> & rIndex
) const
195 // first, reset result
196 sal_Bool bRet
= sal_False
;
199 // get section Properties
200 Reference
<XPropertySet
> xSectionPropSet(rSection
, UNO_QUERY
);
202 // then check if this section happens to be inside an index
203 if (xSectionPropSet
->getPropertySetInfo()->
204 hasPropertyByName(sDocumentIndex
))
206 Any aAny
= xSectionPropSet
->getPropertyValue(sDocumentIndex
);
207 Reference
<XDocumentIndex
> xDocumentIndex
;
208 aAny
>>= xDocumentIndex
;
210 // OK, are we inside of an index
211 if (xDocumentIndex
.is())
213 // is the enclosing index identical with "our" section?
214 Reference
<XPropertySet
> xIndexPropSet(xDocumentIndex
, UNO_QUERY
);
215 aAny
= xIndexPropSet
->getPropertyValue(sContentSection
);
216 Reference
<XTextSection
> xEnclosingSection
;
217 aAny
>>= xEnclosingSection
;
219 // if the enclosing section is "our" section, then we are an index!
220 if (rSection
== xEnclosingSection
)
222 rIndex
= xDocumentIndex
;
225 // else: index header or regular section
227 // is the enclosing index identical with the header section?
228 aAny
= xIndexPropSet
->getPropertyValue(sHeaderSection
);
229 // now mis-named: contains header section
230 aAny
>>= xEnclosingSection
;
232 // if the enclosing section is "our" section, then we are an index!
233 if (rSection
== xEnclosingSection
)
237 // else: regular section
239 // else: we aren't even inside of an index
241 // else: we don't even know what an index is.
247 void XMLSectionExport::ExportSectionEnd(
248 const Reference
<XTextSection
> & rSection
,
249 sal_Bool bAutoStyles
)
251 // no end section for styles
254 enum XMLTokenEnum eElement
= XML_TOKEN_INVALID
;
256 // export index or regular section end
257 Reference
<XDocumentIndex
> xIndex
;
258 if (GetIndex(rSection
, xIndex
))
262 // index end: close index body element
263 GetExport().EndElement( XML_NAMESPACE_TEXT
, XML_INDEX_BODY
,
265 GetExport().IgnorableWhitespace();
267 switch (MapSectionType(xIndex
->getServiceName()))
269 case TEXT_SECTION_TYPE_TOC
:
270 eElement
= XML_TABLE_OF_CONTENT
;
273 case TEXT_SECTION_TYPE_ILLUSTRATION
:
274 eElement
= XML_ILLUSTRATION_INDEX
;
277 case TEXT_SECTION_TYPE_ALPHABETICAL
:
278 eElement
= XML_ALPHABETICAL_INDEX
;
281 case TEXT_SECTION_TYPE_TABLE
:
282 eElement
= XML_TABLE_INDEX
;
285 case TEXT_SECTION_TYPE_OBJECT
:
286 eElement
= XML_OBJECT_INDEX
;
289 case TEXT_SECTION_TYPE_USER
:
290 eElement
= XML_USER_INDEX
;
293 case TEXT_SECTION_TYPE_BIBLIOGRAPHY
:
294 eElement
= XML_BIBLIOGRAPHY
;
298 OSL_FAIL("unknown index type");
299 // default: skip index!
305 eElement
= XML_INDEX_TITLE
;
310 eElement
= XML_SECTION
;
313 if (XML_TOKEN_INVALID
!= eElement
)
315 // any old attributes?
316 GetExport().CheckAttrList();
318 // element surrounded by whitespace
319 GetExport().EndElement( XML_NAMESPACE_TEXT
, eElement
, sal_True
);
320 GetExport().IgnorableWhitespace();
324 OSL_FAIL("Need element name!");
327 // else: autostyles -> ignore
330 void XMLSectionExport::ExportIndexStart(
331 const Reference
<XDocumentIndex
> & rIndex
)
334 Reference
<XPropertySet
> xPropertySet(rIndex
, UNO_QUERY
);
336 switch (MapSectionType(rIndex
->getServiceName()))
338 case TEXT_SECTION_TYPE_TOC
:
339 ExportTableOfContentStart(xPropertySet
);
342 case TEXT_SECTION_TYPE_ILLUSTRATION
:
343 ExportIllustrationIndexStart(xPropertySet
);
346 case TEXT_SECTION_TYPE_ALPHABETICAL
:
347 ExportAlphabeticalIndexStart(xPropertySet
);
350 case TEXT_SECTION_TYPE_TABLE
:
351 ExportTableIndexStart(xPropertySet
);
354 case TEXT_SECTION_TYPE_OBJECT
:
355 ExportObjectIndexStart(xPropertySet
);
358 case TEXT_SECTION_TYPE_USER
:
359 ExportUserIndexStart(xPropertySet
);
362 case TEXT_SECTION_TYPE_BIBLIOGRAPHY
:
363 ExportBibliographyStart(xPropertySet
);
368 OSL_FAIL("unknown index type");
373 void XMLSectionExport::ExportIndexHeaderStart(
374 const Reference
<XTextSection
> & rSection
)
376 // export name, dammit!
377 Reference
<XNamed
> xName(rSection
, UNO_QUERY
);
378 GetExport().AddAttribute(XML_NAMESPACE_TEXT
, XML_NAME
, xName
->getName());
380 // format already handled -> export only start element
381 GetExport().StartElement( XML_NAMESPACE_TEXT
, XML_INDEX_TITLE
, sal_True
);
382 GetExport().IgnorableWhitespace();
386 SvXMLEnumStringMapEntry
const aIndexTypeMap
[] =
388 ENUM_STRING_MAP_ENTRY( "com.sun.star.text.ContentIndex", TEXT_SECTION_TYPE_TOC
),
389 ENUM_STRING_MAP_ENTRY( "com.sun.star.text.DocumentIndex", TEXT_SECTION_TYPE_ALPHABETICAL
),
390 ENUM_STRING_MAP_ENTRY( "com.sun.star.text.TableIndex", TEXT_SECTION_TYPE_TABLE
),
391 ENUM_STRING_MAP_ENTRY( "com.sun.star.text.ObjectIndex", TEXT_SECTION_TYPE_OBJECT
),
392 ENUM_STRING_MAP_ENTRY( "com.sun.star.text.Bibliography", TEXT_SECTION_TYPE_BIBLIOGRAPHY
),
393 ENUM_STRING_MAP_ENTRY( "com.sun.star.text.UserIndex", TEXT_SECTION_TYPE_USER
),
394 ENUM_STRING_MAP_ENTRY( "com.sun.star.text.IllustrationsIndex", TEXT_SECTION_TYPE_ILLUSTRATION
),
395 ENUM_STRING_MAP_END()
398 enum SectionTypeEnum
XMLSectionExport::MapSectionType(
399 const OUString
& rServiceName
)
401 enum SectionTypeEnum eType
= TEXT_SECTION_TYPE_UNKNOWN
;
404 if (SvXMLUnitConverter::convertEnum(nTmp
, rServiceName
, aIndexTypeMap
))
406 eType
= (enum SectionTypeEnum
)nTmp
;
409 // TODO: index header section types, etc.
414 void XMLSectionExport::ExportRegularSectionStart(
415 const Reference
<XTextSection
> & rSection
)
417 // style name already handled in ExportSectionStart(...)
419 Reference
<XNamed
> xName(rSection
, UNO_QUERY
);
420 GetExport().AddAttribute(XML_NAMESPACE_TEXT
, XML_NAME
, xName
->getName());
422 // get XPropertySet for other values
423 Reference
<XPropertySet
> xPropSet(rSection
, UNO_QUERY
);
426 // condition and display
427 aAny
= xPropSet
->getPropertyValue(sCondition
);
430 enum XMLTokenEnum eDisplay
= XML_TOKEN_INVALID
;
431 if (!sCond
.isEmpty())
434 GetExport().GetNamespaceMap().GetQNameByKey( XML_NAMESPACE_OOOW
,
436 GetExport().AddAttribute(XML_NAMESPACE_TEXT
, XML_CONDITION
, sQValue
);
437 eDisplay
= XML_CONDITION
;
439 // #97450# store hidden-status (of conditional sections only)
440 aAny
= xPropSet
->getPropertyValue(sIsCurrentlyVisible
);
441 if (! *(sal_Bool
*)aAny
.getValue())
443 GetExport().AddAttribute(XML_NAMESPACE_TEXT
, XML_IS_HIDDEN
,
451 aAny
= xPropSet
->getPropertyValue(sIsVisible
);
452 if (! *(sal_Bool
*)aAny
.getValue())
454 GetExport().AddAttribute(XML_NAMESPACE_TEXT
, XML_DISPLAY
, eDisplay
);
457 // protect + protection key
458 aAny
= xPropSet
->getPropertyValue(sIsProtected
);
459 if (*(sal_Bool
*)aAny
.getValue())
461 GetExport().AddAttribute(XML_NAMESPACE_TEXT
, XML_PROTECTED
, XML_TRUE
);
463 Sequence
<sal_Int8
> aPassword
;
464 xPropSet
->getPropertyValue(sProtectionKey
) >>= aPassword
;
465 if (aPassword
.getLength() > 0)
467 OUStringBuffer aBuffer
;
468 ::sax::Converter::encodeBase64(aBuffer
, aPassword
);
469 GetExport().AddAttribute(XML_NAMESPACE_TEXT
, XML_PROTECTION_KEY
,
470 aBuffer
.makeStringAndClear());
474 GetExport().IgnorableWhitespace();
475 GetExport().StartElement( XML_NAMESPACE_TEXT
, XML_SECTION
, sal_True
);
478 // unfortunately, we have to test all relevant strings for non-zero length
479 aAny
= xPropSet
->getPropertyValue(sFileLink
);
480 SectionFileLink aFileLink
;
483 aAny
= xPropSet
->getPropertyValue(sLinkRegion
);
484 OUString sRegionName
;
485 aAny
>>= sRegionName
;
487 if ( !aFileLink
.FileURL
.isEmpty() ||
488 !aFileLink
.FilterName
.isEmpty() ||
489 !sRegionName
.isEmpty())
491 if (!aFileLink
.FileURL
.isEmpty())
493 GetExport().AddAttribute(XML_NAMESPACE_XLINK
, XML_HREF
,
494 GetExport().GetRelativeReference( aFileLink
.FileURL
) );
497 if (!aFileLink
.FilterName
.isEmpty())
499 GetExport().AddAttribute(XML_NAMESPACE_TEXT
, XML_FILTER_NAME
,
500 aFileLink
.FilterName
);
503 if (!sRegionName
.isEmpty())
505 GetExport().AddAttribute(XML_NAMESPACE_TEXT
, XML_SECTION_NAME
,
509 SvXMLElementExport
aElem(GetExport(),
510 XML_NAMESPACE_TEXT
, XML_SECTION_SOURCE
,
515 // check for DDE first
516 if (xPropSet
->getPropertySetInfo()->hasPropertyByName(sDdeCommandFile
))
519 // unfortunately, we have to test all relevant strings for
521 aAny
= xPropSet
->getPropertyValue(sDdeCommandFile
);
522 OUString sApplication
;
523 aAny
>>= sApplication
;
524 aAny
= xPropSet
->getPropertyValue(sDdeCommandType
);
527 aAny
= xPropSet
->getPropertyValue(sDdeCommandElement
);
531 if ( !sApplication
.isEmpty() ||
535 GetExport().AddAttribute(XML_NAMESPACE_OFFICE
,
536 XML_DDE_APPLICATION
, sApplication
);
537 GetExport().AddAttribute(XML_NAMESPACE_OFFICE
, XML_DDE_TOPIC
,
539 GetExport().AddAttribute(XML_NAMESPACE_OFFICE
, XML_DDE_ITEM
,
542 aAny
= xPropSet
->getPropertyValue(sIsAutomaticUpdate
);
543 if (*(sal_Bool
*)aAny
.getValue())
545 GetExport().AddAttribute(XML_NAMESPACE_OFFICE
,
546 XML_AUTOMATIC_UPDATE
, XML_TRUE
);
549 SvXMLElementExport
aElem(GetExport(),
550 XML_NAMESPACE_OFFICE
,
551 XML_DDE_SOURCE
, sal_True
, sal_True
);
553 // else: no DDE data source
555 // else: no DDE on this system
559 void XMLSectionExport::ExportTableOfContentStart(
560 const Reference
<XPropertySet
> & rPropertySet
)
562 // export TOC element start
563 ExportBaseIndexStart(XML_TABLE_OF_CONTENT
, rPropertySet
);
565 // scope for table-of-content-source element
570 // TOC specific index source attributes:
572 // outline-level: 1..10
573 sal_Int16 nLevel
= sal_Int16();
574 if( rPropertySet
->getPropertyValue(sLevel
) >>= nLevel
)
576 OUStringBuffer sBuffer
;
577 ::sax::Converter::convertNumber(sBuffer
, (sal_Int32
)nLevel
);
578 GetExport().AddAttribute(XML_NAMESPACE_TEXT
,
580 sBuffer
.makeStringAndClear());
584 ExportBoolean(rPropertySet
, sCreateFromOutline
,
585 XML_USE_OUTLINE_LEVEL
, sal_True
);
588 ExportBoolean(rPropertySet
, sCreateFromMarks
,
589 XML_USE_INDEX_MARKS
, sal_True
);
592 ExportBoolean(rPropertySet
, sCreateFromLevelParagraphStyles
,
593 XML_USE_INDEX_SOURCE_STYLES
, sal_False
);
595 ExportBaseIndexSource(TEXT_SECTION_TYPE_TOC
, rPropertySet
);
598 ExportBaseIndexBody(TEXT_SECTION_TYPE_TOC
, rPropertySet
);
601 void XMLSectionExport::ExportObjectIndexStart(
602 const Reference
<XPropertySet
> & rPropertySet
)
604 // export index start
605 ExportBaseIndexStart(XML_OBJECT_INDEX
, rPropertySet
);
607 // scope for index source element
609 ExportBoolean(rPropertySet
, sCreateFromOtherEmbeddedObjects
,
610 XML_USE_OTHER_OBJECTS
, sal_False
);
611 ExportBoolean(rPropertySet
, sCreateFromStarCalc
,
612 XML_USE_SPREADSHEET_OBJECTS
, sal_False
);
613 ExportBoolean(rPropertySet
, sCreateFromStarChart
,
614 XML_USE_CHART_OBJECTS
, sal_False
);
615 ExportBoolean(rPropertySet
, sCreateFromStarDraw
,
616 XML_USE_DRAW_OBJECTS
, sal_False
);
617 ExportBoolean(rPropertySet
, sCreateFromStarMath
,
618 XML_USE_MATH_OBJECTS
, sal_False
);
620 ExportBaseIndexSource(TEXT_SECTION_TYPE_OBJECT
, rPropertySet
);
623 ExportBaseIndexBody(TEXT_SECTION_TYPE_OBJECT
, rPropertySet
);
626 void XMLSectionExport::ExportIllustrationIndexStart(
627 const Reference
<XPropertySet
> & rPropertySet
)
629 // export index start
630 ExportBaseIndexStart(XML_ILLUSTRATION_INDEX
, rPropertySet
);
632 // scope for index source element
634 // export common attributes for illustration and table indices
635 ExportTableAndIllustrationIndexSourceAttributes(rPropertySet
);
637 ExportBaseIndexSource(TEXT_SECTION_TYPE_ILLUSTRATION
, rPropertySet
);
640 ExportBaseIndexBody(TEXT_SECTION_TYPE_ILLUSTRATION
, rPropertySet
);
643 void XMLSectionExport::ExportTableIndexStart(
644 const Reference
<XPropertySet
> & rPropertySet
)
646 // export index start
647 ExportBaseIndexStart(XML_TABLE_INDEX
, rPropertySet
);
649 // scope for index source element
651 // export common attributes for illustration and table indices
652 ExportTableAndIllustrationIndexSourceAttributes(rPropertySet
);
654 ExportBaseIndexSource(TEXT_SECTION_TYPE_TABLE
, rPropertySet
);
657 ExportBaseIndexBody(TEXT_SECTION_TYPE_TABLE
, rPropertySet
);
660 void XMLSectionExport::ExportAlphabeticalIndexStart(
661 const Reference
<XPropertySet
> & rPropertySet
)
663 // export TOC element start
664 ExportBaseIndexStart(XML_ALPHABETICAL_INDEX
, rPropertySet
);
666 // scope for table-of-content-source element
669 // style name (if present)
671 aAny
= rPropertySet
->getPropertyValue(sMainEntryCharacterStyleName
);
674 if (!sStyleName
.isEmpty())
676 GetExport().AddAttribute(XML_NAMESPACE_TEXT
,
677 XML_MAIN_ENTRY_STYLE_NAME
,
678 GetExport().EncodeStyleName( sStyleName
));
681 // other (boolean) attributes
682 ExportBoolean(rPropertySet
, sIsCaseSensitive
, XML_IGNORE_CASE
,
683 sal_False
, sal_True
);
684 ExportBoolean(rPropertySet
, sUseAlphabeticalSeparators
,
685 XML_ALPHABETICAL_SEPARATORS
, sal_False
);
686 ExportBoolean(rPropertySet
, sUseCombinedEntries
, XML_COMBINE_ENTRIES
,
688 ExportBoolean(rPropertySet
, sUseDash
, XML_COMBINE_ENTRIES_WITH_DASH
,
690 ExportBoolean(rPropertySet
, sUseKeyAsEntry
, XML_USE_KEYS_AS_ENTRIES
,
692 ExportBoolean(rPropertySet
, sUsePP
, XML_COMBINE_ENTRIES_WITH_PP
,
694 ExportBoolean(rPropertySet
, sUseUpperCase
, XML_CAPITALIZE_ENTRIES
,
696 ExportBoolean(rPropertySet
, sIsCommaSeparated
, XML_COMMA_SEPARATED
,
700 aAny
= rPropertySet
->getPropertyValue(sSortAlgorithm
);
703 if (!sAlgorithm
.isEmpty())
705 GetExport().AddAttribute( XML_NAMESPACE_TEXT
, XML_SORT_ALGORITHM
,
710 aAny
= rPropertySet
->getPropertyValue(sLocale
);
713 GetExport().AddAttribute(XML_NAMESPACE_FO
, XML_LANGUAGE
,
715 GetExport().AddAttribute(XML_NAMESPACE_FO
, XML_COUNTRY
,
718 ExportBaseIndexSource(TEXT_SECTION_TYPE_ALPHABETICAL
, rPropertySet
);
721 ExportBaseIndexBody(TEXT_SECTION_TYPE_ALPHABETICAL
, rPropertySet
);
724 void XMLSectionExport::ExportUserIndexStart(
725 const Reference
<XPropertySet
> & rPropertySet
)
727 // export TOC element start
728 ExportBaseIndexStart(XML_USER_INDEX
, rPropertySet
);
730 // scope for table-of-content-source element
733 ExportBoolean(rPropertySet
, sCreateFromEmbeddedObjects
,
734 XML_USE_OBJECTS
, sal_False
);
735 ExportBoolean(rPropertySet
, sCreateFromGraphicObjects
,
736 XML_USE_GRAPHICS
, sal_False
);
737 ExportBoolean(rPropertySet
, sCreateFromMarks
,
738 XML_USE_INDEX_MARKS
, sal_False
);
739 ExportBoolean(rPropertySet
, sCreateFromTables
,
740 XML_USE_TABLES
, sal_False
);
741 ExportBoolean(rPropertySet
, sCreateFromTextFrames
,
742 XML_USE_FLOATING_FRAMES
, sal_False
);
743 ExportBoolean(rPropertySet
, sUseLevelFromSource
,
744 XML_COPY_OUTLINE_LEVELS
, sal_False
);
745 ExportBoolean(rPropertySet
, sCreateFromLevelParagraphStyles
,
746 XML_USE_INDEX_SOURCE_STYLES
, sal_False
);
748 Any aAny
= rPropertySet
->getPropertyValue( sUserIndexName
);
751 GetExport().AddAttribute(XML_NAMESPACE_TEXT
, XML_INDEX_NAME
,
754 ExportBaseIndexSource(TEXT_SECTION_TYPE_USER
, rPropertySet
);
757 ExportBaseIndexBody(TEXT_SECTION_TYPE_USER
, rPropertySet
);
760 void XMLSectionExport::ExportBibliographyStart(
761 const Reference
<XPropertySet
> & rPropertySet
)
763 // export TOC element start
764 ExportBaseIndexStart(XML_BIBLIOGRAPHY
, rPropertySet
);
766 // scope for table-of-content-source element
768 // No attributes. Fine.
770 ExportBaseIndexSource(TEXT_SECTION_TYPE_BIBLIOGRAPHY
, rPropertySet
);
773 ExportBaseIndexBody(TEXT_SECTION_TYPE_BIBLIOGRAPHY
, rPropertySet
);
777 void XMLSectionExport::ExportBaseIndexStart(
778 XMLTokenEnum eElement
,
779 const Reference
<XPropertySet
> & rPropertySet
)
781 // protect + protection key
782 Any aAny
= rPropertySet
->getPropertyValue(sIsProtected
);
783 if (*(sal_Bool
*)aAny
.getValue())
785 GetExport().AddAttribute(XML_NAMESPACE_TEXT
, XML_PROTECTED
, XML_TRUE
);
790 rPropertySet
->getPropertyValue(sName
) >>= sIndexName
;
791 if ( !sIndexName
.isEmpty() )
793 GetExport().AddAttribute(XML_NAMESPACE_TEXT
, XML_NAME
, sIndexName
);
796 // index Element start
797 GetExport().IgnorableWhitespace();
798 GetExport().StartElement( XML_NAMESPACE_TEXT
, eElement
, sal_False
);
801 static const XMLTokenEnum aTypeSourceElementNameMap
[] =
803 XML_TABLE_OF_CONTENT_SOURCE
, // TOC
804 XML_TABLE_INDEX_SOURCE
, // table index
805 XML_ILLUSTRATION_INDEX_SOURCE
, // illustration index
806 XML_OBJECT_INDEX_SOURCE
, // object index
807 XML_USER_INDEX_SOURCE
, // user index
808 XML_ALPHABETICAL_INDEX_SOURCE
, // alphabetical index
809 XML_BIBLIOGRAPHY_SOURCE
// bibliography
812 void XMLSectionExport::ExportBaseIndexSource(
813 SectionTypeEnum eType
,
814 const Reference
<XPropertySet
> & rPropertySet
)
817 OSL_ENSURE(eType
>= TEXT_SECTION_TYPE_TOC
, "illegal index type");
818 OSL_ENSURE(eType
<= TEXT_SECTION_TYPE_BIBLIOGRAPHY
, "illegal index type");
822 // common attributes; not supported by bibliography
823 if (eType
!= TEXT_SECTION_TYPE_BIBLIOGRAPHY
)
825 // document or chapter index?
826 aAny
= rPropertySet
->getPropertyValue(sCreateFromChapter
);
827 if (*(sal_Bool
*)aAny
.getValue())
829 GetExport().AddAttribute(XML_NAMESPACE_TEXT
,
830 XML_INDEX_SCOPE
, XML_CHAPTER
);
833 // tab-stops relative to margin?
834 aAny
= rPropertySet
->getPropertyValue(sIsRelativeTabstops
);
835 if (! *(sal_Bool
*)aAny
.getValue())
837 GetExport().AddAttribute(XML_NAMESPACE_TEXT
,
838 XML_RELATIVE_TAB_STOP_POSITION
,
843 // the index source element (all indices)
844 SvXMLElementExport
aElem(GetExport(),
847 aTypeSourceElementNameMap
[
848 eType
- TEXT_SECTION_TYPE_TOC
]),
851 // scope for title template (all indices)
854 aAny
= rPropertySet
->getPropertyValue(sParaStyleHeading
);
857 GetExport().AddAttribute(XML_NAMESPACE_TEXT
,
859 GetExport().EncodeStyleName( sStyleName
));
862 SvXMLElementExport
aHeaderTemplate(GetExport(),
864 XML_INDEX_TITLE_TEMPLATE
,
865 sal_True
, sal_False
);
867 // title as element content
868 aAny
= rPropertySet
->getPropertyValue(sTitle
);
869 OUString sTitleString
;
870 aAny
>>= sTitleString
;
871 GetExport().Characters(sTitleString
);
874 // export level templates (all indices)
875 aAny
= rPropertySet
->getPropertyValue(sLevelFormat
);
876 Reference
<XIndexReplace
> xLevelTemplates
;
877 aAny
>>= xLevelTemplates
;
879 // iterate over level formats;
880 // skip element 0 (empty template for title)
881 sal_Int32 nLevelCount
= xLevelTemplates
->getCount();
882 for(sal_Int32 i
= 1; i
<nLevelCount
; i
++)
885 Sequence
<PropertyValues
> aTemplateSequence
;
886 aAny
= xLevelTemplates
->getByIndex(i
);
887 aAny
>>= aTemplateSequence
;
889 // export the sequence (abort export if an error occurred; #91214#)
891 ExportIndexTemplate(eType
, i
, rPropertySet
, aTemplateSequence
);
896 // only TOC and user index:
897 // styles from which to build the index (LevelParagraphStyles)
898 if ( (TEXT_SECTION_TYPE_TOC
== eType
) ||
899 (TEXT_SECTION_TYPE_USER
== eType
) )
901 aAny
= rPropertySet
->getPropertyValue(sLevelParagraphStyles
);
902 Reference
<XIndexReplace
> xLevelParagraphStyles
;
903 aAny
>>= xLevelParagraphStyles
;
904 ExportLevelParagraphStyles(xLevelParagraphStyles
);
909 void XMLSectionExport::ExportBaseIndexBody(
911 #if OSL_DEBUG_LEVEL > 0
915 const Reference
<XPropertySet
> &)
917 // type not used; checked anyway.
918 OSL_ENSURE(eType
>= TEXT_SECTION_TYPE_TOC
, "illegal index type");
919 OSL_ENSURE(eType
<= TEXT_SECTION_TYPE_BIBLIOGRAPHY
, "illegal index type");
923 // any old attributes?
924 GetExport().CheckAttrList();
926 // start surrounded by whitespace
927 GetExport().IgnorableWhitespace();
928 GetExport().StartElement( XML_NAMESPACE_TEXT
, XML_INDEX_BODY
, sal_True
);
931 void XMLSectionExport::ExportTableAndIllustrationIndexSourceAttributes(
932 const Reference
<XPropertySet
> & rPropertySet
)
935 Any aAny
= rPropertySet
->getPropertyValue(sCreateFromLabels
);
936 if (! *(sal_Bool
*)aAny
.getValue())
938 GetExport().AddAttribute(XML_NAMESPACE_TEXT
,
939 XML_USE_CAPTION
, XML_FALSE
);
943 aAny
= rPropertySet
->getPropertyValue(sLabelCategory
);
944 OUString sSequenceName
;
945 aAny
>>= sSequenceName
;
946 GetExport().AddAttribute(XML_NAMESPACE_TEXT
,
947 XML_CAPTION_SEQUENCE_NAME
,
951 aAny
= rPropertySet
->getPropertyValue(sLabelDisplayType
);
954 GetExport().AddAttribute(XML_NAMESPACE_TEXT
,
955 XML_CAPTION_SEQUENCE_FORMAT
,
956 XMLTextFieldExport::MapReferenceType(nType
));
960 // map index of LevelFormats to attribute value;
961 // level 0 is always the header
962 static const XMLTokenEnum aLevelNameTOCMap
[] =
963 { XML_TOKEN_INVALID
, XML_1
, XML_2
, XML_3
, XML_4
, XML_5
, XML_6
, XML_7
,
964 XML_8
, XML_9
, XML_10
, XML_TOKEN_INVALID
};
965 static const XMLTokenEnum aLevelNameTableMap
[] =
966 { XML_TOKEN_INVALID
, XML__EMPTY
, XML_TOKEN_INVALID
};
967 static const XMLTokenEnum aLevelNameAlphaMap
[] =
968 { XML_TOKEN_INVALID
, XML_SEPARATOR
, XML_1
, XML_2
, XML_3
, XML_TOKEN_INVALID
};
969 static const XMLTokenEnum aLevelNameBibliographyMap
[] =
970 { XML_TOKEN_INVALID
, XML_ARTICLE
, XML_BOOK
, XML_BOOKLET
, XML_CONFERENCE
,
971 XML_CUSTOM1
, XML_CUSTOM2
, XML_CUSTOM3
, XML_CUSTOM4
,
972 XML_CUSTOM5
, XML_EMAIL
, XML_INBOOK
, XML_INCOLLECTION
,
973 XML_INPROCEEDINGS
, XML_JOURNAL
,
974 XML_MANUAL
, XML_MASTERSTHESIS
, XML_MISC
, XML_PHDTHESIS
,
975 XML_PROCEEDINGS
, XML_TECHREPORT
, XML_UNPUBLISHED
, XML_WWW
,
978 static const XMLTokenEnum
* aTypeLevelNameMap
[] =
980 aLevelNameTOCMap
, // TOC
981 aLevelNameTableMap
, // table index
982 aLevelNameTableMap
, // illustration index
983 aLevelNameTableMap
, // object index
984 aLevelNameTOCMap
, // user index
985 aLevelNameAlphaMap
, // alphabetical index
986 aLevelNameBibliographyMap
// bibliography
989 static const sal_Char
* aLevelStylePropNameTOCMap
[] =
990 { NULL
, "ParaStyleLevel1", "ParaStyleLevel2", "ParaStyleLevel3",
991 "ParaStyleLevel4", "ParaStyleLevel5", "ParaStyleLevel6",
992 "ParaStyleLevel7", "ParaStyleLevel8", "ParaStyleLevel9",
993 "ParaStyleLevel10", NULL
};
994 static const sal_Char
* aLevelStylePropNameTableMap
[] =
995 { NULL
, "ParaStyleLevel1", NULL
};
996 static const sal_Char
* aLevelStylePropNameAlphaMap
[] =
997 { NULL
, "ParaStyleSeparator", "ParaStyleLevel1", "ParaStyleLevel2",
998 "ParaStyleLevel3", NULL
};
999 static const sal_Char
* aLevelStylePropNameBibliographyMap
[] =
1000 // TODO: replace with real property names, when available
1001 { NULL
, "ParaStyleLevel1", "ParaStyleLevel1", "ParaStyleLevel1",
1002 "ParaStyleLevel1", "ParaStyleLevel1", "ParaStyleLevel1",
1003 "ParaStyleLevel1", "ParaStyleLevel1", "ParaStyleLevel1",
1004 "ParaStyleLevel1", "ParaStyleLevel1", "ParaStyleLevel1",
1005 "ParaStyleLevel1", "ParaStyleLevel1", "ParaStyleLevel1",
1006 "ParaStyleLevel1", "ParaStyleLevel1", "ParaStyleLevel1",
1007 "ParaStyleLevel1", "ParaStyleLevel1", "ParaStyleLevel1",
1011 static const sal_Char
** aTypeLevelStylePropNameMap
[] =
1013 aLevelStylePropNameTOCMap
, // TOC
1014 aLevelStylePropNameTableMap
, // table index
1015 aLevelStylePropNameTableMap
, // illustration index
1016 aLevelStylePropNameTableMap
, // object index
1017 aLevelStylePropNameTOCMap
, // user index
1018 aLevelStylePropNameAlphaMap
, // alphabetical index
1019 aLevelStylePropNameBibliographyMap
// bibliography
1022 static const XMLTokenEnum aTypeLevelAttrMap
[] =
1024 XML_OUTLINE_LEVEL
, // TOC
1025 XML_TOKEN_INVALID
, // table index
1026 XML_TOKEN_INVALID
, // illustration index
1027 XML_TOKEN_INVALID
, // object index
1028 XML_OUTLINE_LEVEL
, // user index
1029 XML_OUTLINE_LEVEL
, // alphabetical index
1030 XML_BIBLIOGRAPHY_TYPE
// bibliography
1033 static const XMLTokenEnum aTypeElementNameMap
[] =
1035 XML_TABLE_OF_CONTENT_ENTRY_TEMPLATE
, // TOC
1036 XML_TABLE_INDEX_ENTRY_TEMPLATE
, // table index
1037 XML_ILLUSTRATION_INDEX_ENTRY_TEMPLATE
, // illustration index
1038 XML_OBJECT_INDEX_ENTRY_TEMPLATE
, // object index
1039 XML_USER_INDEX_ENTRY_TEMPLATE
, // user index
1040 XML_ALPHABETICAL_INDEX_ENTRY_TEMPLATE
, // alphabetical index
1041 XML_BIBLIOGRAPHY_ENTRY_TEMPLATE
// bibliography
1045 sal_Bool
XMLSectionExport::ExportIndexTemplate(
1046 SectionTypeEnum eType
,
1047 sal_Int32 nOutlineLevel
,
1048 const Reference
<XPropertySet
> & rPropertySet
,
1049 Sequence
<Sequence
<PropertyValue
> > & rValues
)
1051 OSL_ENSURE(eType
>= TEXT_SECTION_TYPE_TOC
, "illegal index type");
1052 OSL_ENSURE(eType
<= TEXT_SECTION_TYPE_BIBLIOGRAPHY
, "illegal index type");
1053 OSL_ENSURE(nOutlineLevel
>= 0, "illegal outline level");
1055 if ( (eType
>= TEXT_SECTION_TYPE_TOC
) &&
1056 (eType
<= TEXT_SECTION_TYPE_BIBLIOGRAPHY
) &&
1057 (nOutlineLevel
>= 0) )
1059 // get level name and level attribute name from aLevelNameMap;
1060 const XMLTokenEnum
eLevelAttrName(
1061 aTypeLevelAttrMap
[eType
-TEXT_SECTION_TYPE_TOC
]);
1062 const XMLTokenEnum
eLevelName(
1063 aTypeLevelNameMap
[eType
-TEXT_SECTION_TYPE_TOC
][nOutlineLevel
]);
1065 // #92124#: some old documents may be broken, then they have
1066 // too many template levels; we need to recognize this and
1067 // export only as many as is legal for the respective index
1068 // type. To do this, we simply return an error flag, which
1069 // will then abort further template level exports.
1070 OSL_ENSURE(XML_TOKEN_INVALID
!= eLevelName
, "can't find level name");
1071 if ( XML_TOKEN_INVALID
== eLevelName
)
1073 // output level not found? Then end of templates! #91214#
1077 // output level name
1078 if ((XML_TOKEN_INVALID
!= eLevelName
) && (XML_TOKEN_INVALID
!= eLevelAttrName
))
1080 GetExport().AddAttribute(XML_NAMESPACE_TEXT
,
1081 GetXMLToken(eLevelAttrName
),
1082 GetXMLToken(eLevelName
));
1085 // paragraph level style name
1086 const sal_Char
* pPropName(
1087 aTypeLevelStylePropNameMap
[eType
-TEXT_SECTION_TYPE_TOC
][nOutlineLevel
]);
1088 OSL_ENSURE(NULL
!= pPropName
, "can't find property name");
1089 if (NULL
!= pPropName
)
1091 Any aAny
= rPropertySet
->getPropertyValue(
1092 OUString::createFromAscii(pPropName
));
1093 OUString sParaStyleName
;
1094 aAny
>>= sParaStyleName
;
1095 GetExport().AddAttribute(XML_NAMESPACE_TEXT
,
1097 GetExport().EncodeStyleName( sParaStyleName
));
1101 const XMLTokenEnum
eElementName(
1102 aTypeElementNameMap
[eType
- TEXT_SECTION_TYPE_TOC
]);
1103 SvXMLElementExport
aLevelTemplate(GetExport(),
1105 GetXMLToken(eElementName
),
1106 sal_True
, sal_True
);
1109 sal_Int32 nTemplateCount
= rValues
.getLength();
1110 for(sal_Int32 nTemplateNo
= 0;
1111 nTemplateNo
< nTemplateCount
;
1114 ExportIndexTemplateElement(
1116 rValues
[nTemplateNo
]);
1124 enum TemplateTypeEnum
1126 TOK_TTYPE_ENTRY_NUMBER
,
1127 TOK_TTYPE_ENTRY_TEXT
,
1130 TOK_TTYPE_PAGE_NUMBER
,
1131 TOK_TTYPE_CHAPTER_INFO
,
1132 TOK_TTYPE_HYPERLINK_START
,
1133 TOK_TTYPE_HYPERLINK_END
,
1134 TOK_TTYPE_BIBLIOGRAPHY
,
1138 enum TemplateParamEnum
1140 TOK_TPARAM_TOKEN_TYPE
,
1141 TOK_TPARAM_CHAR_STYLE
,
1142 TOK_TPARAM_TAB_RIGHT_ALIGNED
,
1143 TOK_TPARAM_TAB_POSITION
,
1144 TOK_TPARAM_TAB_WITH_TAB
, // #i21237#
1145 TOK_TPARAM_TAB_FILL_CHAR
,
1147 TOK_TPARAM_CHAPTER_FORMAT
,
1148 TOK_TPARAM_CHAPTER_LEVEL
,//i53420
1149 TOK_TPARAM_BIBLIOGRAPHY_DATA
1152 SvXMLEnumStringMapEntry
const aTemplateTypeMap
[] =
1154 ENUM_STRING_MAP_ENTRY( "TokenEntryNumber", TOK_TTYPE_ENTRY_NUMBER
),
1155 ENUM_STRING_MAP_ENTRY( "TokenEntryText", TOK_TTYPE_ENTRY_TEXT
),
1156 ENUM_STRING_MAP_ENTRY( "TokenTabStop", TOK_TTYPE_TAB_STOP
),
1157 ENUM_STRING_MAP_ENTRY( "TokenText", TOK_TTYPE_TEXT
),
1158 ENUM_STRING_MAP_ENTRY( "TokenPageNumber", TOK_TTYPE_PAGE_NUMBER
),
1159 ENUM_STRING_MAP_ENTRY( "TokenChapterInfo", TOK_TTYPE_CHAPTER_INFO
),
1160 ENUM_STRING_MAP_ENTRY( "TokenHyperlinkStart", TOK_TTYPE_HYPERLINK_START
),
1161 ENUM_STRING_MAP_ENTRY( "TokenHyperlinkEnd", TOK_TTYPE_HYPERLINK_END
),
1162 ENUM_STRING_MAP_ENTRY( "TokenBibliographyDataField", TOK_TTYPE_BIBLIOGRAPHY
),
1163 ENUM_STRING_MAP_END()
1166 SvXMLEnumStringMapEntry
const aTemplateParamMap
[] =
1168 ENUM_STRING_MAP_ENTRY( "TokenType", TOK_TPARAM_TOKEN_TYPE
),
1169 ENUM_STRING_MAP_ENTRY( "CharacterStyleName", TOK_TPARAM_CHAR_STYLE
),
1170 ENUM_STRING_MAP_ENTRY( "TabStopRightAligned", TOK_TPARAM_TAB_RIGHT_ALIGNED
),
1171 ENUM_STRING_MAP_ENTRY( "TabStopPosition", TOK_TPARAM_TAB_POSITION
),
1172 ENUM_STRING_MAP_ENTRY( "TabStopFillCharacter", TOK_TPARAM_TAB_FILL_CHAR
),
1174 ENUM_STRING_MAP_ENTRY( "WithTab", TOK_TPARAM_TAB_WITH_TAB
),
1175 ENUM_STRING_MAP_ENTRY( "Text", TOK_TPARAM_TEXT
),
1176 ENUM_STRING_MAP_ENTRY( "ChapterFormat", TOK_TPARAM_CHAPTER_FORMAT
),
1177 ENUM_STRING_MAP_ENTRY( "ChapterLevel", TOK_TPARAM_CHAPTER_LEVEL
),//i53420
1178 ENUM_STRING_MAP_ENTRY( "BibliographyDataField", TOK_TPARAM_BIBLIOGRAPHY_DATA
),
1179 ENUM_STRING_MAP_END()
1182 SvXMLEnumMapEntry
const aBibliographyDataFieldMap
[] =
1184 { XML_ADDRESS
, BibliographyDataField::ADDRESS
},
1185 { XML_ANNOTE
, BibliographyDataField::ANNOTE
},
1186 { XML_AUTHOR
, BibliographyDataField::AUTHOR
},
1187 { XML_BIBLIOGRAPHY_TYPE
, BibliographyDataField::BIBILIOGRAPHIC_TYPE
},
1188 { XML_BOOKTITLE
, BibliographyDataField::BOOKTITLE
},
1189 { XML_CHAPTER
, BibliographyDataField::CHAPTER
},
1190 { XML_CUSTOM1
, BibliographyDataField::CUSTOM1
},
1191 { XML_CUSTOM2
, BibliographyDataField::CUSTOM2
},
1192 { XML_CUSTOM3
, BibliographyDataField::CUSTOM3
},
1193 { XML_CUSTOM4
, BibliographyDataField::CUSTOM4
},
1194 { XML_CUSTOM5
, BibliographyDataField::CUSTOM5
},
1195 { XML_EDITION
, BibliographyDataField::EDITION
},
1196 { XML_EDITOR
, BibliographyDataField::EDITOR
},
1197 { XML_HOWPUBLISHED
, BibliographyDataField::HOWPUBLISHED
},
1198 { XML_IDENTIFIER
, BibliographyDataField::IDENTIFIER
},
1199 { XML_INSTITUTION
, BibliographyDataField::INSTITUTION
},
1200 { XML_ISBN
, BibliographyDataField::ISBN
},
1201 { XML_JOURNAL
, BibliographyDataField::JOURNAL
},
1202 { XML_MONTH
, BibliographyDataField::MONTH
},
1203 { XML_NOTE
, BibliographyDataField::NOTE
},
1204 { XML_NUMBER
, BibliographyDataField::NUMBER
},
1205 { XML_ORGANIZATIONS
, BibliographyDataField::ORGANIZATIONS
},
1206 { XML_PAGES
, BibliographyDataField::PAGES
},
1207 { XML_PUBLISHER
, BibliographyDataField::PUBLISHER
},
1208 { XML_REPORT_TYPE
, BibliographyDataField::REPORT_TYPE
},
1209 { XML_SCHOOL
, BibliographyDataField::SCHOOL
},
1210 { XML_SERIES
, BibliographyDataField::SERIES
},
1211 { XML_TITLE
, BibliographyDataField::TITLE
},
1212 { XML_URL
, BibliographyDataField::URL
},
1213 { XML_VOLUME
, BibliographyDataField::VOLUME
},
1214 { XML_YEAR
, BibliographyDataField::YEAR
},
1215 { XML_TOKEN_INVALID
, 0 }
1218 void XMLSectionExport::ExportIndexTemplateElement(
1219 SectionTypeEnum eType
, //i90246
1220 Sequence
<PropertyValue
> & rValues
)
1222 // variables for template values
1225 OUString sCharStyle
;
1226 sal_Bool bCharStyleOK
= sal_False
;
1230 sal_Bool bTextOK
= sal_False
;
1233 sal_Bool bRightAligned
= sal_False
;
1236 sal_Int32 nTabPosition
= 0;
1237 sal_Bool bTabPositionOK
= sal_False
;
1241 sal_Bool bFillCharOK
= sal_False
;
1244 sal_Int16 nChapterFormat
= 0;
1245 sal_Bool bChapterFormatOK
= sal_False
;
1247 // outline max level
1248 sal_Int16 nLevel
= 0;
1249 sal_Bool bLevelOK
= sal_False
;
1251 // Bibliography Data
1252 sal_Int16 nBibliographyData
= 0;
1253 sal_Bool bBibliographyDataOK
= sal_False
;
1255 // With Tab Stop #i21237#
1256 sal_Bool bWithTabStop
= sal_False
;
1257 sal_Bool bWithTabStopOK
= sal_False
;
1259 //i90246, the ODF version being written to is:
1260 const SvtSaveOptions::ODFDefaultVersion aODFVersion
= rExport
.getDefaultVersion();
1261 //the above version cannot be used for old OOo (OOo 1.0) formats!
1264 enum TemplateTypeEnum nTokenType
= TOK_TTYPE_INVALID
;
1266 sal_Int32 nCount
= rValues
.getLength();
1267 for(sal_Int32 i
= 0; i
<nCount
; i
++)
1270 if ( SvXMLUnitConverter::convertEnum( nToken
, rValues
[i
].Name
,
1271 aTemplateParamMap
) )
1273 // Only use direct and default values.
1274 // Wrong. no property states, so ignore.
1275 // if ( (beans::PropertyState_DIRECT_VALUE == rValues[i].State) ||
1276 // (beans::PropertyState_DEFAULT_VALUE == rValues[i].State) )
1280 case TOK_TPARAM_TOKEN_TYPE
:
1284 rValues
[i
].Value
>>= sVal
;
1285 if (SvXMLUnitConverter::convertEnum( nTmp
, sVal
,
1288 nTokenType
= (enum TemplateTypeEnum
)nTmp
;
1293 case TOK_TPARAM_CHAR_STYLE
:
1294 // only valid, if not empty
1295 rValues
[i
].Value
>>= sCharStyle
;
1296 bCharStyleOK
= !sCharStyle
.isEmpty();
1299 case TOK_TPARAM_TEXT
:
1300 rValues
[i
].Value
>>= sText
;
1304 case TOK_TPARAM_TAB_RIGHT_ALIGNED
:
1306 *(sal_Bool
*)rValues
[i
].Value
.getValue();
1309 case TOK_TPARAM_TAB_POSITION
:
1310 rValues
[i
].Value
>>= nTabPosition
;
1311 bTabPositionOK
= sal_True
;
1315 case TOK_TPARAM_TAB_WITH_TAB
:
1316 bWithTabStop
= *(sal_Bool
*)rValues
[i
].Value
.getValue();
1317 bWithTabStopOK
= sal_True
;
1320 case TOK_TPARAM_TAB_FILL_CHAR
:
1321 rValues
[i
].Value
>>= sFillChar
;
1322 bFillCharOK
= sal_True
;
1325 case TOK_TPARAM_CHAPTER_FORMAT
:
1326 rValues
[i
].Value
>>= nChapterFormat
;
1327 bChapterFormatOK
= sal_True
;
1330 case TOK_TPARAM_CHAPTER_LEVEL
:
1331 rValues
[i
].Value
>>= nLevel
;
1332 bLevelOK
= sal_True
;
1334 case TOK_TPARAM_BIBLIOGRAPHY_DATA
:
1335 rValues
[i
].Value
>>= nBibliographyData
;
1336 bBibliographyDataOK
= sal_True
;
1342 // convert type to token (and check validity) ...
1343 XMLTokenEnum
eElement(XML_TOKEN_INVALID
);
1346 case TOK_TTYPE_ENTRY_TEXT
:
1347 eElement
= XML_INDEX_ENTRY_TEXT
;
1349 case TOK_TTYPE_TAB_STOP
:
1351 if ( bRightAligned
|| bTabPositionOK
|| bFillCharOK
)
1353 eElement
= XML_INDEX_ENTRY_TAB_STOP
;
1356 case TOK_TTYPE_TEXT
:
1360 eElement
= XML_INDEX_ENTRY_SPAN
;
1363 case TOK_TTYPE_PAGE_NUMBER
:
1364 eElement
= XML_INDEX_ENTRY_PAGE_NUMBER
;
1366 case TOK_TTYPE_CHAPTER_INFO
: // keyword index
1367 eElement
= XML_INDEX_ENTRY_CHAPTER
;
1369 case TOK_TTYPE_ENTRY_NUMBER
: // table of content
1370 eElement
= XML_INDEX_ENTRY_CHAPTER
;
1372 case TOK_TTYPE_HYPERLINK_START
:
1373 eElement
= XML_INDEX_ENTRY_LINK_START
;
1375 case TOK_TTYPE_HYPERLINK_END
:
1376 eElement
= XML_INDEX_ENTRY_LINK_END
;
1378 case TOK_TTYPE_BIBLIOGRAPHY
:
1379 if (bBibliographyDataOK
)
1381 eElement
= XML_INDEX_ENTRY_BIBLIOGRAPHY
;
1385 ; // unknown/unimplemented template
1390 //check the ODF version being exported
1391 if( aODFVersion
== SvtSaveOptions::ODFVER_011
1392 || aODFVersion
== SvtSaveOptions::ODFVER_010
)
1394 bLevelOK
= sal_False
;
1395 if (TOK_TTYPE_CHAPTER_INFO
== nTokenType
)
1397 //if we are emitting for ODF 1.1 or 1.0, this information can be used for alphabetical index only
1398 //it's not permitted in other indexes
1399 if (eType
!= TEXT_SECTION_TYPE_ALPHABETICAL
)
1401 eElement
= XML_TOKEN_INVALID
; //not permitted, invalidate the element
1403 else //maps format for 1.1 & 1.0
1405 // a few word here: OOo up to 2.4 uses the field chapter info in Alphabetical index
1406 // in a way different from the ODF 1.1/1.0 specification:
1408 // ODF1.1/1.0 OOo display in chapter info ODF1.2
1409 // (used in alphabetical index only
1411 // number chapter number without pre/postfix plain-number
1412 // number-and-name chapter number without pre/postfix plus title plain-number-and-name
1414 // with issue i89791 the reading of ODF 1.1 and 1.0 was corrected
1415 // this one corrects the writing back from ODF 1.2 to ODF 1.1/1.0
1416 // unfortunately if there is another application which interprets correctly ODF1.1/1.0,
1417 // the resulting alphabetical index will be rendered wrong by OOo 2.4 version
1419 switch( nChapterFormat
)
1421 case ChapterFormat::DIGIT
:
1422 nChapterFormat
= ChapterFormat::NUMBER
;
1424 case ChapterFormat::NO_PREFIX_SUFFIX
:
1425 nChapterFormat
= ChapterFormat::NAME_NUMBER
;
1430 else if (TOK_TTYPE_ENTRY_NUMBER
== nTokenType
)
1432 //in case of ODF 1.1 or 1.0 the only allowed number format is "number"
1434 // The only expected 'foreign' nChapterFormat is
1435 // ' ChapterFormat::DIGIT', forced to 'none, since the
1436 // 'value allowed in ODF 1.1 and 1.0 is 'number' the default
1437 // this can be obtained by simply disabling the chapter format
1438 bChapterFormatOK
= sal_False
;
1442 // ... and write Element
1443 if (eElement
!= XML_TOKEN_INVALID
)
1445 // character style (for most templates)
1450 case TOK_TTYPE_ENTRY_TEXT
:
1451 case TOK_TTYPE_TEXT
:
1452 case TOK_TTYPE_PAGE_NUMBER
:
1453 case TOK_TTYPE_ENTRY_NUMBER
:
1454 case TOK_TTYPE_HYPERLINK_START
:
1455 case TOK_TTYPE_HYPERLINK_END
:
1456 case TOK_TTYPE_BIBLIOGRAPHY
:
1457 case TOK_TTYPE_CHAPTER_INFO
:
1458 case TOK_TTYPE_TAB_STOP
:
1459 GetExport().AddAttribute(XML_NAMESPACE_TEXT
,
1461 GetExport().EncodeStyleName( sCharStyle
) );
1464 ; // nothing: no character style
1470 if (TOK_TTYPE_TAB_STOP
== nTokenType
)
1473 GetExport().AddAttribute(XML_NAMESPACE_STYLE
, XML_TYPE
,
1474 bRightAligned
? XML_RIGHT
: XML_LEFT
);
1476 if (bTabPositionOK
&& (! bRightAligned
))
1478 // position for left tabs (convert to measure)
1479 OUStringBuffer sBuf
;
1480 GetExport().GetMM100UnitConverter().convertMeasureToXML(sBuf
,
1482 GetExport().AddAttribute(XML_NAMESPACE_STYLE
,
1484 sBuf
.makeStringAndClear());
1487 // fill char ("leader char")
1488 if (bFillCharOK
&& !sFillChar
.isEmpty())
1490 GetExport().AddAttribute(XML_NAMESPACE_STYLE
,
1491 XML_LEADER_CHAR
, sFillChar
);
1495 if (bWithTabStopOK
&& ! bWithTabStop
)
1497 GetExport().AddAttribute(XML_NAMESPACE_STYLE
,
1503 // bibliography data
1504 if (TOK_TTYPE_BIBLIOGRAPHY
== nTokenType
)
1506 OSL_ENSURE(bBibliographyDataOK
, "need bibl data");
1507 OUStringBuffer sBuf
;
1508 if (SvXMLUnitConverter::convertEnum( sBuf
, nBibliographyData
,
1509 aBibliographyDataFieldMap
) )
1511 GetExport().AddAttribute(XML_NAMESPACE_TEXT
,
1512 XML_BIBLIOGRAPHY_DATA_FIELD
,
1513 sBuf
.makeStringAndClear());
1518 if (TOK_TTYPE_CHAPTER_INFO
== nTokenType
)
1520 OSL_ENSURE(bChapterFormatOK
, "need chapter info");
1521 GetExport().AddAttribute(
1522 XML_NAMESPACE_TEXT
, XML_DISPLAY
,
1523 XMLTextFieldExport::MapChapterDisplayFormat(nChapterFormat
));
1526 GetExport().AddAttribute(XML_NAMESPACE_TEXT
, XML_OUTLINE_LEVEL
,
1527 OUString::valueOf((sal_Int32
)nLevel
));
1531 if (TOK_TTYPE_ENTRY_NUMBER
== nTokenType
)
1533 if (bChapterFormatOK
)
1534 GetExport().AddAttribute(
1535 XML_NAMESPACE_TEXT
, XML_DISPLAY
,
1536 XMLTextFieldExport::MapChapterDisplayFormat(nChapterFormat
));
1539 GetExport().AddAttribute(XML_NAMESPACE_TEXT
, XML_OUTLINE_LEVEL
,
1540 OUString::valueOf((sal_Int32
)nLevel
));
1543 SvXMLElementExport
aTemplateElement(GetExport(), XML_NAMESPACE_TEXT
,
1544 GetXMLToken(eElement
),
1545 sal_True
, sal_False
)
1548 // entry text or span element: write text
1549 if (TOK_TTYPE_TEXT
== nTokenType
)
1551 GetExport().Characters(sText
);
1556 void XMLSectionExport::ExportLevelParagraphStyles(
1557 Reference
<XIndexReplace
> & xLevelParagraphStyles
)
1559 // iterate over levels
1560 sal_Int32 nPLevelCount
= xLevelParagraphStyles
->getCount();
1561 for(sal_Int32 nLevel
= 0; nLevel
< nPLevelCount
; nLevel
++)
1563 Any aAny
= xLevelParagraphStyles
->getByIndex(nLevel
);
1564 Sequence
<OUString
> aStyleNames
;
1565 aAny
>>= aStyleNames
;
1567 // export only if at least one style is contained
1568 sal_Int32 nNamesCount
= aStyleNames
.getLength();
1569 if (nNamesCount
> 0)
1571 // level attribute; we count 1..10; API 0..9
1572 OUStringBuffer sBuf
;
1573 sal_Int32 nLevelPlusOne
= nLevel
+ 1;
1574 ::sax::Converter::convertNumber(sBuf
, nLevelPlusOne
);
1575 GetExport().AddAttribute(XML_NAMESPACE_TEXT
,
1577 sBuf
.makeStringAndClear());
1579 // source styles element
1580 SvXMLElementExport
aParaStyles(GetExport(),
1582 XML_INDEX_SOURCE_STYLES
,
1583 sal_True
, sal_True
);
1585 // iterate over styles in this level
1586 for(sal_Int32 nName
= 0; nName
< nNamesCount
; nName
++)
1588 // stylename attribute
1589 GetExport().AddAttribute(XML_NAMESPACE_TEXT
,
1591 GetExport().EncodeStyleName( aStyleNames
[nName
]) );
1594 SvXMLElementExport
aParaStyle(GetExport(),
1596 XML_INDEX_SOURCE_STYLE
,
1597 sal_True
, sal_False
);
1603 void XMLSectionExport::ExportBoolean(
1604 const Reference
<XPropertySet
> & rPropSet
,
1605 const OUString
& sPropertyName
,
1606 enum XMLTokenEnum eAttributeName
,
1610 OSL_ENSURE(eAttributeName
!= XML_TOKEN_INVALID
, "Need attribute name");
1612 Any aAny
= rPropSet
->getPropertyValue(sPropertyName
);
1613 sal_Bool bTmp
= *(sal_Bool
*)aAny
.getValue();
1615 // value = value ^ bInvert
1616 // omit if value == default
1617 // negate forces sal_Bool to 0/1, making them comparable
1618 if ((!(bTmp
^ bInvert
)) != (!bDefault
))
1620 // export non-default value (since default is omitted)
1621 GetExport().AddAttribute(XML_NAMESPACE_TEXT
,
1623 bDefault
? XML_FALSE
: XML_TRUE
);
1627 const sal_Char sAPI_FieldMaster_Bibliography
[] =
1628 "com.sun.star.text.FieldMaster.Bibliography";
1629 const sal_Char sAPI_SortKey
[] = "SortKey";
1630 const sal_Char sAPI_IsSortAscending
[] = "IsSortAscending";
1632 void XMLSectionExport::ExportBibliographyConfiguration(SvXMLExport
& rExport
)
1634 // first: get field master (via text field supplier)
1635 Reference
<XTextFieldsSupplier
> xTextFieldsSupp( rExport
.GetModel(),
1637 if ( xTextFieldsSupp
.is() )
1639 const OUString
sFieldMaster_Bibliography(sAPI_FieldMaster_Bibliography
);
1641 // get bibliography field master
1642 Reference
<XNameAccess
> xMasters
=
1643 xTextFieldsSupp
->getTextFieldMasters();
1644 if ( xMasters
->hasByName(sFieldMaster_Bibliography
) )
1647 xMasters
->getByName(sFieldMaster_Bibliography
);
1648 Reference
<XPropertySet
> xPropSet
;
1651 OSL_ENSURE( xPropSet
.is(), "field master must have XPropSet" );
1653 const OUString
sBracketBefore("BracketBefore");
1654 const OUString
sBracketAfter("BracketAfter");
1655 const OUString
sIsNumberEntries("IsNumberEntries");
1656 const OUString
sIsSortByPosition("IsSortByPosition");
1657 const OUString
sSortKeys("SortKeys");
1658 const OUString
sSortAlgorithm("SortAlgorithm");
1659 const OUString
sLocale("Locale");
1663 aAny
= xPropSet
->getPropertyValue(sBracketBefore
);
1665 rExport
.AddAttribute(XML_NAMESPACE_TEXT
, XML_PREFIX
, sTmp
);
1667 aAny
= xPropSet
->getPropertyValue(sBracketAfter
);
1669 rExport
.AddAttribute(XML_NAMESPACE_TEXT
, XML_SUFFIX
, sTmp
);
1671 aAny
= xPropSet
->getPropertyValue(sIsNumberEntries
);
1672 if (*(sal_Bool
*)aAny
.getValue())
1674 rExport
.AddAttribute(XML_NAMESPACE_TEXT
,
1675 XML_NUMBERED_ENTRIES
, XML_TRUE
);
1678 aAny
= xPropSet
->getPropertyValue(sIsSortByPosition
);
1679 if (! *(sal_Bool
*)aAny
.getValue())
1681 rExport
.AddAttribute(XML_NAMESPACE_TEXT
,
1682 XML_SORT_BY_POSITION
, XML_FALSE
);
1686 aAny
= xPropSet
->getPropertyValue(sSortAlgorithm
);
1687 OUString sAlgorithm
;
1688 aAny
>>= sAlgorithm
;
1689 if( !sAlgorithm
.isEmpty() )
1691 rExport
.AddAttribute( XML_NAMESPACE_TEXT
,
1692 XML_SORT_ALGORITHM
, sAlgorithm
);
1696 aAny
= xPropSet
->getPropertyValue(sLocale
);
1699 rExport
.AddAttribute(XML_NAMESPACE_FO
, XML_LANGUAGE
,
1701 rExport
.AddAttribute(XML_NAMESPACE_FO
, XML_COUNTRY
,
1704 // configuration element
1705 SvXMLElementExport
aElement(rExport
, XML_NAMESPACE_TEXT
,
1706 XML_BIBLIOGRAPHY_CONFIGURATION
,
1707 sal_True
, sal_True
);
1710 aAny
= xPropSet
->getPropertyValue(sSortKeys
);
1711 Sequence
<Sequence
<PropertyValue
> > aKeys
;
1713 sal_Int32 nKeysCount
= aKeys
.getLength();
1714 for(sal_Int32 nKeys
= 0; nKeys
< nKeysCount
; nKeys
++)
1716 Sequence
<PropertyValue
> & rKey
= aKeys
[nKeys
];
1718 sal_Int32 nKeyCount
= rKey
.getLength();
1719 for(sal_Int32 nPropertyKey
= 0; nPropertyKey
< nKeyCount
; nPropertyKey
++)
1721 PropertyValue
& rValue
= rKey
[nPropertyKey
];
1723 if (rValue
.Name
.equalsAsciiL(sAPI_SortKey
,
1724 sizeof(sAPI_SortKey
)-1))
1727 rValue
.Value
>>= nKey
;
1728 OUStringBuffer sBuf
;
1729 if (SvXMLUnitConverter::convertEnum( sBuf
, nKey
,
1730 aBibliographyDataFieldMap
) )
1732 rExport
.AddAttribute(XML_NAMESPACE_TEXT
, XML_KEY
,
1733 sBuf
.makeStringAndClear());
1736 else if (rValue
.Name
.equalsAsciiL(sAPI_IsSortAscending
,
1737 sizeof(sAPI_IsSortAscending
)-1))
1739 sal_Bool bTmp
= *(sal_Bool
*)rValue
.Value
.getValue();
1740 rExport
.AddAttribute(XML_NAMESPACE_TEXT
,
1742 bTmp
? XML_TRUE
: XML_FALSE
);
1746 SvXMLElementExport
aKeyElem(rExport
,
1747 XML_NAMESPACE_TEXT
, XML_SORT_KEY
,
1748 sal_True
, sal_True
);
1755 sal_Bool
XMLSectionExport::IsMuteSection(
1756 const Reference
<XTextSection
> & rSection
) const
1758 sal_Bool bRet
= sal_False
;
1760 // a section is mute if
1762 // 2) the SaveLinkedSections flag (at the export) is false
1763 // 3) the IsGlobalDocumentSection property is true
1764 // 4) it is not an Index
1766 if ( (!rExport
.IsSaveLinkedSections()) && rSection
.is() )
1768 // walk the section chain and set bRet if any is linked
1769 for(Reference
<XTextSection
> aSection(rSection
);
1771 aSection
= aSection
->getParentSection())
1773 // check if it is a global document section (linked or index)
1774 Reference
<XPropertySet
> xPropSet(aSection
, UNO_QUERY
);
1777 Any aAny
= xPropSet
->getPropertyValue(sIsGlobalDocumentSection
);
1779 if ( *(sal_Bool
*)aAny
.getValue() )
1781 Reference
<XDocumentIndex
> xIndex
;
1782 if (! GetIndex(rSection
, xIndex
))
1786 // early out if result is known
1791 // section has no properties: ignore
1794 // else: no section, or always save sections: default (false)
1799 sal_Bool
XMLSectionExport::IsMuteSection(
1800 const Reference
<XTextContent
> & rSection
,
1801 sal_Bool bDefault
) const
1803 // default: like default argument
1804 sal_Bool bRet
= bDefault
;
1806 Reference
<XPropertySet
> xPropSet(rSection
->getAnchor(), UNO_QUERY
);
1809 if (xPropSet
->getPropertySetInfo()->hasPropertyByName(sTextSection
))
1811 Any aAny
= xPropSet
->getPropertyValue(sTextSection
);
1812 Reference
<XTextSection
> xSection
;
1815 bRet
= IsMuteSection(xSection
);
1817 // else: return default
1819 // else: return default
1824 sal_Bool
XMLSectionExport::IsInSection(
1825 const Reference
<XTextSection
> & rEnclosingSection
,
1826 const Reference
<XTextContent
> & rContent
,
1829 // default: like default argument
1830 sal_Bool bRet
= bDefault
;
1831 OSL_ENSURE(rEnclosingSection
.is(), "enclosing section expected");
1833 Reference
<XPropertySet
> xPropSet(rContent
, UNO_QUERY
);
1836 if (xPropSet
->getPropertySetInfo()->hasPropertyByName(sTextSection
))
1838 Any aAny
= xPropSet
->getPropertyValue(sTextSection
);
1839 Reference
<XTextSection
> xSection
;
1842 // now walk chain of text sections (if we have one)
1847 bRet
= (rEnclosingSection
== xSection
);
1848 xSection
= xSection
->getParentSection();
1850 while (!bRet
&& xSection
.is());
1853 bRet
= sal_False
; // no section -> can't be inside
1855 // else: no TextSection property -> return default
1857 // else: no XPropertySet -> return default
1863 void XMLSectionExport::ExportMasterDocHeadingDummies()
1865 if( bHeadingDummiesExported
)
1868 Reference
< XChapterNumberingSupplier
> xCNSupplier( rExport
.GetModel(),
1871 Reference
< XIndexReplace
> xChapterNumbering
;
1872 if( xCNSupplier
.is() )
1873 xChapterNumbering
= xCNSupplier
->getChapterNumberingRules();
1875 if( !xChapterNumbering
.is() )
1878 sal_Int32 nCount
= xChapterNumbering
->getCount();
1879 for( sal_Int32 nLevel
= 0; nLevel
< nCount
; nLevel
++ )
1882 Sequence
<PropertyValue
> aProperties
;
1883 xChapterNumbering
->getByIndex( nLevel
) >>= aProperties
;
1884 for( sal_Int32 i
= 0; i
< aProperties
.getLength(); i
++ )
1886 if( aProperties
[i
].Name
== sHeadingStyleName
)
1888 aProperties
[i
].Value
>>= sStyle
;
1892 if( !sStyle
.isEmpty() )
1894 GetExport().AddAttribute( XML_NAMESPACE_TEXT
, XML_STYLE_NAME
,
1895 GetExport().EncodeStyleName( sStyle
) );
1897 OUStringBuffer sTmp
;
1898 sTmp
.append( nLevel
+ 1 );
1899 GetExport().AddAttribute( XML_NAMESPACE_TEXT
, XML_LEVEL
,
1900 sTmp
.makeStringAndClear() );
1901 SvXMLElementExport
aElem( GetExport(), XML_NAMESPACE_TEXT
, XML_H
,
1902 sal_True
, sal_False
);
1906 bHeadingDummiesExported
= sal_True
;
1909 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */