1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: XMLCalculationSettingsContext.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
36 // INCLUDE ---------------------------------------------------------------
37 #include "XMLCalculationSettingsContext.hxx"
38 #include "xmlimprt.hxx"
39 #include "unonames.hxx"
40 #include "docoptio.hxx"
41 #include "document.hxx"
42 #include <xmloff/xmltoken.hxx>
43 #include <xmloff/xmlnmspe.hxx>
44 #include <xmloff/xmluconv.hxx>
45 #include <xmloff/nmspmap.hxx>
46 #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
47 #include <comphelper/extract.hxx>
49 using namespace com::sun::star
;
50 using namespace xmloff::token
;
52 //------------------------------------------------------------------
54 ScXMLCalculationSettingsContext::ScXMLCalculationSettingsContext( ScXMLImport
& rImport
,
56 const ::rtl::OUString
& rLName
,
57 const ::com::sun::star::uno::Reference
<
58 ::com::sun::star::xml::sax::XAttributeList
>& xAttrList
) :
59 SvXMLImportContext( rImport
, nPrfx
, rLName
),
60 fIterationEpsilon(0.001),
63 bIsIterationEnabled(sal_False
),
64 bCalcAsShown(sal_False
),
65 bIgnoreCase(sal_False
),
66 bLookUpLabels(sal_True
),
67 bMatchWholeCell(sal_True
),
68 bUseRegularExpressions(sal_True
)
72 aNullDate
.Year
= 1899;
73 sal_Int16 nAttrCount
= xAttrList
.is() ? xAttrList
->getLength() : 0;
74 for( sal_Int16 i
=0; i
< nAttrCount
; ++i
)
76 const rtl::OUString
& sAttrName(xAttrList
->getNameByIndex( i
));
77 rtl::OUString aLocalName
;
78 sal_uInt16 nPrefix
= GetScImport().GetNamespaceMap().GetKeyByAttrName(
79 sAttrName
, &aLocalName
);
80 const rtl::OUString
& sValue(xAttrList
->getValueByIndex( i
));
82 if (nPrefix
== XML_NAMESPACE_TABLE
)
84 if (IsXMLToken(aLocalName
, XML_CASE_SENSITIVE
))
86 if (IsXMLToken(sValue
, XML_FALSE
))
87 bIgnoreCase
= sal_True
;
89 else if (IsXMLToken(aLocalName
, XML_PRECISION_AS_SHOWN
))
91 if (IsXMLToken(sValue
, XML_TRUE
))
92 bCalcAsShown
= sal_True
;
94 else if (IsXMLToken(aLocalName
, XML_SEARCH_CRITERIA_MUST_APPLY_TO_WHOLE_CELL
))
96 if (IsXMLToken(sValue
, XML_FALSE
))
97 bMatchWholeCell
= sal_False
;
99 else if (IsXMLToken(aLocalName
, XML_AUTOMATIC_FIND_LABELS
))
101 if (IsXMLToken(sValue
, XML_FALSE
))
102 bLookUpLabels
= sal_False
;
104 else if (IsXMLToken(aLocalName
, XML_NULL_YEAR
))
107 GetScImport().GetMM100UnitConverter().convertNumber(nTemp
, sValue
);
108 nYear2000
= static_cast<sal_uInt16
>(nTemp
);
110 else if (IsXMLToken(aLocalName
, XML_USE_REGULAR_EXPRESSIONS
))
112 if (IsXMLToken(sValue
, XML_FALSE
))
113 bUseRegularExpressions
= sal_False
;
119 ScXMLCalculationSettingsContext::~ScXMLCalculationSettingsContext()
123 SvXMLImportContext
*ScXMLCalculationSettingsContext::CreateChildContext( USHORT nPrefix
,
124 const ::rtl::OUString
& rLName
,
125 const ::com::sun::star::uno::Reference
<
126 ::com::sun::star::xml::sax::XAttributeList
>& xAttrList
)
128 SvXMLImportContext
*pContext
= 0;
130 if (nPrefix
== XML_NAMESPACE_TABLE
)
132 if (IsXMLToken(rLName
, XML_NULL_DATE
))
133 pContext
= new ScXMLNullDateContext(GetScImport(), nPrefix
, rLName
, xAttrList
, this);
134 else if (IsXMLToken(rLName
, XML_ITERATION
))
135 pContext
= new ScXMLIterationContext(GetScImport(), nPrefix
, rLName
, xAttrList
, this);
139 pContext
= new SvXMLImportContext( GetImport(), nPrefix
, rLName
);
144 void ScXMLCalculationSettingsContext::EndElement()
146 if (GetScImport().GetModel().is())
148 uno::Reference
<beans::XPropertySet
> xPropertySet (GetScImport().GetModel(), uno::UNO_QUERY
);
149 if (xPropertySet
.is())
151 xPropertySet
->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNO_CALCASSHOWN
)), uno::makeAny(bCalcAsShown
) );
152 xPropertySet
->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNO_IGNORECASE
)), uno::makeAny(bIgnoreCase
) );
153 xPropertySet
->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNO_LOOKUPLABELS
)), uno::makeAny(bLookUpLabels
) );
154 xPropertySet
->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNO_MATCHWHOLE
)), uno::makeAny(bMatchWholeCell
) );
155 xPropertySet
->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNO_REGEXENABLED
)), uno::makeAny(bUseRegularExpressions
) );
156 xPropertySet
->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNO_ITERENABLED
)), uno::makeAny(bIsIterationEnabled
) );
157 xPropertySet
->setPropertyValue( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNO_ITERCOUNT
)), uno::makeAny(nIterationCount
) );
158 xPropertySet
->setPropertyValue( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNO_ITEREPSILON
)), uno::makeAny(fIterationEpsilon
) );
159 xPropertySet
->setPropertyValue( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNO_NULLDATE
)), uno::makeAny(aNullDate
) );
160 if (GetScImport().GetDocument())
162 GetScImport().LockSolarMutex();
163 ScDocOptions
aDocOptions (GetScImport().GetDocument()->GetDocOptions());
164 aDocOptions
.SetYear2000(nYear2000
);
165 GetScImport().GetDocument()->SetDocOptions(aDocOptions
);
166 GetScImport().UnlockSolarMutex();
172 ScXMLNullDateContext::ScXMLNullDateContext( ScXMLImport
& rImport
,
174 const ::rtl::OUString
& rLName
,
175 const ::com::sun::star::uno::Reference
<
176 ::com::sun::star::xml::sax::XAttributeList
>& xAttrList
,
177 ScXMLCalculationSettingsContext
* pCalcSet
) :
178 SvXMLImportContext( rImport
, nPrfx
, rLName
)
180 sal_Int16 nAttrCount
= xAttrList
.is() ? xAttrList
->getLength() : 0;
181 for( sal_Int16 i
=0; i
< nAttrCount
; ++i
)
183 const rtl::OUString
& sAttrName(xAttrList
->getNameByIndex( i
));
184 rtl::OUString aLocalName
;
185 sal_uInt16 nPrefix
= GetScImport().GetNamespaceMap().GetKeyByAttrName(
186 sAttrName
, &aLocalName
);
187 const rtl::OUString
& sValue(xAttrList
->getValueByIndex( i
));
189 if (nPrefix
== XML_NAMESPACE_TABLE
&& IsXMLToken(aLocalName
, XML_DATE_VALUE
))
191 util::DateTime aDateTime
;
192 GetScImport().GetMM100UnitConverter().convertDateTime(aDateTime
, sValue
);
194 aDate
.Day
= aDateTime
.Day
;
195 aDate
.Month
= aDateTime
.Month
;
196 aDate
.Year
= aDateTime
.Year
;
197 pCalcSet
->SetNullDate(aDate
);
202 ScXMLNullDateContext::~ScXMLNullDateContext()
206 SvXMLImportContext
*ScXMLNullDateContext::CreateChildContext( USHORT nPrefix
,
207 const ::rtl::OUString
& rLName
,
208 const ::com::sun::star::uno::Reference
<
209 ::com::sun::star::xml::sax::XAttributeList
>& /* xAttrList */ )
211 SvXMLImportContext
*pContext
= new SvXMLImportContext( GetImport(), nPrefix
, rLName
);
216 void ScXMLNullDateContext::EndElement()
220 ScXMLIterationContext::ScXMLIterationContext( ScXMLImport
& rImport
,
222 const ::rtl::OUString
& rLName
,
223 const ::com::sun::star::uno::Reference
<
224 ::com::sun::star::xml::sax::XAttributeList
>& xAttrList
,
225 ScXMLCalculationSettingsContext
* pCalcSet
) :
226 SvXMLImportContext( rImport
, nPrfx
, rLName
)
228 sal_Int16 nAttrCount
= xAttrList
.is() ? xAttrList
->getLength() : 0;
229 for( sal_Int16 i
=0; i
< nAttrCount
; ++i
)
231 const rtl::OUString
& sAttrName(xAttrList
->getNameByIndex( i
));
232 rtl::OUString aLocalName
;
233 sal_uInt16 nPrefix
= GetScImport().GetNamespaceMap().GetKeyByAttrName(
234 sAttrName
, &aLocalName
);
235 const rtl::OUString
& sValue(xAttrList
->getValueByIndex( i
));
237 if (nPrefix
== XML_NAMESPACE_TABLE
)
239 if (IsXMLToken(aLocalName
, XML_STATUS
))
241 if (IsXMLToken(sValue
, XML_ENABLE
))
242 pCalcSet
->SetIterationStatus(sal_True
);
244 else if (IsXMLToken(aLocalName
, XML_STEPS
))
247 GetScImport().GetMM100UnitConverter().convertNumber(nSteps
, sValue
);
248 pCalcSet
->SetIterationCount(nSteps
);
250 else if (IsXMLToken(aLocalName
, XML_MAXIMUM_DIFFERENCE
))
253 GetScImport().GetMM100UnitConverter().convertDouble(fDif
, sValue
);
254 pCalcSet
->SetIterationEpsilon(fDif
);
260 ScXMLIterationContext::~ScXMLIterationContext()
264 SvXMLImportContext
*ScXMLIterationContext::CreateChildContext( USHORT nPrefix
,
265 const ::rtl::OUString
& rLName
,
266 const ::com::sun::star::uno::Reference
<
267 ::com::sun::star::xml::sax::XAttributeList
>& /* xAttrList */ )
269 SvXMLImportContext
*pContext
= new SvXMLImportContext( GetImport(), nPrefix
, rLName
);
274 void ScXMLIterationContext::EndElement()