1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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
;
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";
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() ) )
68 bool UCBDeadPropertyValue::createFromXML(std::u16string_view rType
,
69 OUString
const& rValue
,
74 if (o3tl::equalsIgnoreAsciiCase(rType
, aTypeString
))
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"))
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();
119 SAL_WARN( "ucb.ucp.webdav",
120 "UCBDeadPropertyValue::createFromXML - "
121 "Unsupported property type!" );
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() )
142 rInData
>>= aStringValue
;
143 aStringType
= aTypeString
;
145 else if ( rType
== cppu::UnoType
<sal_Int32
>::get() )
148 sal_Int32 nValue
= 0;
150 aStringValue
= OUString::number( nValue
);
151 aStringType
= aTypeLong
;
153 else if ( rType
== cppu::UnoType
<sal_Int16
>::get() )
156 sal_Int32 nValue
= 0;
158 aStringValue
= OUString::number( nValue
);
159 aStringType
= aTypeShort
;
161 else if ( rType
== cppu::UnoType
<bool>::get() )
166 aStringValue
= OUString::boolean( bValue
);
167 aStringType
= aTypeBoolean
;
169 else if ( rType
== cppu::UnoType
<cppu::UnoCharType
>::get() )
172 sal_Unicode cValue
= 0;
174 aStringValue
= OUString( cValue
);
175 aStringType
= aTypeChar
;
177 else if ( rType
== cppu::UnoType
<sal_Int8
>::get() )
182 aStringValue
= OUString( sal_Unicode( nValue
) );
183 aStringType
= aTypeByte
;
185 else if ( rType
== cppu::UnoType
<sal_Int64
>::get() )
188 sal_Int64 nValue
= 0;
190 aStringValue
= OUString::number( nValue
);
191 aStringType
= aTypeHyper
;
193 else if ( rType
== cppu::UnoType
<float>::get() )
198 aStringValue
= OUString::number( nValue
);
199 aStringType
= aTypeFloat
;
201 else if ( rType
== cppu::UnoType
<double>::get() )
206 aStringValue
= OUString::number( nValue
);
207 aStringType
= aTypeDouble
;
211 SAL_WARN( "ucb.ucp.webdav",
212 "UCBDeadPropertyValue::toXML - "
213 "Unsupported property type!" );
217 return { { aStringType
, aStringValue
} };
220 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */