From ed5640d8b587fbcfed7dd7967f3de04b37a76f26 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 11:06:44 +0200 Subject: Adding upstream version 4:7.4.7. Signed-off-by: Daniel Baumann --- .../ucp/webdav-curl/UCBDeadPropertyValue.cxx | 220 +++++++++++++++++++++ 1 file changed, 220 insertions(+) create mode 100644 ucb/source/ucp/webdav-curl/UCBDeadPropertyValue.cxx (limited to 'ucb/source/ucp/webdav-curl/UCBDeadPropertyValue.cxx') diff --git a/ucb/source/ucp/webdav-curl/UCBDeadPropertyValue.cxx b/ucb/source/ucp/webdav-curl/UCBDeadPropertyValue.cxx new file mode 100644 index 000000000..1bcf87eac --- /dev/null +++ b/ucb/source/ucp/webdav-curl/UCBDeadPropertyValue.cxx @@ -0,0 +1,220 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * 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/. + * + * This file incorporates work covered by the following license notice: + * + * 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 . + */ + +#include +#include +#include "UCBDeadPropertyValue.hxx" + +using namespace http_dav_ucp; +using namespace ::com::sun::star; + + +// static +constexpr OUStringLiteral aTypeString = u"string"; +constexpr OUStringLiteral aTypeLong = u"long"; +constexpr OUStringLiteral aTypeShort = u"short"; +constexpr OUStringLiteral aTypeBoolean = u"boolean"; +constexpr OUStringLiteral aTypeChar = u"char"; +constexpr OUStringLiteral aTypeByte = u"byte"; +constexpr OUStringLiteral aTypeHyper = u"hyper"; +constexpr OUStringLiteral aTypeFloat = u"float"; +constexpr OUStringLiteral aTypeDouble = u"double"; + +// static +bool UCBDeadPropertyValue::supportsType( const uno::Type & rType ) +{ + if ( ( rType != cppu::UnoType::get() ) + && + ( rType != cppu::UnoType::get() ) + && + ( rType != cppu::UnoType::get() ) + && + ( rType != cppu::UnoType::get() ) + && + ( rType != cppu::UnoType::get() ) + && + ( rType != cppu::UnoType::get() ) + && + ( rType != cppu::UnoType::get() ) + && + ( rType != cppu::UnoType::get() ) + && + ( rType != cppu::UnoType::get() ) ) + { + return false; + } + + return true; +} + + +// static +bool UCBDeadPropertyValue::createFromXML(std::u16string_view rType, + OUString const& rValue, + uno::Any & rOutData) +{ + bool success = true; + + if (o3tl::equalsIgnoreAsciiCase(rType, aTypeString)) + { + rOutData <<= rValue; + } + else if (o3tl::equalsIgnoreAsciiCase(rType, aTypeLong)) + { + rOutData <<= rValue.toInt32(); + } + else if (o3tl::equalsIgnoreAsciiCase(rType, aTypeShort)) + { + rOutData <<= sal_Int16( rValue.toInt32() ); + } + else if (o3tl::equalsIgnoreAsciiCase(rType, aTypeBoolean)) + { + if (rValue.equalsIgnoreAsciiCase(u"true")) + { + rOutData <<= true; + } + else + { + rOutData <<= false; + } + } + else if (o3tl::equalsIgnoreAsciiCase(rType, aTypeChar)) + { + rOutData <<= rValue.toChar(); + } + else if (o3tl::equalsIgnoreAsciiCase(rType, aTypeByte)) + { + rOutData <<= sal_Int8( rValue.toChar() ); + } + else if (o3tl::equalsIgnoreAsciiCase(rType, aTypeHyper)) + { + rOutData <<= rValue.toInt64(); + } + else if (o3tl::equalsIgnoreAsciiCase(rType, aTypeFloat)) + { + rOutData <<= rValue.toFloat(); + } + else if (o3tl::equalsIgnoreAsciiCase(rType, aTypeDouble)) + { + rOutData <<= rValue.toDouble(); + } + else + { + SAL_WARN( "ucb.ucp.webdav", + "UCBDeadPropertyValue::createFromXML - " + "Unsupported property type!" ); + success = false; + } + return success; +} + +// static +::std::optional<::std::pair> +UCBDeadPropertyValue::toXML(const uno::Any & rInData) +{ + // the_typethe_value + + // Check property type. Extract type and value as string. + + const uno::Type& rType = rInData.getValueType(); + OUString aStringValue; + OUString aStringType; + + if ( rType == cppu::UnoType::get() ) + { + // string + rInData >>= aStringValue; + aStringType = aTypeString; + } + else if ( rType == cppu::UnoType::get() ) + { + // long + sal_Int32 nValue = 0; + rInData >>= nValue; + aStringValue = OUString::number( nValue ); + aStringType = aTypeLong; + } + else if ( rType == cppu::UnoType::get() ) + { + // short + sal_Int32 nValue = 0; + rInData >>= nValue; + aStringValue = OUString::number( nValue ); + aStringType = aTypeShort; + } + else if ( rType == cppu::UnoType::get() ) + { + // boolean + bool bValue = false; + rInData >>= bValue; + aStringValue = OUString::boolean( bValue ); + aStringType = aTypeBoolean; + } + else if ( rType == cppu::UnoType::get() ) + { + // char + sal_Unicode cValue = 0; + rInData >>= cValue; + aStringValue = OUString( cValue ); + aStringType = aTypeChar; + } + else if ( rType == cppu::UnoType::get() ) + { + // byte + sal_Int8 nValue = 0; + rInData >>= nValue; + aStringValue = OUString( sal_Unicode( nValue ) ); + aStringType = aTypeByte; + } + else if ( rType == cppu::UnoType::get() ) + { + // hyper + sal_Int64 nValue = 0; + rInData >>= nValue; + aStringValue = OUString::number( nValue ); + aStringType = aTypeHyper; + } + else if ( rType == cppu::UnoType::get() ) + { + // float + float nValue = 0; + rInData >>= nValue; + aStringValue = OUString::number( nValue ); + aStringType = aTypeFloat; + } + else if ( rType == cppu::UnoType::get() ) + { + // double + double nValue = 0; + rInData >>= nValue; + aStringValue = OUString::number( nValue ); + aStringType = aTypeDouble; + } + else + { + SAL_WARN( "ucb.ucp.webdav", + "UCBDeadPropertyValue::toXML - " + "Unsupported property type!" ); + return {}; + } + + return { { aStringType, aStringValue } }; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ -- cgit v1.2.3