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