1 /************************************************************************* 2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3 * 4 * Copyright 2000, 2010 Oracle and/or its affiliates. 5 * 6 * OpenOffice.org - a multi-platform office productivity suite 7 * 8 * This file is part of OpenOffice.org. 9 * 10 * OpenOffice.org is free software: you can redistribute it and/or modify 11 * it under the terms of the GNU Lesser General Public License version 3 12 * only, as published by the Free Software Foundation. 13 * 14 * OpenOffice.org is distributed in the hope that it will be useful, 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 * GNU Lesser General Public License version 3 for more details 18 * (a copy is included in the LICENSE file that accompanied this code). 19 * 20 * You should have received a copy of the GNU Lesser General Public License 21 * version 3 along with OpenOffice.org. If not, see 22 * <http://www.openoffice.org/license.html> 23 * for a copy of the LGPLv3 License. 24 * 25 ************************************************************************/ 26 27 #include "precompiled_xmloff.hxx" 28 29 #include "vcl_date_handler.hxx" 30 #include "xmloff/xmluconv.hxx" 31 32 #include <com/sun/star/util/DateTime.hpp> 33 34 #include <tools/diagnose_ex.h> 35 #include <tools/date.hxx> 36 37 //...................................................................................................................... 38 namespace xmloff 39 { 40 //...................................................................................................................... 41 42 using ::com::sun::star::uno::Any; 43 using ::com::sun::star::uno::makeAny; 44 using ::com::sun::star::util::DateTime; 45 46 //================================================================================================================== 47 //= VCLDateHandler 48 //================================================================================================================== 49 //------------------------------------------------------------------------------------------------------------------ 50 VCLDateHandler::VCLDateHandler() 51 { 52 } 53 54 //------------------------------------------------------------------------------------------------------------------ 55 ::rtl::OUString VCLDateHandler::getAttributeValue( const PropertyValues& /*i_propertyValues*/ ) const 56 { 57 OSL_ENSURE( false, "VCLDateHandler::getAttributeValue: unexpected call!" ); 58 return ::rtl::OUString(); 59 } 60 61 //------------------------------------------------------------------------------------------------------------------ 62 ::rtl::OUString VCLDateHandler::getAttributeValue( const Any& i_propertyValue ) const 63 { 64 sal_Int32 nVCLDate(0); 65 OSL_VERIFY( i_propertyValue >>= nVCLDate ); 66 ::Date aVCLDate( nVCLDate ); 67 68 DateTime aDateTime; // default-inited to 0 69 aDateTime.Day = aVCLDate.GetDay(); 70 aDateTime.Month = aVCLDate.GetMonth(); 71 aDateTime.Year = aVCLDate.GetYear(); 72 73 ::rtl::OUStringBuffer aBuffer; 74 SvXMLUnitConverter::convertDateTime( aBuffer, aDateTime, sal_False ); 75 return aBuffer.makeStringAndClear(); 76 } 77 78 //------------------------------------------------------------------------------------------------------------------ 79 bool VCLDateHandler::getPropertyValues( const ::rtl::OUString i_attributeValue, PropertyValues& o_propertyValues ) const 80 { 81 sal_Int32 nVCLDate(0); 82 83 DateTime aDateTime; 84 if ( SvXMLUnitConverter::convertDateTime( aDateTime, i_attributeValue ) ) 85 { 86 ::Date aVCLDate( aDateTime.Day, aDateTime.Month, aDateTime.Year ); 87 nVCLDate = aVCLDate.GetDate(); 88 } 89 else 90 { 91 // compatibility format, before we wrote those values in XML-schema compatible form 92 if ( !SvXMLUnitConverter::convertNumber( nVCLDate, i_attributeValue ) ) 93 { 94 OSL_ENSURE( false, "VCLDateHandler::getPropertyValues: unknown date format (no XML-schema date, no legacy integer)!" ); 95 return false; 96 } 97 } 98 99 const Any aPropertyValue( makeAny( nVCLDate ) ); 100 101 OSL_ENSURE( o_propertyValues.size() == 1, "VCLDateHandler::getPropertyValues: date strings represent exactly one property - not more, not less!" ); 102 for ( PropertyValues::iterator prop = o_propertyValues.begin(); 103 prop != o_propertyValues.end(); 104 ++prop 105 ) 106 { 107 prop->second = aPropertyValue; 108 } 109 return true; 110 } 111 112 //...................................................................................................................... 113 } // namespace xmloff 114 //...................................................................................................................... 115