LibreOffice Module xmloff (master)  1
XMLFootnoteSeparatorImport.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 
20 
22 
23 #include <rtl/ustring.hxx>
24 #include <sal/log.hxx>
25 
26 #include <com/sun/star/uno/Reference.h>
27 #include <com/sun/star/xml/sax/XAttributeList.hpp>
28 #include <com/sun/star/text/HorizontalAdjust.hpp>
29 
30 
31 #include <sax/tools/converter.hxx>
32 
33 #include <xmloff/xmlimp.hxx>
34 #include <xmloff/xmltoken.hxx>
35 #include <xmloff/xmluconv.hxx>
36 #include <xmloff/xmlprmap.hxx>
37 #include <xmloff/xmlnmspe.hxx>
38 #include <xmloff/nmspmap.hxx>
39 #include <xmloff/maptype.hxx>
40 #include <xmloff/xmlement.hxx>
41 
42 #include <PageMasterStyleMap.hxx>
43 
44 #include <vector>
45 
46 
47 using namespace ::com::sun::star;
48 using namespace ::xmloff::token;
49 
50 using ::std::vector;
51 using ::com::sun::star::uno::Any;
52 using ::com::sun::star::uno::Reference;
53 using ::com::sun::star::xml::sax::XAttributeList;
54 
55 
57  SvXMLImport& rImport,
58  sal_uInt16 nPrefix,
59  const OUString& rLocalName,
60  vector<XMLPropertyState> & rProps,
61  const rtl::Reference<XMLPropertySetMapper> & rMapperRef,
62  sal_Int32 nIndex) :
63  SvXMLImportContext(rImport, nPrefix, rLocalName),
64  rProperties(rProps),
65  rMapper(rMapperRef),
66  nPropIndex(nIndex)
67 {
68 }
69 
71 {
72 }
73 
75  const Reference<XAttributeList> & xAttrList)
76 {
77  // get the values from the properties
78  sal_Int16 nLineWeight = 0;
79  sal_Int32 nLineColor = 0;
80  sal_Int8 nLineRelWidth = 0;
81  text::HorizontalAdjust eLineAdjust = text::HorizontalAdjust_LEFT;
82  sal_Int32 nLineTextDistance = 0;
83  sal_Int32 nLineDistance = 0;
84 
85  // Default separator line style should be SOLID (used to be default before
86  // the choice selector was available)
87  sal_Int8 nLineStyle = 1;
88 
89  // iterate over xattribute list and fill values
90  sal_Int16 nLength = xAttrList->getLength();
91  for(sal_Int16 nAttr = 0; nAttr < nLength; nAttr++)
92  {
93  OUString sLocalName;
94  sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
95  GetKeyByAttrName( xAttrList->getNameByIndex(nAttr),
96  &sLocalName );
97 
98  if (XML_NAMESPACE_STYLE == nPrefix)
99  {
100  OUString sAttrValue = xAttrList->getValueByIndex(nAttr);
101  sal_Int32 nTmp;
102  if (IsXMLToken( sLocalName, XML_WIDTH ))
103  {
104  if (GetImport().GetMM100UnitConverter().convertMeasureToCore(
105  nTmp, sAttrValue))
106  {
107  nLineWeight = static_cast<sal_Int16>(nTmp);
108  }
109  }
110  else if (IsXMLToken( sLocalName, XML_DISTANCE_BEFORE_SEP ))
111  {
113  nTmp, sAttrValue))
114  nLineTextDistance = nTmp;
115  }
116  else if (IsXMLToken( sLocalName, XML_DISTANCE_AFTER_SEP ))
117  {
119  nTmp, sAttrValue))
120  nLineDistance = nTmp;
121  }
122  else if (IsXMLToken( sLocalName, XML_ADJUSTMENT ))
123  {
125  {
126  { XML_LEFT, text::HorizontalAdjust_LEFT },
127  { XML_CENTER, text::HorizontalAdjust_CENTER },
128  { XML_RIGHT, text::HorizontalAdjust_RIGHT },
129  { XML_TOKEN_INVALID, text::HorizontalAdjust(0) }
130  };
131 
133  eLineAdjust, sAttrValue, aXML_HorizontalAdjust_Enum);
134  }
135  else if (IsXMLToken( sLocalName, XML_REL_WIDTH ))
136  {
137  if (::sax::Converter::convertPercent(nTmp, sAttrValue))
138  nLineRelWidth = static_cast<sal_uInt8>(nTmp);
139  }
140  else if (IsXMLToken( sLocalName, XML_COLOR ))
141  {
142  if (::sax::Converter::convertColor(nTmp, sAttrValue))
143  {
144  nLineColor = nTmp;
145  }
146  }
147  else if (IsXMLToken( sLocalName, XML_LINE_STYLE ))
148  {
149  static const SvXMLEnumMapEntry<sal_Int8> aXML_LineStyle_Enum[] =
150  {
151  { XML_NONE, 0 },
152  { XML_SOLID, 1 },
153  { XML_DOTTED, 2 },
154  { XML_DASH, 3 },
155  { XML_TOKEN_INVALID, 0 }
156  };
157 
158  SvXMLUnitConverter::convertEnum(nLineStyle, sAttrValue, aXML_LineStyle_Enum);
159  }
160  }
161  }
162 
163  // OK, now we have all values and can fill the XMLPropertyState vector
164  sal_Int32 nIndex;
165 
166  nIndex = rMapper->FindEntryIndex(CTF_PM_FTN_LINE_ADJUST);
167  XMLPropertyState aLineAdjust( nIndex, uno::Any(sal_Int16(eLineAdjust)) );
168  rProperties.push_back(aLineAdjust);
169 
170  nIndex = rMapper->FindEntryIndex(CTF_PM_FTN_LINE_COLOR);
171  XMLPropertyState aLineColor( nIndex, uno::Any(nLineColor) );
172  rProperties.push_back(aLineColor);
173 
174  nIndex = rMapper->FindEntryIndex(CTF_PM_FTN_LINE_STYLE);
175  XMLPropertyState aLineStyle( nIndex, uno::Any(nLineStyle) );
176  rProperties.push_back(aLineStyle);
177 
178  nIndex = rMapper->FindEntryIndex(CTF_PM_FTN_DISTANCE);
179  XMLPropertyState aLineDistance( nIndex, uno::Any(nLineDistance) );
180  rProperties.push_back(aLineDistance);
181 
182  nIndex = rMapper->FindEntryIndex(CTF_PM_FTN_LINE_WIDTH);
183  XMLPropertyState aLineRelWidth( nIndex, uno::Any(nLineRelWidth));
184  rProperties.push_back(aLineRelWidth);
185 
186  nIndex = rMapper->FindEntryIndex(CTF_PM_FTN_LINE_DISTANCE);
187  XMLPropertyState aLineTextDistance( nIndex, uno::Any(nLineTextDistance));
188  rProperties.push_back(aLineTextDistance);
189 
190  SAL_WARN_IF( rMapper->FindEntryIndex(CTF_PM_FTN_LINE_WEIGHT) != nPropIndex, "xmloff",
191  "Received wrong property map index!" );
192  XMLPropertyState aLineWeight( nPropIndex, uno::Any(nLineWeight) );
193  rProperties.push_back(aLineWeight);
194 }
195 
196 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool IsXMLToken(const OUString &rString, enum XMLTokenEnum eToken)
compare eToken to the string
Definition: xmltoken.cxx:3422
constexpr sal_uInt16 XML_NAMESPACE_STYLE
Definition: xmlnmspe.hxx:30
sal_Int32 nIndex
static bool convertEnum(EnumT &rEnum, const OUString &rValue, const SvXMLEnumMapEntry< EnumT > *pMap)
convert string to enum using given enum map, if the enum is not found in the map, this method will re...
Definition: xmluconv.hxx:128
#define CTF_PM_FTN_LINE_ADJUST
signed char sal_Int8
#define CTF_PM_FTN_LINE_WEIGHT
#define CTF_PM_FTN_LINE_COLOR
SvXMLImport & GetImport()
Definition: xmlictxt.hxx:62
#define CTF_PM_FTN_LINE_WIDTH
SvXMLNamespaceMap & GetNamespaceMap()
Definition: xmlimp.hxx:397
bool convertMeasureToCore(sal_Int32 &rValue, const OUString &rString, sal_Int32 nMin=SAL_MIN_INT32, sal_Int32 nMax=SAL_MAX_INT32) const
convert string to measure with meCoreMeasureUnit, using optional min and max values ...
Definition: xmluconv.cxx:171
#define CTF_PM_FTN_LINE_STYLE
#define CTF_PM_FTN_DISTANCE
rtl::Reference< XMLPropertySetMapper > rMapper
XMLFootnoteSeparatorImport(SvXMLImport &rImport, sal_uInt16 nPrefix, const OUString &rLocalName,::std::vector< XMLPropertyState > &rProperties, const rtl::Reference< XMLPropertySetMapper > &rMapperRef, sal_Int32 nIndex)
This class deliberately does not support XWeak, to improve performance when loading large documents...
Definition: xmlictxt.hxx:44
Map an XMLTokenEnum to an enum value.
Definition: ximpshap.hxx:40
#define SAL_WARN_IF(condition, area, stream)
unsigned char sal_uInt8
static bool convertColor(sal_Int32 &rColor, const OUString &rValue)
#define CTF_PM_FTN_LINE_DISTANCE
Handling of tokens in XML:
Smart struct to transport an Any with an index to the appropriate property-name.
Definition: maptype.hxx:104
const SvXMLUnitConverter & GetMM100UnitConverter() const
Definition: xmlimp.hxx:399
sal_Int32 nLength
Definition: xmltoken.cxx:36
virtual void StartElement(const css::uno::Reference< css::xml::sax::XAttributeList > &xAttrList) override
StartElement is called after a context has been constructed and before an elements context is parsed...
static SvXMLEnumMapEntry< text::HorizontalAdjust > const aXML_HorizontalAdjust_Enum[]
Definition: prhdlfac.cxx:73
static bool convertPercent(sal_Int32 &rValue, const OUString &rString)
::std::vector< XMLPropertyState > & rProperties