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/TransferInfo.hpp>
30 #include <com/sun/star/uno/Sequence.hxx>
31 #include <com/sun/star/util/DateTime.hpp>
32 #include <com/sun/star/ucb/Lock.hpp>
33 #include <com/sun/star/ucb/LockEntry.hpp>
34 #include "webdavcontent.hxx"
35 #include "webdavprovider.hxx"
36 #include "DAVSession.hxx"
37 #include "ContentProperties.hxx"
39 using namespace com::sun::star
;
40 using namespace http_dav_ucp
;
42 //=========================================================================
44 // ContentProvider implementation.
46 //=========================================================================
48 bool ContentProvider::getProperty(
49 const OUString
& rPropName
, beans::Property
& rProp
, bool bStrict
)
53 osl::MutexGuard
aGuard( m_aMutex
);
56 m_pProps
= new PropertyMap
;
58 //////////////////////////////////////////////////////////////
59 // Fill map of known properties...
60 //////////////////////////////////////////////////////////////
62 // Mandatory UCB properties.
65 OUString( "ContentType" ),
67 getCppuType( static_cast< const OUString
* >( 0 ) ),
68 beans::PropertyAttribute::BOUND
69 | beans::PropertyAttribute::READONLY
) );
73 OUString( "IsDocument" ),
76 beans::PropertyAttribute::BOUND
77 | beans::PropertyAttribute::READONLY
) );
81 OUString( "IsFolder" ),
84 beans::PropertyAttribute::BOUND
85 | beans::PropertyAttribute::READONLY
) );
91 getCppuType( static_cast< const OUString
* >( 0 ) ),
92 beans::PropertyAttribute::BOUND
) );
94 // Optional UCB properties.
98 OUString( "DateCreated" ),
100 getCppuType( static_cast< const util::DateTime
* >( 0 ) ),
101 beans::PropertyAttribute::BOUND
102 | beans::PropertyAttribute::READONLY
) );
106 OUString( "DateModified" ),
108 getCppuType( static_cast< const util::DateTime
* >( 0 ) ),
109 beans::PropertyAttribute::BOUND
110 | beans::PropertyAttribute::READONLY
) );
114 OUString( "MediaType" ),
116 getCppuType( static_cast< const OUString
* >( 0 ) ),
117 beans::PropertyAttribute::BOUND
118 | beans::PropertyAttribute::READONLY
) );
124 getCppuType( static_cast< const sal_Int64
* >( 0 ) ),
125 beans::PropertyAttribute::BOUND
126 | beans::PropertyAttribute::READONLY
) );
130 OUString( "BaseURI" ),
132 getCppuType( static_cast< const OUString
* >( 0 ) ),
133 beans::PropertyAttribute::BOUND
134 | beans::PropertyAttribute::READONLY
) );
139 "CreatableContentsInfo" ),
141 getCppuType( static_cast<
142 const uno::Sequence
< ucb::ContentInfo
> * >( 0 ) ),
143 beans::PropertyAttribute::BOUND
144 | beans::PropertyAttribute::READONLY
) );
146 // Standard DAV properties.
150 DAVProperties::CREATIONDATE
,
152 getCppuType( static_cast< const OUString
* >( 0 ) ),
153 beans::PropertyAttribute::BOUND
154 | beans::PropertyAttribute::READONLY
) );
158 DAVProperties::DISPLAYNAME
,
160 getCppuType( static_cast< const OUString
* >( 0 ) ),
161 beans::PropertyAttribute::BOUND
) );
165 DAVProperties::GETCONTENTLANGUAGE
,
167 getCppuType( static_cast< const OUString
* >( 0 ) ),
168 beans::PropertyAttribute::BOUND
169 | beans::PropertyAttribute::READONLY
) );
173 DAVProperties::GETCONTENTLENGTH
,
175 getCppuType( static_cast< const OUString
* >( 0 ) ),
176 beans::PropertyAttribute::BOUND
177 | beans::PropertyAttribute::READONLY
) );
181 DAVProperties::GETCONTENTTYPE
,
183 getCppuType( static_cast< const OUString
* >( 0 ) ),
184 beans::PropertyAttribute::BOUND
185 | beans::PropertyAttribute::READONLY
) );
189 DAVProperties::GETETAG
,
191 getCppuType( static_cast< const OUString
* >( 0 ) ),
192 beans::PropertyAttribute::BOUND
193 | beans::PropertyAttribute::READONLY
) );
197 DAVProperties::GETLASTMODIFIED
,
199 getCppuType( static_cast< const OUString
* >( 0 ) ),
200 beans::PropertyAttribute::BOUND
201 | beans::PropertyAttribute::READONLY
) );
205 DAVProperties::LOCKDISCOVERY
,
207 getCppuType( static_cast<
208 const uno::Sequence
< ucb::Lock
> * >( 0 ) ),
209 beans::PropertyAttribute::BOUND
210 | beans::PropertyAttribute::READONLY
) );
214 DAVProperties::RESOURCETYPE
,
216 getCppuType( static_cast< const OUString
* >( 0 ) ),
217 beans::PropertyAttribute::BOUND
218 | beans::PropertyAttribute::READONLY
) );
222 DAVProperties::SUPPORTEDLOCK
,
224 getCppuType( static_cast<
226 ucb::LockEntry
> * >( 0 ) ),
227 beans::PropertyAttribute::BOUND
228 | beans::PropertyAttribute::READONLY
) );
232 DAVProperties::EXECUTABLE
,
234 getCppuType( static_cast< const OUString
* >( 0 ) ),
235 beans::PropertyAttribute::BOUND
) );
239 //////////////////////////////////////////////////////////////
241 //////////////////////////////////////////////////////////////
243 beans::Property aProp
;
244 aProp
.Name
= rPropName
;
245 const PropertyMap::const_iterator it
= m_pProps
->find( aProp
);
246 if ( it
!= m_pProps
->end() )
255 // All unknown props are treated as:
256 rProp
= beans::Property(
259 getCppuType( static_cast< const OUString
* >( 0 ) ),
260 beans::PropertyAttribute::BOUND
);
266 //=========================================================================
268 // Content implementation.
270 //=========================================================================
273 uno::Sequence
< beans::Property
> Content::getProperties(
274 const uno::Reference
< ucb::XCommandEnvironment
> & xEnv
)
277 std::auto_ptr
< DAVResourceAccess
> xResAccess
;
278 std::auto_ptr
< ContentProperties
> xCachedProps
;
279 rtl::Reference
< ContentProvider
> xProvider
;
282 osl::Guard
< osl::Mutex
> aGuard( m_aMutex
);
284 bTransient
= m_bTransient
;
285 xResAccess
.reset( new DAVResourceAccess( *m_xResAccess
.get() ) );
286 if ( m_xCachedProps
.get() )
288 new ContentProperties( *m_xCachedProps
.get() ) );
289 xProvider
.set( m_pProvider
);
292 typedef std::set
< OUString
> StringSet
;
295 // No server access for just created (not yet committed) objects.
296 // Only a minimal set of properties supported at this stage.
299 // Obtain all properties supported for this resource from server.
302 std::vector
< DAVResourceInfo
> props
;
303 xResAccess
->PROPFIND( DAVZERO
, props
, xEnv
);
305 // Note: vector always contains exactly one resource info, because
306 // we used a depth of DAVZERO for PROPFIND.
307 aPropSet
.insert( (*props
.begin()).properties
.begin(),
308 (*props
.begin()).properties
.end() );
310 catch ( DAVException
const & )
315 // Add DAV properties, map DAV properties to UCB properties.
316 sal_Bool bHasCreationDate
= sal_False
; // creationdate <-> DateCreated
317 sal_Bool bHasGetLastModified
= sal_False
; // getlastmodified <-> DateModified
318 sal_Bool bHasGetContentType
= sal_False
; // getcontenttype <-> MediaType
319 sal_Bool bHasGetContentLength
= sal_False
; // getcontentlength <-> Size
321 sal_Bool bHasContentType
= sal_False
;
322 sal_Bool bHasIsDocument
= sal_False
;
323 sal_Bool bHasIsFolder
= sal_False
;
324 sal_Bool bHasTitle
= sal_False
;
325 sal_Bool bHasBaseURI
= sal_False
;
326 sal_Bool bHasDateCreated
= sal_False
;
327 sal_Bool bHasDateModified
= sal_False
;
328 sal_Bool bHasMediaType
= sal_False
;
329 sal_Bool bHasSize
= sal_False
;
330 sal_Bool bHasCreatableInfos
= sal_False
;
333 std::set
< OUString
>::const_iterator it
= aPropSet
.begin();
334 std::set
< OUString
>::const_iterator end
= aPropSet
.end();
337 if ( !bHasCreationDate
&&
338 ( (*it
) == DAVProperties::CREATIONDATE
) )
340 bHasCreationDate
= sal_True
;
342 else if ( !bHasGetLastModified
&&
343 ( (*it
) == DAVProperties::GETLASTMODIFIED
) )
345 bHasGetLastModified
= sal_True
;
347 else if ( !bHasGetContentType
&&
348 ( (*it
) == DAVProperties::GETCONTENTTYPE
) )
350 bHasGetContentType
= sal_True
;
352 else if ( !bHasGetContentLength
&&
353 ( (*it
) == DAVProperties::GETCONTENTLENGTH
) )
355 bHasGetContentLength
= sal_True
;
357 else if ( !bHasContentType
&& (*it
) == "ContentType" )
359 bHasContentType
= sal_True
;
361 else if ( !bHasIsDocument
&& (*it
) == "IsDocument" )
363 bHasIsDocument
= sal_True
;
365 else if ( !bHasIsFolder
&& (*it
) == "IsFolder" )
367 bHasIsFolder
= sal_True
;
369 else if ( !bHasTitle
&& (*it
) == "Title" )
371 bHasTitle
= sal_True
;
373 else if ( !bHasBaseURI
&& (*it
) == "BaseURI" )
375 bHasBaseURI
= sal_True
;
377 else if ( !bHasDateCreated
&& (*it
) == "DateCreated" )
379 bHasDateCreated
= sal_True
;
381 else if ( !bHasDateModified
&& (*it
) == "DateModified" )
383 bHasDateModified
= sal_True
;
385 else if ( !bHasMediaType
&& (*it
) == "MediaType" )
387 bHasMediaType
= sal_True
;
389 else if ( !bHasSize
&& (*it
) == "Size" )
393 else if ( !bHasCreatableInfos
&& (*it
) == "CreatableContentsInfo" )
395 bHasCreatableInfos
= sal_True
;
401 // Add mandatory properties.
402 if ( !bHasContentType
)
404 OUString( "ContentType" ) );
406 if ( !bHasIsDocument
)
408 OUString( "IsDocument" ) );
412 OUString( "IsFolder" ) );
416 // Always present since it can be calculated from content's URI.
418 OUString( "Title" ) );
421 // Add optional properties.
425 // Always present since it can be calculated from content's URI.
427 OUString( "BaseURI" ) );
430 if ( !bHasDateCreated
&& bHasCreationDate
)
432 OUString( "DateCreated" ) );
434 if ( !bHasDateModified
&& bHasGetLastModified
)
436 OUString( "DateModified" ) );
438 if ( !bHasMediaType
&& bHasGetContentType
)
440 OUString( "MediaType" ) );
442 if ( !bHasSize
&& bHasGetContentLength
)
444 OUString( "Size" ) );
446 if ( !bHasCreatableInfos
)
449 "CreatableContentsInfo" ) );
451 // Add cached properties, if present and still missing.
452 if ( xCachedProps
.get() )
454 const std::set
< OUString
>::const_iterator set_end
457 const std::auto_ptr
< PropertyValueMap
> & xProps
458 = xCachedProps
->getProperties();
460 PropertyValueMap::const_iterator map_it
= xProps
->begin();
461 const PropertyValueMap::const_iterator map_end
= xProps
->end();
463 while ( map_it
!= map_end
)
465 if ( aPropSet
.find( (*map_it
).first
) == set_end
)
466 aPropSet
.insert( (*map_it
).first
);
472 // std::set -> uno::Sequence
473 sal_Int32 nCount
= aPropSet
.size();
474 uno::Sequence
< beans::Property
> aProperties( nCount
);
476 std::set
< OUString
>::const_iterator it
= aPropSet
.begin();
477 beans::Property aProp
;
479 for ( sal_Int32 n
= 0; n
< nCount
; ++n
, ++it
)
481 xProvider
->getProperty( (*it
), aProp
);
482 aProperties
[ n
] = aProp
;
488 //=========================================================================
490 uno::Sequence
< ucb::CommandInfo
> Content::getCommands(
491 const uno::Reference
< ucb::XCommandEnvironment
> & xEnv
)
493 osl::Guard
< osl::Mutex
> aGuard( m_aMutex
);
495 uno::Sequence
< ucb::CommandInfo
> aCmdInfo( 8 );
497 ///////////////////////////////////////////////////////////////
498 // Mandatory commands
499 ///////////////////////////////////////////////////////////////
503 OUString( "getCommandInfo" ),
508 OUString( "getPropertySetInfo" ),
513 OUString( "getPropertyValues" ),
515 getCppuType( static_cast<
516 uno::Sequence
< beans::Property
> * >( 0 ) ) );
519 OUString( "setPropertyValues" ),
521 getCppuType( static_cast<
522 uno::Sequence
< beans::PropertyValue
> * >( 0 ) ) );
524 ///////////////////////////////////////////////////////////////
525 // Optional standard commands
526 ///////////////////////////////////////////////////////////////
530 OUString( "delete" ),
532 getCppuBooleanType() );
535 OUString( "insert" ),
537 getCppuType( static_cast<
538 ucb::InsertCommandArgument
* >( 0 ) ) );
543 getCppuType( static_cast<
544 ucb::OpenCommandArgument2
* >( 0 ) ) );
546 ///////////////////////////////////////////////////////////////
548 ///////////////////////////////////////////////////////////////
554 getCppuType( static_cast<
555 ucb::PostCommandArgument2
* >( 0 ) ) );
557 sal_Bool bFolder
= sal_False
;
561 bFolder
= isFolder( xEnv
);
563 catch ( uno::Exception
const & )
568 sal_Bool bSupportsLocking
= supportsExclusiveWriteLock( xEnv
);
570 sal_Int32 nPos
= aCmdInfo
.getLength();
571 sal_Int32 nMoreCmds
= ( bFolder
? 2 : 0 ) + ( bSupportsLocking
? 2 : 0 );
573 aCmdInfo
.realloc( nPos
+ nMoreCmds
);
579 ///////////////////////////////////////////////////////////////
580 // Optional standard commands
581 ///////////////////////////////////////////////////////////////
585 OUString( "transfer" ),
587 getCppuType( static_cast< ucb::TransferInfo
* >( 0 ) ) );
592 "createNewContent" ),
594 getCppuType( static_cast< ucb::ContentInfo
* >( 0 ) ) );
599 // no document-only commands at the moment.
602 if ( bSupportsLocking
)
612 OUString( "unlock" ),
620 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */