1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
20 #include "XMLSectionFootnoteConfigImport.hxx"
21 
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/txtprmap.hxx>
35 
36 #include <vector>
37 
38 
39 using namespace ::xmloff::token;
40 using namespace ::com::sun::star::style;
41 
42 using ::std::vector;
43 using ::com::sun::star::uno::Any;
44 using ::com::sun::star::uno::Reference;
45 using ::com::sun::star::xml::sax::XAttributeList;
46 
47 
XMLSectionFootnoteConfigImport(SvXMLImport & rImport,sal_uInt16 nPrefix,const OUString & rLocalName,vector<XMLPropertyState> & rProps,const rtl::Reference<XMLPropertySetMapper> & rMapperRef)48 XMLSectionFootnoteConfigImport::XMLSectionFootnoteConfigImport(
49     SvXMLImport& rImport,
50     sal_uInt16 nPrefix,
51     const OUString& rLocalName,
52     vector<XMLPropertyState> & rProps,
53     const rtl::Reference<XMLPropertySetMapper> & rMapperRef) :
54         SvXMLImportContext(rImport, nPrefix, rLocalName),
55         rProperties(rProps),
56         rMapper(rMapperRef)
57 {
58 }
59 
~XMLSectionFootnoteConfigImport()60 XMLSectionFootnoteConfigImport::~XMLSectionFootnoteConfigImport()
61 {
62 }
63 
StartElement(const Reference<XAttributeList> & xAttrList)64 void XMLSectionFootnoteConfigImport::StartElement(
65     const Reference<XAttributeList> & xAttrList)
66 {
67     bool bNumOwn = false;
68     bool bNumRestart = false;
69     bool bEndnote = false;
70     sal_Int16 nNumRestartAt = 0;
71     OUString sNumPrefix;
72     OUString sNumSuffix;
73     OUString sNumFormat;
74     OUString sNumLetterSync;
75 
76     // iterate over xattribute list and fill values
77     sal_Int16 nLength = xAttrList->getLength();
78     for(sal_Int16 nAttr = 0; nAttr < nLength; nAttr++)
79     {
80         OUString sLocalName;
81         sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
82             GetKeyByAttrName( xAttrList->getNameByIndex(nAttr),
83                               &sLocalName );
84         OUString sAttrValue = xAttrList->getValueByIndex(nAttr);
85 
86         if (XML_NAMESPACE_TEXT == nPrefix)
87         {
88             if (IsXMLToken(sLocalName, XML_START_VALUE))
89             {
90                 sal_Int32 nTmp;
91                 if (::sax::Converter::convertNumber(nTmp, sAttrValue))
92                 {
93                     nNumRestartAt = static_cast< sal_Int16 >( nTmp ) - 1;
94                     bNumRestart = true;
95                 }
96             }
97             else if( IsXMLToken( sLocalName, XML_NOTE_CLASS ) )
98             {
99                 if( IsXMLToken( sAttrValue, XML_ENDNOTE ) )
100                     bEndnote = true;
101             }
102         }
103         else if (XML_NAMESPACE_STYLE == nPrefix)
104         {
105             if (IsXMLToken(sLocalName, XML_NUM_PREFIX))
106             {
107                 sNumPrefix = sAttrValue;
108                 bNumOwn = true;
109             }
110             else if (IsXMLToken(sLocalName, XML_NUM_SUFFIX))
111             {
112                 sNumSuffix = sAttrValue;
113                 bNumOwn = true;
114             }
115             else if (IsXMLToken(sLocalName, XML_NUM_FORMAT))
116             {
117                 sNumFormat = sAttrValue;
118                 bNumOwn = true;
119             }
120             else if (IsXMLToken(sLocalName, XML_NUM_LETTER_SYNC))
121             {
122                 sNumLetterSync = sAttrValue;
123                 bNumOwn = true;
124             }
125         }
126     }
127 
128     // OK, now we have all values and can fill the XMLPropertyState vector
129 
130     sal_Int32 nIndex = rMapper->FindEntryIndex( bEndnote ?
131         CTF_SECTION_ENDNOTE_NUM_OWN : CTF_SECTION_FOOTNOTE_NUM_OWN );
132     XMLPropertyState aNumOwn( nIndex, css::uno::Any(bNumOwn) );
133     rProperties.push_back( aNumOwn );
134 
135     nIndex = rMapper->FindEntryIndex( bEndnote ?
136         CTF_SECTION_ENDNOTE_NUM_RESTART : CTF_SECTION_FOOTNOTE_NUM_RESTART );
137     XMLPropertyState aNumRestart( nIndex, css::uno::Any(bNumRestart) );
138     rProperties.push_back( aNumRestart );
139 
140     nIndex = rMapper->FindEntryIndex( bEndnote ?
141         CTF_SECTION_ENDNOTE_NUM_RESTART_AT :
142         CTF_SECTION_FOOTNOTE_NUM_RESTART_AT );
143     XMLPropertyState aNumRestartAtState( nIndex, css::uno::Any(nNumRestartAt) );
144     rProperties.push_back( aNumRestartAtState );
145 
146     sal_Int16 nNumType = NumberingType::ARABIC;
147     GetImport().GetMM100UnitConverter().convertNumFormat( nNumType,
148                                                     sNumFormat,
149                                                     sNumLetterSync );
150     nIndex = rMapper->FindEntryIndex( bEndnote ?
151         CTF_SECTION_ENDNOTE_NUM_TYPE : CTF_SECTION_FOOTNOTE_NUM_TYPE );
152     XMLPropertyState aNumFormatState( nIndex, css::uno::Any(nNumType) );
153     rProperties.push_back( aNumFormatState );
154 
155     nIndex = rMapper->FindEntryIndex( bEndnote ?
156         CTF_SECTION_ENDNOTE_NUM_PREFIX : CTF_SECTION_FOOTNOTE_NUM_PREFIX );
157     XMLPropertyState aPrefixState( nIndex, css::uno::Any(sNumPrefix) );
158     rProperties.push_back( aPrefixState );
159 
160     nIndex = rMapper->FindEntryIndex( bEndnote ?
161         CTF_SECTION_ENDNOTE_NUM_SUFFIX : CTF_SECTION_FOOTNOTE_NUM_SUFFIX );
162     XMLPropertyState aSuffixState( nIndex, css::uno::Any(sNumSuffix) );
163     rProperties.push_back( aSuffixState );
164 
165     nIndex = rMapper->FindEntryIndex( bEndnote ?
166         CTF_SECTION_ENDNOTE_END : CTF_SECTION_FOOTNOTE_END );
167     XMLPropertyState aEndState( nIndex, css::uno::Any(true) ); // we're inside the element, so this is true
168     rProperties.push_back( aEndState );
169 }
170 
171 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
172