2011-09-29 21:42:27 +01:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-11-12 17:21:24 +00:00
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
2010-09-15 13:55:34 +02:00
|
|
|
*
|
2012-11-12 17:21:24 +00:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
2010-09-15 13:55:34 +02:00
|
|
|
*
|
2012-11-12 17:21:24 +00:00
|
|
|
* This file incorporates work covered by the following license notice:
|
2010-09-15 13:55:34 +02:00
|
|
|
*
|
2012-11-12 17:21:24 +00:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed
|
|
|
|
* with this work for additional information regarding copyright
|
|
|
|
* ownership. The ASF licenses this file to you under the Apache
|
|
|
|
* License, Version 2.0 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
|
|
|
|
*/
|
2010-09-15 13:55:34 +02:00
|
|
|
|
|
|
|
|
|
|
|
#include "vcl_time_handler.hxx"
|
|
|
|
|
#i108468#: clean up xmluconv code duplication, part 1:
move convertNumber64 from SvXMLUnitConverter to sax::converter.
remove duplicate methods from SvXMLUnitConverter:
convertBool, convertPercent, convertColor, convertNumber, convertDouble,
indexOfComma, encodeBase64, decodeBase64, decodeBase64SomeChars,
clearUndefinedChars
2011-10-11 14:19:00 +02:00
|
|
|
#include <rtl/ustrbuf.hxx>
|
|
|
|
|
2011-10-11 14:19:08 +02:00
|
|
|
#include <com/sun/star/util/Duration.hpp>
|
2010-09-15 13:55:34 +02:00
|
|
|
|
#i108468#: clean up xmluconv code duplication, part 1:
move convertNumber64 from SvXMLUnitConverter to sax::converter.
remove duplicate methods from SvXMLUnitConverter:
convertBool, convertPercent, convertColor, convertNumber, convertDouble,
indexOfComma, encodeBase64, decodeBase64, decodeBase64SomeChars,
clearUndefinedChars
2011-10-11 14:19:00 +02:00
|
|
|
#include <sax/tools/converter.hxx>
|
|
|
|
|
2010-09-15 13:55:34 +02:00
|
|
|
#include <tools/diagnose_ex.h>
|
|
|
|
#include <tools/time.hxx>
|
|
|
|
|
|
|
|
//......................................................................................................................
|
|
|
|
namespace xmloff
|
|
|
|
{
|
|
|
|
//......................................................................................................................
|
|
|
|
|
|
|
|
using ::com::sun::star::uno::Any;
|
|
|
|
using ::com::sun::star::uno::makeAny;
|
2011-10-11 14:19:08 +02:00
|
|
|
using ::com::sun::star::util::Duration;
|
2010-09-15 13:55:34 +02:00
|
|
|
|
|
|
|
//==================================================================================================================
|
|
|
|
//= VCLTimeHandler
|
|
|
|
//==================================================================================================================
|
|
|
|
//------------------------------------------------------------------------------------------------------------------
|
|
|
|
VCLTimeHandler::VCLTimeHandler()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------------------------------------------
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString VCLTimeHandler::getAttributeValue( const PropertyValues& /*i_propertyValues*/ ) const
|
2010-09-15 13:55:34 +02:00
|
|
|
{
|
|
|
|
OSL_ENSURE( false, "VCLTimeHandler::getAttributeValue: unexpected call!" );
|
2013-04-07 12:06:47 +02:00
|
|
|
return OUString();
|
2010-09-15 13:55:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------------------------------------------
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString VCLTimeHandler::getAttributeValue( const Any& i_propertyValue ) const
|
2010-09-15 13:55:34 +02:00
|
|
|
{
|
|
|
|
sal_Int32 nVCLTime(0);
|
|
|
|
OSL_VERIFY( i_propertyValue >>= nVCLTime );
|
|
|
|
::Time aVCLTime( nVCLTime );
|
|
|
|
|
2011-10-11 14:19:08 +02:00
|
|
|
Duration aDuration; // default-inited to 0
|
|
|
|
aDuration.Hours = aVCLTime.GetHour();
|
|
|
|
aDuration.Minutes = aVCLTime.GetMin();
|
|
|
|
aDuration.Seconds = aVCLTime.GetSec();
|
2013-03-17 08:36:26 +01:00
|
|
|
aDuration.NanoSeconds = aVCLTime.GetNanoSec();
|
2010-09-15 13:55:34 +02:00
|
|
|
|
2013-04-07 12:06:47 +02:00
|
|
|
OUStringBuffer aBuffer;
|
2011-10-11 14:19:08 +02:00
|
|
|
::sax::Converter::convertDuration( aBuffer, aDuration );
|
2010-09-15 13:55:34 +02:00
|
|
|
return aBuffer.makeStringAndClear();
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------------------------------------------
|
2013-04-07 12:06:47 +02:00
|
|
|
bool VCLTimeHandler::getPropertyValues( const OUString i_attributeValue, PropertyValues& o_propertyValues ) const
|
2010-09-15 13:55:34 +02:00
|
|
|
{
|
|
|
|
sal_Int32 nVCLTime(0);
|
|
|
|
|
2011-10-11 14:19:08 +02:00
|
|
|
Duration aDuration;
|
|
|
|
if (::sax::Converter::convertDuration( aDuration, i_attributeValue ))
|
2010-09-15 13:55:34 +02:00
|
|
|
{
|
2011-10-11 14:19:08 +02:00
|
|
|
::Time aVCLTime(aDuration.Hours, aDuration.Minutes,
|
2013-03-17 08:36:26 +01:00
|
|
|
aDuration.Seconds, aDuration.NanoSeconds);
|
2010-09-15 13:55:34 +02:00
|
|
|
nVCLTime = aVCLTime.GetTime();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// compatibility format, before we wrote those values in XML-schema compatible form
|
#i108468#: clean up xmluconv code duplication, part 1:
move convertNumber64 from SvXMLUnitConverter to sax::converter.
remove duplicate methods from SvXMLUnitConverter:
convertBool, convertPercent, convertColor, convertNumber, convertDouble,
indexOfComma, encodeBase64, decodeBase64, decodeBase64SomeChars,
clearUndefinedChars
2011-10-11 14:19:00 +02:00
|
|
|
if (!::sax::Converter::convertNumber(nVCLTime, i_attributeValue))
|
2010-09-15 13:55:34 +02:00
|
|
|
{
|
|
|
|
OSL_ENSURE( false, "VCLTimeHandler::getPropertyValues: unknown time format (no XML-schema time, no legacy integer)!" );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const Any aPropertyValue( makeAny( nVCLTime ) );
|
|
|
|
|
|
|
|
OSL_ENSURE( o_propertyValues.size() == 1, "VCLTimeHandler::getPropertyValues: time strings represent exactly one property - not more, not less!" );
|
|
|
|
for ( PropertyValues::iterator prop = o_propertyValues.begin();
|
|
|
|
prop != o_propertyValues.end();
|
|
|
|
++prop
|
|
|
|
)
|
|
|
|
{
|
|
|
|
prop->second = aPropertyValue;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//......................................................................................................................
|
|
|
|
} // namespace xmloff
|
|
|
|
//......................................................................................................................
|
2011-09-29 21:42:27 +01:00
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|