LibreOffice Module sc (master) 1
XMLCalculationSettingsContext.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#include "xmlimprt.hxx"
22#include <unonames.hxx>
23#include <docoptio.hxx>
24#include <document.hxx>
25#include <xmloff/xmltoken.hxx>
28
29#include <com/sun/star/beans/XPropertySet.hpp>
30#include <com/sun/star/frame/XModel.hpp>
31
32using namespace com::sun::star;
33using namespace xmloff::token;
34
37 ScXMLImportContext( rImport ),
38 fIterationEpsilon(0.001),
39 nIterationCount(100),
40 nYear2000(1930),
41 eSearchType(utl::SearchParam::SearchType::Regexp),
42 bIsIterationEnabled(false),
43 bCalcAsShown(false),
44 bIgnoreCase(false),
45 bLookUpLabels(true),
46 bMatchWholeCell(true)
47{
48 aNullDate.Day = 30;
49 aNullDate.Month = 12;
50 aNullDate.Year = 1899;
51 if ( !rAttrList.is() )
52 return;
53
54 for (auto &aIter : *rAttrList)
55 {
56 switch (aIter.getToken())
57 {
59 if( IsXMLToken( aIter, XML_FALSE ) )
60 bIgnoreCase = true;
61 break;
63 if( IsXMLToken( aIter, XML_TRUE ) )
64 bCalcAsShown = true;
65 break;
67 if( IsXMLToken( aIter, XML_FALSE ) )
68 bMatchWholeCell = false;
69 break;
71 if( IsXMLToken( aIter, XML_FALSE ) )
72 bLookUpLabels = false;
73 break;
75 sal_Int32 nTemp;
76 ::sax::Converter::convertNumber( nTemp, aIter.toView() );
77 nYear2000 = static_cast<sal_uInt16>(nTemp);
78 break;
80 // Overwrite only the default (regex true) value, not wildcard.
83 break;
85 if( IsXMLToken( aIter, XML_TRUE ) )
87 break;
88 }
89 }
90}
91
93{
94}
95
96uno::Reference< xml::sax::XFastContextHandler > SAL_CALL ScXMLCalculationSettingsContext::createFastChildContext(
97 sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
98{
99 SvXMLImportContext *pContext = nullptr;
102
103 if (nElement == XML_ELEMENT( TABLE, XML_NULL_DATE ))
104 pContext = new ScXMLNullDateContext(GetScImport(), pAttribList, this);
105 else if (nElement == XML_ELEMENT( TABLE, XML_ITERATION ))
106 pContext = new ScXMLIterationContext(GetScImport(), pAttribList, this);
107
108 return pContext;
109}
110
111void SAL_CALL ScXMLCalculationSettingsContext::endFastElement( sal_Int32 /*nElement*/ )
112{
113 if (!GetScImport().GetModel().is())
114 return;
115
116 uno::Reference <beans::XPropertySet> xPropertySet (GetScImport().GetModel(), uno::UNO_QUERY);
117 if (!xPropertySet.is())
118 return;
119
120 xPropertySet->setPropertyValue( SC_UNO_CALCASSHOWN, uno::Any(bCalcAsShown) );
121 xPropertySet->setPropertyValue( SC_UNO_IGNORECASE, uno::Any(bIgnoreCase) );
122 xPropertySet->setPropertyValue( SC_UNO_LOOKUPLABELS, uno::Any(bLookUpLabels) );
123 xPropertySet->setPropertyValue( SC_UNO_MATCHWHOLE, uno::Any(bMatchWholeCell) );
124 bool bWildcards, bRegex;
125 utl::SearchParam::ConvertToBool( eSearchType, bWildcards, bRegex);
126 xPropertySet->setPropertyValue( SC_UNO_REGEXENABLED, uno::Any(bRegex) );
127 xPropertySet->setPropertyValue( SC_UNO_WILDCARDSENABLED, uno::Any(bWildcards) );
128 xPropertySet->setPropertyValue( SC_UNO_ITERENABLED, uno::Any(bIsIterationEnabled) );
129 xPropertySet->setPropertyValue( SC_UNO_ITERCOUNT, uno::Any(nIterationCount) );
130 xPropertySet->setPropertyValue( SC_UNO_ITEREPSILON, uno::Any(fIterationEpsilon) );
131 xPropertySet->setPropertyValue( SC_UNO_NULLDATE, uno::Any(aNullDate) );
132 if (GetScImport().GetDocument())
133 {
135 ScDocOptions aDocOptions (GetScImport().GetDocument()->GetDocOptions());
136 aDocOptions.SetYear2000(nYear2000);
137 GetScImport().GetDocument()->SetDocOptions(aDocOptions);
138 }
139}
140
144 ScXMLImportContext( rImport )
145{
146 if ( !rAttrList.is() )
147 return;
148
149 auto aIter( rAttrList->find( XML_ELEMENT( TABLE, XML_DATE_VALUE ) ) );
150 if (aIter != rAttrList->end())
151 {
152 util::DateTime aDateTime;
153 if (::sax::Converter::parseDateTime(aDateTime, aIter.toView()))
154 {
155 util::Date aDate;
156 aDate.Day = aDateTime.Day;
157 aDate.Month = aDateTime.Month;
158 aDate.Year = aDateTime.Year;
159 pCalcSet->SetNullDate(aDate);
160 }
161 else
162 {
163 SAL_WARN("sc.filter","ignoring invalid NullDate '" << aIter.toView() << "'");
164 }
165 }
166}
167
169{
170}
171
175 ScXMLImportContext( rImport )
176{
177 if ( !rAttrList.is() )
178 return;
179
180 for (auto &aIter : *rAttrList)
181 {
182 switch (aIter.getToken())
183 {
185 if (IsXMLToken(aIter, XML_ENABLE))
186 pCalcSet->SetIterationStatus(true);
187 break;
188 case XML_ELEMENT( TABLE, XML_STEPS ):
189 pCalcSet->SetIterationCount(aIter.toInt32());
190 break;
192 pCalcSet->SetIterationEpsilon( aIter.toDouble() );
193 break;
194 }
195 }
196}
197
199{
200}
201
202/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void SetYear2000(sal_uInt16 nVal)
Definition: docoptio.hxx:84
SC_DLLPUBLIC void SetDocOptions(const ScDocOptions &rOpt)
Definition: documen3.cxx:1960
void SetIterationCount(const sal_Int32 nValue)
virtual void SAL_CALL endFastElement(sal_Int32 Element) override
virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList) override
ScXMLCalculationSettingsContext(ScXMLImport &rImport, const rtl::Reference< sax_fastparser::FastAttributeList > &rAttrList)
void SetNullDate(const css::util::Date &aDate)
This class exists only to provide GetScImport() to its derived classes.
ScXMLImport & GetScImport()
Use this class to manage solar mutex locking instead of calling LockSolarMutex() and UnlockSolarMutex...
Definition: xmlimprt.hxx:289
ScDocument * GetDocument()
Definition: xmlimprt.hxx:205
ScXMLIterationContext(ScXMLImport &rImport, const rtl::Reference< sax_fastparser::FastAttributeList > &rAttrList, ScXMLCalculationSettingsContext *pCalcSet)
ScXMLNullDateContext(ScXMLImport &rImport, const rtl::Reference< sax_fastparser::FastAttributeList > &rAttrList, ScXMLCalculationSettingsContext *pCalcSet)
static bool parseDateTime(css::util::DateTime &rDateTime, std::u16string_view rString)
static bool convertNumber(sal_Int32 &rValue, std::u16string_view aString, sal_Int32 nMin=SAL_MIN_INT32, sal_Int32 nMax=SAL_MAX_INT32)
static void ConvertToBool(const SearchType eSearchType, bool &rbWildcard, bool &rbRegExp)
#define SAL_WARN(area, stream)
TABLE
FastAttributeList & castToFastAttributeList(const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
XML_STATUS
XML_STEPS
XML_ENABLE
XML_DATE_VALUE
XML_NULL_YEAR
XML_CASE_SENSITIVE
XML_TRUE
XML_AUTOMATIC_FIND_LABELS
XML_USE_WILDCARDS
XML_MAXIMUM_DIFFERENCE
XML_ITERATION
XML_PRECISION_AS_SHOWN
XML_FALSE
XML_SEARCH_CRITERIA_MUST_APPLY_TO_WHOLE_CELL
XML_NULL_DATE
XML_USE_REGULAR_EXPRESSIONS
bool IsXMLToken(std::u16string_view rString, enum XMLTokenEnum eToken)
#define SC_UNO_NULLDATE
Definition: unonames.hxx:513
#define SC_UNO_WILDCARDSENABLED
Definition: unonames.hxx:517
#define SC_UNO_IGNORECASE
Definition: unonames.hxx:507
#define SC_UNO_ITERCOUNT
Definition: unonames.hxx:508
#define SC_UNO_REGEXENABLED
Definition: unonames.hxx:516
#define SC_UNO_LOOKUPLABELS
Definition: unonames.hxx:511
#define SC_UNO_ITERENABLED
Definition: unonames.hxx:509
#define SC_UNO_CALCASSHOWN
Definition: unonames.hxx:504
#define SC_UNO_ITEREPSILON
Definition: unonames.hxx:510
#define SC_UNO_MATCHWHOLE
Definition: unonames.hxx:512
#define XML_ELEMENT(prefix, name)