Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / ucb / source / ucp / webdav-curl / UCBDeadPropertyValue.cxx
blob1bcf87eacf3d1e340ac1d61896b65bf352aa4728
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <sal/log.hxx>
21 #include <o3tl/string_view.hxx>
22 #include "UCBDeadPropertyValue.hxx"
24 using namespace http_dav_ucp;
25 using namespace ::com::sun::star;
28 // static
29 constexpr OUStringLiteral aTypeString = u"string";
30 constexpr OUStringLiteral aTypeLong = u"long";
31 constexpr OUStringLiteral aTypeShort = u"short";
32 constexpr OUStringLiteral aTypeBoolean = u"boolean";
33 constexpr OUStringLiteral aTypeChar = u"char";
34 constexpr OUStringLiteral aTypeByte = u"byte";
35 constexpr OUStringLiteral aTypeHyper = u"hyper";
36 constexpr OUStringLiteral aTypeFloat = u"float";
37 constexpr OUStringLiteral aTypeDouble = u"double";
39 // static
40 bool UCBDeadPropertyValue::supportsType( const uno::Type & rType )
42 if ( ( rType != cppu::UnoType<OUString>::get() )
44 ( rType != cppu::UnoType<sal_Int32>::get() )
46 ( rType != cppu::UnoType<sal_Int16>::get() )
48 ( rType != cppu::UnoType<bool>::get() )
50 ( rType != cppu::UnoType<cppu::UnoCharType>::get() )
52 ( rType != cppu::UnoType<sal_Int8>::get() )
54 ( rType != cppu::UnoType<sal_Int64>::get() )
56 ( rType != cppu::UnoType<float>::get() )
58 ( rType != cppu::UnoType<double>::get() ) )
60 return false;
63 return true;
67 // static
68 bool UCBDeadPropertyValue::createFromXML(std::u16string_view rType,
69 OUString const& rValue,
70 uno::Any & rOutData)
72 bool success = true;
74 if (o3tl::equalsIgnoreAsciiCase(rType, aTypeString))
76 rOutData <<= rValue;
78 else if (o3tl::equalsIgnoreAsciiCase(rType, aTypeLong))
80 rOutData <<= rValue.toInt32();
82 else if (o3tl::equalsIgnoreAsciiCase(rType, aTypeShort))
84 rOutData <<= sal_Int16( rValue.toInt32() );
86 else if (o3tl::equalsIgnoreAsciiCase(rType, aTypeBoolean))
88 if (rValue.equalsIgnoreAsciiCase(u"true"))
90 rOutData <<= true;
92 else
94 rOutData <<= false;
97 else if (o3tl::equalsIgnoreAsciiCase(rType, aTypeChar))
99 rOutData <<= rValue.toChar();
101 else if (o3tl::equalsIgnoreAsciiCase(rType, aTypeByte))
103 rOutData <<= sal_Int8( rValue.toChar() );
105 else if (o3tl::equalsIgnoreAsciiCase(rType, aTypeHyper))
107 rOutData <<= rValue.toInt64();
109 else if (o3tl::equalsIgnoreAsciiCase(rType, aTypeFloat))
111 rOutData <<= rValue.toFloat();
113 else if (o3tl::equalsIgnoreAsciiCase(rType, aTypeDouble))
115 rOutData <<= rValue.toDouble();
117 else
119 SAL_WARN( "ucb.ucp.webdav",
120 "UCBDeadPropertyValue::createFromXML - "
121 "Unsupported property type!" );
122 success = false;
124 return success;
127 // static
128 ::std::optional<::std::pair<OUString, OUString>>
129 UCBDeadPropertyValue::toXML(const uno::Any & rInData)
131 // <ucbprop><type>the_type</type><value>the_value</value></ucbprop>
133 // Check property type. Extract type and value as string.
135 const uno::Type& rType = rInData.getValueType();
136 OUString aStringValue;
137 OUString aStringType;
139 if ( rType == cppu::UnoType<OUString>::get() )
141 // string
142 rInData >>= aStringValue;
143 aStringType = aTypeString;
145 else if ( rType == cppu::UnoType<sal_Int32>::get() )
147 // long
148 sal_Int32 nValue = 0;
149 rInData >>= nValue;
150 aStringValue = OUString::number( nValue );
151 aStringType = aTypeLong;
153 else if ( rType == cppu::UnoType<sal_Int16>::get() )
155 // short
156 sal_Int32 nValue = 0;
157 rInData >>= nValue;
158 aStringValue = OUString::number( nValue );
159 aStringType = aTypeShort;
161 else if ( rType == cppu::UnoType<bool>::get() )
163 // boolean
164 bool bValue = false;
165 rInData >>= bValue;
166 aStringValue = OUString::boolean( bValue );
167 aStringType = aTypeBoolean;
169 else if ( rType == cppu::UnoType<cppu::UnoCharType>::get() )
171 // char
172 sal_Unicode cValue = 0;
173 rInData >>= cValue;
174 aStringValue = OUString( cValue );
175 aStringType = aTypeChar;
177 else if ( rType == cppu::UnoType<sal_Int8>::get() )
179 // byte
180 sal_Int8 nValue = 0;
181 rInData >>= nValue;
182 aStringValue = OUString( sal_Unicode( nValue ) );
183 aStringType = aTypeByte;
185 else if ( rType == cppu::UnoType<sal_Int64>::get() )
187 // hyper
188 sal_Int64 nValue = 0;
189 rInData >>= nValue;
190 aStringValue = OUString::number( nValue );
191 aStringType = aTypeHyper;
193 else if ( rType == cppu::UnoType<float>::get() )
195 // float
196 float nValue = 0;
197 rInData >>= nValue;
198 aStringValue = OUString::number( nValue );
199 aStringType = aTypeFloat;
201 else if ( rType == cppu::UnoType<double>::get() )
203 // double
204 double nValue = 0;
205 rInData >>= nValue;
206 aStringValue = OUString::number( nValue );
207 aStringType = aTypeDouble;
209 else
211 SAL_WARN( "ucb.ucp.webdav",
212 "UCBDeadPropertyValue::toXML - "
213 "Unsupported property type!" );
214 return {};
217 return { { aStringType, aStringValue } };
220 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */