LibreOffice Module xmloff (master)  1
XMLSectionFootnoteConfigImport.cxx
Go to the documentation of this file.
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 
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 <sal/log.hxx>
27 #include <sax/tools/converter.hxx>
28 #include <xmloff/xmlimp.hxx>
29 #include <xmloff/xmltoken.hxx>
30 #include <xmloff/xmluconv.hxx>
31 #include <xmloff/xmlprmap.hxx>
32 #include <xmloff/xmlnamespace.hxx>
33 #include <xmloff/namespacemap.hxx>
34 #include <xmloff/maptype.hxx>
35 #include <xmloff/txtprmap.hxx>
36 
37 #include <vector>
38 
39 
40 using namespace ::xmloff::token;
41 using namespace ::com::sun::star::style;
42 
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;
47 
48 
50  SvXMLImport& rImport,
51  sal_Int32 /*nElement*/,
52  vector<XMLPropertyState> & rProps,
53  const rtl::Reference<XMLPropertySetMapper> & rMapperRef) :
54  SvXMLImportContext(rImport),
55  rProperties(rProps),
56  rMapper(rMapperRef)
57 {
58 }
59 
61 {
62 }
63 
65  sal_Int32 /*nElement*/,
66  const Reference<css::xml::sax::XFastAttributeList> & xAttrList)
67 {
68  bool bNumOwn = false;
69  bool bNumRestart = false;
70  bool bEndnote = false;
71  sal_Int16 nNumRestartAt = 0;
72  OUString sNumPrefix;
73  OUString sNumSuffix;
74  OUString sNumFormat;
75  OUString sNumLetterSync;
76 
77  // iterate over xattribute list and fill values
78  for (auto &aIter : sax_fastparser::castToFastAttributeList(xAttrList))
79  {
80  OUString sAttrValue = aIter.toString();
81 
82  switch(aIter.getToken())
83  {
85  {
86  sal_Int32 nTmp;
87  if (::sax::Converter::convertNumber(nTmp, sAttrValue))
88  {
89  nNumRestartAt = static_cast< sal_Int16 >( nTmp ) - 1;
90  bNumRestart = true;
91  }
92  break;
93  }
95  {
96  if( IsXMLToken( sAttrValue, XML_ENDNOTE ) )
97  bEndnote = true;
98  break;
99  }
101  {
102  sNumPrefix = sAttrValue;
103  bNumOwn = true;
104  break;
105  }
107  {
108  sNumSuffix = sAttrValue;
109  bNumOwn = true;
110  break;
111  }
113  {
114  sNumFormat = sAttrValue;
115  bNumOwn = true;
116  break;
117  }
119  {
120  sNumLetterSync = sAttrValue;
121  bNumOwn = true;
122  break;
123  }
124  default:
125  SAL_WARN("xmloff", "unknown attribute " << SvXMLImport::getPrefixAndNameFromToken(aIter.getToken()) << "=" << sAttrValue);
126  }
127  }
128 
129  // OK, now we have all values and can fill the XMLPropertyState vector
130 
131  sal_Int32 nIndex = rMapper->FindEntryIndex( bEndnote ?
133  XMLPropertyState aNumOwn( nIndex, css::uno::Any(bNumOwn) );
134  rProperties.push_back( aNumOwn );
135 
136  nIndex = rMapper->FindEntryIndex( bEndnote ?
138  XMLPropertyState aNumRestart( nIndex, css::uno::Any(bNumRestart) );
139  rProperties.push_back( aNumRestart );
140 
141  nIndex = rMapper->FindEntryIndex( bEndnote ?
144  XMLPropertyState aNumRestartAtState( nIndex, css::uno::Any(nNumRestartAt) );
145  rProperties.push_back( aNumRestartAtState );
146 
147  sal_Int16 nNumType = NumberingType::ARABIC;
149  sNumFormat,
150  sNumLetterSync );
151  nIndex = rMapper->FindEntryIndex( bEndnote ?
153  XMLPropertyState aNumFormatState( nIndex, css::uno::Any(nNumType) );
154  rProperties.push_back( aNumFormatState );
155 
156  nIndex = rMapper->FindEntryIndex( bEndnote ?
158  XMLPropertyState aPrefixState( nIndex, css::uno::Any(sNumPrefix) );
159  rProperties.push_back( aPrefixState );
160 
161  nIndex = rMapper->FindEntryIndex( bEndnote ?
163  XMLPropertyState aSuffixState( nIndex, css::uno::Any(sNumSuffix) );
164  rProperties.push_back( aSuffixState );
165 
166  nIndex = rMapper->FindEntryIndex( bEndnote ?
168  XMLPropertyState aEndState( nIndex, css::uno::Any(true) ); // we're inside the element, so this is true
169  rProperties.push_back( aEndState );
170 }
171 
172 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool IsXMLToken(const OUString &rString, enum XMLTokenEnum eToken)
compare eToken to the string
Definition: xmltoken.cxx:3434
sal_Int32 nIndex
#define CTF_SECTION_FOOTNOTE_NUM_PREFIX
Definition: txtprmap.hxx:119
bool convertNumFormat(sal_Int16 &rType, const OUString &rNumFormat, const OUString &rNumLetterSync, bool bNumberNone=false) const
convert num-format and num-letter-sync values to NumberingType
Definition: xmluconv.cxx:574
#define CTF_SECTION_ENDNOTE_NUM_RESTART
Definition: txtprmap.hxx:123
SvXMLImport & GetImport()
Definition: xmlictxt.hxx:62
#define CTF_SECTION_ENDNOTE_NUM_TYPE
Definition: txtprmap.hxx:125
FastAttributeList & castToFastAttributeList(const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
rtl::Reference< XMLPropertySetMapper > rMapper
#define CTF_SECTION_ENDNOTE_NUM_PREFIX
Definition: txtprmap.hxx:126
#define CTF_SECTION_ENDNOTE_END
Definition: txtprmap.hxx:122
sal_Int16 nNumType
static OUString getPrefixAndNameFromToken(sal_Int32 nToken)
Definition: xmlimp.cxx:2025
#define CTF_SECTION_FOOTNOTE_NUM_TYPE
Definition: txtprmap.hxx:118
#define CTF_SECTION_ENDNOTE_NUM_SUFFIX
Definition: txtprmap.hxx:127
#define CTF_SECTION_FOOTNOTE_NUM_RESTART
Definition: txtprmap.hxx:116
virtual void SAL_CALL startFastElement(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &) override
#define CTF_SECTION_FOOTNOTE_NUM_SUFFIX
Definition: txtprmap.hxx:120
XMLSectionFootnoteConfigImport(SvXMLImport &rImport, sal_Int32 nElement,::std::vector< XMLPropertyState > &rProperties, const rtl::Reference< XMLPropertySetMapper > &rMapperRef)
#define CTF_SECTION_FOOTNOTE_NUM_RESTART_AT
Definition: txtprmap.hxx:117
#define CTF_SECTION_FOOTNOTE_NUM_OWN
Definition: txtprmap.hxx:121
This class deliberately does not support XWeak, to improve performance when loading large documents...
Definition: xmlictxt.hxx:44
Handling of tokens in XML:
#define XML_ELEMENT(prefix, name)
Definition: xmlimp.hxx:94
Smart struct to transport an Any with an index to the appropriate property-name.
Definition: maptype.hxx:122
const SvXMLUnitConverter & GetMM100UnitConverter() const
Definition: xmlimp.hxx:404
::std::vector< XMLPropertyState > & rProperties
#define CTF_SECTION_ENDNOTE_NUM_RESTART_AT
Definition: txtprmap.hxx:124
#define SAL_WARN(area, stream)
#define CTF_SECTION_ENDNOTE_NUM_OWN
Definition: txtprmap.hxx:128
TEXT
static bool convertNumber(sal_Int32 &rValue, std::u16string_view aString, sal_Int32 nMin=SAL_MIN_INT32, sal_Int32 nMax=SAL_MAX_INT32)
#define CTF_SECTION_FOOTNOTE_END
Definition: txtprmap.hxx:115