1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #include "precompiled_xmloff.hxx"
25 
26 #include "vcl_time_handler.hxx"
27 #include "xmloff/xmluconv.hxx"
28 
29 #include <com/sun/star/util/DateTime.hpp>
30 
31 #include <tools/diagnose_ex.h>
32 #include <tools/time.hxx>
33 
34 //......................................................................................................................
35 namespace xmloff
36 {
37 //......................................................................................................................
38 
39     using ::com::sun::star::uno::Any;
40     using ::com::sun::star::uno::makeAny;
41     using ::com::sun::star::util::DateTime;
42 
43 	//==================================================================================================================
44 	//= VCLTimeHandler
45 	//==================================================================================================================
46 	//------------------------------------------------------------------------------------------------------------------
VCLTimeHandler()47     VCLTimeHandler::VCLTimeHandler()
48     {
49     }
50 
51 	//------------------------------------------------------------------------------------------------------------------
getAttributeValue(const PropertyValues &) const52     ::rtl::OUString VCLTimeHandler::getAttributeValue( const PropertyValues& /*i_propertyValues*/ ) const
53     {
54         OSL_ENSURE( false, "VCLTimeHandler::getAttributeValue: unexpected call!" );
55         return ::rtl::OUString();
56     }
57 
58 	//------------------------------------------------------------------------------------------------------------------
getAttributeValue(const Any & i_propertyValue) const59     ::rtl::OUString VCLTimeHandler::getAttributeValue( const Any& i_propertyValue ) const
60     {
61         sal_Int32 nVCLTime(0);
62         OSL_VERIFY( i_propertyValue >>= nVCLTime );
63         ::Time aVCLTime( nVCLTime );
64 
65         DateTime aDateTime; // default-inited to 0
66         aDateTime.Hours = aVCLTime.GetHour();
67         aDateTime.Minutes = aVCLTime.GetMin();
68         aDateTime.Seconds = aVCLTime.GetSec();
69         aDateTime.HundredthSeconds = aVCLTime.Get100Sec();
70 
71         ::rtl::OUStringBuffer aBuffer;
72         SvXMLUnitConverter::convertTime( aBuffer, aDateTime );
73         return aBuffer.makeStringAndClear();
74     }
75 
76 	//------------------------------------------------------------------------------------------------------------------
getPropertyValues(const::rtl::OUString i_attributeValue,PropertyValues & o_propertyValues) const77     bool VCLTimeHandler::getPropertyValues( const ::rtl::OUString i_attributeValue, PropertyValues& o_propertyValues ) const
78     {
79         sal_Int32 nVCLTime(0);
80 
81         DateTime aDateTime;
82         if ( SvXMLUnitConverter::convertTime( aDateTime, i_attributeValue ) )
83         {
84             ::Time aVCLTime( aDateTime.Hours, aDateTime.Minutes, aDateTime.Seconds, aDateTime.HundredthSeconds );
85             nVCLTime = aVCLTime.GetTime();
86         }
87         else
88         {
89             // compatibility format, before we wrote those values in XML-schema compatible form
90 			if ( !SvXMLUnitConverter::convertNumber( nVCLTime, i_attributeValue ) )
91             {
92                 OSL_ENSURE( false, "VCLTimeHandler::getPropertyValues: unknown time format (no XML-schema time, no legacy integer)!" );
93                 return false;
94             }
95         }
96 
97         const Any aPropertyValue( makeAny( nVCLTime ) );
98 
99         OSL_ENSURE( o_propertyValues.size() == 1, "VCLTimeHandler::getPropertyValues: time strings represent exactly one property - not more, not less!" );
100         for (   PropertyValues::iterator prop = o_propertyValues.begin();
101                 prop != o_propertyValues.end();
102                 ++prop
103             )
104         {
105             prop->second = aPropertyValue;
106         }
107         return true;
108     }
109 
110 //......................................................................................................................
111 } // namespace xmloff
112 //......................................................................................................................
113