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