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_time_handler.hxx"
30 : :
31 : : #include <rtl/ustrbuf.hxx>
32 : :
33 : : #include <com/sun/star/util/Duration.hpp>
34 : :
35 : : #include <sax/tools/converter.hxx>
36 : :
37 : : #include <tools/diagnose_ex.h>
38 : : #include <tools/time.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::Duration;
48 : :
49 : : //==================================================================================================================
50 : : //= VCLTimeHandler
51 : : //==================================================================================================================
52 : : //------------------------------------------------------------------------------------------------------------------
53 : 0 : VCLTimeHandler::VCLTimeHandler()
54 : : {
55 : 0 : }
56 : :
57 : : //------------------------------------------------------------------------------------------------------------------
58 : 0 : ::rtl::OUString VCLTimeHandler::getAttributeValue( const PropertyValues& /*i_propertyValues*/ ) const
59 : : {
60 : : OSL_ENSURE( false, "VCLTimeHandler::getAttributeValue: unexpected call!" );
61 : 0 : return ::rtl::OUString();
62 : : }
63 : :
64 : : //------------------------------------------------------------------------------------------------------------------
65 : 0 : ::rtl::OUString VCLTimeHandler::getAttributeValue( const Any& i_propertyValue ) const
66 : : {
67 : 0 : sal_Int32 nVCLTime(0);
68 : 0 : OSL_VERIFY( i_propertyValue >>= nVCLTime );
69 : 0 : ::Time aVCLTime( nVCLTime );
70 : :
71 : 0 : Duration aDuration; // default-inited to 0
72 : 0 : aDuration.Hours = aVCLTime.GetHour();
73 : 0 : aDuration.Minutes = aVCLTime.GetMin();
74 : 0 : aDuration.Seconds = aVCLTime.GetSec();
75 : 0 : aDuration.MilliSeconds = aVCLTime.Get100Sec() * 10;
76 : :
77 : 0 : ::rtl::OUStringBuffer aBuffer;
78 [ # # ]: 0 : ::sax::Converter::convertDuration( aBuffer, aDuration );
79 [ # # ]: 0 : return aBuffer.makeStringAndClear();
80 : : }
81 : :
82 : : //------------------------------------------------------------------------------------------------------------------
83 : 0 : bool VCLTimeHandler::getPropertyValues( const ::rtl::OUString i_attributeValue, PropertyValues& o_propertyValues ) const
84 : : {
85 : 0 : sal_Int32 nVCLTime(0);
86 : :
87 : 0 : Duration aDuration;
88 [ # # ][ # # ]: 0 : if (::sax::Converter::convertDuration( aDuration, i_attributeValue ))
89 : : {
90 : : ::Time aVCLTime(aDuration.Hours, aDuration.Minutes,
91 [ # # ]: 0 : aDuration.Seconds, aDuration.MilliSeconds / 10);
92 : 0 : nVCLTime = aVCLTime.GetTime();
93 : : }
94 : : else
95 : : {
96 : : // compatibility format, before we wrote those values in XML-schema compatible form
97 [ # # ][ # # ]: 0 : if (!::sax::Converter::convertNumber(nVCLTime, i_attributeValue))
98 : : {
99 : : OSL_ENSURE( false, "VCLTimeHandler::getPropertyValues: unknown time format (no XML-schema time, no legacy integer)!" );
100 : 0 : return false;
101 : : }
102 : : }
103 : :
104 [ # # ]: 0 : const Any aPropertyValue( makeAny( nVCLTime ) );
105 : :
106 : : OSL_ENSURE( o_propertyValues.size() == 1, "VCLTimeHandler::getPropertyValues: time strings represent exactly one property - not more, not less!" );
107 [ # # ]: 0 : for ( PropertyValues::iterator prop = o_propertyValues.begin();
108 : 0 : prop != o_propertyValues.end();
109 : : ++prop
110 : : )
111 : : {
112 : 0 : prop->second = aPropertyValue;
113 : : }
114 : 0 : return true;
115 : : }
116 : :
117 : : //......................................................................................................................
118 : : } // namespace xmloff
119 : : //......................................................................................................................
120 : :
121 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|