1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: webdavcontentcaps.cxx,v $
10 * $Revision: 1.21.20.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_ucb.hxx"
33 /**************************************************************************
35 **************************************************************************
37 *************************************************************************/
40 #include <com/sun/star/beans/Property.hpp>
41 #include <com/sun/star/beans/PropertyAttribute.hpp>
42 #include <com/sun/star/beans/PropertyValue.hpp>
43 #include <com/sun/star/ucb/CommandInfo.hpp>
44 #include <com/sun/star/ucb/OpenCommandArgument2.hpp>
45 #include <com/sun/star/ucb/InsertCommandArgument.hpp>
46 #include <com/sun/star/ucb/PostCommandArgument2.hpp>
47 #include <com/sun/star/ucb/TransferInfo.hpp>
48 #include <com/sun/star/uno/Sequence.hxx>
49 #ifndef _COM_SUN_STAR_UTIL_DATETIME_HXX_
50 #include <com/sun/star/util/DateTime.hpp>
52 #include <com/sun/star/ucb/Link.hpp>
53 #include <com/sun/star/ucb/Lock.hpp>
54 #include <com/sun/star/ucb/LockEntry.hpp>
55 #include "webdavcontent.hxx"
56 #ifndef _WEBDAV_UCP_PROVIDFER_HXX
57 #include "webdavprovider.hxx"
59 #ifndef _WEBDAV_SESSION_HXX
60 #include "DAVSession.hxx"
62 #include "ContentProperties.hxx"
64 using namespace com::sun::star
;
65 using namespace webdav_ucp
;
67 //=========================================================================
69 // ContentProvider implementation.
71 //=========================================================================
73 bool ContentProvider::getProperty(
74 const rtl::OUString
& rPropName
, beans::Property
& rProp
, bool bStrict
)
78 osl::MutexGuard
aGuard( m_aMutex
);
81 m_pProps
= new PropertyMap
;
83 //////////////////////////////////////////////////////////////
84 // Fill map of known properties...
85 //////////////////////////////////////////////////////////////
87 // Mandatory UCB properties.
91 RTL_CONSTASCII_USTRINGPARAM( "ContentType" ) ),
93 getCppuType( static_cast< const rtl::OUString
* >( 0 ) ),
94 beans::PropertyAttribute::BOUND
95 | beans::PropertyAttribute::READONLY
) );
100 RTL_CONSTASCII_USTRINGPARAM( "IsDocument" ) ),
102 getCppuBooleanType(),
103 beans::PropertyAttribute::BOUND
104 | beans::PropertyAttribute::READONLY
) );
108 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IsFolder" ) ),
110 getCppuBooleanType(),
111 beans::PropertyAttribute::BOUND
112 | beans::PropertyAttribute::READONLY
) );
116 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Title" ) ),
118 getCppuType( static_cast< const rtl::OUString
* >( 0 ) ),
119 beans::PropertyAttribute::BOUND
) );
121 // Optional UCB properties.
126 RTL_CONSTASCII_USTRINGPARAM( "DateCreated" ) ),
128 getCppuType( static_cast< const util::DateTime
* >( 0 ) ),
129 beans::PropertyAttribute::BOUND
130 | beans::PropertyAttribute::READONLY
) );
135 RTL_CONSTASCII_USTRINGPARAM( "DateModified" ) ),
137 getCppuType( static_cast< const util::DateTime
* >( 0 ) ),
138 beans::PropertyAttribute::BOUND
139 | beans::PropertyAttribute::READONLY
) );
143 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MediaType" ) ),
145 getCppuType( static_cast< const rtl::OUString
* >( 0 ) ),
146 beans::PropertyAttribute::BOUND
147 | beans::PropertyAttribute::READONLY
) );
151 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Size" ) ),
153 getCppuType( static_cast< const sal_Int64
* >( 0 ) ),
154 beans::PropertyAttribute::BOUND
155 | beans::PropertyAttribute::READONLY
) );
159 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "BaseURI" ) ),
161 getCppuType( static_cast< const rtl::OUString
* >( 0 ) ),
162 beans::PropertyAttribute::BOUND
163 | beans::PropertyAttribute::READONLY
) );
165 // Standard DAV properties.
169 DAVProperties::CREATIONDATE
,
171 getCppuType( static_cast< const rtl::OUString
* >( 0 ) ),
172 beans::PropertyAttribute::BOUND
173 | beans::PropertyAttribute::READONLY
) );
177 DAVProperties::DISPLAYNAME
,
179 getCppuType( static_cast< const rtl::OUString
* >( 0 ) ),
180 beans::PropertyAttribute::BOUND
) );
184 DAVProperties::GETCONTENTLANGUAGE
,
186 getCppuType( static_cast< const rtl::OUString
* >( 0 ) ),
187 beans::PropertyAttribute::BOUND
188 | beans::PropertyAttribute::READONLY
) );
192 DAVProperties::GETCONTENTLENGTH
,
194 getCppuType( static_cast< const rtl::OUString
* >( 0 ) ),
195 beans::PropertyAttribute::BOUND
196 | beans::PropertyAttribute::READONLY
) );
200 DAVProperties::GETCONTENTTYPE
,
202 getCppuType( static_cast< const rtl::OUString
* >( 0 ) ),
203 beans::PropertyAttribute::BOUND
204 | beans::PropertyAttribute::READONLY
) );
208 DAVProperties::GETETAG
,
210 getCppuType( static_cast< const rtl::OUString
* >( 0 ) ),
211 beans::PropertyAttribute::BOUND
212 | beans::PropertyAttribute::READONLY
) );
216 DAVProperties::GETLASTMODIFIED
,
218 getCppuType( static_cast< const rtl::OUString
* >( 0 ) ),
219 beans::PropertyAttribute::BOUND
220 | beans::PropertyAttribute::READONLY
) );
224 DAVProperties::LOCKDISCOVERY
,
226 getCppuType( static_cast<
228 com::sun::star::ucb::Lock
> * >( 0 ) ),
229 beans::PropertyAttribute::BOUND
230 | beans::PropertyAttribute::READONLY
) );
234 DAVProperties::RESOURCETYPE
,
236 getCppuType( static_cast< const rtl::OUString
* >( 0 ) ),
237 beans::PropertyAttribute::BOUND
238 | beans::PropertyAttribute::READONLY
) );
242 DAVProperties::SOURCE
,
244 getCppuType( static_cast<
246 com::sun::star::ucb::Link
> * >( 0 ) ),
247 beans::PropertyAttribute::BOUND
) );
251 DAVProperties::SUPPORTEDLOCK
,
253 getCppuType( static_cast<
255 com::sun::star::ucb::LockEntry
> * >(
257 beans::PropertyAttribute::BOUND
258 | beans::PropertyAttribute::READONLY
) );
262 DAVProperties::EXECUTABLE
,
264 getCppuType( static_cast< const rtl::OUString
* >( 0 ) ),
265 beans::PropertyAttribute::BOUND
) );
270 RTL_CONSTASCII_USTRINGPARAM( "SupportsActiveStreaming" ) ),
272 getCppuBooleanType(),
273 beans::PropertyAttribute::BOUND
274 | beans::PropertyAttribute::READONLY
) );
279 RTL_CONSTASCII_USTRINGPARAM( "IsReadOnly" ) ),
281 getCppuBooleanType(),
282 beans::PropertyAttribute::BOUND
283 | beans::PropertyAttribute::READONLY
) );
287 //////////////////////////////////////////////////////////////
289 //////////////////////////////////////////////////////////////
291 beans::Property aProp
;
292 aProp
.Name
= rPropName
;
293 const PropertyMap::const_iterator it
= m_pProps
->find( aProp
);
294 if ( it
!= m_pProps
->end() )
303 // All unknown props are treated as:
304 rProp
= beans::Property(
307 getCppuType( static_cast< const rtl::OUString
* >( 0 ) ),
308 beans::PropertyAttribute::BOUND
);
314 //=========================================================================
316 // Content implementation.
318 //=========================================================================
321 uno::Sequence
< beans::Property
> Content::getProperties(
322 const uno::Reference
< com::sun::star::ucb::XCommandEnvironment
> & xEnv
)
325 std::auto_ptr
< DAVResourceAccess
> xResAccess
;
326 std::auto_ptr
< ContentProperties
> xCachedProps
;
327 rtl::Reference
< ContentProvider
> xProvider
;
330 osl::Guard
< osl::Mutex
> aGuard( m_aMutex
);
332 bTransient
= m_bTransient
;
333 xResAccess
.reset( new DAVResourceAccess( *m_xResAccess
.get() ) );
334 if ( m_xCachedProps
.get() )
335 xCachedProps
.reset( new ContentProperties( *m_xCachedProps
.get() ) );
336 xProvider
.set( m_pProvider
);
339 typedef std::set
< rtl::OUString
> StringSet
;
342 // No server access for just created (not yet committed) objects.
343 // Only a minimal set of properties supported at this stage.
346 // Obtain all properties supported for this resource from server.
349 std::vector
< DAVResourceInfo
> props
;
350 xResAccess
->PROPFIND( DAVZERO
, props
, xEnv
);
352 // Note: vector always contains exactly one resource info, because
353 // we used a depth of DAVZERO for PROPFIND.
354 aPropSet
.insert( (*props
.begin()).properties
.begin(),
355 (*props
.begin()).properties
.end() );
357 catch ( DAVException
const & )
362 // Add DAV properties, map DAV properties to UCB properties.
363 sal_Bool bHasCreationDate
= sal_False
; // creationdate <-> DateCreated
364 sal_Bool bHasGetLastModified
= sal_False
; // getlastmodified <-> DateModified
365 sal_Bool bHasGetContentType
= sal_False
; // getcontenttype <-> MediaType
366 sal_Bool bHasGetContentLength
= sal_False
; // getcontentlength <-> Size
368 sal_Bool bHasContentType
= sal_False
;
369 sal_Bool bHasIsDocument
= sal_False
;
370 sal_Bool bHasIsFolder
= sal_False
;
371 sal_Bool bHasTitle
= sal_False
;
372 sal_Bool bHasBaseURI
= sal_False
;
373 sal_Bool bHasDateCreated
= sal_False
;
374 sal_Bool bHasDateModified
= sal_False
;
375 sal_Bool bHasMediaType
= sal_False
;
376 sal_Bool bHasSize
= sal_False
;
379 std::set
< rtl::OUString
>::const_iterator it
= aPropSet
.begin();
380 std::set
< rtl::OUString
>::const_iterator end
= aPropSet
.end();
383 if ( !bHasCreationDate
&&
384 ( (*it
) == DAVProperties::CREATIONDATE
) )
386 bHasCreationDate
= sal_True
;
388 else if ( !bHasGetLastModified
&&
389 ( (*it
) == DAVProperties::GETLASTMODIFIED
) )
391 bHasGetLastModified
= sal_True
;
393 else if ( !bHasGetContentType
&&
394 ( (*it
) == DAVProperties::GETCONTENTTYPE
) )
396 bHasGetContentType
= sal_True
;
398 else if ( !bHasGetContentLength
&&
399 ( (*it
) == DAVProperties::GETCONTENTLENGTH
) )
401 bHasGetContentLength
= sal_True
;
403 else if ( !bHasContentType
&&
405 RTL_CONSTASCII_STRINGPARAM( "ContentType" ) ) )
407 bHasContentType
= sal_True
;
409 else if ( !bHasIsDocument
&&
411 RTL_CONSTASCII_STRINGPARAM( "IsDocument" ) ) )
413 bHasIsDocument
= sal_True
;
415 else if ( !bHasIsFolder
&&
417 RTL_CONSTASCII_STRINGPARAM( "IsFolder" ) ) )
419 bHasIsFolder
= sal_True
;
421 else if ( !bHasTitle
&&
423 RTL_CONSTASCII_STRINGPARAM( "Title" ) ) )
425 bHasTitle
= sal_True
;
427 else if ( !bHasBaseURI
&&
429 RTL_CONSTASCII_STRINGPARAM( "BaseURI" ) ) )
431 bHasBaseURI
= sal_True
;
433 else if ( !bHasDateCreated
&&
435 RTL_CONSTASCII_STRINGPARAM( "DateCreated" ) ) )
437 bHasDateCreated
= sal_True
;
439 else if ( !bHasDateModified
&&
441 RTL_CONSTASCII_STRINGPARAM( "DateModified" ) ) )
443 bHasDateModified
= sal_True
;
445 else if ( !bHasMediaType
&&
447 RTL_CONSTASCII_STRINGPARAM( "MediaType" ) ) )
449 bHasMediaType
= sal_True
;
451 else if ( !bHasSize
&&
453 RTL_CONSTASCII_STRINGPARAM( "Size" ) ) )
462 // Add mandatory properties.
463 if ( !bHasContentType
)
465 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ContentType" ) ) );
467 if ( !bHasIsDocument
)
469 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IsDocument" ) ) );
473 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IsFolder" ) ) );
477 // Always present since it can be calculated from content's URI.
479 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Title" ) ) );
482 // Add optional properties.
486 // Always present since it can be calculated from content's URI.
488 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "BaseURI" ) ) );
491 if ( !bHasDateCreated
&& bHasCreationDate
)
493 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DateCreated" ) ) );
495 if ( !bHasDateModified
&& bHasGetLastModified
)
497 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DateModified" ) ) );
499 if ( !bHasMediaType
&& bHasGetContentType
)
501 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MediaType" ) ) );
503 if ( !bHasSize
&& bHasGetContentLength
)
505 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Size" ) ) );
507 // Add cached properties, if present and still missing.
508 if ( xCachedProps
.get() )
510 const std::set
< rtl::OUString
>::const_iterator set_end
513 const std::auto_ptr
< PropertyValueMap
> & xProps
514 = xCachedProps
->getProperties();
516 PropertyValueMap::const_iterator map_it
= xProps
->begin();
517 const PropertyValueMap::const_iterator map_end
= xProps
->end();
519 while ( map_it
!= map_end
)
521 if ( aPropSet
.find( (*map_it
).first
) == set_end
)
522 aPropSet
.insert( (*map_it
).first
);
528 // std::set -> uno::Sequence
529 sal_Int32 nCount
= aPropSet
.size();
530 uno::Sequence
< beans::Property
> aProperties( nCount
);
532 std::set
< rtl::OUString
>::const_iterator it
= aPropSet
.begin();
533 beans::Property aProp
;
535 for ( sal_Int32 n
= 0; n
< nCount
; ++n
, ++it
)
537 xProvider
->getProperty( (*it
), aProp
);
538 aProperties
[ n
] = aProp
;
544 //=========================================================================
546 uno::Sequence
< com::sun::star::ucb::CommandInfo
> Content::getCommands(
547 const uno::Reference
< com::sun::star::ucb::XCommandEnvironment
> & xEnv
)
549 osl::Guard
< osl::Mutex
> aGuard( m_aMutex
);
551 sal_Bool bFolder
= sal_False
;
555 bFolder
= isFolder( xEnv
);
557 catch ( uno::Exception
const & )
559 static com::sun::star::ucb::CommandInfo aDefaultCommandInfoTable
[] =
561 ///////////////////////////////////////////////////////////////
562 // Just mandatory commands avail.
563 ///////////////////////////////////////////////////////////////
565 com::sun::star::ucb::CommandInfo(
567 RTL_CONSTASCII_USTRINGPARAM( "getCommandInfo" ) ),
571 com::sun::star::ucb::CommandInfo(
573 RTL_CONSTASCII_USTRINGPARAM( "getPropertySetInfo" ) ),
577 com::sun::star::ucb::CommandInfo(
579 RTL_CONSTASCII_USTRINGPARAM( "getPropertyValues" ) ),
581 getCppuType( static_cast<
582 uno::Sequence
< beans::Property
> * >( 0 ) )
584 com::sun::star::ucb::CommandInfo(
586 RTL_CONSTASCII_USTRINGPARAM( "setPropertyValues" ) ),
588 getCppuType( static_cast<
589 uno::Sequence
< beans::PropertyValue
> * >( 0 ) )
592 return uno::Sequence
< com::sun::star::ucb::CommandInfo
>(
593 aDefaultCommandInfoTable
, 4 );
598 //=================================================================
600 // Folder: Supported commands
602 //=================================================================
604 static com::sun::star::ucb::CommandInfo aFolderCommandInfoTable
[] =
606 ///////////////////////////////////////////////////////////////
608 ///////////////////////////////////////////////////////////////
610 com::sun::star::ucb::CommandInfo(
612 RTL_CONSTASCII_USTRINGPARAM( "getCommandInfo" ) ),
616 com::sun::star::ucb::CommandInfo(
618 RTL_CONSTASCII_USTRINGPARAM( "getPropertySetInfo" ) ),
622 com::sun::star::ucb::CommandInfo(
624 RTL_CONSTASCII_USTRINGPARAM( "getPropertyValues" ) ),
626 getCppuType( static_cast<
627 uno::Sequence
< beans::Property
> * >( 0 ) )
629 com::sun::star::ucb::CommandInfo(
631 RTL_CONSTASCII_USTRINGPARAM( "setPropertyValues" ) ),
633 getCppuType( static_cast<
634 uno::Sequence
< beans::PropertyValue
> * >( 0 ) )
637 ///////////////////////////////////////////////////////////////
638 // Optional standard commands
639 ///////////////////////////////////////////////////////////////
641 com::sun::star::ucb::CommandInfo(
642 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "delete" ) ),
646 com::sun::star::ucb::CommandInfo(
647 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "insert" ) ),
649 getCppuType( static_cast<
650 com::sun::star::ucb::InsertCommandArgument
* >( 0 ) )
652 com::sun::star::ucb::CommandInfo(
653 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "open" ) ),
655 getCppuType( static_cast<
656 com::sun::star::ucb::OpenCommandArgument2
* >( 0 ) )
658 com::sun::star::ucb::CommandInfo(
659 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "transfer" ) ),
661 getCppuType( static_cast<
662 com::sun::star::ucb::TransferInfo
* >( 0 ) )
665 ///////////////////////////////////////////////////////////////
667 ///////////////////////////////////////////////////////////////
670 com::sun::star::ucb::CommandInfo(
671 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "COPY" ) ),
673 getCppuType( static_cast< const rtl::OUString * >( 0 ) ),
675 com::sun::star::ucb::CommandInfo(
676 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MOVE" ) ),
678 getCppuType( static_cast< const rtl::OUString * >( 0 ) ),
683 return uno::Sequence
< com::sun::star::ucb::CommandInfo
>(
684 aFolderCommandInfoTable
, 8 );
688 //=================================================================
690 // Document: Supported commands
692 //=================================================================
694 static com::sun::star::ucb::CommandInfo aDocumentCommandInfoTable
[] =
696 ///////////////////////////////////////////////////////////////
698 ///////////////////////////////////////////////////////////////
700 com::sun::star::ucb::CommandInfo(
702 RTL_CONSTASCII_USTRINGPARAM( "getCommandInfo" ) ),
706 com::sun::star::ucb::CommandInfo(
708 RTL_CONSTASCII_USTRINGPARAM( "getPropertySetInfo" ) ),
712 com::sun::star::ucb::CommandInfo(
714 RTL_CONSTASCII_USTRINGPARAM( "getPropertyValues" ) ),
716 getCppuType( static_cast<
717 uno::Sequence
< beans::Property
> * >( 0 ) )
719 com::sun::star::ucb::CommandInfo(
721 RTL_CONSTASCII_USTRINGPARAM( "setPropertyValues" ) ),
723 getCppuType( static_cast<
724 uno::Sequence
< beans::PropertyValue
> * >( 0 ) )
727 ///////////////////////////////////////////////////////////////
728 // Optional standard commands
729 ///////////////////////////////////////////////////////////////
731 com::sun::star::ucb::CommandInfo(
732 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "delete" ) ),
736 com::sun::star::ucb::CommandInfo(
737 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "insert" ) ),
739 getCppuType( static_cast<
740 com::sun::star::ucb::InsertCommandArgument
* >( 0 ) )
742 com::sun::star::ucb::CommandInfo(
743 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "open" ) ),
745 getCppuType( static_cast<
746 com::sun::star::ucb::OpenCommandArgument2
* >( 0 ) )
749 ///////////////////////////////////////////////////////////////
751 ///////////////////////////////////////////////////////////////
753 com::sun::star::ucb::CommandInfo(
754 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "post" ) ),
756 getCppuType( static_cast<
757 com::sun::star::ucb::PostCommandArgument2
* >( 0 ) )
761 com::sun::star::ucb::CommandInfo(
762 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "COPY" ) ),
764 getCppuType( static_cast< const rtl::OUString * >( 0 ) ),
766 com::sun::star::ucb::CommandInfo(
767 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MOVE" ) ),
769 getCppuType( static_cast< const rtl::OUString * >( 0 ) ),
774 return uno::Sequence
< com::sun::star::ucb::CommandInfo
>(
775 aDocumentCommandInfoTable
, 8 );