Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 :
21 : #include "vcl_date_handler.hxx"
22 :
23 : #include <rtl/ustrbuf.hxx>
24 :
25 : #include <com/sun/star/util/DateTime.hpp>
26 :
27 : #include <sax/tools/converter.hxx>
28 :
29 : #include <tools/diagnose_ex.h>
30 : #include <tools/date.hxx>
31 :
32 : //......................................................................................................................
33 : namespace xmloff
34 : {
35 : //......................................................................................................................
36 :
37 : using ::com::sun::star::uno::Any;
38 : using ::com::sun::star::uno::makeAny;
39 : using ::com::sun::star::util::DateTime;
40 :
41 : //==================================================================================================================
42 : //= VCLDateHandler
43 : //==================================================================================================================
44 : //------------------------------------------------------------------------------------------------------------------
45 0 : VCLDateHandler::VCLDateHandler()
46 : {
47 0 : }
48 :
49 : //------------------------------------------------------------------------------------------------------------------
50 0 : ::rtl::OUString VCLDateHandler::getAttributeValue( const PropertyValues& /*i_propertyValues*/ ) const
51 : {
52 : OSL_ENSURE( false, "VCLDateHandler::getAttributeValue: unexpected call!" );
53 0 : return ::rtl::OUString();
54 : }
55 :
56 : //------------------------------------------------------------------------------------------------------------------
57 0 : ::rtl::OUString VCLDateHandler::getAttributeValue( const Any& i_propertyValue ) const
58 : {
59 0 : sal_Int32 nVCLDate(0);
60 0 : OSL_VERIFY( i_propertyValue >>= nVCLDate );
61 0 : ::Date aVCLDate( nVCLDate );
62 :
63 0 : DateTime aDateTime; // default-inited to 0
64 0 : aDateTime.Day = aVCLDate.GetDay();
65 0 : aDateTime.Month = aVCLDate.GetMonth();
66 0 : aDateTime.Year = aVCLDate.GetYear();
67 :
68 0 : ::rtl::OUStringBuffer aBuffer;
69 0 : ::sax::Converter::convertDateTime( aBuffer, aDateTime, false );
70 0 : return aBuffer.makeStringAndClear();
71 : }
72 :
73 : //------------------------------------------------------------------------------------------------------------------
74 0 : bool VCLDateHandler::getPropertyValues( const ::rtl::OUString i_attributeValue, PropertyValues& o_propertyValues ) const
75 : {
76 0 : sal_Int32 nVCLDate(0);
77 :
78 0 : DateTime aDateTime;
79 0 : if (::sax::Converter::convertDateTime( aDateTime, i_attributeValue ))
80 : {
81 0 : ::Date aVCLDate( aDateTime.Day, aDateTime.Month, aDateTime.Year );
82 0 : nVCLDate = aVCLDate.GetDate();
83 : }
84 : else
85 : {
86 : // compatibility format, before we wrote those values in XML-schema compatible form
87 0 : if (!::sax::Converter::convertNumber(nVCLDate, i_attributeValue))
88 : {
89 : OSL_ENSURE( false, "VCLDateHandler::getPropertyValues: unknown date format (no XML-schema date, no legacy integer)!" );
90 0 : return false;
91 : }
92 : }
93 :
94 0 : const Any aPropertyValue( makeAny( nVCLDate ) );
95 :
96 : OSL_ENSURE( o_propertyValues.size() == 1, "VCLDateHandler::getPropertyValues: date strings represent exactly one property - not more, not less!" );
97 0 : for ( PropertyValues::iterator prop = o_propertyValues.begin();
98 0 : prop != o_propertyValues.end();
99 : ++prop
100 : )
101 : {
102 0 : prop->second = aPropertyValue;
103 : }
104 0 : return true;
105 : }
106 :
107 : //......................................................................................................................
108 : } // namespace xmloff
109 : //......................................................................................................................
110 :
111 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|