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 "XMLSectionFootnoteConfigImport.hxx"
31 
32 #ifndef _RTL_USTRING
33 #include <rtl/ustring.hxx>
34 #endif
35 #include <com/sun/star/uno/Reference.h>
36 #include <com/sun/star/xml/sax/XAttributeList.hpp>
37 #include <com/sun/star/style/NumberingType.hpp>
38 #include <xmloff/xmlimp.hxx>
39 #include <xmloff/xmltoken.hxx>
40 #include <xmloff/xmluconv.hxx>
41 #include <xmloff/xmlprmap.hxx>
42 #include "xmloff/xmlnmspe.hxx"
43 #include <xmloff/nmspmap.hxx>
44 #include <xmloff/maptype.hxx>
45 #include <xmloff/xmlnumi.hxx>
46 #include <xmloff/txtprmap.hxx>
47 #include <tools/debug.hxx>
48 
49 #include <vector>
50 
51 
52 using namespace ::xmloff::token;
53 using namespace ::com::sun::star::style;
54 
55 using ::rtl::OUString;
56 using ::std::vector;
57 using ::com::sun::star::uno::Any;
58 using ::com::sun::star::uno::Reference;
59 using ::com::sun::star::xml::sax::XAttributeList;
60 
61 
62 TYPEINIT1(XMLSectionFootnoteConfigImport, SvXMLImportContext);
63 
64 
65 XMLSectionFootnoteConfigImport::XMLSectionFootnoteConfigImport(
66 	SvXMLImport& rImport,
67 	sal_uInt16 nPrefix,
68 	const OUString& rLocalName,
69 	vector<XMLPropertyState> & rProps,
70 	const UniReference<XMLPropertySetMapper> & rMapperRef) :
71 		SvXMLImportContext(rImport, nPrefix, rLocalName),
72 		rProperties(rProps),
73 		rMapper(rMapperRef)
74 {
75 }
76 
77 XMLSectionFootnoteConfigImport::~XMLSectionFootnoteConfigImport()
78 {
79 }
80 
81 void XMLSectionFootnoteConfigImport::StartElement(
82 	const Reference<XAttributeList> & xAttrList)
83 {
84 	sal_Bool bEnd = sal_True;	// we're inside the element, so this is true
85 	sal_Bool bNumOwn = sal_False;
86 	sal_Bool bNumRestart = sal_False;
87 	sal_Bool bEndnote = sal_False;
88 	sal_Int16 nNumRestartAt = 0;
89 	OUString sNumPrefix;
90 	OUString sNumSuffix;
91 	OUString sNumFormat;
92 	OUString sNumLetterSync;
93 
94 	// iterate over xattribute list and fill values
95 	sal_Int16 nLength = xAttrList->getLength();
96 	for(sal_Int16 nAttr = 0; nAttr < nLength; nAttr++)
97 	{
98 		OUString sLocalName;
99 		sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
100 			GetKeyByAttrName( xAttrList->getNameByIndex(nAttr),
101 							  &sLocalName );
102 		OUString sAttrValue = xAttrList->getValueByIndex(nAttr);
103 
104 		if (XML_NAMESPACE_TEXT == nPrefix)
105 		{
106 			if (IsXMLToken(sLocalName, XML_START_VALUE))
107 			{
108 				sal_Int32 nTmp;
109 				if (SvXMLUnitConverter::convertNumber(nTmp, sAttrValue))
110 				{
111 					nNumRestartAt = static_cast< sal_Int16 >( nTmp ) - 1;
112 					bNumRestart = sal_True;
113 				}
114 			}
115 			else if( IsXMLToken( sLocalName, XML_NOTE_CLASS ) )
116 			{
117 				if( IsXMLToken( sAttrValue, XML_ENDNOTE ) )
118 					bEndnote = sal_True;
119 			}
120 		}
121 		else if (XML_NAMESPACE_STYLE == nPrefix)
122 		{
123 			if (IsXMLToken(sLocalName, XML_NUM_PREFIX))
124 			{
125 				sNumPrefix = sAttrValue;
126 				bNumOwn = sal_True;
127 			}
128 			else if (IsXMLToken(sLocalName, XML_NUM_SUFFIX))
129 			{
130 				sNumSuffix = sAttrValue;
131 				bNumOwn = sal_True;
132 			}
133 			else if (IsXMLToken(sLocalName, XML_NUM_FORMAT))
134 			{
135 				sNumFormat = sAttrValue;
136 				bNumOwn = sal_True;
137 			}
138 			else if (IsXMLToken(sLocalName, XML_NUM_LETTER_SYNC))
139 			{
140 				sNumLetterSync = sAttrValue;
141 				bNumOwn = sal_True;
142 			}
143 		}
144 	}
145 
146 	// OK, now we have all values and can fill the XMLPropertyState vector
147 	Any aAny;
148 
149 	aAny.setValue( &bNumOwn, ::getBooleanCppuType() );
150 	sal_Int32 nIndex = rMapper->FindEntryIndex( bEndnote ?
151 		CTF_SECTION_ENDNOTE_NUM_OWN : CTF_SECTION_FOOTNOTE_NUM_OWN );
152 	XMLPropertyState aNumOwn( nIndex, aAny );
153 	rProperties.push_back( aNumOwn );
154 
155 	aAny.setValue( &bNumRestart, ::getBooleanCppuType() );
156 	nIndex = rMapper->FindEntryIndex( bEndnote ?
157 		CTF_SECTION_ENDNOTE_NUM_RESTART : CTF_SECTION_FOOTNOTE_NUM_RESTART );
158 	XMLPropertyState aNumRestart( nIndex, aAny );
159 	rProperties.push_back( aNumRestart );
160 
161 	aAny <<= nNumRestartAt;
162 	nIndex = rMapper->FindEntryIndex( bEndnote ?
163 		CTF_SECTION_ENDNOTE_NUM_RESTART_AT :
164 		CTF_SECTION_FOOTNOTE_NUM_RESTART_AT );
165 	XMLPropertyState aNumRestartAtState( nIndex, aAny );
166 	rProperties.push_back( aNumRestartAtState );
167 
168 	sal_Int16 nNumType = NumberingType::ARABIC;
169 	GetImport().GetMM100UnitConverter().convertNumFormat( nNumType,
170 													sNumFormat,
171 													sNumLetterSync );
172 	aAny <<= nNumType;
173 	nIndex = rMapper->FindEntryIndex( bEndnote ?
174 		CTF_SECTION_ENDNOTE_NUM_TYPE : CTF_SECTION_FOOTNOTE_NUM_TYPE );
175 	XMLPropertyState aNumFormatState( nIndex, aAny );
176 	rProperties.push_back( aNumFormatState );
177 
178 	aAny <<= sNumPrefix;
179 	nIndex = rMapper->FindEntryIndex( bEndnote ?
180 		CTF_SECTION_ENDNOTE_NUM_PREFIX : CTF_SECTION_FOOTNOTE_NUM_PREFIX );
181 	XMLPropertyState aPrefixState( nIndex, aAny );
182 	rProperties.push_back( aPrefixState );
183 
184 	aAny <<= sNumSuffix;
185 	nIndex = rMapper->FindEntryIndex( bEndnote ?
186 		CTF_SECTION_ENDNOTE_NUM_SUFFIX : CTF_SECTION_FOOTNOTE_NUM_SUFFIX );
187 	XMLPropertyState aSuffixState( nIndex, aAny );
188 	rProperties.push_back( aSuffixState );
189 
190 	aAny.setValue( &bEnd, ::getBooleanCppuType() );
191 	nIndex = rMapper->FindEntryIndex( bEndnote ?
192 		CTF_SECTION_ENDNOTE_END : CTF_SECTION_FOOTNOTE_END );
193 	XMLPropertyState aEndState( nIndex, aAny );
194 	rProperties.push_back( aEndState );
195 }
196