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 <osl/diagnose.h>
21 #include <com/sun/star/uno/Type.hxx>
22 #include <com/sun/star/uno/Sequence.hxx>
23 #include <com/sun/star/uno/Reference.hxx>
24 #include <com/sun/star/beans/PropertyAttribute.hpp>
25 #include <com/sun/star/ucb/CrossReference.hpp>
26 #include <com/sun/star/util/DateTime.hpp>
27 #include <com/sun/star/ucb/DocumentHeaderField.hpp>
28 #include <com/sun/star/ucb/RecipientInfo.hpp>
29 #include <com/sun/star/ucb/RuleSet.hpp>
30 #include <com/sun/star/ucb/SendInfo.hpp>
31 #include <com/sun/star/ucb/SendMediaTypes.hpp>
32 #include <com/sun/star/ucb/XDataContainer.hpp>
33 #include "ucbprops.hxx"
35 using namespace com::sun::star::beans
;
36 using namespace com::sun::star::lang
;
37 using namespace com::sun::star::ucb
;
38 using namespace com::sun::star::uno
;
39 using namespace com::sun::star::util
;
44 // struct PropertyTableEntry
48 struct PropertyTableEntry
52 sal_Int16 nAttributes
;
53 const com::sun::star::uno::Type
& (*pGetCppuType
)();
58 // CPPU type access functions.
62 static const com::sun::star::uno::Type
& OUString_getCppuType()
64 return cppu::UnoType
<OUString
>::get();
67 static const com::sun::star::uno::Type
& sal_uInt16_getCppuType()
69 // ! uInt -> Int, because of Java !!!
70 return cppu::UnoType
<sal_Int16
>::get();
73 static const com::sun::star::uno::Type
& sal_uInt32_getCppuType()
75 // ! uInt -> Int, because of Java !!!
76 return cppu::UnoType
<sal_Int32
>::get();
79 static const com::sun::star::uno::Type
& sal_uInt64_getCppuType()
81 // ! uInt -> Int, because of Java !!!
82 return cppu::UnoType
<sal_Int64
>::get();
85 static const com::sun::star::uno::Type
& enum_getCppuType()
87 // ! enum -> Int, because of Java !!!
88 return cppu::UnoType
<sal_Int16
>::get();
91 static const com::sun::star::uno::Type
& sal_Bool_getCppuType()
93 return cppu::UnoType
<bool>::get();
96 static const com::sun::star::uno::Type
& byte_getCppuType()
98 return cppu::UnoType
<sal_Int8
>::get();
101 static const com::sun::star::uno::Type
& Sequence_CrossReference_getCppuType()
103 return cppu::UnoType
<
104 com::sun::star::uno::Sequence
<
105 com::sun::star::ucb::CrossReference
>>::get();
108 static const com::sun::star::uno::Type
& DateTime_getCppuType()
110 return cppu::UnoType
<
111 com::sun::star::util::DateTime
>::get();
114 static const com::sun::star::uno::Type
& Sequence_byte_getCppuType()
116 return cppu::UnoType
<
117 com::sun::star::uno::Sequence
< sal_Int8
>>::get();
120 static const com::sun::star::uno::Type
& Sequence_DocumentHeaderField_getCppuType()
122 return cppu::UnoType
<
123 com::sun::star::uno::Sequence
<
124 com::sun::star::ucb::DocumentHeaderField
>>::get();
127 static const com::sun::star::uno::Type
& XDataContainer_getCppuType()
129 return cppu::UnoType
<
130 com::sun::star::uno::Reference
<
131 com::sun::star::ucb::XDataContainer
>>::get();
134 static const com::sun::star::uno::Type
& Sequence_RecipientInfo_getCppuType()
136 return cppu::UnoType
<
137 com::sun::star::uno::Sequence
<
138 com::sun::star::ucb::RecipientInfo
>>::get();
141 static const com::sun::star::uno::Type
& RuleSet_getCppuType()
143 return cppu::UnoType
<com::sun::star::ucb::RuleSet
>::get();
146 static const com::sun::star::uno::Type
& Sequence_SendInfo_getCppuType()
148 return cppu::UnoType
<
149 com::sun::star::uno::Sequence
<
150 com::sun::star::ucb::SendInfo
>>::get();
153 static const com::sun::star::uno::Type
& Sequence_SendMediaTypes_getCppuType()
155 return cppu::UnoType
<
156 com::sun::star::uno::Sequence
<
157 com::sun::star::ucb::SendMediaTypes
>>::get();
161 // A table with all well-known UCB properties.
164 #define ATTR_DEFAULT ( PropertyAttribute::BOUND | PropertyAttribute::MAYBEVOID | PropertyAttribute::MAYBEDEFAULT )
166 static const PropertyTableEntry __aPropertyTable
[] =
168 { "Account", -1, ATTR_DEFAULT
, &OUString_getCppuType
},
169 { "AutoUpdateInterval", -1, ATTR_DEFAULT
, &sal_uInt32_getCppuType
},
170 { "ConfirmEmpty", -1, ATTR_DEFAULT
, &sal_Bool_getCppuType
},
171 { "ConnectionLimit", -1, ATTR_DEFAULT
, &byte_getCppuType
},
172 { "ConnectionMode", -1, ATTR_DEFAULT
, &enum_getCppuType
},
173 { "ContentCountLimit", -1, ATTR_DEFAULT
, &sal_uInt16_getCppuType
},
174 { "ContentType", -1, ATTR_DEFAULT
, &OUString_getCppuType
},
175 { "Cookie", -1, ATTR_DEFAULT
, &OUString_getCppuType
},
176 { "CrossReferences", -1, ATTR_DEFAULT
, &Sequence_CrossReference_getCppuType
},
177 { "DateCreated", -1, ATTR_DEFAULT
, &DateTime_getCppuType
},
178 { "DateModified", -1, ATTR_DEFAULT
, &DateTime_getCppuType
},
179 { "DeleteOnServer", -1, ATTR_DEFAULT
, &sal_Bool_getCppuType
},
180 { "DocumentBody", -1, ATTR_DEFAULT
, &Sequence_byte_getCppuType
},
181 { "DocumentCount", -1, ATTR_DEFAULT
| PropertyAttribute::READONLY
,
182 &sal_uInt32_getCppuType
},
183 { "DocumentCountMarked",
184 -1, ATTR_DEFAULT
| PropertyAttribute::READONLY
,
185 &sal_uInt32_getCppuType
},
186 { "DocumentHeader", -1, ATTR_DEFAULT
, &Sequence_DocumentHeaderField_getCppuType
},
187 { "DocumentStoreMode", -1, ATTR_DEFAULT
, &enum_getCppuType
},
188 { "DocumentViewMode", -1, ATTR_DEFAULT
, &enum_getCppuType
},
189 { "FTPAccount", -1, ATTR_DEFAULT
, &OUString_getCppuType
},
190 { "Flags", -1, ATTR_DEFAULT
, &sal_uInt32_getCppuType
},
191 { "FolderCount", -1, ATTR_DEFAULT
| PropertyAttribute::READONLY
,
192 &sal_uInt32_getCppuType
},
193 { "FolderViewMode", -1, ATTR_DEFAULT
, &enum_getCppuType
},
194 { "FreeSpace", -1, ATTR_DEFAULT
| PropertyAttribute::READONLY
,
195 &sal_uInt64_getCppuType
},
196 { "HasDocuments", -1, ATTR_DEFAULT
| PropertyAttribute::READONLY
,
197 &sal_Bool_getCppuType
},
198 { "HasFolders", -1, ATTR_DEFAULT
| PropertyAttribute::READONLY
,
199 &sal_Bool_getCppuType
},
200 { "IsAutoDelete", -1, ATTR_DEFAULT
, &sal_Bool_getCppuType
},
201 { "IsAutoUpdate", -1, ATTR_DEFAULT
, &sal_Bool_getCppuType
},
202 { "IsDocument", -1, ATTR_DEFAULT
| PropertyAttribute::READONLY
,
203 &sal_Bool_getCppuType
},
204 { "IsFolder", -1, ATTR_DEFAULT
| PropertyAttribute::READONLY
,
205 &sal_Bool_getCppuType
},
206 { "IsKeepExpired", -1, ATTR_DEFAULT
, &sal_Bool_getCppuType
},
207 { "IsLimitedContentCount",
208 -1, ATTR_DEFAULT
, &sal_Bool_getCppuType
},
209 { "IsMarked", -1, ATTR_DEFAULT
, &sal_Bool_getCppuType
},
210 { "IsRead", -1, ATTR_DEFAULT
, &sal_Bool_getCppuType
},
211 { "IsReadOnly", -1, ATTR_DEFAULT
, &sal_Bool_getCppuType
},
212 { "IsSubscribed", -1, ATTR_DEFAULT
, &sal_Bool_getCppuType
},
213 { "IsTimeLimitedStore", -1, ATTR_DEFAULT
, &sal_Bool_getCppuType
},
214 { "Keywords", -1, ATTR_DEFAULT
, &OUString_getCppuType
},
215 { "LocalBase", -1, ATTR_DEFAULT
, &OUString_getCppuType
},
216 { "MessageBCC", -1, ATTR_DEFAULT
, &OUString_getCppuType
},
217 { "MessageBody", -1, ATTR_DEFAULT
, &XDataContainer_getCppuType
},
218 { "MessageCC", -1, ATTR_DEFAULT
, &OUString_getCppuType
},
219 { "MessageFrom", -1, ATTR_DEFAULT
, &OUString_getCppuType
},
220 { "MessageId", -1, ATTR_DEFAULT
, &OUString_getCppuType
},
221 { "MessageInReplyTo", -1, ATTR_DEFAULT
, &OUString_getCppuType
},
222 { "MessageReplyTo", -1, ATTR_DEFAULT
, &OUString_getCppuType
},
223 { "MessageTo", -1, ATTR_DEFAULT
, &OUString_getCppuType
},
224 { "NewsGroups", -1, ATTR_DEFAULT
, &OUString_getCppuType
},
225 { "NoCacheList", -1, ATTR_DEFAULT
, &OUString_getCppuType
},
226 { "Origin", -1, ATTR_DEFAULT
| PropertyAttribute::READONLY
,
227 &OUString_getCppuType
},
228 { "OutgoingMessageRecipients",
229 -1, ATTR_DEFAULT
, &Sequence_RecipientInfo_getCppuType
},
230 { "OutgoingMessageState",
231 -1, ATTR_DEFAULT
| PropertyAttribute::READONLY
,
233 { "OutgoingMessageViewMode",
234 -1, ATTR_DEFAULT
, &enum_getCppuType
},
235 { "Password", -1, ATTR_DEFAULT
, &OUString_getCppuType
},
236 { "Priority", -1, ATTR_DEFAULT
, &enum_getCppuType
},
237 { "References", -1, ATTR_DEFAULT
, &OUString_getCppuType
},
238 { "Referer", -1, ATTR_DEFAULT
, &OUString_getCppuType
},
239 { "Rules", -1, ATTR_DEFAULT
, &RuleSet_getCppuType
},
240 { "SearchCriteria", -1, ATTR_DEFAULT
, &RuleSet_getCppuType
},
241 { "SearchIndirections", -1, ATTR_DEFAULT
, &sal_Bool_getCppuType
},
242 { "SearchLocations", -1, ATTR_DEFAULT
, &OUString_getCppuType
},
243 { "SearchRecursive", -1, ATTR_DEFAULT
, &sal_Bool_getCppuType
},
244 { "SeenCount", -1, ATTR_DEFAULT
| PropertyAttribute::READONLY
,
245 &sal_uInt32_getCppuType
},
246 { "SendCopyTarget", -1, ATTR_DEFAULT
, &Sequence_SendInfo_getCppuType
},
247 { "SendFormats", -1, ATTR_DEFAULT
, &Sequence_SendMediaTypes_getCppuType
},
248 { "SendFroms", -1, ATTR_DEFAULT
, &Sequence_SendInfo_getCppuType
},
249 { "SendPasswords", -1, ATTR_DEFAULT
, &Sequence_SendInfo_getCppuType
},
250 { "SendProtocolPrivate",-1, ATTR_DEFAULT
, &sal_uInt16_getCppuType
},
251 { "SendProtocolPublic", -1, ATTR_DEFAULT
, &sal_uInt16_getCppuType
},
252 { "SendReplyTos", -1, ATTR_DEFAULT
, &Sequence_SendInfo_getCppuType
},
253 { "SendServerNames", -1, ATTR_DEFAULT
, &Sequence_SendInfo_getCppuType
},
254 { "SendUserNames", -1, ATTR_DEFAULT
, &Sequence_SendInfo_getCppuType
},
255 { "SendVIMPostOfficePath",
256 -1, ATTR_DEFAULT
, &OUString_getCppuType
},
257 { "ServerBase", -1, ATTR_DEFAULT
, &OUString_getCppuType
},
258 { "ServerName", -1, ATTR_DEFAULT
, &OUString_getCppuType
},
259 { "ServerPort", -1, ATTR_DEFAULT
, &sal_uInt16_getCppuType
},
260 { "Size", -1, ATTR_DEFAULT
| PropertyAttribute::READONLY
,
261 &sal_uInt64_getCppuType
},
262 { "SizeLimit", -1, ATTR_DEFAULT
, &sal_uInt64_getCppuType
},
263 { "SubscribedCount", -1, ATTR_DEFAULT
| PropertyAttribute::READONLY
,
264 &sal_uInt32_getCppuType
},
265 { "SynchronizePolicy", -1, ATTR_DEFAULT
, &enum_getCppuType
},
266 { "TargetFrames", -1, ATTR_DEFAULT
, &OUString_getCppuType
},
267 { "TargetURL", -1, ATTR_DEFAULT
, &OUString_getCppuType
},
268 { "TimeLimitStore", -1, ATTR_DEFAULT
, &sal_uInt16_getCppuType
},
269 { "Title", -1, ATTR_DEFAULT
, &OUString_getCppuType
},
270 { "UpdateOnOpen", -1, ATTR_DEFAULT
, &sal_Bool_getCppuType
},
271 { "UseOutBoxPrivateProtocolSettings",
272 -1, ATTR_DEFAULT
, &sal_Bool_getCppuType
},
273 { "UseOutBoxPublicProtocolSettings",
274 -1, ATTR_DEFAULT
, &sal_Bool_getCppuType
},
275 { "UserName", -1, ATTR_DEFAULT
, &OUString_getCppuType
},
276 { "UserSortCriterium", -1, ATTR_DEFAULT
, &OUString_getCppuType
},
277 { "VIMPostOfficePath", -1, ATTR_DEFAULT
, &OUString_getCppuType
},
278 { "VerificationMode", -1, ATTR_DEFAULT
, &enum_getCppuType
},
290 // UcbPropertiesManager Implementation.
295 UcbPropertiesManager::UcbPropertiesManager(
296 const Reference
< XMultiServiceFactory
>& )
303 UcbPropertiesManager::~UcbPropertiesManager()
310 // XServiceInfo methods.
314 XSERVICEINFO_IMPL_1( UcbPropertiesManager
,
315 OUString( "com.sun.star.comp.ucb.UcbPropertiesManager" ),
316 PROPERTIES_MANAGER_SERVICE_NAME
);
320 // Service factory implementation.
324 ONE_INSTANCE_SERVICE_FACTORY_IMPL( UcbPropertiesManager
);
328 // XPropertySetInfo methods.
333 Sequence
< Property
> SAL_CALL
UcbPropertiesManager::getProperties()
334 throw( RuntimeException
, std::exception
)
336 osl::Guard
< osl::Mutex
> aGuard( m_aMutex
);
340 m_pProps
= new Sequence
< Property
>( 128 );
341 Property
* pProps
= m_pProps
->getArray();
343 sal_Int32 nSize
= m_pProps
->getLength();
346 // Get info for well-known properties.
349 const PropertyTableEntry
* pCurr
= &__aPropertyTable
[ 0 ];
350 while ( pCurr
->pName
)
354 OSL_FAIL( "UcbPropertiesManager::getProperties - "
355 "Initial size of property sequence too small!" );
357 m_pProps
->realloc( 128 );
361 Property
& rProp
= pProps
[ nPos
];
363 rProp
.Name
= OUString::createFromAscii( pCurr
->pName
);
364 rProp
.Handle
= pCurr
->nHandle
;
365 rProp
.Type
= pCurr
->pGetCppuType();
366 rProp
.Attributes
= pCurr
->nAttributes
;
374 m_pProps
->realloc( nPos
);
375 nSize
= m_pProps
->getLength();
383 Property SAL_CALL
UcbPropertiesManager::getPropertyByName( const OUString
& aName
)
384 throw( UnknownPropertyException
, RuntimeException
, std::exception
)
387 if ( queryProperty( aName
, aProp
) )
390 throw UnknownPropertyException();
395 sal_Bool SAL_CALL
UcbPropertiesManager::hasPropertyByName( const OUString
& Name
)
396 throw( RuntimeException
, std::exception
)
399 return queryProperty( Name
, aProp
);
404 // Non-Interface methods.
408 bool UcbPropertiesManager::queryProperty(
409 const OUString
& rName
, Property
& rProp
)
411 osl::Guard
< osl::Mutex
> aGuard( m_aMutex
);
415 const Property
* pProps
= m_pProps
->getConstArray();
416 sal_Int32 nCount
= m_pProps
->getLength();
417 for ( sal_Int32 n
= 0; n
< nCount
; ++n
)
419 const Property
& rCurrProp
= pProps
[ n
];
420 if ( rCurrProp
.Name
== rName
)
430 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */