Line data Source code
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 : #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>
31 :
32 : using namespace com::sun::star;
33 : using namespace xmloff::token;
34 :
35 0 : ScXMLCalculationSettingsContext::ScXMLCalculationSettingsContext( ScXMLImport& rImport,
36 : sal_uInt16 nPrfx,
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),
42 : nIterationCount(100),
43 : nYear2000(1930),
44 : bIsIterationEnabled(false),
45 : bCalcAsShown(false),
46 : bIgnoreCase(false),
47 : bLookUpLabels(true),
48 : bMatchWholeCell(true),
49 0 : bUseRegularExpressions(true)
50 : {
51 0 : aNullDate.Day = 30;
52 0 : aNullDate.Month = 12;
53 0 : aNullDate.Year = 1899;
54 0 : sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
55 0 : for( sal_Int16 i=0; i < nAttrCount; ++i )
56 : {
57 0 : const OUString& sAttrName(xAttrList->getNameByIndex( i ));
58 0 : OUString aLocalName;
59 0 : sal_uInt16 nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
60 0 : sAttrName, &aLocalName );
61 0 : const OUString& sValue(xAttrList->getValueByIndex( i ));
62 :
63 0 : if (nPrefix == XML_NAMESPACE_TABLE)
64 : {
65 0 : if (IsXMLToken(aLocalName, XML_CASE_SENSITIVE))
66 : {
67 0 : if (IsXMLToken(sValue, XML_FALSE))
68 0 : bIgnoreCase = true;
69 : }
70 0 : else if (IsXMLToken(aLocalName, XML_PRECISION_AS_SHOWN))
71 : {
72 0 : if (IsXMLToken(sValue, XML_TRUE))
73 0 : bCalcAsShown = true;
74 : }
75 0 : else if (IsXMLToken(aLocalName, XML_SEARCH_CRITERIA_MUST_APPLY_TO_WHOLE_CELL))
76 : {
77 0 : if (IsXMLToken(sValue, XML_FALSE))
78 0 : bMatchWholeCell = false;
79 : }
80 0 : else if (IsXMLToken(aLocalName, XML_AUTOMATIC_FIND_LABELS))
81 : {
82 0 : if (IsXMLToken(sValue, XML_FALSE))
83 0 : bLookUpLabels = false;
84 : }
85 0 : else if (IsXMLToken(aLocalName, XML_NULL_YEAR))
86 : {
87 : sal_Int32 nTemp;
88 0 : ::sax::Converter::convertNumber(nTemp, sValue);
89 0 : nYear2000 = static_cast<sal_uInt16>(nTemp);
90 : }
91 0 : else if (IsXMLToken(aLocalName, XML_USE_REGULAR_EXPRESSIONS))
92 : {
93 0 : if (IsXMLToken(sValue, XML_FALSE))
94 0 : bUseRegularExpressions = false;
95 : }
96 : }
97 0 : }
98 0 : }
99 :
100 0 : ScXMLCalculationSettingsContext::~ScXMLCalculationSettingsContext()
101 : {
102 0 : }
103 :
104 0 : 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 )
108 : {
109 0 : SvXMLImportContext *pContext = 0;
110 :
111 0 : if (nPrefix == XML_NAMESPACE_TABLE)
112 : {
113 0 : if (IsXMLToken(rLName, XML_NULL_DATE))
114 0 : pContext = new ScXMLNullDateContext(GetScImport(), nPrefix, rLName, xAttrList, this);
115 0 : else if (IsXMLToken(rLName, XML_ITERATION))
116 0 : pContext = new ScXMLIterationContext(GetScImport(), nPrefix, rLName, xAttrList, this);
117 : }
118 :
119 0 : if( !pContext )
120 0 : pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
121 :
122 0 : return pContext;
123 : }
124 :
125 0 : void ScXMLCalculationSettingsContext::EndElement()
126 : {
127 0 : if (GetScImport().GetModel().is())
128 : {
129 0 : uno::Reference <beans::XPropertySet> xPropertySet (GetScImport().GetModel(), uno::UNO_QUERY);
130 0 : if (xPropertySet.is())
131 : {
132 0 : xPropertySet->setPropertyValue(OUString(SC_UNO_CALCASSHOWN), uno::makeAny(bCalcAsShown) );
133 0 : xPropertySet->setPropertyValue(OUString(SC_UNO_IGNORECASE), uno::makeAny(bIgnoreCase) );
134 0 : xPropertySet->setPropertyValue(OUString(SC_UNO_LOOKUPLABELS), uno::makeAny(bLookUpLabels) );
135 0 : xPropertySet->setPropertyValue(OUString(SC_UNO_MATCHWHOLE), uno::makeAny(bMatchWholeCell) );
136 0 : xPropertySet->setPropertyValue(OUString(SC_UNO_REGEXENABLED), uno::makeAny(bUseRegularExpressions) );
137 0 : xPropertySet->setPropertyValue(OUString(SC_UNO_ITERENABLED), uno::makeAny(bIsIterationEnabled) );
138 0 : xPropertySet->setPropertyValue( OUString(SC_UNO_ITERCOUNT), uno::makeAny(nIterationCount) );
139 0 : xPropertySet->setPropertyValue( OUString(SC_UNO_ITEREPSILON), uno::makeAny(fIterationEpsilon) );
140 0 : xPropertySet->setPropertyValue( OUString(SC_UNO_NULLDATE), uno::makeAny(aNullDate) );
141 0 : if (GetScImport().GetDocument())
142 : {
143 0 : ScXMLImport::MutexGuard aGuard(GetScImport());
144 0 : ScDocOptions aDocOptions (GetScImport().GetDocument()->GetDocOptions());
145 0 : aDocOptions.SetYear2000(nYear2000);
146 0 : GetScImport().GetDocument()->SetDocOptions(aDocOptions);
147 : }
148 0 : }
149 : }
150 0 : }
151 :
152 0 : ScXMLNullDateContext::ScXMLNullDateContext( ScXMLImport& rImport,
153 : sal_uInt16 nPrfx,
154 : const OUString& rLName,
155 : const ::com::sun::star::uno::Reference<
156 : ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
157 : ScXMLCalculationSettingsContext* pCalcSet) :
158 0 : SvXMLImportContext( rImport, nPrfx, rLName )
159 : {
160 0 : sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
161 0 : for( sal_Int16 i=0; i < nAttrCount; ++i )
162 : {
163 0 : const OUString& sAttrName(xAttrList->getNameByIndex( i ));
164 0 : OUString aLocalName;
165 0 : sal_uInt16 nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
166 0 : sAttrName, &aLocalName );
167 0 : const OUString& sValue(xAttrList->getValueByIndex( i ));
168 :
169 0 : if (nPrefix == XML_NAMESPACE_TABLE && IsXMLToken(aLocalName, XML_DATE_VALUE))
170 : {
171 0 : util::DateTime aDateTime;
172 0 : ::sax::Converter::parseDateTime(aDateTime, 0, sValue);
173 0 : util::Date aDate;
174 0 : aDate.Day = aDateTime.Day;
175 0 : aDate.Month = aDateTime.Month;
176 0 : aDate.Year = aDateTime.Year;
177 0 : pCalcSet->SetNullDate(aDate);
178 : }
179 0 : }
180 0 : }
181 :
182 0 : ScXMLNullDateContext::~ScXMLNullDateContext()
183 : {
184 0 : }
185 :
186 0 : 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 */ )
190 : {
191 0 : SvXMLImportContext *pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
192 :
193 0 : return pContext;
194 : }
195 :
196 0 : void ScXMLNullDateContext::EndElement()
197 : {
198 0 : }
199 :
200 0 : ScXMLIterationContext::ScXMLIterationContext( ScXMLImport& rImport,
201 : sal_uInt16 nPrfx,
202 : const OUString& rLName,
203 : const ::com::sun::star::uno::Reference<
204 : ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
205 : ScXMLCalculationSettingsContext* pCalcSet) :
206 0 : SvXMLImportContext( rImport, nPrfx, rLName )
207 : {
208 0 : sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
209 0 : for( sal_Int16 i=0; i < nAttrCount; ++i )
210 : {
211 0 : const OUString& sAttrName(xAttrList->getNameByIndex( i ));
212 0 : OUString aLocalName;
213 0 : sal_uInt16 nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
214 0 : sAttrName, &aLocalName );
215 0 : const OUString& sValue(xAttrList->getValueByIndex( i ));
216 :
217 0 : if (nPrefix == XML_NAMESPACE_TABLE)
218 : {
219 0 : if (IsXMLToken(aLocalName, XML_STATUS))
220 : {
221 0 : if (IsXMLToken(sValue, XML_ENABLE))
222 0 : pCalcSet->SetIterationStatus(true);
223 : }
224 0 : else if (IsXMLToken(aLocalName, XML_STEPS))
225 : {
226 : sal_Int32 nSteps;
227 0 : ::sax::Converter::convertNumber(nSteps, sValue);
228 0 : pCalcSet->SetIterationCount(nSteps);
229 : }
230 0 : else if (IsXMLToken(aLocalName, XML_MAXIMUM_DIFFERENCE))
231 : {
232 : double fDif;
233 0 : ::sax::Converter::convertDouble(fDif, sValue);
234 0 : pCalcSet->SetIterationEpsilon(fDif);
235 : }
236 : }
237 0 : }
238 0 : }
239 :
240 0 : ScXMLIterationContext::~ScXMLIterationContext()
241 : {
242 0 : }
243 :
244 0 : 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 */ )
248 : {
249 0 : SvXMLImportContext *pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
250 :
251 0 : return pContext;
252 : }
253 :
254 0 : void ScXMLIterationContext::EndElement()
255 : {
256 0 : }
257 :
258 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|