1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_xmloff.hxx"
30 #include <XMLCalculationSettingsContext.hxx>
31 #include <com/sun/star/beans/XPropertySet.hpp>
32 #include <com/sun/star/text/XTextDocument.hpp>
33 #include <xmloff/xmlimp.hxx>
34 #include <xmloff/nmspmap.hxx>
35 #include "xmloff/xmlnmspe.hxx"
36 #include <xmloff/xmltoken.hxx>
37 #include <xmloff/xmluconv.hxx>
38 
39 
40 using ::rtl::OUString;
41 using ::rtl::OUStringBuffer;
42 
43 using namespace ::com::sun::star::uno;
44 using namespace ::com::sun::star::beans;
45 using namespace ::com::sun::star::text;
46 using namespace ::xmloff::token;
47 
48 XMLCalculationSettingsContext::XMLCalculationSettingsContext( SvXMLImport& rImport,
49 									sal_uInt16 p_nPrefix,
50 									const ::rtl::OUString& rLocalName,
51 				 					const ::com::sun::star::uno::Reference<
52 				 						::com::sun::star::xml::sax::XAttributeList >& xAttrList )
53 : SvXMLImportContext ( rImport, p_nPrefix, rLocalName )
54 , nYear( 1930 )
55 {
56 	sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
57 	for( sal_Int16 i=0; i < nAttrCount; i++ )
58 	{
59 		rtl::OUString sAttrName = xAttrList->getNameByIndex( i );
60 		rtl::OUString aLocalName;
61 		sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName(
62 											sAttrName, &aLocalName );
63 		rtl::OUString sValue = xAttrList->getValueByIndex( i );
64 
65 		if (nPrefix == XML_NAMESPACE_TABLE)
66 		{
67 			if ( IsXMLToken( aLocalName, XML_NULL_YEAR ) )
68 			{
69 				sal_Int32 nTemp;
70 				GetImport().GetMM100UnitConverter().convertNumber(nTemp, sValue);
71 				nYear= static_cast <sal_Int16> (nTemp);
72 			}
73 		}
74 	}
75 }
76 
77 XMLCalculationSettingsContext::~XMLCalculationSettingsContext()
78 {
79 }
80 void XMLCalculationSettingsContext::EndElement()
81 {
82 	if (nYear != 1930 )
83 	{
84 		Reference < XTextDocument > xTextDoc ( GetImport().GetModel(), UNO_QUERY);
85 		if (xTextDoc.is())
86 		{
87 			Reference < XPropertySet > xPropSet ( xTextDoc, UNO_QUERY );
88 			OUString sTwoDigitYear ( RTL_CONSTASCII_USTRINGPARAM ( "TwoDigitYear" ) );
89 			Any aAny;
90 			aAny <<= nYear;
91 			xPropSet->setPropertyValue ( sTwoDigitYear, aAny );
92 		}
93 	}
94 }
95