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 .
21 #include <com/sun/star/beans/Property.hpp>
22 #include <com/sun/star/beans/PropertyAttribute.hpp>
23 #include <com/sun/star/beans/PropertyValue.hpp>
24 #include <com/sun/star/ucb/CommandInfo.hpp>
25 #include <com/sun/star/ucb/ContentInfo.hpp>
26 #include <com/sun/star/ucb/OpenCommandArgument2.hpp>
27 #include <com/sun/star/ucb/InsertCommandArgument.hpp>
28 #include <com/sun/star/ucb/PostCommandArgument2.hpp>
29 #include <com/sun/star/ucb/PropertyCommandArgument.hpp>
30 #include <com/sun/star/ucb/TransferInfo.hpp>
31 #include <com/sun/star/uno/Sequence.hxx>
32 #include <com/sun/star/util/DateTime.hpp>
33 #include <com/sun/star/ucb/Lock.hpp>
34 #include <com/sun/star/ucb/LockEntry.hpp>
35 #include "webdavcontent.hxx"
36 #include "webdavprovider.hxx"
37 #include "DAVSession.hxx"
38 #include "ContentProperties.hxx"
40 using namespace com::sun::star
;
41 using namespace http_dav_ucp
;
45 // ContentProvider implementation.
49 bool ContentProvider::getProperty(
50 const OUString
& rPropName
, beans::Property
& rProp
, bool bStrict
)
54 osl::MutexGuard
aGuard( m_aMutex
);
57 m_pProps
= new PropertyMap
;
60 // Fill map of known properties...
63 // Mandatory UCB properties.
66 OUString( "ContentType" ),
68 cppu::UnoType
<OUString
>::get(),
69 beans::PropertyAttribute::BOUND
70 | beans::PropertyAttribute::READONLY
) );
74 OUString( "IsDocument" ),
76 cppu::UnoType
<bool>::get(),
77 beans::PropertyAttribute::BOUND
78 | beans::PropertyAttribute::READONLY
) );
82 OUString( "IsFolder" ),
84 cppu::UnoType
<bool>::get(),
85 beans::PropertyAttribute::BOUND
86 | beans::PropertyAttribute::READONLY
) );
92 cppu::UnoType
<OUString
>::get(),
93 beans::PropertyAttribute::BOUND
) );
95 // Optional UCB properties.
99 OUString( "DateCreated" ),
101 cppu::UnoType
<util::DateTime
>::get(),
102 beans::PropertyAttribute::BOUND
103 | beans::PropertyAttribute::READONLY
) );
107 OUString( "DateModified" ),
109 cppu::UnoType
<util::DateTime
>::get(),
110 beans::PropertyAttribute::BOUND
111 | beans::PropertyAttribute::READONLY
) );
115 OUString( "MediaType" ),
117 cppu::UnoType
<OUString
>::get(),
118 beans::PropertyAttribute::BOUND
119 | beans::PropertyAttribute::READONLY
) );
125 cppu::UnoType
<sal_Int64
>::get(),
126 beans::PropertyAttribute::BOUND
127 | beans::PropertyAttribute::READONLY
) );
131 OUString( "BaseURI" ),
133 cppu::UnoType
<OUString
>::get(),
134 beans::PropertyAttribute::BOUND
135 | beans::PropertyAttribute::READONLY
) );
140 "CreatableContentsInfo" ),
142 cppu::UnoType
<uno::Sequence
< ucb::ContentInfo
>>::get(),
143 beans::PropertyAttribute::BOUND
144 | beans::PropertyAttribute::READONLY
) );
146 // Standard DAV properties.
150 DAVProperties::CREATIONDATE
,
152 cppu::UnoType
<OUString
>::get(),
153 beans::PropertyAttribute::BOUND
154 | beans::PropertyAttribute::READONLY
) );
158 DAVProperties::DISPLAYNAME
,
160 cppu::UnoType
<OUString
>::get(),
161 beans::PropertyAttribute::BOUND
) );
165 DAVProperties::GETCONTENTLANGUAGE
,
167 cppu::UnoType
<OUString
>::get(),
168 beans::PropertyAttribute::BOUND
169 | beans::PropertyAttribute::READONLY
) );
173 DAVProperties::GETCONTENTLENGTH
,
175 cppu::UnoType
<OUString
>::get(),
176 beans::PropertyAttribute::BOUND
177 | beans::PropertyAttribute::READONLY
) );
181 DAVProperties::GETCONTENTTYPE
,
183 cppu::UnoType
<OUString
>::get(),
184 beans::PropertyAttribute::BOUND
185 | beans::PropertyAttribute::READONLY
) );
189 DAVProperties::GETETAG
,
191 cppu::UnoType
<OUString
>::get(),
192 beans::PropertyAttribute::BOUND
193 | beans::PropertyAttribute::READONLY
) );
197 DAVProperties::GETLASTMODIFIED
,
199 cppu::UnoType
<OUString
>::get(),
200 beans::PropertyAttribute::BOUND
201 | beans::PropertyAttribute::READONLY
) );
205 DAVProperties::LOCKDISCOVERY
,
207 cppu::UnoType
<uno::Sequence
< ucb::Lock
>>::get(),
208 beans::PropertyAttribute::BOUND
209 | beans::PropertyAttribute::READONLY
) );
213 DAVProperties::RESOURCETYPE
,
215 cppu::UnoType
<OUString
>::get(),
216 beans::PropertyAttribute::BOUND
217 | beans::PropertyAttribute::READONLY
) );
221 DAVProperties::SUPPORTEDLOCK
,
223 cppu::UnoType
<uno::Sequence
< ucb::LockEntry
>>::get(),
224 beans::PropertyAttribute::BOUND
225 | beans::PropertyAttribute::READONLY
) );
229 DAVProperties::EXECUTABLE
,
231 cppu::UnoType
<OUString
>::get(),
232 beans::PropertyAttribute::BOUND
) );
240 beans::Property aProp
;
241 aProp
.Name
= rPropName
;
242 const PropertyMap::const_iterator it
= m_pProps
->find( aProp
);
243 if ( it
!= m_pProps
->end() )
252 // All unknown props are treated as:
253 rProp
= beans::Property(
256 cppu::UnoType
<OUString
>::get(),
257 beans::PropertyAttribute::BOUND
);
265 // Content implementation.
270 uno::Sequence
< beans::Property
> Content::getProperties(
271 const uno::Reference
< ucb::XCommandEnvironment
> & xEnv
)
274 boost::scoped_ptr
< DAVResourceAccess
> xResAccess
;
275 boost::scoped_ptr
< ContentProperties
> xCachedProps
;
276 rtl::Reference
< ContentProvider
> xProvider
;
279 osl::Guard
< osl::Mutex
> aGuard( m_aMutex
);
281 bTransient
= m_bTransient
;
282 xResAccess
.reset( new DAVResourceAccess( *m_xResAccess
.get() ) );
283 if ( m_xCachedProps
.get() )
285 new ContentProperties( *m_xCachedProps
.get() ) );
286 xProvider
.set( m_pProvider
);
289 typedef std::set
< OUString
> StringSet
;
292 // No server access for just created (not yet committed) objects.
293 // Only a minimal set of properties supported at this stage.
296 // Obtain all properties supported for this resource from server.
299 std::vector
< DAVResourceInfo
> props
;
300 xResAccess
->PROPFIND( DAVZERO
, props
, xEnv
);
302 // Note: vector always contains exactly one resource info, because
303 // we used a depth of DAVZERO for PROPFIND.
304 aPropSet
.insert( (*props
.begin()).properties
.begin(),
305 (*props
.begin()).properties
.end() );
307 catch ( DAVException
const & )
312 // Add DAV properties, map DAV properties to UCB properties.
313 bool bHasCreationDate
= false; // creationdate <-> DateCreated
314 bool bHasGetLastModified
= false; // getlastmodified <-> DateModified
315 bool bHasGetContentType
= false; // getcontenttype <-> MediaType
316 bool bHasGetContentLength
= false; // getcontentlength <-> Size
318 bool bHasContentType
= false;
319 bool bHasIsDocument
= false;
320 bool bHasIsFolder
= false;
321 bool bHasTitle
= false;
322 bool bHasBaseURI
= false;
323 bool bHasDateCreated
= false;
324 bool bHasDateModified
= false;
325 bool bHasMediaType
= false;
326 bool bHasSize
= false;
327 bool bHasCreatableInfos
= false;
330 std::set
< OUString
>::const_iterator it
= aPropSet
.begin();
331 std::set
< OUString
>::const_iterator end
= aPropSet
.end();
334 if ( !bHasCreationDate
&&
335 ( (*it
) == DAVProperties::CREATIONDATE
) )
337 bHasCreationDate
= true;
339 else if ( !bHasGetLastModified
&&
340 ( (*it
) == DAVProperties::GETLASTMODIFIED
) )
342 bHasGetLastModified
= true;
344 else if ( !bHasGetContentType
&&
345 ( (*it
) == DAVProperties::GETCONTENTTYPE
) )
347 bHasGetContentType
= true;
349 else if ( !bHasGetContentLength
&&
350 ( (*it
) == DAVProperties::GETCONTENTLENGTH
) )
352 bHasGetContentLength
= true;
354 else if ( !bHasContentType
&& (*it
) == "ContentType" )
356 bHasContentType
= true;
358 else if ( !bHasIsDocument
&& (*it
) == "IsDocument" )
360 bHasIsDocument
= true;
362 else if ( !bHasIsFolder
&& (*it
) == "IsFolder" )
366 else if ( !bHasTitle
&& (*it
) == "Title" )
370 else if ( !bHasBaseURI
&& (*it
) == "BaseURI" )
374 else if ( !bHasDateCreated
&& (*it
) == "DateCreated" )
376 bHasDateCreated
= true;
378 else if ( !bHasDateModified
&& (*it
) == "DateModified" )
380 bHasDateModified
= true;
382 else if ( !bHasMediaType
&& (*it
) == "MediaType" )
384 bHasMediaType
= true;
386 else if ( !bHasSize
&& (*it
) == "Size" )
390 else if ( !bHasCreatableInfos
&& (*it
) == "CreatableContentsInfo" )
392 bHasCreatableInfos
= true;
398 // Add mandatory properties.
399 if ( !bHasContentType
)
401 OUString( "ContentType" ) );
403 if ( !bHasIsDocument
)
405 OUString( "IsDocument" ) );
409 OUString( "IsFolder" ) );
413 // Always present since it can be calculated from content's URI.
415 OUString( "Title" ) );
418 // Add optional properties.
422 // Always present since it can be calculated from content's URI.
424 OUString( "BaseURI" ) );
427 if ( !bHasDateCreated
&& bHasCreationDate
)
429 OUString( "DateCreated" ) );
431 if ( !bHasDateModified
&& bHasGetLastModified
)
433 OUString( "DateModified" ) );
435 if ( !bHasMediaType
&& bHasGetContentType
)
437 OUString( "MediaType" ) );
439 if ( !bHasSize
&& bHasGetContentLength
)
441 OUString( "Size" ) );
443 if ( !bHasCreatableInfos
)
446 "CreatableContentsInfo" ) );
448 // Add cached properties, if present and still missing.
449 if ( xCachedProps
.get() )
451 const std::set
< OUString
>::const_iterator set_end
454 const boost::scoped_ptr
< PropertyValueMap
> & xProps
455 = xCachedProps
->getProperties();
457 PropertyValueMap::const_iterator map_it
= xProps
->begin();
458 const PropertyValueMap::const_iterator map_end
= xProps
->end();
460 while ( map_it
!= map_end
)
462 if ( aPropSet
.find( (*map_it
).first
) == set_end
)
463 aPropSet
.insert( (*map_it
).first
);
469 // std::set -> uno::Sequence
470 sal_Int32 nCount
= aPropSet
.size();
471 uno::Sequence
< beans::Property
> aProperties( nCount
);
473 std::set
< OUString
>::const_iterator it
= aPropSet
.begin();
474 beans::Property aProp
;
476 for ( sal_Int32 n
= 0; n
< nCount
; ++n
, ++it
)
478 xProvider
->getProperty( (*it
), aProp
);
479 aProperties
[ n
] = aProp
;
487 uno::Sequence
< ucb::CommandInfo
> Content::getCommands(
488 const uno::Reference
< ucb::XCommandEnvironment
> & xEnv
)
490 osl::Guard
< osl::Mutex
> aGuard( m_aMutex
);
492 uno::Sequence
< ucb::CommandInfo
> aCmdInfo( 10 );
495 // Mandatory commands
500 OUString( "getCommandInfo" ),
502 cppu::UnoType
<void>::get() );
505 OUString( "getPropertySetInfo" ),
507 cppu::UnoType
<void>::get() );
510 OUString( "getPropertyValues" ),
512 cppu::UnoType
<uno::Sequence
< beans::Property
>>::get());
515 OUString( "setPropertyValues" ),
517 cppu::UnoType
<uno::Sequence
< beans::PropertyValue
>>::get());
520 // Optional standard commands
525 OUString( "delete" ),
527 cppu::UnoType
<bool>::get() );
530 OUString( "insert" ),
532 cppu::UnoType
<ucb::InsertCommandArgument
>::get() );
537 cppu::UnoType
<ucb::OpenCommandArgument2
>::get() );
547 cppu::UnoType
<ucb::PostCommandArgument2
>::get() );
550 OUString( "addProperty" ),
552 cppu::UnoType
<ucb::PropertyCommandArgument
>::get() );
555 OUString( "removeProperty" ),
557 cppu::UnoType
<rtl::OUString
>::get() );
559 bool bFolder
= false;
563 bFolder
= isFolder( xEnv
);
565 catch ( uno::Exception
const & )
570 bool bSupportsLocking
= supportsExclusiveWriteLock( xEnv
);
572 sal_Int32 nPos
= aCmdInfo
.getLength();
573 sal_Int32 nMoreCmds
= ( bFolder
? 2 : 0 ) + ( bSupportsLocking
? 2 : 0 );
575 aCmdInfo
.realloc( nPos
+ nMoreCmds
);
582 // Optional standard commands
587 OUString( "transfer" ),
589 cppu::UnoType
<ucb::TransferInfo
>::get() );
594 "createNewContent" ),
596 cppu::UnoType
<ucb::ContentInfo
>::get() );
601 // no document-only commands at the moment.
604 if ( bSupportsLocking
)
610 cppu::UnoType
<void>::get() );
614 OUString( "unlock" ),
616 cppu::UnoType
<void>::get() );
622 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */