LibreOffice Module xmloff (master)  1
XMLLineNumberingImportContext.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 
22 #include <com/sun/star/beans/XPropertySet.hpp>
23 #include <com/sun/star/frame/XModel.hpp>
24 #include <com/sun/star/text/XLineNumberingProperties.hpp>
25 #include <com/sun/star/style/LineNumberPosition.hpp>
26 #include <com/sun/star/style/NumberingType.hpp>
27 #include <sax/tools/converter.hxx>
28 #include <xmloff/xmlimp.hxx>
29 #include <xmloff/xmluconv.hxx>
30 #include <xmloff/xmlnamespace.hxx>
31 #include <xmloff/namespacemap.hxx>
32 #include <xmloff/xmltoken.hxx>
33 #include <xmloff/xmlement.hxx>
34 
35 
36 using namespace ::com::sun::star;
37 using namespace ::com::sun::star::uno;
38 using namespace ::com::sun::star::style;
39 using namespace ::xmloff::token;
40 
41 using ::com::sun::star::beans::XPropertySet;
42 using ::com::sun::star::xml::sax::XAttributeList;
43 using ::com::sun::star::xml::sax::XFastAttributeList;
44 using ::com::sun::star::text::XLineNumberingProperties;
45 
46 
47 constexpr OUStringLiteral gsCharStyleName(u"CharStyleName");
48 constexpr OUStringLiteral gsCountEmptyLines(u"CountEmptyLines");
49 constexpr OUStringLiteral gsCountLinesInFrames(u"CountLinesInFrames");
50 constexpr OUStringLiteral gsDistance(u"Distance");
51 constexpr OUStringLiteral gsInterval(u"Interval");
52 constexpr OUStringLiteral gsSeparatorText(u"SeparatorText");
53 constexpr OUStringLiteral gsNumberPosition(u"NumberPosition");
54 constexpr OUStringLiteral gsNumberingType(u"NumberingType");
55 constexpr OUStringLiteral gsIsOn(u"IsOn");
56 constexpr OUStringLiteral gsRestartAtEachPage(u"RestartAtEachPage");
57 constexpr OUStringLiteral gsSeparatorInterval(u"SeparatorInterval");
58 
60  SvXMLImport& rImport)
62 , sNumFormat(GetXMLToken(XML_1))
63 , sNumLetterSync(GetXMLToken(XML_FALSE))
64 , nOffset(-1)
65 , nNumberPosition(style::LineNumberPosition::LEFT)
66 , nIncrement(-1)
67 , nSeparatorIncrement(-1)
68 , bNumberLines(true)
69 , bCountEmptyLines(true)
70 , bCountInFloatingFrames(false)
71 , bRestartNumbering(false)
72 {
73 }
74 
76 {
77 }
78 
79 void XMLLineNumberingImportContext::SetAttribute( sal_uInt16 nPrefixKey,
80  const OUString& rLocalName,
81  const OUString& rValue )
82 {
83  static const SvXMLTokenMapEntry aLineNumberingTokenMap[] =
84  {
101  // { XML_NAMESPACE_TEXT, XML_LINENUMBERING_CONFIGURATION,
102  // XML_TOK_LINENUMBERING_LINENUMBERING_CONFIGURATION },
103  // { XML_NAMESPACE_TEXT, XML_INCREMENT, XML_TOK_LINENUMBERING_INCREMENT },
104  // { XML_NAMESPACE_TEXT, XML_LINENUMBERING_SEPARATOR,
105  // XML_TOK_LINENUMBERING_LINENUMBERING_SEPARATOR },
106 
108  };
109 
110  static const SvXMLTokenMap aTokenMap(aLineNumberingTokenMap);
111 
112  auto eToken = aTokenMap.Get(nPrefixKey, rLocalName);
113 
114  bool bTmp(false);
115  sal_Int32 nTmp;
116 
117  switch (eToken)
118  {
120  sStyleName = rValue;
121  break;
122 
124  if (::sax::Converter::convertBool(bTmp, rValue))
125  {
126  bNumberLines = bTmp;
127  }
128  break;
129 
131  if (::sax::Converter::convertBool(bTmp, rValue))
132  {
133  bCountEmptyLines = bTmp;
134  }
135  break;
136 
138  if (::sax::Converter::convertBool(bTmp, rValue))
139  {
140  bCountInFloatingFrames = bTmp;
141  }
142  break;
143 
145  if (::sax::Converter::convertBool(bTmp, rValue))
146  {
147  bRestartNumbering = bTmp;
148  }
149  break;
150 
152  if (GetImport().GetMM100UnitConverter().
153  convertMeasureToCore(nTmp, rValue))
154  {
155  nOffset = nTmp;
156  }
157  break;
158 
160  sNumFormat = rValue;
161  break;
162 
165  break;
166 
168  {
170  {
171  { XML_LEFT, style::LineNumberPosition::LEFT },
172  { XML_RIGHT, style::LineNumberPosition::RIGHT },
173  { XML_INSIDE, style::LineNumberPosition::INSIDE },
174  { XML_OUTSIDE, style::LineNumberPosition::OUTSIDE },
175  { XML_TOKEN_INVALID, 0 }
176  };
177 
179  aLineNumberPositionMap);
180  break;
181  }
182 
184  if (::sax::Converter::convertNumber(nTmp, rValue, 0))
185  {
186  nIncrement = static_cast<sal_Int16>(nTmp);
187  }
188  break;
189  }
190 }
191 
193 {
194  // insert and block mode is handled in insertStyleFamily
195 
196  // we'll try to get the LineNumberingProperties
197  Reference<XLineNumberingProperties> xSupplier(GetImport().GetModel(),
198  UNO_QUERY);
199  if (!xSupplier.is())
200  return;
201 
202  Reference<XPropertySet> xLineNumbering =
203  xSupplier->getLineNumberingProperties();
204 
205  if (!xLineNumbering.is())
206  return;
207 
208  Any aAny;
209 
210  // set style name (if it exists)
212  XmlStyleFamily::TEXT_TEXT, sStyleName ) != nullptr )
213  {
214  aAny <<= GetImport().GetStyleDisplayName(
216  xLineNumbering->setPropertyValue(gsCharStyleName, aAny);
217  }
218 
219  xLineNumbering->setPropertyValue(gsSeparatorText, Any(sSeparator));
220  xLineNumbering->setPropertyValue(gsDistance, Any(nOffset));
221  xLineNumbering->setPropertyValue(gsNumberPosition, Any(nNumberPosition));
222 
223  if (nIncrement >= 0)
224  {
225  xLineNumbering->setPropertyValue(gsInterval, Any(nIncrement));
226  }
227 
228  if (nSeparatorIncrement >= 0)
229  {
230  xLineNumbering->setPropertyValue(gsSeparatorInterval, Any(nSeparatorIncrement));
231  }
232 
233  xLineNumbering->setPropertyValue(gsIsOn, Any(bNumberLines));
234  xLineNumbering->setPropertyValue(gsCountEmptyLines, Any(bCountEmptyLines));
235  xLineNumbering->setPropertyValue(gsCountLinesInFrames, Any(bCountInFloatingFrames));
236  xLineNumbering->setPropertyValue(gsRestartAtEachPage, Any(bRestartNumbering));
237 
238  sal_Int16 nNumType = NumberingType::ARABIC;
240  sNumFormat,
241  sNumLetterSync );
242  xLineNumbering->setPropertyValue(gsNumberingType, Any(nNumType));
243 }
244 
245 css::uno::Reference< css::xml::sax::XFastContextHandler > XMLLineNumberingImportContext::createFastChildContext(
246  sal_Int32 nElement,
247  const css::uno::Reference< css::xml::sax::XFastAttributeList >& )
248 {
249  if ( nElement == XML_ELEMENT(TEXT, XML_LINENUMBERING_SEPARATOR) )
251  return nullptr;
252 }
253 
255  const OUString& sText)
256 {
257  sSeparator = sText;
258 }
259 
261  sal_Int16 nIncr)
262 {
263  nSeparatorIncrement = nIncr;
264 }
265 
266 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
constexpr OUStringLiteral gsSeparatorText(u"SeparatorText")
XMLTokenEnum const aTokenMap[]
Definition: Oasis2OOo.cxx:1145
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
constexpr OUStringLiteral gsSeparatorInterval(u"SeparatorInterval")
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
SvXMLImport & GetImport()
Definition: xmlictxt.hxx:59
constexpr OUStringLiteral gsNumberPosition(u"NumberPosition")
#define XML_TOKEN_MAP_END
Definition: xmltkmap.hxx:33
css::uno::Any const & rValue
Definition: ImageStyle.hxx:38
XmlStyleFamily
Definition: families.hxx:47
virtual void CreateAndInsert(bool bOverwrite) override
constexpr OUStringLiteral gsDistance(u"Distance")
sal_Int16 nNumType
constexpr OUStringLiteral gsIsOn(u"IsOn")
SvXMLStylesContext * GetStyles()
Definition: xmlimp.cxx:1639
virtual void SetAttribute(sal_uInt16 nPrefixKey, const OUString &rLocalName, const OUString &rValue) override
SvXMLEnumMapEntry< sal_uInt16 > const aLineNumberPositionMap[]
void SetSeparatorText(const OUString &sText)
constexpr sal_uInt16 XML_NAMESPACE_TEXT
constexpr OUStringLiteral gsCountLinesInFrames(u"CountLinesInFrames")
sal_uInt16 Get(sal_uInt16 nPrefix, const OUString &rLName) const
Definition: xmltkmap.cxx:99
virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &AttrList) override
LineNumberPosition
exports com.sun.star. style
static bool convertBool(bool &rBool, std::u16string_view rString)
constexpr OUStringLiteral gsCharStyleName(u"CharStyleName")
Map an XMLTokenEnum to an enum value.
Definition: ximpshap.hxx:40
const sal_uInt32 LEFT
constexpr OUStringLiteral gsNumberingType(u"NumberingType")
OUString GetStyleDisplayName(XmlStyleFamily nFamily, const OUString &rName) const
Definition: xmlimp.cxx:1468
const OUString & GetXMLToken(enum XMLTokenEnum eToken)
return the OUString representation for eToken
Definition: xmltoken.cxx:3405
constexpr OUStringLiteral gsCountEmptyLines(u"CountEmptyLines")
Handling of tokens in XML:
#define XML_ELEMENT(prefix, name)
Definition: xmlimp.hxx:94
constexpr OUStringLiteral gsRestartAtEachPage(u"RestartAtEachPage")
const SvXMLUnitConverter & GetMM100UnitConverter() const
Definition: xmlimp.hxx:395
const SvXMLStyleContext * FindStyleChildContext(XmlStyleFamily nFamily, const OUString &rName, bool bCreateIndex=false) const
Definition: xmlstyle.cxx:808
XMLTokenEnum eToken
Definition: xmltoken.cxx:40
TEXT
constexpr OUStringLiteral gsInterval(u"Interval")
constexpr sal_uInt16 XML_NAMESPACE_STYLE
static bool convertNumber(sal_Int32 &rValue, std::u16string_view aString, sal_Int32 nMin=SAL_MIN_INT32, sal_Int32 nMax=SAL_MAX_INT32)
typedef void(CALLTYPE *GetFuncDataPtr)(sal_uInt16 &nNo