1 /*************************************************************************
2  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3  *
4  * Copyright 2000, 2010 Oracle and/or its affiliates.
5  *
6  * OpenOffice.org - a multi-platform office productivity suite
7  *
8  * This file is part of OpenOffice.org.
9  *
10  * OpenOffice.org is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU Lesser General Public License version 3
12  * only, as published by the Free Software Foundation.
13  *
14  * OpenOffice.org is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU Lesser General Public License version 3 for more details
18  * (a copy is included in the LICENSE file that accompanied this code).
19  *
20  * You should have received a copy of the GNU Lesser General Public License
21  * version 3 along with OpenOffice.org.  If not, see
22  * <http://www.openoffice.org/license.html>
23  * for a copy of the LGPLv3 License.
24  *
25  ************************************************************************/
26 
27 #include "precompiled_xmloff.hxx"
28 
29 #include "vcl_time_handler.hxx"
30 #include "xmloff/xmluconv.hxx"
31 
32 #include <com/sun/star/util/DateTime.hpp>
33 
34 #include <tools/diagnose_ex.h>
35 #include <tools/time.hxx>
36 
37 //......................................................................................................................
38 namespace xmloff
39 {
40 //......................................................................................................................
41 
42     using ::com::sun::star::uno::Any;
43     using ::com::sun::star::uno::makeAny;
44     using ::com::sun::star::util::DateTime;
45 
46 	//==================================================================================================================
47 	//= VCLTimeHandler
48 	//==================================================================================================================
49 	//------------------------------------------------------------------------------------------------------------------
50     VCLTimeHandler::VCLTimeHandler()
51     {
52     }
53 
54 	//------------------------------------------------------------------------------------------------------------------
55     ::rtl::OUString VCLTimeHandler::getAttributeValue( const PropertyValues& /*i_propertyValues*/ ) const
56     {
57         OSL_ENSURE( false, "VCLTimeHandler::getAttributeValue: unexpected call!" );
58         return ::rtl::OUString();
59     }
60 
61 	//------------------------------------------------------------------------------------------------------------------
62     ::rtl::OUString VCLTimeHandler::getAttributeValue( const Any& i_propertyValue ) const
63     {
64         sal_Int32 nVCLTime(0);
65         OSL_VERIFY( i_propertyValue >>= nVCLTime );
66         ::Time aVCLTime( nVCLTime );
67 
68         DateTime aDateTime; // default-inited to 0
69         aDateTime.Hours = aVCLTime.GetHour();
70         aDateTime.Minutes = aVCLTime.GetMin();
71         aDateTime.Seconds = aVCLTime.GetSec();
72         aDateTime.HundredthSeconds = aVCLTime.Get100Sec();
73 
74         ::rtl::OUStringBuffer aBuffer;
75         SvXMLUnitConverter::convertTime( aBuffer, aDateTime );
76         return aBuffer.makeStringAndClear();
77     }
78 
79 	//------------------------------------------------------------------------------------------------------------------
80     bool VCLTimeHandler::getPropertyValues( const ::rtl::OUString i_attributeValue, PropertyValues& o_propertyValues ) const
81     {
82         sal_Int32 nVCLTime(0);
83 
84         DateTime aDateTime;
85         if ( SvXMLUnitConverter::convertTime( aDateTime, i_attributeValue ) )
86         {
87             ::Time aVCLTime( aDateTime.Hours, aDateTime.Minutes, aDateTime.Seconds, aDateTime.HundredthSeconds );
88             nVCLTime = aVCLTime.GetTime();
89         }
90         else
91         {
92             // compatibility format, before we wrote those values in XML-schema compatible form
93 			if ( !SvXMLUnitConverter::convertNumber( nVCLTime, i_attributeValue ) )
94             {
95                 OSL_ENSURE( false, "VCLTimeHandler::getPropertyValues: unknown time format (no XML-schema time, no legacy integer)!" );
96                 return false;
97             }
98         }
99 
100         const Any aPropertyValue( makeAny( nVCLTime ) );
101 
102         OSL_ENSURE( o_propertyValues.size() == 1, "VCLTimeHandler::getPropertyValues: time strings represent exactly one property - not more, not less!" );
103         for (   PropertyValues::iterator prop = o_propertyValues.begin();
104                 prop != o_propertyValues.end();
105                 ++prop
106             )
107         {
108             prop->second = aPropertyValue;
109         }
110         return true;
111     }
112 
113 //......................................................................................................................
114 } // namespace xmloff
115 //......................................................................................................................
116