Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 : :
29 : : #include "vcl_date_handler.hxx"
30 : :
31 : : #include <rtl/ustrbuf.hxx>
32 : :
33 : : #include <com/sun/star/util/DateTime.hpp>
34 : :
35 : : #include <sax/tools/converter.hxx>
36 : :
37 : : #include <tools/diagnose_ex.h>
38 : : #include <tools/date.hxx>
39 : :
40 : : //......................................................................................................................
41 : : namespace xmloff
42 : : {
43 : : //......................................................................................................................
44 : :
45 : : using ::com::sun::star::uno::Any;
46 : : using ::com::sun::star::uno::makeAny;
47 : : using ::com::sun::star::util::DateTime;
48 : :
49 : : //==================================================================================================================
50 : : //= VCLDateHandler
51 : : //==================================================================================================================
52 : : //------------------------------------------------------------------------------------------------------------------
53 : 0 : VCLDateHandler::VCLDateHandler()
54 : : {
55 : 0 : }
56 : :
57 : : //------------------------------------------------------------------------------------------------------------------
58 : 0 : ::rtl::OUString VCLDateHandler::getAttributeValue( const PropertyValues& /*i_propertyValues*/ ) const
59 : : {
60 : : OSL_ENSURE( false, "VCLDateHandler::getAttributeValue: unexpected call!" );
61 : 0 : return ::rtl::OUString();
62 : : }
63 : :
64 : : //------------------------------------------------------------------------------------------------------------------
65 : 0 : ::rtl::OUString VCLDateHandler::getAttributeValue( const Any& i_propertyValue ) const
66 : : {
67 : 0 : sal_Int32 nVCLDate(0);
68 : 0 : OSL_VERIFY( i_propertyValue >>= nVCLDate );
69 : 0 : ::Date aVCLDate( nVCLDate );
70 : :
71 : 0 : DateTime aDateTime; // default-inited to 0
72 : 0 : aDateTime.Day = aVCLDate.GetDay();
73 : 0 : aDateTime.Month = aVCLDate.GetMonth();
74 : 0 : aDateTime.Year = aVCLDate.GetYear();
75 : :
76 : 0 : ::rtl::OUStringBuffer aBuffer;
77 [ # # ]: 0 : ::sax::Converter::convertDateTime( aBuffer, aDateTime, false );
78 [ # # ]: 0 : return aBuffer.makeStringAndClear();
79 : : }
80 : :
81 : : //------------------------------------------------------------------------------------------------------------------
82 : 0 : bool VCLDateHandler::getPropertyValues( const ::rtl::OUString i_attributeValue, PropertyValues& o_propertyValues ) const
83 : : {
84 : 0 : sal_Int32 nVCLDate(0);
85 : :
86 : 0 : DateTime aDateTime;
87 [ # # ][ # # ]: 0 : if (::sax::Converter::convertDateTime( aDateTime, i_attributeValue ))
88 : : {
89 : 0 : ::Date aVCLDate( aDateTime.Day, aDateTime.Month, aDateTime.Year );
90 : 0 : nVCLDate = aVCLDate.GetDate();
91 : : }
92 : : else
93 : : {
94 : : // compatibility format, before we wrote those values in XML-schema compatible form
95 [ # # ][ # # ]: 0 : if (!::sax::Converter::convertNumber(nVCLDate, i_attributeValue))
96 : : {
97 : : OSL_ENSURE( false, "VCLDateHandler::getPropertyValues: unknown date format (no XML-schema date, no legacy integer)!" );
98 : 0 : return false;
99 : : }
100 : : }
101 : :
102 [ # # ]: 0 : const Any aPropertyValue( makeAny( nVCLDate ) );
103 : :
104 : : OSL_ENSURE( o_propertyValues.size() == 1, "VCLDateHandler::getPropertyValues: date strings represent exactly one property - not more, not less!" );
105 [ # # ]: 0 : for ( PropertyValues::iterator prop = o_propertyValues.begin();
106 : 0 : prop != o_propertyValues.end();
107 : : ++prop
108 : : )
109 : : {
110 : 0 : prop->second = aPropertyValue;
111 : : }
112 : 0 : return true;
113 : : }
114 : :
115 : : //......................................................................................................................
116 : : } // namespace xmloff
117 : : //......................................................................................................................
118 : :
119 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|