1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 /**************************************************************************
31 **************************************************************************
33 *************************************************************************/
36 #include <com/sun/star/beans/Property.hpp>
37 #include <com/sun/star/beans/PropertyAttribute.hpp>
38 #include <com/sun/star/beans/PropertyValue.hpp>
39 #include <com/sun/star/ucb/CommandInfo.hpp>
40 #include <com/sun/star/ucb/ContentInfo.hpp>
41 #include <com/sun/star/ucb/OpenCommandArgument2.hpp>
42 #include <com/sun/star/ucb/InsertCommandArgument.hpp>
43 #include <com/sun/star/ucb/PostCommandArgument2.hpp>
44 #include <com/sun/star/ucb/TransferInfo.hpp>
45 #include <com/sun/star/uno/Sequence.hxx>
46 #include <com/sun/star/util/DateTime.hpp>
47 #include <com/sun/star/ucb/Link.hpp>
48 #include <com/sun/star/ucb/Lock.hpp>
49 #include <com/sun/star/ucb/LockEntry.hpp>
50 #include "webdavcontent.hxx"
51 #include "webdavprovider.hxx"
52 #include "DAVSession.hxx"
53 #include "ContentProperties.hxx"
55 using namespace com::sun::star
;
56 using namespace webdav_ucp
;
58 //=========================================================================
60 // ContentProvider implementation.
62 //=========================================================================
64 bool ContentProvider::getProperty(
65 const rtl::OUString
& rPropName
, beans::Property
& rProp
, bool bStrict
)
69 osl::MutexGuard
aGuard( m_aMutex
);
72 m_pProps
= new PropertyMap
;
74 //////////////////////////////////////////////////////////////
75 // Fill map of known properties...
76 //////////////////////////////////////////////////////////////
78 // Mandatory UCB properties.
82 RTL_CONSTASCII_USTRINGPARAM( "ContentType" ) ),
84 getCppuType( static_cast< const rtl::OUString
* >( 0 ) ),
85 beans::PropertyAttribute::BOUND
86 | beans::PropertyAttribute::READONLY
) );
91 RTL_CONSTASCII_USTRINGPARAM( "IsDocument" ) ),
94 beans::PropertyAttribute::BOUND
95 | beans::PropertyAttribute::READONLY
) );
99 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IsFolder" ) ),
101 getCppuBooleanType(),
102 beans::PropertyAttribute::BOUND
103 | beans::PropertyAttribute::READONLY
) );
107 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Title" ) ),
109 getCppuType( static_cast< const rtl::OUString
* >( 0 ) ),
110 beans::PropertyAttribute::BOUND
) );
112 // Optional UCB properties.
117 RTL_CONSTASCII_USTRINGPARAM( "DateCreated" ) ),
119 getCppuType( static_cast< const util::DateTime
* >( 0 ) ),
120 beans::PropertyAttribute::BOUND
121 | beans::PropertyAttribute::READONLY
) );
126 RTL_CONSTASCII_USTRINGPARAM( "DateModified" ) ),
128 getCppuType( static_cast< const util::DateTime
* >( 0 ) ),
129 beans::PropertyAttribute::BOUND
130 | beans::PropertyAttribute::READONLY
) );
134 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MediaType" ) ),
136 getCppuType( static_cast< const rtl::OUString
* >( 0 ) ),
137 beans::PropertyAttribute::BOUND
138 | beans::PropertyAttribute::READONLY
) );
142 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Size" ) ),
144 getCppuType( static_cast< const sal_Int64
* >( 0 ) ),
145 beans::PropertyAttribute::BOUND
146 | beans::PropertyAttribute::READONLY
) );
150 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "BaseURI" ) ),
152 getCppuType( static_cast< const rtl::OUString
* >( 0 ) ),
153 beans::PropertyAttribute::BOUND
154 | beans::PropertyAttribute::READONLY
) );
158 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
159 "CreatableContentsInfo" ) ),
161 getCppuType( static_cast<
162 const uno::Sequence
< ucb::ContentInfo
> * >( 0 ) ),
163 beans::PropertyAttribute::BOUND
164 | beans::PropertyAttribute::READONLY
) );
166 // Standard DAV properties.
170 DAVProperties::CREATIONDATE
,
172 getCppuType( static_cast< const rtl::OUString
* >( 0 ) ),
173 beans::PropertyAttribute::BOUND
174 | beans::PropertyAttribute::READONLY
) );
178 DAVProperties::DISPLAYNAME
,
180 getCppuType( static_cast< const rtl::OUString
* >( 0 ) ),
181 beans::PropertyAttribute::BOUND
) );
185 DAVProperties::GETCONTENTLANGUAGE
,
187 getCppuType( static_cast< const rtl::OUString
* >( 0 ) ),
188 beans::PropertyAttribute::BOUND
189 | beans::PropertyAttribute::READONLY
) );
193 DAVProperties::GETCONTENTLENGTH
,
195 getCppuType( static_cast< const rtl::OUString
* >( 0 ) ),
196 beans::PropertyAttribute::BOUND
197 | beans::PropertyAttribute::READONLY
) );
201 DAVProperties::GETCONTENTTYPE
,
203 getCppuType( static_cast< const rtl::OUString
* >( 0 ) ),
204 beans::PropertyAttribute::BOUND
205 | beans::PropertyAttribute::READONLY
) );
209 DAVProperties::GETETAG
,
211 getCppuType( static_cast< const rtl::OUString
* >( 0 ) ),
212 beans::PropertyAttribute::BOUND
213 | beans::PropertyAttribute::READONLY
) );
217 DAVProperties::GETLASTMODIFIED
,
219 getCppuType( static_cast< const rtl::OUString
* >( 0 ) ),
220 beans::PropertyAttribute::BOUND
221 | beans::PropertyAttribute::READONLY
) );
225 DAVProperties::LOCKDISCOVERY
,
227 getCppuType( static_cast<
228 const uno::Sequence
< 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<
245 const uno::Sequence
< ucb::Link
> * >( 0 ) ),
246 beans::PropertyAttribute::BOUND
) );
250 DAVProperties::SUPPORTEDLOCK
,
252 getCppuType( static_cast<
254 ucb::LockEntry
> * >( 0 ) ),
255 beans::PropertyAttribute::BOUND
256 | beans::PropertyAttribute::READONLY
) );
260 DAVProperties::EXECUTABLE
,
262 getCppuType( static_cast< const rtl::OUString
* >( 0 ) ),
263 beans::PropertyAttribute::BOUND
) );
267 //////////////////////////////////////////////////////////////
269 //////////////////////////////////////////////////////////////
271 beans::Property aProp
;
272 aProp
.Name
= rPropName
;
273 const PropertyMap::const_iterator it
= m_pProps
->find( aProp
);
274 if ( it
!= m_pProps
->end() )
283 // All unknown props are treated as:
284 rProp
= beans::Property(
287 getCppuType( static_cast< const rtl::OUString
* >( 0 ) ),
288 beans::PropertyAttribute::BOUND
);
294 //=========================================================================
296 // Content implementation.
298 //=========================================================================
301 uno::Sequence
< beans::Property
> Content::getProperties(
302 const uno::Reference
< ucb::XCommandEnvironment
> & xEnv
)
305 SAL_WNODEPRECATED_DECLARATIONS_PUSH
306 std::auto_ptr
< DAVResourceAccess
> xResAccess
;
307 std::auto_ptr
< ContentProperties
> xCachedProps
;
308 SAL_WNODEPRECATED_DECLARATIONS_POP
309 rtl::Reference
< ContentProvider
> xProvider
;
312 osl::Guard
< osl::Mutex
> aGuard( m_aMutex
);
314 bTransient
= m_bTransient
;
315 xResAccess
.reset( new DAVResourceAccess( *m_xResAccess
.get() ) );
316 if ( m_xCachedProps
.get() )
318 new ContentProperties( *m_xCachedProps
.get() ) );
319 xProvider
.set( m_pProvider
);
322 typedef std::set
< rtl::OUString
> StringSet
;
325 // No server access for just created (not yet committed) objects.
326 // Only a minimal set of properties supported at this stage.
329 // Obtain all properties supported for this resource from server.
332 std::vector
< DAVResourceInfo
> props
;
333 xResAccess
->PROPFIND( DAVZERO
, props
, xEnv
);
335 // Note: vector always contains exactly one resource info, because
336 // we used a depth of DAVZERO for PROPFIND.
337 aPropSet
.insert( (*props
.begin()).properties
.begin(),
338 (*props
.begin()).properties
.end() );
340 catch ( DAVException
const & )
345 // Add DAV properties, map DAV properties to UCB properties.
346 sal_Bool bHasCreationDate
= sal_False
; // creationdate <-> DateCreated
347 sal_Bool bHasGetLastModified
= sal_False
; // getlastmodified <-> DateModified
348 sal_Bool bHasGetContentType
= sal_False
; // getcontenttype <-> MediaType
349 sal_Bool bHasGetContentLength
= sal_False
; // getcontentlength <-> Size
351 sal_Bool bHasContentType
= sal_False
;
352 sal_Bool bHasIsDocument
= sal_False
;
353 sal_Bool bHasIsFolder
= sal_False
;
354 sal_Bool bHasTitle
= sal_False
;
355 sal_Bool bHasBaseURI
= sal_False
;
356 sal_Bool bHasDateCreated
= sal_False
;
357 sal_Bool bHasDateModified
= sal_False
;
358 sal_Bool bHasMediaType
= sal_False
;
359 sal_Bool bHasSize
= sal_False
;
360 sal_Bool bHasCreatableInfos
= sal_False
;
363 std::set
< rtl::OUString
>::const_iterator it
= aPropSet
.begin();
364 std::set
< rtl::OUString
>::const_iterator end
= aPropSet
.end();
367 if ( !bHasCreationDate
&&
368 ( (*it
) == DAVProperties::CREATIONDATE
) )
370 bHasCreationDate
= sal_True
;
372 else if ( !bHasGetLastModified
&&
373 ( (*it
) == DAVProperties::GETLASTMODIFIED
) )
375 bHasGetLastModified
= sal_True
;
377 else if ( !bHasGetContentType
&&
378 ( (*it
) == DAVProperties::GETCONTENTTYPE
) )
380 bHasGetContentType
= sal_True
;
382 else if ( !bHasGetContentLength
&&
383 ( (*it
) == DAVProperties::GETCONTENTLENGTH
) )
385 bHasGetContentLength
= sal_True
;
387 else if ( !bHasContentType
&& (*it
) == "ContentType" )
389 bHasContentType
= sal_True
;
391 else if ( !bHasIsDocument
&& (*it
) == "IsDocument" )
393 bHasIsDocument
= sal_True
;
395 else if ( !bHasIsFolder
&& (*it
) == "IsFolder" )
397 bHasIsFolder
= sal_True
;
399 else if ( !bHasTitle
&& (*it
) == "Title" )
401 bHasTitle
= sal_True
;
403 else if ( !bHasBaseURI
&& (*it
) == "BaseURI" )
405 bHasBaseURI
= sal_True
;
407 else if ( !bHasDateCreated
&& (*it
) == "DateCreated" )
409 bHasDateCreated
= sal_True
;
411 else if ( !bHasDateModified
&& (*it
) == "DateModified" )
413 bHasDateModified
= sal_True
;
415 else if ( !bHasMediaType
&& (*it
) == "MediaType" )
417 bHasMediaType
= sal_True
;
419 else if ( !bHasSize
&& (*it
) == "Size" )
423 else if ( !bHasCreatableInfos
&& (*it
) == "CreatableContentsInfo" )
425 bHasCreatableInfos
= sal_True
;
431 // Add mandatory properties.
432 if ( !bHasContentType
)
434 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ContentType" ) ) );
436 if ( !bHasIsDocument
)
438 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IsDocument" ) ) );
442 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IsFolder" ) ) );
446 // Always present since it can be calculated from content's URI.
448 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Title" ) ) );
451 // Add optional properties.
455 // Always present since it can be calculated from content's URI.
457 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "BaseURI" ) ) );
460 if ( !bHasDateCreated
&& bHasCreationDate
)
462 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DateCreated" ) ) );
464 if ( !bHasDateModified
&& bHasGetLastModified
)
466 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DateModified" ) ) );
468 if ( !bHasMediaType
&& bHasGetContentType
)
470 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MediaType" ) ) );
472 if ( !bHasSize
&& bHasGetContentLength
)
474 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Size" ) ) );
476 if ( !bHasCreatableInfos
)
478 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
479 "CreatableContentsInfo" ) ) );
481 // Add cached properties, if present and still missing.
482 if ( xCachedProps
.get() )
484 const std::set
< rtl::OUString
>::const_iterator set_end
487 SAL_WNODEPRECATED_DECLARATIONS_PUSH
488 const std::auto_ptr
< PropertyValueMap
> & xProps
489 = xCachedProps
->getProperties();
490 SAL_WNODEPRECATED_DECLARATIONS_POP
492 PropertyValueMap::const_iterator map_it
= xProps
->begin();
493 const PropertyValueMap::const_iterator map_end
= xProps
->end();
495 while ( map_it
!= map_end
)
497 if ( aPropSet
.find( (*map_it
).first
) == set_end
)
498 aPropSet
.insert( (*map_it
).first
);
504 // std::set -> uno::Sequence
505 sal_Int32 nCount
= aPropSet
.size();
506 uno::Sequence
< beans::Property
> aProperties( nCount
);
508 std::set
< rtl::OUString
>::const_iterator it
= aPropSet
.begin();
509 beans::Property aProp
;
511 for ( sal_Int32 n
= 0; n
< nCount
; ++n
, ++it
)
513 xProvider
->getProperty( (*it
), aProp
);
514 aProperties
[ n
] = aProp
;
520 //=========================================================================
522 uno::Sequence
< ucb::CommandInfo
> Content::getCommands(
523 const uno::Reference
< ucb::XCommandEnvironment
> & xEnv
)
525 osl::Guard
< osl::Mutex
> aGuard( m_aMutex
);
527 uno::Sequence
< ucb::CommandInfo
> aCmdInfo( 8 );
529 ///////////////////////////////////////////////////////////////
530 // Mandatory commands
531 ///////////////////////////////////////////////////////////////
536 RTL_CONSTASCII_USTRINGPARAM( "getCommandInfo" ) ),
542 RTL_CONSTASCII_USTRINGPARAM( "getPropertySetInfo" ) ),
548 RTL_CONSTASCII_USTRINGPARAM( "getPropertyValues" ) ),
550 getCppuType( static_cast<
551 uno::Sequence
< beans::Property
> * >( 0 ) ) );
555 RTL_CONSTASCII_USTRINGPARAM( "setPropertyValues" ) ),
557 getCppuType( static_cast<
558 uno::Sequence
< beans::PropertyValue
> * >( 0 ) ) );
560 ///////////////////////////////////////////////////////////////
561 // Optional standard commands
562 ///////////////////////////////////////////////////////////////
566 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "delete" ) ),
568 getCppuBooleanType() );
571 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "insert" ) ),
573 getCppuType( static_cast<
574 ucb::InsertCommandArgument
* >( 0 ) ) );
577 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "open" ) ),
579 getCppuType( static_cast<
580 ucb::OpenCommandArgument2
* >( 0 ) ) );
582 ///////////////////////////////////////////////////////////////
584 ///////////////////////////////////////////////////////////////
588 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "post" ) ),
590 getCppuType( static_cast<
591 ucb::PostCommandArgument2
* >( 0 ) ) );
593 sal_Bool bFolder
= sal_False
;
597 bFolder
= isFolder( xEnv
);
599 catch ( uno::Exception
const & )
604 sal_Bool bSupportsLocking
= supportsExclusiveWriteLock( xEnv
);
606 sal_Int32 nPos
= aCmdInfo
.getLength();
607 sal_Int32 nMoreCmds
= ( bFolder
? 2 : 0 ) + ( bSupportsLocking
? 2 : 0 );
609 aCmdInfo
.realloc( nPos
+ nMoreCmds
);
615 ///////////////////////////////////////////////////////////////
616 // Optional standard commands
617 ///////////////////////////////////////////////////////////////
621 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "transfer" ) ),
623 getCppuType( static_cast< ucb::TransferInfo
* >( 0 ) ) );
627 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
628 "createNewContent" ) ),
630 getCppuType( static_cast< ucb::ContentInfo
* >( 0 ) ) );
635 // no document-only commands at the moment.
638 if ( bSupportsLocking
)
642 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "lock" ) ),
648 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "unlock" ) ),
656 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */