1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
20 #include "XMLCalculationSettingsContext.hxx"
21 #include "xmlimprt.hxx"
22 #include "unonames.hxx"
23 #include "docoptio.hxx"
24 #include "document.hxx"
25 #include <xmloff/xmltoken.hxx>
26 #include <xmloff/xmlnmspe.hxx>
27 #include <xmloff/nmspmap.hxx>
28 #include <sax/tools/converter.hxx>
29 #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
30 #include <comphelper/extract.hxx>
32 using namespace com::sun::star
;
33 using namespace xmloff::token
;
35 ScXMLCalculationSettingsContext::ScXMLCalculationSettingsContext( ScXMLImport
& rImport
,
37 const OUString
& rLName
,
38 const ::com::sun::star::uno::Reference
<
39 ::com::sun::star::xml::sax::XAttributeList
>& xAttrList
) :
40 SvXMLImportContext( rImport
, nPrfx
, rLName
),
41 fIterationEpsilon(0.001),
44 bIsIterationEnabled(false),
48 bMatchWholeCell(true),
49 bUseRegularExpressions(true)
53 aNullDate
.Year
= 1899;
54 sal_Int16 nAttrCount
= xAttrList
.is() ? xAttrList
->getLength() : 0;
55 for( sal_Int16 i
=0; i
< nAttrCount
; ++i
)
57 const OUString
& sAttrName(xAttrList
->getNameByIndex( i
));
59 sal_uInt16 nPrefix
= GetScImport().GetNamespaceMap().GetKeyByAttrName(
60 sAttrName
, &aLocalName
);
61 const OUString
& sValue(xAttrList
->getValueByIndex( i
));
63 if (nPrefix
== XML_NAMESPACE_TABLE
)
65 if (IsXMLToken(aLocalName
, XML_CASE_SENSITIVE
))
67 if (IsXMLToken(sValue
, XML_FALSE
))
70 else if (IsXMLToken(aLocalName
, XML_PRECISION_AS_SHOWN
))
72 if (IsXMLToken(sValue
, XML_TRUE
))
75 else if (IsXMLToken(aLocalName
, XML_SEARCH_CRITERIA_MUST_APPLY_TO_WHOLE_CELL
))
77 if (IsXMLToken(sValue
, XML_FALSE
))
78 bMatchWholeCell
= false;
80 else if (IsXMLToken(aLocalName
, XML_AUTOMATIC_FIND_LABELS
))
82 if (IsXMLToken(sValue
, XML_FALSE
))
83 bLookUpLabels
= false;
85 else if (IsXMLToken(aLocalName
, XML_NULL_YEAR
))
88 ::sax::Converter::convertNumber(nTemp
, sValue
);
89 nYear2000
= static_cast<sal_uInt16
>(nTemp
);
91 else if (IsXMLToken(aLocalName
, XML_USE_REGULAR_EXPRESSIONS
))
93 if (IsXMLToken(sValue
, XML_FALSE
))
94 bUseRegularExpressions
= false;
100 ScXMLCalculationSettingsContext::~ScXMLCalculationSettingsContext()
104 SvXMLImportContext
*ScXMLCalculationSettingsContext::CreateChildContext( sal_uInt16 nPrefix
,
105 const OUString
& rLName
,
106 const ::com::sun::star::uno::Reference
<
107 ::com::sun::star::xml::sax::XAttributeList
>& xAttrList
)
109 SvXMLImportContext
*pContext
= 0;
111 if (nPrefix
== XML_NAMESPACE_TABLE
)
113 if (IsXMLToken(rLName
, XML_NULL_DATE
))
114 pContext
= new ScXMLNullDateContext(GetScImport(), nPrefix
, rLName
, xAttrList
, this);
115 else if (IsXMLToken(rLName
, XML_ITERATION
))
116 pContext
= new ScXMLIterationContext(GetScImport(), nPrefix
, rLName
, xAttrList
, this);
120 pContext
= new SvXMLImportContext( GetImport(), nPrefix
, rLName
);
125 void ScXMLCalculationSettingsContext::EndElement()
127 if (GetScImport().GetModel().is())
129 uno::Reference
<beans::XPropertySet
> xPropertySet (GetScImport().GetModel(), uno::UNO_QUERY
);
130 if (xPropertySet
.is())
132 xPropertySet
->setPropertyValue(OUString(SC_UNO_CALCASSHOWN
), uno::makeAny(bCalcAsShown
) );
133 xPropertySet
->setPropertyValue(OUString(SC_UNO_IGNORECASE
), uno::makeAny(bIgnoreCase
) );
134 xPropertySet
->setPropertyValue(OUString(SC_UNO_LOOKUPLABELS
), uno::makeAny(bLookUpLabels
) );
135 xPropertySet
->setPropertyValue(OUString(SC_UNO_MATCHWHOLE
), uno::makeAny(bMatchWholeCell
) );
136 xPropertySet
->setPropertyValue(OUString(SC_UNO_REGEXENABLED
), uno::makeAny(bUseRegularExpressions
) );
137 xPropertySet
->setPropertyValue(OUString(SC_UNO_ITERENABLED
), uno::makeAny(bIsIterationEnabled
) );
138 xPropertySet
->setPropertyValue( OUString(SC_UNO_ITERCOUNT
), uno::makeAny(nIterationCount
) );
139 xPropertySet
->setPropertyValue( OUString(SC_UNO_ITEREPSILON
), uno::makeAny(fIterationEpsilon
) );
140 xPropertySet
->setPropertyValue( OUString(SC_UNO_NULLDATE
), uno::makeAny(aNullDate
) );
141 if (GetScImport().GetDocument())
143 ScXMLImport::MutexGuard
aGuard(GetScImport());
144 ScDocOptions
aDocOptions (GetScImport().GetDocument()->GetDocOptions());
145 aDocOptions
.SetYear2000(nYear2000
);
146 GetScImport().GetDocument()->SetDocOptions(aDocOptions
);
152 ScXMLNullDateContext::ScXMLNullDateContext( ScXMLImport
& rImport
,
154 const OUString
& rLName
,
155 const ::com::sun::star::uno::Reference
<
156 ::com::sun::star::xml::sax::XAttributeList
>& xAttrList
,
157 ScXMLCalculationSettingsContext
* pCalcSet
) :
158 SvXMLImportContext( rImport
, nPrfx
, rLName
)
160 sal_Int16 nAttrCount
= xAttrList
.is() ? xAttrList
->getLength() : 0;
161 for( sal_Int16 i
=0; i
< nAttrCount
; ++i
)
163 const OUString
& sAttrName(xAttrList
->getNameByIndex( i
));
165 sal_uInt16 nPrefix
= GetScImport().GetNamespaceMap().GetKeyByAttrName(
166 sAttrName
, &aLocalName
);
167 const OUString
& sValue(xAttrList
->getValueByIndex( i
));
169 if (nPrefix
== XML_NAMESPACE_TABLE
&& IsXMLToken(aLocalName
, XML_DATE_VALUE
))
171 util::DateTime aDateTime
;
172 ::sax::Converter::parseDateTime(aDateTime
, 0, sValue
);
174 aDate
.Day
= aDateTime
.Day
;
175 aDate
.Month
= aDateTime
.Month
;
176 aDate
.Year
= aDateTime
.Year
;
177 pCalcSet
->SetNullDate(aDate
);
182 ScXMLNullDateContext::~ScXMLNullDateContext()
186 SvXMLImportContext
*ScXMLNullDateContext::CreateChildContext( sal_uInt16 nPrefix
,
187 const OUString
& rLName
,
188 const ::com::sun::star::uno::Reference
<
189 ::com::sun::star::xml::sax::XAttributeList
>& /* xAttrList */ )
191 SvXMLImportContext
*pContext
= new SvXMLImportContext( GetImport(), nPrefix
, rLName
);
196 void ScXMLNullDateContext::EndElement()
200 ScXMLIterationContext::ScXMLIterationContext( ScXMLImport
& rImport
,
202 const OUString
& rLName
,
203 const ::com::sun::star::uno::Reference
<
204 ::com::sun::star::xml::sax::XAttributeList
>& xAttrList
,
205 ScXMLCalculationSettingsContext
* pCalcSet
) :
206 SvXMLImportContext( rImport
, nPrfx
, rLName
)
208 sal_Int16 nAttrCount
= xAttrList
.is() ? xAttrList
->getLength() : 0;
209 for( sal_Int16 i
=0; i
< nAttrCount
; ++i
)
211 const OUString
& sAttrName(xAttrList
->getNameByIndex( i
));
213 sal_uInt16 nPrefix
= GetScImport().GetNamespaceMap().GetKeyByAttrName(
214 sAttrName
, &aLocalName
);
215 const OUString
& sValue(xAttrList
->getValueByIndex( i
));
217 if (nPrefix
== XML_NAMESPACE_TABLE
)
219 if (IsXMLToken(aLocalName
, XML_STATUS
))
221 if (IsXMLToken(sValue
, XML_ENABLE
))
222 pCalcSet
->SetIterationStatus(true);
224 else if (IsXMLToken(aLocalName
, XML_STEPS
))
227 ::sax::Converter::convertNumber(nSteps
, sValue
);
228 pCalcSet
->SetIterationCount(nSteps
);
230 else if (IsXMLToken(aLocalName
, XML_MAXIMUM_DIFFERENCE
))
233 ::sax::Converter::convertDouble(fDif
, sValue
);
234 pCalcSet
->SetIterationEpsilon(fDif
);
240 ScXMLIterationContext::~ScXMLIterationContext()
244 SvXMLImportContext
*ScXMLIterationContext::CreateChildContext( sal_uInt16 nPrefix
,
245 const OUString
& rLName
,
246 const ::com::sun::star::uno::Reference
<
247 ::com::sun::star::xml::sax::XAttributeList
>& /* xAttrList */ )
249 SvXMLImportContext
*pContext
= new SvXMLImportContext( GetImport(), nPrefix
, rLName
);
254 void ScXMLIterationContext::EndElement()
258 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */