1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 #ifndef _XMLOFF_XMLSECTIONEXPORT_HXX_ 29 #define _XMLOFF_XMLSECTIONEXPORT_HXX_ 30 31 #include <rtl/ustring.hxx> 32 #include <com/sun/star/uno/Reference.h> 33 #include <com/sun/star/uno/Sequence.h> 34 #include <com/sun/star/beans/PropertyValue.hpp> 35 #include <xmloff/xmltoken.hxx> 36 37 class SvXMLExport; 38 class XMLTextParagraphExport; 39 namespace com { namespace sun { namespace star { 40 namespace text 41 { 42 class XTextSection; 43 class XDocumentIndex; 44 class XTextContent; 45 } 46 namespace beans 47 { 48 class XPropertySet; 49 } 50 namespace container 51 { 52 class XIndexReplace; 53 } 54 } } } 55 56 57 enum SectionTypeEnum 58 { 59 TEXT_SECTION_TYPE_SECTION, 60 61 // indices: keep index valued together and do not change order, 62 // because they are used to index into array 63 TEXT_SECTION_TYPE_TOC, 64 TEXT_SECTION_TYPE_TABLE, 65 TEXT_SECTION_TYPE_ILLUSTRATION, 66 TEXT_SECTION_TYPE_OBJECT, 67 TEXT_SECTION_TYPE_USER, 68 TEXT_SECTION_TYPE_ALPHABETICAL, 69 TEXT_SECTION_TYPE_BIBLIOGRAPHY, 70 71 // index header sections: 72 TEXT_SECTION_TYPE_HEADER, 73 74 TEXT_SECTION_TYPE_UNKNOWN 75 }; 76 77 78 /** 79 * This class handles the export of sections and indices (which are, 80 * internally, just sections). It is intended to be used only from 81 * within the XMLTextParagraphExport class. 82 */ 83 class XMLSectionExport 84 { 85 const ::rtl::OUString sCondition; 86 const ::rtl::OUString sCreateFromChapter; 87 const ::rtl::OUString sCreateFromEmbeddedObjects; 88 const ::rtl::OUString sCreateFromGraphicObjects; 89 const ::rtl::OUString sCreateFromLabels; 90 const ::rtl::OUString sCreateFromMarks; 91 const ::rtl::OUString sCreateFromOtherEmbeddedObjects; 92 const ::rtl::OUString sCreateFromOutline; 93 const ::rtl::OUString sCreateFromStarCalc; 94 const ::rtl::OUString sCreateFromStarChart; 95 const ::rtl::OUString sCreateFromStarDraw; 96 const ::rtl::OUString sCreateFromStarImage; 97 const ::rtl::OUString sCreateFromStarMath; 98 const ::rtl::OUString sCreateFromTables; 99 const ::rtl::OUString sCreateFromTextFrames; 100 const ::rtl::OUString sDdeCommandElement; 101 const ::rtl::OUString sDdeCommandFile; 102 const ::rtl::OUString sDdeCommandType; 103 const ::rtl::OUString sFileLink; 104 const ::rtl::OUString sIsCaseSensitive; 105 const ::rtl::OUString sIsProtected; 106 const ::rtl::OUString sIsVisible; 107 const ::rtl::OUString sLabelCategory; 108 const ::rtl::OUString sLabelDisplayType; 109 const ::rtl::OUString sLevel; 110 const ::rtl::OUString sLevelFormat; 111 const ::rtl::OUString sLevelParagraphStyles; 112 const ::rtl::OUString sLinkRegion; 113 const ::rtl::OUString sMainEntryCharacterStyleName; 114 const ::rtl::OUString sParaStyleHeading; 115 const ::rtl::OUString sParaStyleLevel; 116 const ::rtl::OUString sTitle; 117 const ::rtl::OUString sName; 118 const ::rtl::OUString sUseAlphabeticalSeparators; 119 const ::rtl::OUString sUseCombinedEntries; 120 const ::rtl::OUString sUseDash; 121 const ::rtl::OUString sUseKeyAsEntry; 122 const ::rtl::OUString sUseLevelFromSource; 123 const ::rtl::OUString sUsePP; 124 const ::rtl::OUString sUseUpperCase; 125 const ::rtl::OUString sIsCommaSeparated; 126 const ::rtl::OUString sIsAutomaticUpdate; 127 const ::rtl::OUString sIsRelativeTabstops; 128 const ::rtl::OUString sCreateFromLevelParagraphStyles; 129 const ::rtl::OUString sDocumentIndex; 130 const ::rtl::OUString sContentSection; 131 const ::rtl::OUString sHeaderSection; 132 133 const ::rtl::OUString sTextSection; 134 const ::rtl::OUString sIsGlobalDocumentSection; 135 const ::rtl::OUString sProtectionKey; 136 const ::rtl::OUString sSortAlgorithm; 137 const ::rtl::OUString sLocale; 138 const ::rtl::OUString sUserIndexName; 139 140 const ::rtl::OUString sIsCurrentlyVisible; 141 const ::rtl::OUString sHeadingStyleName; 142 143 const ::rtl::OUString sEmpty; 144 145 SvXMLExport& rExport; 146 XMLTextParagraphExport& rParaExport; 147 148 sal_Bool bHeadingDummiesExported; 149 150 public: 151 XMLSectionExport(SvXMLExport& rExp, 152 XMLTextParagraphExport& rParaExp); 153 154 /** 155 * export section or index start and source elements. This 156 * method handles the section styles, and delegates to the 157 * appropriate section or index method. 158 */ 159 void ExportSectionStart( 160 const ::com::sun::star::uno::Reference < 161 ::com::sun::star::text::XTextSection > & rSection, 162 sal_Bool bAutoStyles); 163 164 /** 165 * export section or index end elements 166 */ 167 void ExportSectionEnd( 168 const ::com::sun::star::uno::Reference < 169 ::com::sun::star::text::XTextSection > & rSection, 170 sal_Bool bAutoStyles); 171 172 /** 173 * Should the content of this section be exported? 174 * (E.g. linked sections in global documents are not always exported) 175 */ 176 sal_Bool IsMuteSection( 177 const ::com::sun::star::uno::Reference < 178 ::com::sun::star::text::XTextSection > & rSection) const; 179 180 /** 181 * XTextContent-version of IsMuteSection(Reference<XTextSection>&) 182 * returns *true* for all non-section elements 183 */ 184 sal_Bool IsMuteSection( 185 const ::com::sun::star::uno::Reference < 186 ::com::sun::star::text::XTextContent > & rSection, 187 /// return value if this content doesn't support the section property 188 sal_Bool bDefault) const; 189 190 /** 191 * Determine whether rContent is contained in rEnclosingSection. If the 192 * current section of rContent can not be determined, return bDefault. 193 */ 194 sal_Bool IsInSection( 195 const ::com::sun::star::uno::Reference < 196 ::com::sun::star::text::XTextSection > & rEnclosingSection, 197 const ::com::sun::star::uno::Reference < 198 ::com::sun::star::text::XTextContent > & rContent, 199 /// return value if this content doesn't support the section property 200 sal_Bool bDefault); 201 202 /** 203 * Export the configuration element for bibliography indices. 204 * 205 * (This is part of XMLSectionExport because all section- and 206 * index-related items are handled here.) 207 */ 208 static void ExportBibliographyConfiguration(SvXMLExport& rExport); 209 210 /** export a heading for every level. This is used by master documents 211 * to not loose the heading information if master documents are exported 212 * without section contents 213 */ 214 void ExportMasterDocHeadingDummies(); 215 216 217 218 protected: 219 220 inline SvXMLExport& GetExport() { return rExport; } 221 inline XMLTextParagraphExport& GetParaExport() { return rParaExport; } 222 223 // export methods for section and index start: 224 225 /// export an index start element. 226 void ExportIndexStart( 227 const ::com::sun::star::uno::Reference < 228 ::com::sun::star::text::XDocumentIndex > & rSection); 229 230 /// export an index header start element. 231 void ExportIndexHeaderStart( 232 const ::com::sun::star::uno::Reference < 233 ::com::sun::star::text::XTextSection > & rSection); 234 235 /// export a proper section (and source elements) 236 void ExportRegularSectionStart( 237 const ::com::sun::star::uno::Reference < 238 ::com::sun::star::text::XTextSection > & rSection); 239 240 /// export a table of content (and source element) 241 void ExportTableOfContentStart( 242 const ::com::sun::star::uno::Reference < 243 ::com::sun::star::beans::XPropertySet > & rSection); 244 245 /// export a table index (and source element) 246 void ExportTableIndexStart( 247 const ::com::sun::star::uno::Reference < 248 ::com::sun::star::beans::XPropertySet > & rSection); 249 250 /// export an object index (and source element) 251 void ExportObjectIndexStart( 252 const ::com::sun::star::uno::Reference < 253 ::com::sun::star::beans::XPropertySet > & rSection); 254 255 /// export an illustration index (and source element) 256 void ExportIllustrationIndexStart( 257 const ::com::sun::star::uno::Reference < 258 ::com::sun::star::beans::XPropertySet > & rSection); 259 260 /// export an alphabetical/keyword index (and source element) 261 void ExportAlphabeticalIndexStart( 262 const ::com::sun::star::uno::Reference < 263 ::com::sun::star::beans::XPropertySet > & rSection); 264 265 /// export a user index (and source element) 266 void ExportUserIndexStart( 267 const ::com::sun::star::uno::Reference < 268 ::com::sun::star::beans::XPropertySet > & rSection); 269 270 /// export the bibliography (and source element) 271 void ExportBibliographyStart( 272 const ::com::sun::star::uno::Reference < 273 ::com::sun::star::beans::XPropertySet > & rIndex); 274 275 // helper methods: 276 277 /** 278 * If this section is an index, the index is written in the 279 * rIndex parameter. The return value is sal_True for all "special" 280 * sections. 281 * 282 * Thus we have: 283 * return sal_False: regular section 284 * return sal_True, xIndex is empty: index header section 285 * return sal_True, xIndex is set: index section */ 286 sal_Bool GetIndex( 287 const ::com::sun::star::uno::Reference < 288 ::com::sun::star::text::XTextSection > & rSection, 289 ::com::sun::star::uno::Reference < 290 ::com::sun::star::text::XDocumentIndex > & rIndex) const; 291 292 /// map service name to section type 293 enum SectionTypeEnum MapSectionType(const ::rtl::OUString& rSectionName); 294 295 /** 296 * Export the index element start (for all index types). 297 * 298 * All additional attributes (usually none) for the index element 299 * should have been set at GetExport() before calling this method. 300 */ 301 void ExportBaseIndexStart( 302 ::xmloff::token::XMLTokenEnum eElement, 303 const ::com::sun::star::uno::Reference < 304 ::com::sun::star::beans::XPropertySet > & rSection); 305 306 /** 307 * Export the index source element (common for all index types). 308 * 309 * All additional attributes for the source element should have 310 * been set at the GetExport() before calling this method. 311 */ 312 void ExportBaseIndexSource( 313 SectionTypeEnum eType, /// index type 314 const ::com::sun::star::uno::Reference < 315 ::com::sun::star::beans::XPropertySet > & rSection); 316 317 /** 318 * Export the index body (common for all index types). 319 */ 320 void ExportBaseIndexBody( 321 SectionTypeEnum eType, /// index type 322 const ::com::sun::star::uno::Reference < 323 ::com::sun::star::beans::XPropertySet > & rSection); 324 325 326 /** 327 * Helper method to export common attributes for table and 328 * illustration indices 329 */ 330 void ExportTableAndIllustrationIndexSourceAttributes( 331 const ::com::sun::star::uno::Reference < 332 ::com::sun::star::beans::XPropertySet > & rSection); 333 334 /// export one template for the specific index type 335 sal_Bool ExportIndexTemplate( 336 SectionTypeEnum eType, /// index type 337 sal_Int32 nLevel, /// outline level (if applicable) 338 const ::com::sun::star::uno::Reference< 339 ::com::sun::star::beans::XPropertySet> & rPropSet, 340 ::com::sun::star::uno::Sequence< 341 ::com::sun::star::uno::Sequence< 342 ::com::sun::star::beans::PropertyValue> > & rValues); 343 344 /// export a single template element (e.g. span or tab-stop) 345 void ExportIndexTemplateElement( 346 SectionTypeEnum eType, //i90246, needed for ODF 1.0, 1.0 and 1.2 management 347 ::com::sun::star::uno::Sequence< 348 ::com::sun::star::beans::PropertyValue> & rValues); 349 350 /// export level paragraph styles 351 void ExportLevelParagraphStyles( 352 ::com::sun::star::uno::Reference< 353 ::com::sun::star::container::XIndexReplace> & xStyles); 354 355 356 /// helper to export boolean properties 357 void ExportBoolean( 358 const ::com::sun::star::uno::Reference< 359 ::com::sun::star::beans::XPropertySet> & rPropSet, 360 const ::rtl::OUString& sPropertyName, 361 enum ::xmloff::token::XMLTokenEnum eAttributeName, 362 sal_Bool bDefault, 363 sal_Bool bInvert = sal_False); 364 }; 365 366 #endif 367