1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_xmloff.hxx"
26 #include "XMLSectionFootnoteConfigExport.hxx"
27 #include <xmloff/xmlexp.hxx>
28 #include <xmloff/xmlprmap.hxx>
29 #include <com/sun/star/style/NumberingType.hpp>
30 #include <xmloff/maptype.hxx>
31 
32 #ifndef _XMLOFF_TXTPRMAP_HXX
33 #include <xmloff/txtprmap.hxx>
34 #endif
35 #include <xmloff/nmspmap.hxx>
36 #include "xmloff/xmlnmspe.hxx"
37 #include <xmloff/xmluconv.hxx>
38 #include <xmloff/xmltoken.hxx>
39 #include <xmloff/xmlnume.hxx>
40 #include <tools/debug.hxx>
41 
42 #ifndef _RTL_USTRING
43 #include <rtl/ustring.hxx>
44 #endif
45 #include <rtl/ustrbuf.hxx>
46 
47 #include <vector>
48 
49 
50 using namespace ::xmloff::token;
51 
52 using ::std::vector;
53 using ::rtl::OUString;
54 using ::rtl::OUStringBuffer;
55 using ::com::sun::star::style::NumberingType::ARABIC;
56 
57 
exportXML(SvXMLExport & rExport,sal_Bool bEndnote,const vector<XMLPropertyState> * pProperties,sal_uInt32 nIdx,const UniReference<XMLPropertySetMapper> & rMapper)58 void XMLSectionFootnoteConfigExport::exportXML(
59 	SvXMLExport& rExport,
60 	sal_Bool bEndnote,
61 	const vector<XMLPropertyState> *pProperties,
62 	sal_uInt32
63     #ifdef DBG_UTIL
64     nIdx
65     #endif
66     ,
67 	const UniReference<XMLPropertySetMapper> & rMapper)
68 {
69 	// store and initialize the values
70 	sal_Bool bNumOwn = sal_False;
71 	sal_Bool bNumRestart = sal_False;
72 	sal_Int16 nNumRestartAt = 0;
73 	sal_Int16 nNumberingType = ARABIC;
74 	OUString sNumPrefix;
75 	OUString sNumSuffix;
76 	sal_Bool bEnd = sal_False;
77 
78 	// find entries in property states vector
79 	sal_uInt32 nCount = pProperties->size();
80 	for(sal_uInt32 i = 0; i < nCount; i++)
81 	{
82 		const XMLPropertyState& rState = (*pProperties)[i];
83 
84 		sal_Int16 nContextId = rMapper->GetEntryContextId(rState.mnIndex);
85 		if (!bEndnote)
86 		{
87 			switch (nContextId)
88 			{
89 				case CTF_SECTION_FOOTNOTE_NUM_OWN:
90 					rState.maValue >>= bNumOwn;
91 					break;
92 				case CTF_SECTION_FOOTNOTE_NUM_RESTART:
93 					rState.maValue >>= bNumRestart;
94 					break;
95 				case CTF_SECTION_FOOTNOTE_NUM_RESTART_AT:
96 					rState.maValue >>= nNumRestartAt;
97 					break;
98 				case CTF_SECTION_FOOTNOTE_NUM_TYPE:
99 					rState.maValue >>= nNumberingType;
100 					break;
101 				case CTF_SECTION_FOOTNOTE_NUM_PREFIX:
102 					rState.maValue >>= sNumPrefix;
103 					break;
104 				case CTF_SECTION_FOOTNOTE_NUM_SUFFIX:
105 					rState.maValue >>= sNumSuffix;
106 					break;
107 				case CTF_SECTION_FOOTNOTE_END:
108 					DBG_ASSERT( i == nIdx,
109 								"received wrong property state index" );
110 					rState.maValue >>= bEnd;
111 					break;
112 			}
113 		}
114 		else
115 		{
116 			switch (nContextId)
117 			{
118 				case CTF_SECTION_ENDNOTE_NUM_OWN:
119 					rState.maValue >>= bNumOwn;
120 					break;
121 				case CTF_SECTION_ENDNOTE_NUM_RESTART:
122 					rState.maValue >>= bNumRestart;
123 					break;
124 				case CTF_SECTION_ENDNOTE_NUM_RESTART_AT:
125 					rState.maValue >>= nNumRestartAt;
126 					break;
127 				case CTF_SECTION_ENDNOTE_NUM_TYPE:
128 					rState.maValue >>= nNumberingType;
129 					break;
130 				case CTF_SECTION_ENDNOTE_NUM_PREFIX:
131 					rState.maValue >>= sNumPrefix;
132 					break;
133 				case CTF_SECTION_ENDNOTE_NUM_SUFFIX:
134 					rState.maValue >>= sNumSuffix;
135 					break;
136 				case CTF_SECTION_ENDNOTE_END:
137 					DBG_ASSERT( i == nIdx,
138 								"received wrong property state index" );
139 					rState.maValue >>= bEnd;
140 					break;
141 			}
142 		}
143 	}
144 
145 	// we only make an element if we have an own footnote/endnote numbering
146 	if (bEnd)
147 	{
148 		rExport.AddAttribute(XML_NAMESPACE_TEXT, XML_NOTE_CLASS,
149 								 GetXMLToken( bEndnote ? XML_ENDNOTE
150 														 : XML_FOOTNOTE ) );
151 		// start numbering
152 		OUStringBuffer sBuf;
153 		if (bNumRestart)
154 		{
155 			// restart number is stored as 0.., but interpreted as 1..
156 			SvXMLUnitConverter::convertNumber(sBuf,
157 											  (sal_Int32)(nNumRestartAt+1));
158 			rExport.AddAttribute(XML_NAMESPACE_TEXT, XML_START_VALUE,
159 								 sBuf.makeStringAndClear());
160 		}
161 
162 		if (bNumOwn)
163 		{
164 			// prefix and suffix
165 			if (sNumPrefix.getLength() > 0)
166 			{
167 					rExport.AddAttribute(XML_NAMESPACE_STYLE, XML_NUM_PREFIX,
168 										 sNumPrefix);
169 			}
170 			if (sNumSuffix.getLength() > 0)
171 			{
172 				rExport.AddAttribute(XML_NAMESPACE_STYLE, XML_NUM_SUFFIX,
173 									 sNumSuffix);
174 			}
175 
176 			// number type: num format
177 			rExport.GetMM100UnitConverter().convertNumFormat( sBuf,
178 															  nNumberingType );
179 			rExport.AddAttribute(XML_NAMESPACE_STYLE, XML_NUM_FORMAT,
180 								 sBuf.makeStringAndClear());
181 
182 			// and letter sync, if applicable
183 			rExport.GetMM100UnitConverter().convertNumLetterSync(
184 				sBuf, nNumberingType );
185 			if (sBuf.getLength())
186 			{
187 				rExport.AddAttribute(XML_NAMESPACE_STYLE,
188 									 XML_NUM_LETTER_SYNC,
189 									 sBuf.makeStringAndClear());
190 			}
191 		}
192 
193 		// and finally, the element
194 		SvXMLElementExport rElem(rExport, XML_NAMESPACE_TEXT,
195 								 XML_NOTES_CONFIGURATION,
196 								 sal_True, sal_True);
197 	}
198 }
199