Avoid potential negative array index access to cached text.
[LibreOffice.git] / xmloff / source / text / XMLSectionFootnoteConfigExport.cxx
blob6e1c06319110cb5c800eab0766f929891af3dced
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "XMLSectionFootnoteConfigExport.hxx"
21 #include <xmloff/xmlexp.hxx>
22 #include <xmloff/xmlprmap.hxx>
23 #include <com/sun/star/style/NumberingType.hpp>
24 #include <xmloff/maptype.hxx>
26 #include <xmloff/txtprmap.hxx>
27 #include <xmloff/xmlnamespace.hxx>
28 #include <xmloff/xmluconv.hxx>
29 #include <xmloff/xmltoken.hxx>
30 #include <rtl/ustring.hxx>
31 #include <rtl/ustrbuf.hxx>
32 #include <sal/log.hxx>
34 #include <vector>
37 using namespace ::xmloff::token;
39 using ::std::vector;
40 using css::style::NumberingType::ARABIC;
43 void XMLSectionFootnoteConfigExport::exportXML(
44 SvXMLExport& rExport,
45 bool bEndnote,
46 const vector<XMLPropertyState> *pProperties,
47 sal_uInt32 nIdx,
48 const rtl::Reference<XMLPropertySetMapper> & rMapper)
50 // store and initialize the values
51 bool bNumOwn = false;
52 bool bNumRestart = false;
53 sal_Int16 nNumRestartAt = 0;
54 sal_Int16 nNumberingType = ARABIC;
55 OUString sNumPrefix;
56 OUString sNumSuffix;
57 bool bEnd = false;
59 // find entries in property states vector
60 sal_uInt32 nCount = pProperties->size();
61 for(sal_uInt32 i = 0; i < nCount; i++)
63 const XMLPropertyState& rState = (*pProperties)[i];
65 sal_Int16 nContextId = rMapper->GetEntryContextId(rState.mnIndex);
66 if (!bEndnote)
68 switch (nContextId)
70 case CTF_SECTION_FOOTNOTE_NUM_OWN:
71 rState.maValue >>= bNumOwn;
72 break;
73 case CTF_SECTION_FOOTNOTE_NUM_RESTART:
74 rState.maValue >>= bNumRestart;
75 break;
76 case CTF_SECTION_FOOTNOTE_NUM_RESTART_AT:
77 rState.maValue >>= nNumRestartAt;
78 break;
79 case CTF_SECTION_FOOTNOTE_NUM_TYPE:
80 rState.maValue >>= nNumberingType;
81 break;
82 case CTF_SECTION_FOOTNOTE_NUM_PREFIX:
83 rState.maValue >>= sNumPrefix;
84 break;
85 case CTF_SECTION_FOOTNOTE_NUM_SUFFIX:
86 rState.maValue >>= sNumSuffix;
87 break;
88 case CTF_SECTION_FOOTNOTE_END:
89 SAL_WARN_IF( i != nIdx, "xmloff",
90 "received wrong property state index" );
91 rState.maValue >>= bEnd;
92 break;
95 else
97 switch (nContextId)
99 case CTF_SECTION_ENDNOTE_NUM_OWN:
100 rState.maValue >>= bNumOwn;
101 break;
102 case CTF_SECTION_ENDNOTE_NUM_RESTART:
103 rState.maValue >>= bNumRestart;
104 break;
105 case CTF_SECTION_ENDNOTE_NUM_RESTART_AT:
106 rState.maValue >>= nNumRestartAt;
107 break;
108 case CTF_SECTION_ENDNOTE_NUM_TYPE:
109 rState.maValue >>= nNumberingType;
110 break;
111 case CTF_SECTION_ENDNOTE_NUM_PREFIX:
112 rState.maValue >>= sNumPrefix;
113 break;
114 case CTF_SECTION_ENDNOTE_NUM_SUFFIX:
115 rState.maValue >>= sNumSuffix;
116 break;
117 case CTF_SECTION_ENDNOTE_END:
118 SAL_WARN_IF( i != nIdx, "xmloff",
119 "received wrong property state index" );
120 rState.maValue >>= bEnd;
121 break;
126 // we only make an element if we have an own footnote/endnote numbering
127 if (!bEnd)
128 return;
130 rExport.AddAttribute(XML_NAMESPACE_TEXT, XML_NOTE_CLASS,
131 GetXMLToken( bEndnote ? XML_ENDNOTE
132 : XML_FOOTNOTE ) );
133 // start numbering
134 if (bNumRestart)
136 // restart number is stored as 0.., but interpreted as 1..
137 rExport.AddAttribute(XML_NAMESPACE_TEXT, XML_START_VALUE,
138 OUString::number(nNumRestartAt+1));
141 if (bNumOwn)
143 // prefix and suffix
144 if (!sNumPrefix.isEmpty())
146 rExport.AddAttribute(XML_NAMESPACE_STYLE, XML_NUM_PREFIX,
147 sNumPrefix);
149 if (!sNumSuffix.isEmpty())
151 rExport.AddAttribute(XML_NAMESPACE_STYLE, XML_NUM_SUFFIX,
152 sNumSuffix);
155 // number type: num format
156 OUStringBuffer sBuf;
157 rExport.GetMM100UnitConverter().convertNumFormat( sBuf,
158 nNumberingType );
159 rExport.AddAttribute(XML_NAMESPACE_STYLE, XML_NUM_FORMAT,
160 sBuf.makeStringAndClear());
162 // and letter sync, if applicable
163 SvXMLUnitConverter::convertNumLetterSync(
164 sBuf, nNumberingType );
165 if (!sBuf.isEmpty())
167 rExport.AddAttribute(XML_NAMESPACE_STYLE,
168 XML_NUM_LETTER_SYNC,
169 sBuf.makeStringAndClear());
173 // and finally, the element
174 SvXMLElementExport rElem(rExport, XML_NAMESPACE_TEXT,
175 XML_NOTES_CONFIGURATION,
176 true, true);
179 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */