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 197 : 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 197 : bUseRegularExpressions(true)
50 : {
51 197 : aNullDate.Day = 30;
52 197 : aNullDate.Month = 12;
53 197 : aNullDate.Year = 1899;
54 197 : sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
55 240 : for( sal_Int16 i=0; i < nAttrCount; ++i )
56 : {
57 43 : const OUString& sAttrName(xAttrList->getNameByIndex( i ));
58 86 : OUString aLocalName;
59 43 : sal_uInt16 nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
60 43 : sAttrName, &aLocalName );
61 86 : const OUString& sValue(xAttrList->getValueByIndex( i ));
62 :
63 43 : if (nPrefix == XML_NAMESPACE_TABLE)
64 : {
65 43 : if (IsXMLToken(aLocalName, XML_CASE_SENSITIVE))
66 : {
67 14 : if (IsXMLToken(sValue, XML_FALSE))
68 14 : bIgnoreCase = true;
69 : }
70 29 : else if (IsXMLToken(aLocalName, XML_PRECISION_AS_SHOWN))
71 : {
72 2 : if (IsXMLToken(sValue, XML_TRUE))
73 2 : bCalcAsShown = true;
74 : }
75 27 : 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 27 : else if (IsXMLToken(aLocalName, XML_AUTOMATIC_FIND_LABELS))
81 : {
82 14 : if (IsXMLToken(sValue, XML_FALSE))
83 14 : bLookUpLabels = false;
84 : }
85 13 : 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 13 : else if (IsXMLToken(aLocalName, XML_USE_REGULAR_EXPRESSIONS))
92 : {
93 13 : if (IsXMLToken(sValue, XML_FALSE))
94 13 : bUseRegularExpressions = false;
95 : }
96 : }
97 43 : }
98 197 : }
99 :
100 225 : ScXMLCalculationSettingsContext::~ScXMLCalculationSettingsContext()
101 : {
102 225 : }
103 :
104 17 : 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 17 : SvXMLImportContext *pContext = 0;
110 :
111 17 : if (nPrefix == XML_NAMESPACE_TABLE)
112 : {
113 17 : if (IsXMLToken(rLName, XML_NULL_DATE))
114 8 : pContext = new ScXMLNullDateContext(GetScImport(), nPrefix, rLName, xAttrList, this);
115 9 : else if (IsXMLToken(rLName, XML_ITERATION))
116 9 : pContext = new ScXMLIterationContext(GetScImport(), nPrefix, rLName, xAttrList, this);
117 : }
118 :
119 17 : if( !pContext )
120 0 : pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
121 :
122 17 : return pContext;
123 : }
124 :
125 197 : void ScXMLCalculationSettingsContext::EndElement()
126 : {
127 197 : if (GetScImport().GetModel().is())
128 : {
129 197 : uno::Reference <beans::XPropertySet> xPropertySet (GetScImport().GetModel(), uno::UNO_QUERY);
130 197 : if (xPropertySet.is())
131 : {
132 197 : xPropertySet->setPropertyValue(OUString(SC_UNO_CALCASSHOWN), uno::makeAny(bCalcAsShown) );
133 197 : xPropertySet->setPropertyValue(OUString(SC_UNO_IGNORECASE), uno::makeAny(bIgnoreCase) );
134 197 : xPropertySet->setPropertyValue(OUString(SC_UNO_LOOKUPLABELS), uno::makeAny(bLookUpLabels) );
135 197 : xPropertySet->setPropertyValue(OUString(SC_UNO_MATCHWHOLE), uno::makeAny(bMatchWholeCell) );
136 197 : xPropertySet->setPropertyValue(OUString(SC_UNO_REGEXENABLED), uno::makeAny(bUseRegularExpressions) );
137 197 : xPropertySet->setPropertyValue(OUString(SC_UNO_ITERENABLED), uno::makeAny(bIsIterationEnabled) );
138 197 : xPropertySet->setPropertyValue( OUString(SC_UNO_ITERCOUNT), uno::makeAny(nIterationCount) );
139 197 : xPropertySet->setPropertyValue( OUString(SC_UNO_ITEREPSILON), uno::makeAny(fIterationEpsilon) );
140 197 : xPropertySet->setPropertyValue( OUString(SC_UNO_NULLDATE), uno::makeAny(aNullDate) );
141 197 : if (GetScImport().GetDocument())
142 : {
143 197 : ScXMLImport::MutexGuard aGuard(GetScImport());
144 394 : ScDocOptions aDocOptions (GetScImport().GetDocument()->GetDocOptions());
145 197 : aDocOptions.SetYear2000(nYear2000);
146 394 : GetScImport().GetDocument()->SetDocOptions(aDocOptions);
147 : }
148 197 : }
149 : }
150 197 : }
151 :
152 8 : 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 8 : SvXMLImportContext( rImport, nPrfx, rLName )
159 : {
160 8 : sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
161 16 : for( sal_Int16 i=0; i < nAttrCount; ++i )
162 : {
163 8 : const OUString& sAttrName(xAttrList->getNameByIndex( i ));
164 16 : OUString aLocalName;
165 8 : sal_uInt16 nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
166 8 : sAttrName, &aLocalName );
167 16 : const OUString& sValue(xAttrList->getValueByIndex( i ));
168 :
169 8 : if (nPrefix == XML_NAMESPACE_TABLE && IsXMLToken(aLocalName, XML_DATE_VALUE))
170 : {
171 8 : util::DateTime aDateTime;
172 8 : ::sax::Converter::parseDateTime(aDateTime, 0, sValue);
173 8 : util::Date aDate;
174 8 : aDate.Day = aDateTime.Day;
175 8 : aDate.Month = aDateTime.Month;
176 8 : aDate.Year = aDateTime.Year;
177 8 : pCalcSet->SetNullDate(aDate);
178 : }
179 8 : }
180 8 : }
181 :
182 16 : ScXMLNullDateContext::~ScXMLNullDateContext()
183 : {
184 16 : }
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 8 : void ScXMLNullDateContext::EndElement()
197 : {
198 8 : }
199 :
200 9 : 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 9 : SvXMLImportContext( rImport, nPrfx, rLName )
207 : {
208 9 : sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
209 22 : for( sal_Int16 i=0; i < nAttrCount; ++i )
210 : {
211 13 : const OUString& sAttrName(xAttrList->getNameByIndex( i ));
212 26 : OUString aLocalName;
213 13 : sal_uInt16 nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
214 13 : sAttrName, &aLocalName );
215 26 : const OUString& sValue(xAttrList->getValueByIndex( i ));
216 :
217 13 : if (nPrefix == XML_NAMESPACE_TABLE)
218 : {
219 13 : if (IsXMLToken(aLocalName, XML_STATUS))
220 : {
221 3 : if (IsXMLToken(sValue, XML_ENABLE))
222 3 : pCalcSet->SetIterationStatus(true);
223 : }
224 10 : else if (IsXMLToken(aLocalName, XML_STEPS))
225 : {
226 : sal_Int32 nSteps;
227 3 : ::sax::Converter::convertNumber(nSteps, sValue);
228 3 : pCalcSet->SetIterationCount(nSteps);
229 : }
230 7 : else if (IsXMLToken(aLocalName, XML_MAXIMUM_DIFFERENCE))
231 : {
232 : double fDif;
233 7 : ::sax::Converter::convertDouble(fDif, sValue);
234 7 : pCalcSet->SetIterationEpsilon(fDif);
235 : }
236 : }
237 13 : }
238 9 : }
239 :
240 18 : ScXMLIterationContext::~ScXMLIterationContext()
241 : {
242 18 : }
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 9 : void ScXMLIterationContext::EndElement()
255 : {
256 165 : }
257 :
258 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|