| 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_date_handler.hxx" |
| 21 |
|
| 22 |
#include <rtl/ustrbuf.hxx> |
| 23 |
|
| 24 |
#include <com/sun/star/util/DateTime.hpp> |
| 25 |
#include <com/sun/star/util/Date.hpp> |
| 26 |
|
| 27 |
#include <sax/tools/converter.hxx> |
| 28 |
|
| 29 |
#include <osl/diagnose.h> |
| 30 |
#include <tools/date.hxx> |
| 31 |
|
| 32 |
namespace xmloff |
| 33 |
{ |
| 34 |
|
| 35 |
using ::com::sun::star::uno::Any; |
| 36 |
using ::com::sun::star::util::DateTime; |
| 37 |
using ::com::sun::star::util::Date; |
| 38 |
|
| 39 |
//= VCLDateHandler |
| 40 |
VCLDateHandler::VCLDateHandler() |
| 41 |
{ |
| 42 |
} |
| 43 |
|
| 44 |
OUString VCLDateHandler::getAttributeValue( const Any& i_propertyValue ) const |
| 45 |
{ |
| 46 |
Date aDate; |
| 47 |
OSL_VERIFY( i_propertyValue >>= aDate ); |
| 48 |
|
| 49 |
DateTime aDateTime; // default-inited to 0 |
| 50 |
aDateTime.Day = aDate.Day; |
| 51 |
aDateTime.Month = aDate.Month; |
| 52 |
aDateTime.Year = aDate.Year; |
| 53 |
|
| 54 |
OUStringBuffer aBuffer; |
| 55 |
::sax::Converter::convertDateTime( aBuffer, aDateTime, nullptr ); |
| 56 |
return aBuffer.makeStringAndClear(); |
| 57 |
} |
| 58 |
|
| 59 |
bool VCLDateHandler::getPropertyValues( const OUString& i_attributeValue, PropertyValues& o_propertyValues ) const |
| 60 |
{ |
| 61 |
DateTime aDateTime; |
| 62 |
Date aDate; |
| 63 |
if (::sax::Converter::parseDateTime( aDateTime, i_attributeValue )) |
| 64 |
{ |
| 65 |
aDate.Day = aDateTime.Day; |
| 66 |
aDate.Month = aDateTime.Month; |
| 67 |
aDate.Year = aDateTime.Year; |
| 68 |
} |
| 69 |
else |
| 70 |
{ |
| 71 |
// compatibility format, before we wrote those values in XML-schema compatible form |
| 72 |
sal_Int32 nVCLDate(0); |
| 73 |
if (!::sax::Converter::convertNumber(nVCLDate, i_attributeValue)) |
| 74 |
{ |
| 75 |
OSL_ENSURE( false, "VCLDateHandler::getPropertyValues: unknown date format (no XML-schema date, no legacy integer)!" ); |
| 76 |
return false; |
| 77 |
} |
| 78 |
aDate = ::Date(nVCLDate).GetUNODate(); |
| 79 |
} |
| 80 |
|
| 81 |
const Any aPropertyValue( aDate ); |
| 82 |
|
| 83 |
OSL_ENSURE( o_propertyValues.size() == 1, "VCLDateHandler::getPropertyValues: date strings represent exactly one property - not more, not less!" ); |
| 84 |
for ( auto& prop : o_propertyValues ) |
| 85 |
{ |
| 86 |
prop.second = aPropertyValue; |
| 87 |
} |
| 88 |
return true; |
| 89 |
} |
| 90 |
|
| 91 |
} // namespace xmloff |
| 92 |
|
| 93 |
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |