| 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 <sal/log.hxx> |
| 21 |
#include <o3tl/string_view.hxx> |
| 22 |
#include "UCBDeadPropertyValue.hxx" |
| 23 |
|
| 24 |
using namespace http_dav_ucp; |
| 25 |
using namespace ::com::sun::star; |
| 26 |
|
| 27 |
|
| 28 |
// static |
| 29 |
constexpr OUString aTypeString = u"string"_ustr; |
| 30 |
constexpr OUString aTypeLong = u"long"_ustr; |
| 31 |
constexpr OUString aTypeShort = u"short"_ustr; |
| 32 |
constexpr OUString aTypeBoolean = u"boolean"_ustr; |
| 33 |
constexpr OUString aTypeChar = u"char"_ustr; |
| 34 |
constexpr OUString aTypeByte = u"byte"_ustr; |
| 35 |
constexpr OUString aTypeHyper = u"hyper"_ustr; |
| 36 |
constexpr OUString aTypeFloat = u"float"_ustr; |
| 37 |
constexpr OUString aTypeDouble = u"double"_ustr; |
| 38 |
|
| 39 |
// static |
| 40 |
bool UCBDeadPropertyValue::supportsType( const uno::Type & rType ) |
| 41 |
{ |
| 42 |
if ( ( rType != cppu::UnoType<OUString>::get() ) |
| 43 |
&& |
| 44 |
( rType != cppu::UnoType<sal_Int32>::get() ) |
| 45 |
&& |
| 46 |
( rType != cppu::UnoType<sal_Int16>::get() ) |
| 47 |
&& |
| 48 |
( rType != cppu::UnoType<bool>::get() ) |
| 49 |
&& |
| 50 |
( rType != cppu::UnoType<cppu::UnoCharType>::get() ) |
| 51 |
&& |
| 52 |
( rType != cppu::UnoType<sal_Int8>::get() ) |
| 53 |
&& |
| 54 |
( rType != cppu::UnoType<sal_Int64>::get() ) |
| 55 |
&& |
| 56 |
( rType != cppu::UnoType<float>::get() ) |
| 57 |
&& |
| 58 |
( rType != cppu::UnoType<double>::get() ) ) |
| 59 |
{ |
| 60 |
return false; |
| 61 |
} |
| 62 |
|
| 63 |
return true; |
| 64 |
} |
| 65 |
|
| 66 |
|
| 67 |
// static |
| 68 |
bool UCBDeadPropertyValue::createFromXML(std::u16string_view rType, |
| 69 |
OUString const& rValue, |
| 70 |
uno::Any & rOutData) |
| 71 |
{ |
| 72 |
bool success = true; |
| 73 |
|
| 74 |
if (o3tl::equalsIgnoreAsciiCase(rType, aTypeString)) |
| 75 |
{ |
| 76 |
rOutData <<= rValue; |
| 77 |
} |
| 78 |
else if (o3tl::equalsIgnoreAsciiCase(rType, aTypeLong)) |
| 79 |
{ |
| 80 |
rOutData <<= rValue.toInt32(); |
| 81 |
} |
| 82 |
else if (o3tl::equalsIgnoreAsciiCase(rType, aTypeShort)) |
| 83 |
{ |
| 84 |
rOutData <<= sal_Int16( rValue.toInt32() ); |
| 85 |
} |
| 86 |
else if (o3tl::equalsIgnoreAsciiCase(rType, aTypeBoolean)) |
| 87 |
{ |
| 88 |
if (rValue.equalsIgnoreAsciiCase(u"true")) |
| 89 |
{ |
| 90 |
rOutData <<= true; |
| 91 |
} |
| 92 |
else |
| 93 |
{ |
| 94 |
rOutData <<= false; |
| 95 |
} |
| 96 |
} |
| 97 |
else if (o3tl::equalsIgnoreAsciiCase(rType, aTypeChar)) |
| 98 |
{ |
| 99 |
rOutData <<= rValue.toChar(); |
| 100 |
} |
| 101 |
else if (o3tl::equalsIgnoreAsciiCase(rType, aTypeByte)) |
| 102 |
{ |
| 103 |
rOutData <<= sal_Int8( rValue.toChar() ); |
| 104 |
} |
| 105 |
else if (o3tl::equalsIgnoreAsciiCase(rType, aTypeHyper)) |
| 106 |
{ |
| 107 |
rOutData <<= rValue.toInt64(); |
| 108 |
} |
| 109 |
else if (o3tl::equalsIgnoreAsciiCase(rType, aTypeFloat)) |
| 110 |
{ |
| 111 |
rOutData <<= rValue.toFloat(); |
| 112 |
} |
| 113 |
else if (o3tl::equalsIgnoreAsciiCase(rType, aTypeDouble)) |
| 114 |
{ |
| 115 |
rOutData <<= rValue.toDouble(); |
| 116 |
} |
| 117 |
else |
| 118 |
{ |
| 119 |
SAL_WARN( "ucb.ucp.webdav", |
| 120 |
"UCBDeadPropertyValue::createFromXML - " |
| 121 |
"Unsupported property type!" ); |
| 122 |
success = false; |
| 123 |
} |
| 124 |
return success; |
| 125 |
} |
| 126 |
|
| 127 |
// static |
| 128 |
::std::optional<::std::pair<OUString, OUString>> |
| 129 |
UCBDeadPropertyValue::toXML(const uno::Any & rInData) |
| 130 |
{ |
| 131 |
// <ucbprop><type>the_type</type><value>the_value</value></ucbprop> |
| 132 |
|
| 133 |
// Check property type. Extract type and value as string. |
| 134 |
|
| 135 |
const uno::Type& rType = rInData.getValueType(); |
| 136 |
OUString aStringValue; |
| 137 |
OUString aStringType; |
| 138 |
|
| 139 |
if ( rType == cppu::UnoType<OUString>::get() ) |
| 140 |
{ |
| 141 |
// string |
| 142 |
rInData >>= aStringValue; |
| 143 |
aStringType = aTypeString; |
| 144 |
} |
| 145 |
else if ( rType == cppu::UnoType<sal_Int32>::get() ) |
| 146 |
{ |
| 147 |
// long |
| 148 |
sal_Int32 nValue = 0; |
| 149 |
rInData >>= nValue; |
| 150 |
aStringValue = OUString::number( nValue ); |
| 151 |
aStringType = aTypeLong; |
| 152 |
} |
| 153 |
else if ( rType == cppu::UnoType<sal_Int16>::get() ) |
| 154 |
{ |
| 155 |
// short |
| 156 |
sal_Int32 nValue = 0; |
| 157 |
rInData >>= nValue; |
| 158 |
aStringValue = OUString::number( nValue ); |
| 159 |
aStringType = aTypeShort; |
| 160 |
} |
| 161 |
else if ( rType == cppu::UnoType<bool>::get() ) |
| 162 |
{ |
| 163 |
// boolean |
| 164 |
bool bValue = false; |
| 165 |
rInData >>= bValue; |
| 166 |
aStringValue = OUString::boolean( bValue ); |
| 167 |
aStringType = aTypeBoolean; |
| 168 |
} |
| 169 |
else if ( rType == cppu::UnoType<cppu::UnoCharType>::get() ) |
| 170 |
{ |
| 171 |
// char |
| 172 |
sal_Unicode cValue = 0; |
| 173 |
rInData >>= cValue; |
| 174 |
aStringValue = OUString( cValue ); |
| 175 |
aStringType = aTypeChar; |
| 176 |
} |
| 177 |
else if ( rType == cppu::UnoType<sal_Int8>::get() ) |
| 178 |
{ |
| 179 |
// byte |
| 180 |
sal_Int8 nValue = 0; |
| 181 |
rInData >>= nValue; |
| 182 |
aStringValue = OUString( sal_Unicode( nValue ) ); |
| 183 |
aStringType = aTypeByte; |
| 184 |
} |
| 185 |
else if ( rType == cppu::UnoType<sal_Int64>::get() ) |
| 186 |
{ |
| 187 |
// hyper |
| 188 |
sal_Int64 nValue = 0; |
| 189 |
rInData >>= nValue; |
| 190 |
aStringValue = OUString::number( nValue ); |
| 191 |
aStringType = aTypeHyper; |
| 192 |
} |
| 193 |
else if ( rType == cppu::UnoType<float>::get() ) |
| 194 |
{ |
| 195 |
// float |
| 196 |
float nValue = 0; |
| 197 |
rInData >>= nValue; |
| 198 |
aStringValue = OUString::number( nValue ); |
| 199 |
aStringType = aTypeFloat; |
| 200 |
} |
| 201 |
else if ( rType == cppu::UnoType<double>::get() ) |
| 202 |
{ |
| 203 |
// double |
| 204 |
double nValue = 0; |
| 205 |
rInData >>= nValue; |
| 206 |
aStringValue = OUString::number( nValue ); |
| 207 |
aStringType = aTypeDouble; |
| 208 |
} |
| 209 |
else |
| 210 |
{ |
| 211 |
SAL_WARN( "ucb.ucp.webdav", |
| 212 |
"UCBDeadPropertyValue::toXML - " |
| 213 |
"Unsupported property type!" ); |
| 214 |
return {}; |
| 215 |
} |
| 216 |
|
| 217 |
return { { aStringType, aStringValue } }; |
| 218 |
} |
| 219 |
|
| 220 |
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |