bump product version to 5.0.4.1
[LibreOffice.git] / xmloff / source / text / XMLSectionFootnoteConfigImport.cxx
blob3a705e68f0790a8d6697fc393bb33f3b8e35e272
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 "XMLSectionFootnoteConfigImport.hxx"
22 #include <rtl/ustring.hxx>
23 #include <com/sun/star/uno/Reference.h>
24 #include <com/sun/star/xml/sax/XAttributeList.hpp>
25 #include <com/sun/star/style/NumberingType.hpp>
26 #include <sax/tools/converter.hxx>
27 #include <xmloff/xmlimp.hxx>
28 #include <xmloff/xmltoken.hxx>
29 #include <xmloff/xmluconv.hxx>
30 #include <xmloff/xmlprmap.hxx>
31 #include <xmloff/xmlnmspe.hxx>
32 #include <xmloff/nmspmap.hxx>
33 #include <xmloff/maptype.hxx>
34 #include <xmloff/xmlnumi.hxx>
35 #include <xmloff/txtprmap.hxx>
37 #include <vector>
40 using namespace ::xmloff::token;
41 using namespace ::com::sun::star::style;
43 using ::std::vector;
44 using ::com::sun::star::uno::Any;
45 using ::com::sun::star::uno::Reference;
46 using ::com::sun::star::xml::sax::XAttributeList;
49 TYPEINIT1(XMLSectionFootnoteConfigImport, SvXMLImportContext);
52 XMLSectionFootnoteConfigImport::XMLSectionFootnoteConfigImport(
53 SvXMLImport& rImport,
54 sal_uInt16 nPrefix,
55 const OUString& rLocalName,
56 vector<XMLPropertyState> & rProps,
57 const rtl::Reference<XMLPropertySetMapper> & rMapperRef) :
58 SvXMLImportContext(rImport, nPrefix, rLocalName),
59 rProperties(rProps),
60 rMapper(rMapperRef)
64 XMLSectionFootnoteConfigImport::~XMLSectionFootnoteConfigImport()
68 void XMLSectionFootnoteConfigImport::StartElement(
69 const Reference<XAttributeList> & xAttrList)
71 sal_Bool bEnd = sal_True; // we're inside the element, so this is true
72 sal_Bool bNumOwn = sal_False;
73 sal_Bool bNumRestart = sal_False;
74 bool bEndnote = false;
75 sal_Int16 nNumRestartAt = 0;
76 OUString sNumPrefix;
77 OUString sNumSuffix;
78 OUString sNumFormat;
79 OUString sNumLetterSync;
81 // iterate over xattribute list and fill values
82 sal_Int16 nLength = xAttrList->getLength();
83 for(sal_Int16 nAttr = 0; nAttr < nLength; nAttr++)
85 OUString sLocalName;
86 sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
87 GetKeyByAttrName( xAttrList->getNameByIndex(nAttr),
88 &sLocalName );
89 OUString sAttrValue = xAttrList->getValueByIndex(nAttr);
91 if (XML_NAMESPACE_TEXT == nPrefix)
93 if (IsXMLToken(sLocalName, XML_START_VALUE))
95 sal_Int32 nTmp;
96 if (::sax::Converter::convertNumber(nTmp, sAttrValue))
98 nNumRestartAt = static_cast< sal_Int16 >( nTmp ) - 1;
99 bNumRestart = sal_True;
102 else if( IsXMLToken( sLocalName, XML_NOTE_CLASS ) )
104 if( IsXMLToken( sAttrValue, XML_ENDNOTE ) )
105 bEndnote = true;
108 else if (XML_NAMESPACE_STYLE == nPrefix)
110 if (IsXMLToken(sLocalName, XML_NUM_PREFIX))
112 sNumPrefix = sAttrValue;
113 bNumOwn = sal_True;
115 else if (IsXMLToken(sLocalName, XML_NUM_SUFFIX))
117 sNumSuffix = sAttrValue;
118 bNumOwn = sal_True;
120 else if (IsXMLToken(sLocalName, XML_NUM_FORMAT))
122 sNumFormat = sAttrValue;
123 bNumOwn = sal_True;
125 else if (IsXMLToken(sLocalName, XML_NUM_LETTER_SYNC))
127 sNumLetterSync = sAttrValue;
128 bNumOwn = sal_True;
133 // OK, now we have all values and can fill the XMLPropertyState vector
134 Any aAny;
136 aAny.setValue( &bNumOwn, cppu::UnoType<bool>::get() );
137 sal_Int32 nIndex = rMapper->FindEntryIndex( bEndnote ?
138 CTF_SECTION_ENDNOTE_NUM_OWN : CTF_SECTION_FOOTNOTE_NUM_OWN );
139 XMLPropertyState aNumOwn( nIndex, aAny );
140 rProperties.push_back( aNumOwn );
142 aAny.setValue( &bNumRestart, cppu::UnoType<bool>::get() );
143 nIndex = rMapper->FindEntryIndex( bEndnote ?
144 CTF_SECTION_ENDNOTE_NUM_RESTART : CTF_SECTION_FOOTNOTE_NUM_RESTART );
145 XMLPropertyState aNumRestart( nIndex, aAny );
146 rProperties.push_back( aNumRestart );
148 aAny <<= nNumRestartAt;
149 nIndex = rMapper->FindEntryIndex( bEndnote ?
150 CTF_SECTION_ENDNOTE_NUM_RESTART_AT :
151 CTF_SECTION_FOOTNOTE_NUM_RESTART_AT );
152 XMLPropertyState aNumRestartAtState( nIndex, aAny );
153 rProperties.push_back( aNumRestartAtState );
155 sal_Int16 nNumType = NumberingType::ARABIC;
156 GetImport().GetMM100UnitConverter().convertNumFormat( nNumType,
157 sNumFormat,
158 sNumLetterSync );
159 aAny <<= nNumType;
160 nIndex = rMapper->FindEntryIndex( bEndnote ?
161 CTF_SECTION_ENDNOTE_NUM_TYPE : CTF_SECTION_FOOTNOTE_NUM_TYPE );
162 XMLPropertyState aNumFormatState( nIndex, aAny );
163 rProperties.push_back( aNumFormatState );
165 aAny <<= sNumPrefix;
166 nIndex = rMapper->FindEntryIndex( bEndnote ?
167 CTF_SECTION_ENDNOTE_NUM_PREFIX : CTF_SECTION_FOOTNOTE_NUM_PREFIX );
168 XMLPropertyState aPrefixState( nIndex, aAny );
169 rProperties.push_back( aPrefixState );
171 aAny <<= sNumSuffix;
172 nIndex = rMapper->FindEntryIndex( bEndnote ?
173 CTF_SECTION_ENDNOTE_NUM_SUFFIX : CTF_SECTION_FOOTNOTE_NUM_SUFFIX );
174 XMLPropertyState aSuffixState( nIndex, aAny );
175 rProperties.push_back( aSuffixState );
177 aAny.setValue( &bEnd, cppu::UnoType<bool>::get() );
178 nIndex = rMapper->FindEntryIndex( bEndnote ?
179 CTF_SECTION_ENDNOTE_END : CTF_SECTION_FOOTNOTE_END );
180 XMLPropertyState aEndState( nIndex, aAny );
181 rProperties.push_back( aEndState );
184 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */