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 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_xmloff.hxx"
30 #include "XMLSectionFootnoteConfigExport.hxx"
31 #include <xmloff/xmlexp.hxx>
32 #include <xmloff/xmlprmap.hxx>
33 #include <com/sun/star/style/NumberingType.hpp>
34 #include <xmloff/maptype.hxx>
35 
36 #ifndef _XMLOFF_TXTPRMAP_HXX
37 #include <xmloff/txtprmap.hxx>
38 #endif
39 #include <xmloff/nmspmap.hxx>
40 #include "xmloff/xmlnmspe.hxx"
41 #include <xmloff/xmluconv.hxx>
42 #include <xmloff/xmltoken.hxx>
43 #include <xmloff/xmlnume.hxx>
44 #include <tools/debug.hxx>
45 
46 #ifndef _RTL_USTRING
47 #include <rtl/ustring.hxx>
48 #endif
49 #include <rtl/ustrbuf.hxx>
50 
51 #include <vector>
52 
53 
54 using namespace ::xmloff::token;
55 
56 using ::std::vector;
57 using ::rtl::OUString;
58 using ::rtl::OUStringBuffer;
59 using ::com::sun::star::style::NumberingType::ARABIC;
60 
61 
62 void XMLSectionFootnoteConfigExport::exportXML(
63 	SvXMLExport& rExport,
64 	sal_Bool bEndnote,
65 	const vector<XMLPropertyState> *pProperties,
66 	sal_uInt32
67     #ifdef DBG_UTIL
68     nIdx
69     #endif
70     ,
71 	const UniReference<XMLPropertySetMapper> & rMapper)
72 {
73 	// store and initialize the values
74 	sal_Bool bNumOwn = sal_False;
75 	sal_Bool bNumRestart = sal_False;
76 	sal_Int16 nNumRestartAt = 0;
77 	sal_Int16 nNumberingType = ARABIC;
78 	OUString sNumPrefix;
79 	OUString sNumSuffix;
80 	sal_Bool bEnd = sal_False;
81 
82 	// find entries in property states vector
83 	sal_uInt32 nCount = pProperties->size();
84 	for(sal_uInt32 i = 0; i < nCount; i++)
85 	{
86 		const XMLPropertyState& rState = (*pProperties)[i];
87 
88 		sal_Int16 nContextId = rMapper->GetEntryContextId(rState.mnIndex);
89 		if (!bEndnote)
90 		{
91 			switch (nContextId)
92 			{
93 				case CTF_SECTION_FOOTNOTE_NUM_OWN:
94 					rState.maValue >>= bNumOwn;
95 					break;
96 				case CTF_SECTION_FOOTNOTE_NUM_RESTART:
97 					rState.maValue >>= bNumRestart;
98 					break;
99 				case CTF_SECTION_FOOTNOTE_NUM_RESTART_AT:
100 					rState.maValue >>= nNumRestartAt;
101 					break;
102 				case CTF_SECTION_FOOTNOTE_NUM_TYPE:
103 					rState.maValue >>= nNumberingType;
104 					break;
105 				case CTF_SECTION_FOOTNOTE_NUM_PREFIX:
106 					rState.maValue >>= sNumPrefix;
107 					break;
108 				case CTF_SECTION_FOOTNOTE_NUM_SUFFIX:
109 					rState.maValue >>= sNumSuffix;
110 					break;
111 				case CTF_SECTION_FOOTNOTE_END:
112 					DBG_ASSERT( i == nIdx,
113 								"received wrong property state index" );
114 					rState.maValue >>= bEnd;
115 					break;
116 			}
117 		}
118 		else
119 		{
120 			switch (nContextId)
121 			{
122 				case CTF_SECTION_ENDNOTE_NUM_OWN:
123 					rState.maValue >>= bNumOwn;
124 					break;
125 				case CTF_SECTION_ENDNOTE_NUM_RESTART:
126 					rState.maValue >>= bNumRestart;
127 					break;
128 				case CTF_SECTION_ENDNOTE_NUM_RESTART_AT:
129 					rState.maValue >>= nNumRestartAt;
130 					break;
131 				case CTF_SECTION_ENDNOTE_NUM_TYPE:
132 					rState.maValue >>= nNumberingType;
133 					break;
134 				case CTF_SECTION_ENDNOTE_NUM_PREFIX:
135 					rState.maValue >>= sNumPrefix;
136 					break;
137 				case CTF_SECTION_ENDNOTE_NUM_SUFFIX:
138 					rState.maValue >>= sNumSuffix;
139 					break;
140 				case CTF_SECTION_ENDNOTE_END:
141 					DBG_ASSERT( i == nIdx,
142 								"received wrong property state index" );
143 					rState.maValue >>= bEnd;
144 					break;
145 			}
146 		}
147 	}
148 
149 	// we only make an element if we have an own footnote/endnote numbering
150 	if (bEnd)
151 	{
152 		rExport.AddAttribute(XML_NAMESPACE_TEXT, XML_NOTE_CLASS,
153 								 GetXMLToken( bEndnote ? XML_ENDNOTE
154 														 : XML_FOOTNOTE ) );
155 		// start numbering
156 		OUStringBuffer sBuf;
157 		if (bNumRestart)
158 		{
159 			// restart number is stored as 0.., but interpreted as 1..
160 			SvXMLUnitConverter::convertNumber(sBuf,
161 											  (sal_Int32)(nNumRestartAt+1));
162 			rExport.AddAttribute(XML_NAMESPACE_TEXT, XML_START_VALUE,
163 								 sBuf.makeStringAndClear());
164 		}
165 
166 		if (bNumOwn)
167 		{
168 			// prefix and suffix
169 			if (sNumPrefix.getLength() > 0)
170 			{
171 					rExport.AddAttribute(XML_NAMESPACE_STYLE, XML_NUM_PREFIX,
172 										 sNumPrefix);
173 			}
174 			if (sNumSuffix.getLength() > 0)
175 			{
176 				rExport.AddAttribute(XML_NAMESPACE_STYLE, XML_NUM_SUFFIX,
177 									 sNumSuffix);
178 			}
179 
180 			// number type: num format
181 			rExport.GetMM100UnitConverter().convertNumFormat( sBuf,
182 															  nNumberingType );
183 			rExport.AddAttribute(XML_NAMESPACE_STYLE, XML_NUM_FORMAT,
184 								 sBuf.makeStringAndClear());
185 
186 			// and letter sync, if applicable
187 			rExport.GetMM100UnitConverter().convertNumLetterSync(
188 				sBuf, nNumberingType );
189 			if (sBuf.getLength())
190 			{
191 				rExport.AddAttribute(XML_NAMESPACE_STYLE,
192 									 XML_NUM_LETTER_SYNC,
193 									 sBuf.makeStringAndClear());
194 			}
195 		}
196 
197 		// and finally, the element
198 		SvXMLElementExport rElem(rExport, XML_NAMESPACE_TEXT,
199 								 XML_NOTES_CONFIGURATION,
200 								 sal_True, sal_True);
201 	}
202 }
203