LCOV - code coverage report
Current view: top level - xmloff/source/forms/handler - vcl_time_handler.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 30 0.0 %
Date: 2014-04-14 Functions: 0 4 0.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10