Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include "XMLCalculationSettingsContext.hxx"
30 : : #include "xmlimprt.hxx"
31 : : #include "unonames.hxx"
32 : : #include "docoptio.hxx"
33 : : #include "document.hxx"
34 : : #include <xmloff/xmltoken.hxx>
35 : : #include <xmloff/xmlnmspe.hxx>
36 : : #include <xmloff/nmspmap.hxx>
37 : : #include <sax/tools/converter.hxx>
38 : : #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
39 : : #include <comphelper/extract.hxx>
40 : :
41 : : using namespace com::sun::star;
42 : : using namespace xmloff::token;
43 : :
44 : : //------------------------------------------------------------------
45 : :
46 : 93 : ScXMLCalculationSettingsContext::ScXMLCalculationSettingsContext( ScXMLImport& rImport,
47 : : sal_uInt16 nPrfx,
48 : : const ::rtl::OUString& rLName,
49 : : const ::com::sun::star::uno::Reference<
50 : : ::com::sun::star::xml::sax::XAttributeList>& xAttrList) :
51 : : SvXMLImportContext( rImport, nPrfx, rLName ),
52 : : fIterationEpsilon(0.001),
53 : : nIterationCount(100),
54 : : nYear2000(1930),
55 : : bIsIterationEnabled(false),
56 : : bCalcAsShown(false),
57 : : bIgnoreCase(false),
58 : : bLookUpLabels(true),
59 : : bMatchWholeCell(true),
60 : 93 : bUseRegularExpressions(true)
61 : : {
62 : 93 : aNullDate.Day = 30;
63 : 93 : aNullDate.Month = 12;
64 : 93 : aNullDate.Year = 1899;
65 [ + - ][ + - ]: 93 : sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
[ + + ]
66 [ + + ]: 103 : for( sal_Int16 i=0; i < nAttrCount; ++i )
67 : : {
68 [ + - ][ + - ]: 10 : const rtl::OUString& sAttrName(xAttrList->getNameByIndex( i ));
69 : 10 : rtl::OUString aLocalName;
70 : 10 : sal_uInt16 nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
71 [ + - ]: 10 : sAttrName, &aLocalName );
72 [ + - ][ + - ]: 10 : const rtl::OUString& sValue(xAttrList->getValueByIndex( i ));
73 : :
74 [ + - ]: 10 : if (nPrefix == XML_NAMESPACE_TABLE)
75 : : {
76 [ + - ][ + + ]: 10 : if (IsXMLToken(aLocalName, XML_CASE_SENSITIVE))
77 : : {
78 [ + - ][ + - ]: 4 : if (IsXMLToken(sValue, XML_FALSE))
79 : 4 : bIgnoreCase = true;
80 : : }
81 [ + - ][ - + ]: 6 : else if (IsXMLToken(aLocalName, XML_PRECISION_AS_SHOWN))
82 : : {
83 [ # # ][ # # ]: 0 : if (IsXMLToken(sValue, XML_TRUE))
84 : 0 : bCalcAsShown = true;
85 : : }
86 [ + - ][ - + ]: 6 : else if (IsXMLToken(aLocalName, XML_SEARCH_CRITERIA_MUST_APPLY_TO_WHOLE_CELL))
87 : : {
88 [ # # ][ # # ]: 0 : if (IsXMLToken(sValue, XML_FALSE))
89 : 0 : bMatchWholeCell = false;
90 : : }
91 [ + - ][ + + ]: 6 : else if (IsXMLToken(aLocalName, XML_AUTOMATIC_FIND_LABELS))
92 : : {
93 [ + - ][ + - ]: 2 : if (IsXMLToken(sValue, XML_FALSE))
94 : 2 : bLookUpLabels = false;
95 : : }
96 [ + - ][ - + ]: 4 : else if (IsXMLToken(aLocalName, XML_NULL_YEAR))
97 : : {
98 : : sal_Int32 nTemp;
99 [ # # ]: 0 : ::sax::Converter::convertNumber(nTemp, sValue);
100 : 0 : nYear2000 = static_cast<sal_uInt16>(nTemp);
101 : : }
102 [ + - ][ + - ]: 4 : else if (IsXMLToken(aLocalName, XML_USE_REGULAR_EXPRESSIONS))
103 : : {
104 [ + - ][ + - ]: 4 : if (IsXMLToken(sValue, XML_FALSE))
105 : 4 : bUseRegularExpressions = false;
106 : : }
107 : : }
108 : 10 : }
109 : 93 : }
110 : :
111 : 4 : ScXMLCalculationSettingsContext::~ScXMLCalculationSettingsContext()
112 : : {
113 [ - + ]: 8 : }
114 : :
115 : 0 : SvXMLImportContext *ScXMLCalculationSettingsContext::CreateChildContext( sal_uInt16 nPrefix,
116 : : const ::rtl::OUString& rLName,
117 : : const ::com::sun::star::uno::Reference<
118 : : ::com::sun::star::xml::sax::XAttributeList>& xAttrList )
119 : : {
120 : 0 : SvXMLImportContext *pContext = 0;
121 : :
122 [ # # ]: 0 : if (nPrefix == XML_NAMESPACE_TABLE)
123 : : {
124 [ # # ]: 0 : if (IsXMLToken(rLName, XML_NULL_DATE))
125 [ # # ]: 0 : pContext = new ScXMLNullDateContext(GetScImport(), nPrefix, rLName, xAttrList, this);
126 [ # # ]: 0 : else if (IsXMLToken(rLName, XML_ITERATION))
127 [ # # ]: 0 : pContext = new ScXMLIterationContext(GetScImport(), nPrefix, rLName, xAttrList, this);
128 : : }
129 : :
130 [ # # ]: 0 : if( !pContext )
131 [ # # ]: 0 : pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
132 : :
133 : 0 : return pContext;
134 : : }
135 : :
136 : 93 : void ScXMLCalculationSettingsContext::EndElement()
137 : : {
138 [ + - ]: 93 : if (GetScImport().GetModel().is())
139 : : {
140 [ + - ]: 93 : uno::Reference <beans::XPropertySet> xPropertySet (GetScImport().GetModel(), uno::UNO_QUERY);
141 [ + - ]: 93 : if (xPropertySet.is())
142 : : {
143 [ + - ][ + - ]: 93 : xPropertySet->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNO_CALCASSHOWN)), uno::makeAny(bCalcAsShown) );
[ + - ][ + - ]
144 [ + - ][ + - ]: 93 : xPropertySet->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNO_IGNORECASE)), uno::makeAny(bIgnoreCase) );
[ + - ][ + - ]
145 [ + - ][ + - ]: 93 : xPropertySet->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNO_LOOKUPLABELS)), uno::makeAny(bLookUpLabels) );
[ + - ][ + - ]
146 [ + - ][ + - ]: 93 : xPropertySet->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNO_MATCHWHOLE)), uno::makeAny(bMatchWholeCell) );
[ + - ][ + - ]
147 [ + - ][ + - ]: 93 : xPropertySet->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNO_REGEXENABLED)), uno::makeAny(bUseRegularExpressions) );
[ + - ][ + - ]
148 [ + - ][ + - ]: 93 : xPropertySet->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNO_ITERENABLED)), uno::makeAny(bIsIterationEnabled) );
[ + - ][ + - ]
149 [ + - ][ + - ]: 93 : xPropertySet->setPropertyValue( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNO_ITERCOUNT)), uno::makeAny(nIterationCount) );
[ + - ][ + - ]
150 [ + - ][ + - ]: 93 : xPropertySet->setPropertyValue( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNO_ITEREPSILON)), uno::makeAny(fIterationEpsilon) );
[ + - ][ + - ]
151 [ + - ][ + - ]: 93 : xPropertySet->setPropertyValue( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNO_NULLDATE)), uno::makeAny(aNullDate) );
[ + - ][ + - ]
152 [ + - ]: 93 : if (GetScImport().GetDocument())
153 : : {
154 [ + - ]: 93 : ScXMLImport::MutexGuard aGuard(GetScImport());
155 [ + - ][ + - ]: 93 : ScDocOptions aDocOptions (GetScImport().GetDocument()->GetDocOptions());
156 : 93 : aDocOptions.SetYear2000(nYear2000);
157 [ + - ][ + - ]: 93 : GetScImport().GetDocument()->SetDocOptions(aDocOptions);
[ + - ]
158 : : }
159 : 93 : }
160 : : }
161 : 93 : }
162 : :
163 : 0 : ScXMLNullDateContext::ScXMLNullDateContext( ScXMLImport& rImport,
164 : : sal_uInt16 nPrfx,
165 : : const ::rtl::OUString& rLName,
166 : : const ::com::sun::star::uno::Reference<
167 : : ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
168 : : ScXMLCalculationSettingsContext* pCalcSet) :
169 : 0 : SvXMLImportContext( rImport, nPrfx, rLName )
170 : : {
171 [ # # ][ # # ]: 0 : sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
[ # # ]
172 [ # # ]: 0 : for( sal_Int16 i=0; i < nAttrCount; ++i )
173 : : {
174 [ # # ][ # # ]: 0 : const rtl::OUString& sAttrName(xAttrList->getNameByIndex( i ));
175 : 0 : rtl::OUString aLocalName;
176 : 0 : sal_uInt16 nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
177 [ # # ]: 0 : sAttrName, &aLocalName );
178 [ # # ][ # # ]: 0 : const rtl::OUString& sValue(xAttrList->getValueByIndex( i ));
179 : :
180 [ # # ][ # # ]: 0 : if (nPrefix == XML_NAMESPACE_TABLE && IsXMLToken(aLocalName, XML_DATE_VALUE))
[ # # ][ # # ]
181 : : {
182 : 0 : util::DateTime aDateTime;
183 [ # # ]: 0 : ::sax::Converter::convertDateTime(aDateTime, sValue);
184 : 0 : util::Date aDate;
185 : 0 : aDate.Day = aDateTime.Day;
186 : 0 : aDate.Month = aDateTime.Month;
187 : 0 : aDate.Year = aDateTime.Year;
188 : 0 : pCalcSet->SetNullDate(aDate);
189 : : }
190 : 0 : }
191 : 0 : }
192 : :
193 : 0 : ScXMLNullDateContext::~ScXMLNullDateContext()
194 : : {
195 [ # # ]: 0 : }
196 : :
197 : 0 : SvXMLImportContext *ScXMLNullDateContext::CreateChildContext( sal_uInt16 nPrefix,
198 : : const ::rtl::OUString& rLName,
199 : : const ::com::sun::star::uno::Reference<
200 : : ::com::sun::star::xml::sax::XAttributeList>& /* xAttrList */ )
201 : : {
202 [ # # ]: 0 : SvXMLImportContext *pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
203 : :
204 : 0 : return pContext;
205 : : }
206 : :
207 : 0 : void ScXMLNullDateContext::EndElement()
208 : : {
209 : 0 : }
210 : :
211 : 0 : ScXMLIterationContext::ScXMLIterationContext( ScXMLImport& rImport,
212 : : sal_uInt16 nPrfx,
213 : : const ::rtl::OUString& rLName,
214 : : const ::com::sun::star::uno::Reference<
215 : : ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
216 : : ScXMLCalculationSettingsContext* pCalcSet) :
217 : 0 : SvXMLImportContext( rImport, nPrfx, rLName )
218 : : {
219 [ # # ][ # # ]: 0 : sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
[ # # ]
220 [ # # ]: 0 : for( sal_Int16 i=0; i < nAttrCount; ++i )
221 : : {
222 [ # # ][ # # ]: 0 : const rtl::OUString& sAttrName(xAttrList->getNameByIndex( i ));
223 : 0 : rtl::OUString aLocalName;
224 : 0 : sal_uInt16 nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
225 [ # # ]: 0 : sAttrName, &aLocalName );
226 [ # # ][ # # ]: 0 : const rtl::OUString& sValue(xAttrList->getValueByIndex( i ));
227 : :
228 [ # # ]: 0 : if (nPrefix == XML_NAMESPACE_TABLE)
229 : : {
230 [ # # ][ # # ]: 0 : if (IsXMLToken(aLocalName, XML_STATUS))
231 : : {
232 [ # # ][ # # ]: 0 : if (IsXMLToken(sValue, XML_ENABLE))
233 : 0 : pCalcSet->SetIterationStatus(true);
234 : : }
235 [ # # ][ # # ]: 0 : else if (IsXMLToken(aLocalName, XML_STEPS))
236 : : {
237 : : sal_Int32 nSteps;
238 [ # # ]: 0 : ::sax::Converter::convertNumber(nSteps, sValue);
239 : 0 : pCalcSet->SetIterationCount(nSteps);
240 : : }
241 [ # # ][ # # ]: 0 : else if (IsXMLToken(aLocalName, XML_MAXIMUM_DIFFERENCE))
242 : : {
243 : : double fDif;
244 [ # # ]: 0 : ::sax::Converter::convertDouble(fDif, sValue);
245 : 0 : pCalcSet->SetIterationEpsilon(fDif);
246 : : }
247 : : }
248 : 0 : }
249 : 0 : }
250 : :
251 : 0 : ScXMLIterationContext::~ScXMLIterationContext()
252 : : {
253 [ # # ]: 0 : }
254 : :
255 : 0 : SvXMLImportContext *ScXMLIterationContext::CreateChildContext( sal_uInt16 nPrefix,
256 : : const ::rtl::OUString& rLName,
257 : : const ::com::sun::star::uno::Reference<
258 : : ::com::sun::star::xml::sax::XAttributeList>& /* xAttrList */ )
259 : : {
260 [ # # ]: 0 : SvXMLImportContext *pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
261 : :
262 : 0 : return pContext;
263 : : }
264 : :
265 : 0 : void ScXMLIterationContext::EndElement()
266 : : {
267 : 0 : }
268 : :
269 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|