LibreOffice Module ucb (master) 1
UCBDeadPropertyValue.cxx
Go to the documentation of this file.
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>
23
24using namespace http_dav_ucp;
25using namespace ::com::sun::star;
26
27
28// static
29constexpr OUStringLiteral aTypeString = u"string";
30constexpr OUStringLiteral aTypeLong = u"long";
31constexpr OUStringLiteral aTypeShort = u"short";
32constexpr OUStringLiteral aTypeBoolean = u"boolean";
33constexpr OUStringLiteral aTypeChar = u"char";
34constexpr OUStringLiteral aTypeByte = u"byte";
35constexpr OUStringLiteral aTypeHyper = u"hyper";
36constexpr OUStringLiteral aTypeFloat = u"float";
37constexpr OUStringLiteral aTypeDouble = u"double";
38
39// static
40bool UCBDeadPropertyValue::supportsType( const uno::Type & rType )
41{
42 if ( ( rType != cppu::UnoType<OUString>::get() )
43 &&
45 &&
47 &&
48 ( rType != cppu::UnoType<bool>::get() )
49 &&
51 &&
52 ( rType != cppu::UnoType<sal_Int8>::get() )
53 &&
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
68bool UCBDeadPropertyValue::createFromXML(std::u16string_view rType,
69 OUString const& rValue,
70 uno::Any & rOutData)
71{
72 bool success = true;
73
75 {
76 rOutData <<= rValue;
77 }
79 {
80 rOutData <<= rValue.toInt32();
81 }
83 {
84 rOutData <<= sal_Int16( rValue.toInt32() );
85 }
87 {
88 if (rValue.equalsIgnoreAsciiCase(u"true"))
89 {
90 rOutData <<= true;
91 }
92 else
93 {
94 rOutData <<= false;
95 }
96 }
98 {
99 rOutData <<= rValue.toChar();
100 }
101 else if (o3tl::equalsIgnoreAsciiCase(rType, aTypeByte))
102 {
103 rOutData <<= sal_Int8( rValue.toChar() );
104 }
106 {
107 rOutData <<= rValue.toInt64();
108 }
110 {
111 rOutData <<= rValue.toFloat();
112 }
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>>
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: */
constexpr OUStringLiteral aTypeString
constexpr OUStringLiteral aTypeFloat
constexpr OUStringLiteral aTypeLong
constexpr OUStringLiteral aTypeByte
constexpr OUStringLiteral aTypeHyper
constexpr OUStringLiteral aTypeBoolean
constexpr OUStringLiteral aTypeDouble
constexpr OUStringLiteral aTypeShort
constexpr OUStringLiteral aTypeChar
static ::std::optional<::std::pair< OUString, OUString > > toXML(const css::uno::Any &rInData)
static bool createFromXML(std::u16string_view rType, OUString const &rValue, css::uno::Any &rOutData)
float u
sal_Int16 nValue
#define SAL_WARN(area, stream)
bool equalsIgnoreAsciiCase(std::u16string_view s1, std::u16string_view s2)
sal_uInt16 sal_Unicode
signed char sal_Int8