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