LibreOffice Module xmloff (master)  1
XMLIndexTabStopEntryContext.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 <sax/tools/converter.hxx>
24 
26 #include <xmloff/xmlimp.hxx>
27 #include <xmloff/namespacemap.hxx>
28 #include <xmloff/xmlnamespace.hxx>
29 #include <xmloff/xmltoken.hxx>
30 #include <xmloff/xmluconv.hxx>
31 #include <rtl/ustring.hxx>
32 #include <sal/log.hxx>
33 
34 using namespace ::xmloff::token;
35 
36 using ::com::sun::star::uno::Sequence;
37 using ::com::sun::star::uno::Reference;
38 using ::com::sun::star::beans::PropertyValue;
39 using ::com::sun::star::xml::sax::XAttributeList;
40 
41 
43  SvXMLImport& rImport,
44  XMLIndexTemplateContext& rTemplate,
45  sal_uInt16 nPrfx,
46  const OUString& rLocalName ) :
47  XMLIndexSimpleEntryContext(rImport, "TokenTabStop",
48  rTemplate, nPrfx, rLocalName),
49  sLeaderChar(),
50  nTabPosition(0),
51  bTabPositionOK(false),
52  bTabRightAligned(false),
53  bLeaderCharOK(false),
54  bWithTab(true) // #i21237#
55 {
56 }
57 
59 {
60 }
61 
63  const Reference<XAttributeList> & xAttrList)
64 {
65  // process three attributes: type, position, leader char
66  sal_Int16 nLength = xAttrList->getLength();
67  for(sal_Int16 nAttr = 0; nAttr < nLength; nAttr++)
68  {
69  OUString sLocalName;
70  sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
71  GetKeyByAttrName( xAttrList->getNameByIndex(nAttr),
72  &sLocalName );
73  OUString sAttr = xAttrList->getValueByIndex(nAttr);
74  if (XML_NAMESPACE_STYLE == nPrefix)
75  {
76  if ( IsXMLToken( sLocalName, XML_TYPE ) )
77  {
78  // if it's neither left nor right, value is
79  // ignored. Since left is default, we only need to
80  // check for right
82  }
83  else if ( IsXMLToken( sLocalName, XML_POSITION ) )
84  {
85  sal_Int32 nTmp;
86  if (GetImport().GetMM100UnitConverter().
87  convertMeasureToCore(nTmp, sAttr))
88  {
89  nTabPosition = nTmp;
90  bTabPositionOK = true;
91  }
92  }
93  else if ( IsXMLToken( sLocalName, XML_LEADER_CHAR ) )
94  {
95  sLeaderChar = sAttr;
96  // valid only, if we have a char!
97  bLeaderCharOK = !sAttr.isEmpty();
98  }
99  // #i21237#
100  else if ( IsXMLToken( sLocalName, XML_WITH_TAB ) )
101  {
102  bool bTmp(false);
103  if (::sax::Converter::convertBool(bTmp, sAttr))
104  bWithTab = bTmp;
105  }
106  // else: unknown style: attribute -> ignore
107  }
108  // else: no style attribute -> ignore
109  }
110 
111  // how many entries? #i21237#
112  m_nValues += 2 + (bTabPositionOK ? 1 : 0) + (bLeaderCharOK ? 1 : 0);
113 
114  // now try parent class (for character style)
116 }
117 
119  Sequence<PropertyValue> & rValues)
120 {
121  // fill values from parent class (type + style name)
123 
124  // get values array and next entry to be written;
125  sal_Int32 nNextEntry = m_bCharStyleNameOK ? 2 : 1;
126  PropertyValue* pValues = rValues.getArray();
127 
128  // right aligned?
129  pValues[nNextEntry].Name = "TabStopRightAligned";
130  pValues[nNextEntry].Value <<= bTabRightAligned;
131  nNextEntry++;
132 
133  // position
134  if (bTabPositionOK)
135  {
136  pValues[nNextEntry].Name = "TabStopPosition";
137  pValues[nNextEntry].Value <<= nTabPosition;
138  nNextEntry++;
139  }
140 
141  // leader char
142  if (bLeaderCharOK)
143  {
144  pValues[nNextEntry].Name = "TabStopFillCharacter";
145  pValues[nNextEntry].Value <<= sLeaderChar;
146  nNextEntry++;
147  }
148 
149  // tab character #i21237#
150  pValues[nNextEntry].Name = "WithTab";
151  pValues[nNextEntry].Value <<= bWithTab;
152  nNextEntry++;
153 
154  // check whether we really filled all elements of the sequence
155  SAL_WARN_IF( nNextEntry != rValues.getLength(), "xmloff",
156  "length incorrectly precomputed!" );
157 }
158 
159 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool IsXMLToken(const OUString &rString, enum XMLTokenEnum eToken)
compare eToken to the string
Definition: xmltoken.cxx:3434
static bool convertBool(bool &rBool, const OUString &rString)
sal_Int32 nTabPosition
fill ("leader") character
virtual void FillPropertyValues(css::uno::Sequence< css::beans::PropertyValue > &rValues)
fill property values for this template entry
SvXMLImport & GetImport()
Definition: xmlictxt.hxx:62
Import index entry templates.
SvXMLNamespaceMap & GetNamespaceMap()
Definition: xmlimp.hxx:402
virtual void FillPropertyValues(css::uno::Sequence< css::beans::PropertyValue > &rValues) override
fill property values for this template entry
virtual void StartElement(const css::uno::Reference< css::xml::sax::XAttributeList > &xAttrList) override
process parameters
virtual void StartElement(const css::uno::Reference< css::xml::sax::XAttributeList > &xAttrList) override
process parameters
XMLIndexTabStopEntryContext(SvXMLImport &rImport, XMLIndexTemplateContext &rTemplate, sal_uInt16 nPrfx, const OUString &rLocalName)
is tab char present? #i21237#
Import index entry templates.
const PropertyValue * pValues
bool bTabRightAligned
is tab right aligned?
#define SAL_WARN_IF(condition, area, stream)
Handling of tokens in XML:
bool bLeaderCharOK
is nTabPosition valid?
sal_Int32 nLength
Definition: xmltoken.cxx:36
constexpr sal_uInt16 XML_NAMESPACE_STYLE