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 <XMLCalculationSettingsContext.hxx>
27 #include <com/sun/star/beans/XPropertySet.hpp>
28 #include <com/sun/star/text/XTextDocument.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::text;
42 using namespace ::xmloff::token;
43
XMLCalculationSettingsContext(SvXMLImport & rImport,sal_uInt16 p_nPrefix,const::rtl::OUString & rLocalName,const::com::sun::star::uno::Reference<::com::sun::star::xml::sax::XAttributeList> & xAttrList)44 XMLCalculationSettingsContext::XMLCalculationSettingsContext( 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 , nYear( 1930 )
51 {
52 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
53 for( sal_Int16 i=0; i < nAttrCount; i++ )
54 {
55 rtl::OUString sAttrName = xAttrList->getNameByIndex( i );
56 rtl::OUString aLocalName;
57 sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName(
58 sAttrName, &aLocalName );
59 rtl::OUString sValue = xAttrList->getValueByIndex( i );
60
61 if (nPrefix == XML_NAMESPACE_TABLE)
62 {
63 if ( IsXMLToken( aLocalName, XML_NULL_YEAR ) )
64 {
65 sal_Int32 nTemp;
66 GetImport().GetMM100UnitConverter().convertNumber(nTemp, sValue);
67 nYear= static_cast <sal_Int16> (nTemp);
68 }
69 }
70 }
71 }
72
~XMLCalculationSettingsContext()73 XMLCalculationSettingsContext::~XMLCalculationSettingsContext()
74 {
75 }
EndElement()76 void XMLCalculationSettingsContext::EndElement()
77 {
78 if (nYear != 1930 )
79 {
80 Reference < XTextDocument > xTextDoc ( GetImport().GetModel(), UNO_QUERY);
81 if (xTextDoc.is())
82 {
83 Reference < XPropertySet > xPropSet ( xTextDoc, UNO_QUERY );
84 OUString sTwoDigitYear ( RTL_CONSTASCII_USTRINGPARAM ( "TwoDigitYear" ) );
85 Any aAny;
86 aAny <<= nYear;
87 xPropSet->setPropertyValue ( sTwoDigitYear, aAny );
88 }
89 }
90 }
91