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