1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_xmloff.hxx"
26 #include <SchXMLCalculationSettingsContext.hxx>
27 #include <com/sun/star/beans/XPropertySet.hpp>
28 #include <com/sun/star/util/DateTime.hpp>
29 #include <xmloff/xmlimp.hxx>
30 #include <xmloff/nmspmap.hxx>
31 #include "xmloff/xmlnmspe.hxx"
32 #include <xmloff/xmltoken.hxx>
33 #include <xmloff/xmluconv.hxx>
34 
35 
36 using ::rtl::OUString;
37 using ::rtl::OUStringBuffer;
38 
39 using namespace ::com::sun::star::uno;
40 using namespace ::com::sun::star::beans;
41 using namespace ::com::sun::star;
42 using namespace ::xmloff::token;
43 
44 SchXMLCalculationSettingsContext::SchXMLCalculationSettingsContext( SvXMLImport& rImport,
45 									sal_uInt16 p_nPrefix,
46 									const ::rtl::OUString& rLocalName,
47 				 					const ::com::sun::star::uno::Reference<
48 				 						::com::sun::star::xml::sax::XAttributeList >& xAttrList )
49 : SvXMLImportContext ( rImport, p_nPrefix, rLocalName )
50 {
51     const SvXMLNamespaceMap& rMap = GetImport().GetNamespaceMap();
52 	const sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
53 	for( sal_Int16 i=0; i < nAttrCount; i++ )
54 	{
55 		const rtl::OUString sAttrName = xAttrList->getNameByIndex( i );
56 		rtl::OUString aLocalName;
57 		const sal_uInt16 nPrefix = rMap.GetKeyByAttrName(sAttrName, &aLocalName );
58 		if ( nPrefix == XML_NAMESPACE_TABLE && IsXMLToken( aLocalName, XML_DATE_VALUE ) )
59 		{
60             util::DateTime aNullDate;
61             const rtl::OUString sValue = xAttrList->getValueByIndex( i );
62 			GetImport().GetMM100UnitConverter().convertDateTime(aNullDate, sValue);
63             m_aNullDate <<= aNullDate;
64 		}
65 	}
66 }
67 SvXMLImportContext* SchXMLCalculationSettingsContext::CreateChildContext( sal_uInt16 nPrefix,
68 								   const ::rtl::OUString& rLocalName,
69 								   const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& xAttrList )
70 {
71     return new SchXMLCalculationSettingsContext(GetImport(),nPrefix,rLocalName,xAttrList);
72 }
73 
74 void SchXMLCalculationSettingsContext::EndElement()
75 {
76     if ( m_aNullDate.hasValue() )
77     {
78 	    Reference < XPropertySet > xPropSet ( GetImport().GetModel(), UNO_QUERY );
79         ::rtl::OUString sNullDate( RTL_CONSTASCII_USTRINGPARAM ( "NullDate" ) );
80         xPropSet->setPropertyValue ( sNullDate, m_aNullDate );
81     }
82 }
83