LibreOffice Module xmloff (master) 1
XMLIndexMarkExport.cxx
Go to the documentation of this file.
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
21#include <o3tl/any.hxx>
22#include <tools/debug.hxx>
23#include <rtl/ustring.hxx>
24#include <rtl/ustrbuf.hxx>
25#include <com/sun/star/beans/XPropertySet.hpp>
26#include <com/sun/star/beans/XPropertySetInfo.hpp>
28#include <xmloff/xmltoken.hxx>
30#include <xmloff/xmlexp.hxx>
31
32
33using namespace ::xmloff::token;
34
35using ::com::sun::star::beans::XPropertySet;
36using ::com::sun::star::beans::XPropertySetInfo;
37using ::com::sun::star::uno::Reference;
38using ::com::sun::star::uno::Any;
39
41 SvXMLExport& rExp)
42: rExport(rExp)
43{
44}
45
55
56
58 const Reference<XPropertySet> & rPropSet,
59 bool bAutoStyles)
60{
62 if (bAutoStyles)
63 return;
64
65 const enum XMLTokenEnum * pElements = nullptr;
66 sal_Int8 nElementNo = -1;
67
68 // get index mark
69 Any aAny = rPropSet->getPropertyValue(gsDocumentIndexMark);
70 Reference<XPropertySet> xIndexMarkPropSet;
71 aAny >>= xIndexMarkPropSet;
72
73 // common: handling of start, end, collapsed entries and
74 // alternative text
75
76 // collapsed/alternative text entry?
77 aAny = rPropSet->getPropertyValue(gsIsCollapsed);
78 if (*o3tl::doAccess<bool>(aAny))
79 {
80 // collapsed entry: needs alternative text
81 nElementNo = 0;
82
83 aAny = xIndexMarkPropSet->getPropertyValue(gsAlternativeText);
84 OUString sTmp;
85 aAny >>= sTmp;
86 DBG_ASSERT(!sTmp.isEmpty(),
87 "collapsed index mark without alternative text");
89 }
90 else
91 {
92 // start and end entries: has ID
93 aAny = rPropSet->getPropertyValue(gsIsStart);
94 nElementNo = *o3tl::doAccess<bool>(aAny) ? 1 : 2;
95
96 // generate ID
97 OUStringBuffer sBuf;
98 GetID(sBuf, xIndexMarkPropSet);
100 sBuf.makeStringAndClear());
101 }
102
103 // distinguish between TOC, user, alphab. index marks by
104 // asking for specific properties
105 // Export attributes for -mark-start and -mark elements,
106 // but not for -mark-end
107 Reference<XPropertySetInfo> xPropertySetInfo =
108 xIndexMarkPropSet->getPropertySetInfo();
109 if (xPropertySetInfo->hasPropertyByName(gsUserIndexName))
110 {
111 // user index mark
112 pElements = lcl_pUserIndexMarkName;
113 if (nElementNo != 2)
114 {
115 ExportUserIndexMarkAttributes(xIndexMarkPropSet);
116 }
117 }
118 else if (xPropertySetInfo->hasPropertyByName(gsPrimaryKey))
119 {
120 // alphabetical index mark
121 pElements = lcl_pAlphaIndexMarkName;
122 if (nElementNo != 2)
123 {
124 ExportAlphabeticalIndexMarkAttributes(xIndexMarkPropSet);
125 }
126 }
127 else
128 {
129 // table of content:
130 pElements = lcl_pTocMarkNames;
131 if (nElementNo != 2)
132 {
133 ExportTOCMarkAttributes(xIndexMarkPropSet);
134 }
135 }
136
137 // export element
138 DBG_ASSERT(pElements != nullptr, "illegal element array");
139 DBG_ASSERT(nElementNo >= 0, "illegal name array index");
140 DBG_ASSERT(nElementNo <= 2, "illegal name array index");
141
142 if ((pElements != nullptr) && (nElementNo != -1))
143 {
146 pElements[nElementNo],
147 false, false);
148 }
149
150}
151
153 const Reference<XPropertySet> & rPropSet)
154{
155 // outline level
156 sal_Int16 nLevel = 0;
157 Any aAny = rPropSet->getPropertyValue(gsLevel);
158 aAny >>= nLevel;
160 OUString::number(nLevel + 1));
161}
162
164 const Reference<XPropertySet> & rPropSet,
165 const OUString & sProperty,
167 Any& rAny )
168{
169 rAny = rPropSet->getPropertyValue( sProperty );
170
171 OUString sValue;
172 if( (rAny >>= sValue) && !sValue.isEmpty() )
173 {
174 rExport.AddAttribute( XML_NAMESPACE_TEXT, eToken, sValue );
175 }
176}
177
179 const Reference<XPropertySet> & rPropSet,
180 const OUString & sProperty,
182 Any& rAny )
183{
184 rAny = rPropSet->getPropertyValue( sProperty );
185
186 bool bValue;
187 if( (rAny >>= bValue) && bValue )
188 {
190 }
191}
192
194 const Reference<XPropertySet> & rPropSet)
195{
196 // name of user index
197 // (unless it's the default index; then it has no name)
198 Any aAny;
200
201 // additionally export outline level; just reuse ExportTOCMarkAttributes
202 ExportTOCMarkAttributes( rPropSet );
203}
204
206 const Reference<XPropertySet> & rPropSet)
207{
208 // primary and secondary keys (if available)
209 Any aAny;
216}
217
219 OUStringBuffer& sBuf,
220 const Reference<XPropertySet> & rPropSet)
221{
222 // HACK: use address of object to form identifier
223 sal_Int64 nId = sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_uIntPtr>(rPropSet.get()));
224 sBuf.append("IMark");
225 sBuf.append(nId);
226}
227
228/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
enum XMLTokenEnum lcl_pTocMarkNames[]
enum XMLTokenEnum lcl_pAlphaIndexMarkName[]
static void lcl_ExportPropertyString(SvXMLExport &rExport, const Reference< XPropertySet > &rPropSet, const OUString &sProperty, XMLTokenEnum eToken, Any &rAny)
static void lcl_ExportPropertyBool(SvXMLExport &rExport, const Reference< XPropertySet > &rPropSet, const OUString &sProperty, XMLTokenEnum eToken, Any &rAny)
enum XMLTokenEnum lcl_pUserIndexMarkName[]
void AddAttribute(sal_uInt16 nPrefix, const OUString &rName, const OUString &rValue)
Definition: xmlexp.cxx:907
static constexpr OUStringLiteral gsAlternativeText
static void GetID(OUStringBuffer &sBuffer, const css::uno::Reference< css::beans::XPropertySet > &rPropSet)
create a numerical ID for this index mark (represented by its properties)
static constexpr OUStringLiteral gsDocumentIndexMark
static constexpr OUStringLiteral gsPrimaryKeyReading
static constexpr OUStringLiteral gsSecondaryKey
static constexpr OUStringLiteral gsUserIndexName
XMLIndexMarkExport(SvXMLExport &rExp)
static constexpr OUStringLiteral gsTextReading
static constexpr OUStringLiteral gsSecondaryKeyReading
static constexpr OUStringLiteral gsIsStart
void ExportTOCMarkAttributes(const css::uno::Reference< css::beans::XPropertySet > &rPropSet)
export attributes of table-of-content index marks
void ExportIndexMark(const css::uno::Reference< css::beans::XPropertySet > &rPropSet, bool bAutoStyles)
export by the property set of its text portion.
static constexpr OUStringLiteral gsIsCollapsed
static constexpr OUStringLiteral gsPrimaryKey
static constexpr OUStringLiteral gsLevel
void ExportUserIndexMarkAttributes(const css::uno::Reference< css::beans::XPropertySet > &rPropSet)
export attributes of user index marks
static constexpr OUStringLiteral gsMainEntry
void ExportAlphabeticalIndexMarkAttributes(const css::uno::Reference< css::beans::XPropertySet > &rPropSet)
export attributes of alphabetical index marks
#define DBG_ASSERT(sCon, aError)
Handling of tokens in XML:
XMLTokenEnum
The enumeration of all XML tokens.
Definition: xmltoken.hxx:50
@ XML_ALPHABETICAL_INDEX_MARK
Definition: xmltoken.hxx:239
@ XML_USER_INDEX_MARK_END
Definition: xmltoken.hxx:2095
@ XML_ALPHABETICAL_INDEX_MARK_START
Definition: xmltoken.hxx:241
@ XML_USER_INDEX_MARK_START
Definition: xmltoken.hxx:2096
@ XML_ALPHABETICAL_INDEX_MARK_END
Definition: xmltoken.hxx:240
@ XML_STRING_VALUE_PHONETIC
Definition: xmltoken.hxx:2345
sal_Int16 nId
signed char sal_Int8
constexpr sal_uInt16 XML_NAMESPACE_TEXT
XMLTokenEnum eToken
Definition: xmltoken.cxx:40