LanguageTool: don't crash if REST protocol isn't set
[LibreOffice.git] / xmloff / source / text / XMLIndexTabStopEntryContext.cxx
blob528b72a7a33a616b59a6709dd4ecbfb0e3e8130e
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include "XMLIndexTabStopEntryContext.hxx"
23 #include <sax/tools/converter.hxx>
25 #include "XMLIndexTemplateContext.hxx"
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>
34 using namespace ::xmloff::token;
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;
42 XMLIndexTabStopEntryContext::XMLIndexTabStopEntryContext(
43 SvXMLImport& rImport,
44 XMLIndexTemplateContext& rTemplate ) :
45 XMLIndexSimpleEntryContext(rImport, "TokenTabStop",
46 rTemplate),
47 nTabPosition(0),
48 bTabPositionOK(false),
49 bTabRightAligned(false),
50 bLeaderCharOK(false),
51 bWithTab(true) // #i21237#
55 XMLIndexTabStopEntryContext::~XMLIndexTabStopEntryContext()
59 void XMLIndexTabStopEntryContext::startFastElement(
60 sal_Int32 nElement,
61 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
63 // process three attributes: type, position, leader char
64 for( auto& aIter : sax_fastparser::castToFastAttributeList(xAttrList) )
66 switch(aIter.getToken())
68 case XML_ELEMENT(STYLE, XML_TYPE):
70 // if it's neither left nor right, value is
71 // ignored. Since left is default, we only need to
72 // check for right
73 bTabRightAligned = IsXMLToken( aIter, XML_RIGHT );
74 break;
76 case XML_ELEMENT(STYLE, XML_POSITION):
78 sal_Int32 nTmp;
79 if (GetImport().GetMM100UnitConverter().
80 convertMeasureToCore(nTmp, aIter.toView()))
82 nTabPosition = nTmp;
83 bTabPositionOK = true;
85 break;
87 case XML_ELEMENT(STYLE, XML_LEADER_CHAR):
89 sLeaderChar = aIter.toString();
90 // valid only, if we have a char!
91 bLeaderCharOK = !sLeaderChar.isEmpty();
92 break;
94 case XML_ELEMENT(STYLE, XML_WITH_TAB):
96 // #i21237#
97 bool bTmp(false);
98 if (::sax::Converter::convertBool(bTmp, aIter.toView()))
99 bWithTab = bTmp;
100 break;
102 default:
103 XMLOFF_WARN_UNKNOWN("xmloff", aIter);
104 // else: unknown style: attribute -> ignore
108 // how many entries? #i21237#
109 m_nValues += 2 + (bTabPositionOK ? 1 : 0) + (bLeaderCharOK ? 1 : 0);
111 // now try parent class (for character style)
112 XMLIndexSimpleEntryContext::startFastElement( nElement, xAttrList );
115 void XMLIndexTabStopEntryContext::FillPropertyValues(
116 Sequence<PropertyValue> & rValues)
118 // fill values from parent class (type + style name)
119 XMLIndexSimpleEntryContext::FillPropertyValues(rValues);
121 // get values array and next entry to be written;
122 sal_Int32 nNextEntry = m_bCharStyleNameOK ? 2 : 1;
123 PropertyValue* pValues = rValues.getArray();
125 // right aligned?
126 pValues[nNextEntry].Name = "TabStopRightAligned";
127 pValues[nNextEntry].Value <<= bTabRightAligned;
128 nNextEntry++;
130 // position
131 if (bTabPositionOK)
133 pValues[nNextEntry].Name = "TabStopPosition";
134 pValues[nNextEntry].Value <<= nTabPosition;
135 nNextEntry++;
138 // leader char
139 if (bLeaderCharOK)
141 pValues[nNextEntry].Name = "TabStopFillCharacter";
142 pValues[nNextEntry].Value <<= sLeaderChar;
143 nNextEntry++;
146 // tab character #i21237#
147 pValues[nNextEntry].Name = "WithTab";
148 pValues[nNextEntry].Value <<= bWithTab;
149 nNextEntry++;
151 // check whether we really filled all elements of the sequence
152 SAL_WARN_IF( nNextEntry != rValues.getLength(), "xmloff",
153 "length incorrectly precomputed!" );
156 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */