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