Bump for 3.6-28
[LibreOffice.git] / ucb / source / ucp / webdav / webdavcontentcaps.cxx
blob478dc66a4bb4ef6e1265cfe7b5461dce2b9e67fe
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 /**************************************************************************
30 TODO
31 **************************************************************************
33 *************************************************************************/
35 #include <set>
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 )
67 if ( !m_pProps )
69 osl::MutexGuard aGuard( m_aMutex );
70 if ( !m_pProps )
72 m_pProps = new PropertyMap;
74 //////////////////////////////////////////////////////////////
75 // Fill map of known properties...
76 //////////////////////////////////////////////////////////////
78 // Mandatory UCB properties.
79 m_pProps->insert(
80 beans::Property(
81 rtl::OUString(
82 RTL_CONSTASCII_USTRINGPARAM( "ContentType" ) ),
83 -1,
84 getCppuType( static_cast< const rtl::OUString * >( 0 ) ),
85 beans::PropertyAttribute::BOUND
86 | beans::PropertyAttribute::READONLY ) );
88 m_pProps->insert(
89 beans::Property(
90 rtl::OUString(
91 RTL_CONSTASCII_USTRINGPARAM( "IsDocument" ) ),
92 -1,
93 getCppuBooleanType(),
94 beans::PropertyAttribute::BOUND
95 | beans::PropertyAttribute::READONLY ) );
97 m_pProps->insert(
98 beans::Property(
99 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IsFolder" ) ),
101 getCppuBooleanType(),
102 beans::PropertyAttribute::BOUND
103 | beans::PropertyAttribute::READONLY ) );
105 m_pProps->insert(
106 beans::Property(
107 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Title" ) ),
109 getCppuType( static_cast< const rtl::OUString * >( 0 ) ),
110 beans::PropertyAttribute::BOUND ) );
112 // Optional UCB properties.
114 m_pProps->insert(
115 beans::Property(
116 rtl::OUString(
117 RTL_CONSTASCII_USTRINGPARAM( "DateCreated" ) ),
119 getCppuType( static_cast< const util::DateTime * >( 0 ) ),
120 beans::PropertyAttribute::BOUND
121 | beans::PropertyAttribute::READONLY ) );
123 m_pProps->insert(
124 beans::Property(
125 rtl::OUString(
126 RTL_CONSTASCII_USTRINGPARAM( "DateModified" ) ),
128 getCppuType( static_cast< const util::DateTime * >( 0 ) ),
129 beans::PropertyAttribute::BOUND
130 | beans::PropertyAttribute::READONLY ) );
132 m_pProps->insert(
133 beans::Property(
134 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MediaType" ) ),
136 getCppuType( static_cast< const rtl::OUString * >( 0 ) ),
137 beans::PropertyAttribute::BOUND
138 | beans::PropertyAttribute::READONLY ) );
140 m_pProps->insert(
141 beans::Property(
142 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Size" ) ),
144 getCppuType( static_cast< const sal_Int64 * >( 0 ) ),
145 beans::PropertyAttribute::BOUND
146 | beans::PropertyAttribute::READONLY ) );
148 m_pProps->insert(
149 beans::Property(
150 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "BaseURI" ) ),
152 getCppuType( static_cast< const rtl::OUString * >( 0 ) ),
153 beans::PropertyAttribute::BOUND
154 | beans::PropertyAttribute::READONLY ) );
156 m_pProps->insert(
157 beans::Property(
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.
168 m_pProps->insert(
169 beans::Property(
170 DAVProperties::CREATIONDATE,
172 getCppuType( static_cast< const rtl::OUString * >( 0 ) ),
173 beans::PropertyAttribute::BOUND
174 | beans::PropertyAttribute::READONLY ) );
176 m_pProps->insert(
177 beans::Property(
178 DAVProperties::DISPLAYNAME,
180 getCppuType( static_cast< const rtl::OUString * >( 0 ) ),
181 beans::PropertyAttribute::BOUND ) );
183 m_pProps->insert(
184 beans::Property(
185 DAVProperties::GETCONTENTLANGUAGE,
187 getCppuType( static_cast< const rtl::OUString * >( 0 ) ),
188 beans::PropertyAttribute::BOUND
189 | beans::PropertyAttribute::READONLY ) );
191 m_pProps->insert(
192 beans::Property(
193 DAVProperties::GETCONTENTLENGTH,
195 getCppuType( static_cast< const rtl::OUString * >( 0 ) ),
196 beans::PropertyAttribute::BOUND
197 | beans::PropertyAttribute::READONLY ) );
199 m_pProps->insert(
200 beans::Property(
201 DAVProperties::GETCONTENTTYPE ,
203 getCppuType( static_cast< const rtl::OUString * >( 0 ) ),
204 beans::PropertyAttribute::BOUND
205 | beans::PropertyAttribute::READONLY ) );
207 m_pProps->insert(
208 beans::Property(
209 DAVProperties::GETETAG,
211 getCppuType( static_cast< const rtl::OUString * >( 0 ) ),
212 beans::PropertyAttribute::BOUND
213 | beans::PropertyAttribute::READONLY ) );
215 m_pProps->insert(
216 beans::Property(
217 DAVProperties::GETLASTMODIFIED,
219 getCppuType( static_cast< const rtl::OUString * >( 0 ) ),
220 beans::PropertyAttribute::BOUND
221 | beans::PropertyAttribute::READONLY ) );
223 m_pProps->insert(
224 beans::Property(
225 DAVProperties::LOCKDISCOVERY,
227 getCppuType( static_cast<
228 const uno::Sequence< ucb::Lock > * >( 0 ) ),
229 beans::PropertyAttribute::BOUND
230 | beans::PropertyAttribute::READONLY ) );
232 m_pProps->insert(
233 beans::Property(
234 DAVProperties::RESOURCETYPE,
236 getCppuType( static_cast< const rtl::OUString * >( 0 ) ),
237 beans::PropertyAttribute::BOUND
238 | beans::PropertyAttribute::READONLY ) );
240 m_pProps->insert(
241 beans::Property(
242 DAVProperties::SOURCE,
244 getCppuType( static_cast<
245 const uno::Sequence< ucb::Link > * >( 0 ) ),
246 beans::PropertyAttribute::BOUND ) );
248 m_pProps->insert(
249 beans::Property(
250 DAVProperties::SUPPORTEDLOCK,
252 getCppuType( static_cast<
253 const uno::Sequence<
254 ucb::LockEntry > * >( 0 ) ),
255 beans::PropertyAttribute::BOUND
256 | beans::PropertyAttribute::READONLY ) );
258 m_pProps->insert(
259 beans::Property(
260 DAVProperties::EXECUTABLE,
262 getCppuType( static_cast< const rtl::OUString * >( 0 ) ),
263 beans::PropertyAttribute::BOUND ) );
267 //////////////////////////////////////////////////////////////
268 // Lookup property.
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() )
276 rProp = (*it);
278 else
280 if ( bStrict )
281 return false;
283 // All unknown props are treated as:
284 rProp = beans::Property(
285 rPropName,
286 - 1,
287 getCppuType( static_cast< const rtl::OUString * >( 0 ) ),
288 beans::PropertyAttribute::BOUND );
291 return true;
294 //=========================================================================
296 // Content implementation.
298 //=========================================================================
300 // virtual
301 uno::Sequence< beans::Property > Content::getProperties(
302 const uno::Reference< ucb::XCommandEnvironment > & xEnv )
304 sal_Bool bTransient;
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() )
317 xCachedProps.reset(
318 new ContentProperties( *m_xCachedProps.get() ) );
319 xProvider.set( m_pProvider );
322 typedef std::set< rtl::OUString > StringSet;
323 StringSet aPropSet;
325 // No server access for just created (not yet committed) objects.
326 // Only a minimal set of properties supported at this stage.
327 if ( !bTransient )
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();
365 while ( it != 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" )
421 bHasSize = sal_True;
423 else if ( !bHasCreatableInfos && (*it) == "CreatableContentsInfo" )
425 bHasCreatableInfos = sal_True;
427 ++it;
431 // Add mandatory properties.
432 if ( !bHasContentType )
433 aPropSet.insert(
434 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ContentType" ) ) );
436 if ( !bHasIsDocument )
437 aPropSet.insert(
438 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IsDocument" ) ) );
440 if ( !bHasIsFolder )
441 aPropSet.insert(
442 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IsFolder" ) ) );
444 if ( !bHasTitle )
446 // Always present since it can be calculated from content's URI.
447 aPropSet.insert(
448 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Title" ) ) );
451 // Add optional properties.
453 if ( !bHasBaseURI )
455 // Always present since it can be calculated from content's URI.
456 aPropSet.insert(
457 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "BaseURI" ) ) );
460 if ( !bHasDateCreated && bHasCreationDate )
461 aPropSet.insert(
462 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DateCreated" ) ) );
464 if ( !bHasDateModified && bHasGetLastModified )
465 aPropSet.insert(
466 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DateModified" ) ) );
468 if ( !bHasMediaType && bHasGetContentType )
469 aPropSet.insert(
470 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MediaType" ) ) );
472 if ( !bHasSize && bHasGetContentLength )
473 aPropSet.insert(
474 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Size" ) ) );
476 if ( !bHasCreatableInfos )
477 aPropSet.insert(
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
485 = aPropSet.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 );
500 ++map_it;
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;
517 return aProperties;
520 //=========================================================================
521 // virtual
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 ///////////////////////////////////////////////////////////////
533 aCmdInfo[ 0 ] =
534 ucb::CommandInfo(
535 rtl::OUString(
536 RTL_CONSTASCII_USTRINGPARAM( "getCommandInfo" ) ),
538 getCppuVoidType() );
539 aCmdInfo[ 1 ] =
540 ucb::CommandInfo(
541 rtl::OUString(
542 RTL_CONSTASCII_USTRINGPARAM( "getPropertySetInfo" ) ),
544 getCppuVoidType() );
545 aCmdInfo[ 2 ] =
546 ucb::CommandInfo(
547 rtl::OUString(
548 RTL_CONSTASCII_USTRINGPARAM( "getPropertyValues" ) ),
550 getCppuType( static_cast<
551 uno::Sequence< beans::Property > * >( 0 ) ) );
552 aCmdInfo[ 3 ] =
553 ucb::CommandInfo(
554 rtl::OUString(
555 RTL_CONSTASCII_USTRINGPARAM( "setPropertyValues" ) ),
557 getCppuType( static_cast<
558 uno::Sequence< beans::PropertyValue > * >( 0 ) ) );
560 ///////////////////////////////////////////////////////////////
561 // Optional standard commands
562 ///////////////////////////////////////////////////////////////
564 aCmdInfo[ 4 ] =
565 ucb::CommandInfo(
566 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "delete" ) ),
568 getCppuBooleanType() );
569 aCmdInfo[ 5 ] =
570 ucb::CommandInfo(
571 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "insert" ) ),
573 getCppuType( static_cast<
574 ucb::InsertCommandArgument * >( 0 ) ) );
575 aCmdInfo[ 6 ] =
576 ucb::CommandInfo(
577 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "open" ) ),
579 getCppuType( static_cast<
580 ucb::OpenCommandArgument2 * >( 0 ) ) );
582 ///////////////////////////////////////////////////////////////
583 // New commands
584 ///////////////////////////////////////////////////////////////
586 aCmdInfo[ 7 ] =
587 ucb::CommandInfo(
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 & )
601 return aCmdInfo;
604 sal_Bool bSupportsLocking = supportsExclusiveWriteLock( xEnv );
606 sal_Int32 nPos = aCmdInfo.getLength();
607 sal_Int32 nMoreCmds = ( bFolder ? 2 : 0 ) + ( bSupportsLocking ? 2 : 0 );
608 if ( nMoreCmds )
609 aCmdInfo.realloc( nPos + nMoreCmds );
610 else
611 return aCmdInfo;
613 if ( bFolder )
615 ///////////////////////////////////////////////////////////////
616 // Optional standard commands
617 ///////////////////////////////////////////////////////////////
619 aCmdInfo[ nPos ] =
620 ucb::CommandInfo(
621 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "transfer" ) ),
623 getCppuType( static_cast< ucb::TransferInfo * >( 0 ) ) );
624 nPos++;
625 aCmdInfo[ nPos ] =
626 ucb::CommandInfo(
627 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
628 "createNewContent" ) ),
630 getCppuType( static_cast< ucb::ContentInfo * >( 0 ) ) );
631 nPos++;
633 else
635 // no document-only commands at the moment.
638 if ( bSupportsLocking )
640 aCmdInfo[ nPos ] =
641 ucb::CommandInfo(
642 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "lock" ) ),
644 getCppuVoidType() );
645 nPos++;
646 aCmdInfo[ nPos ] =
647 ucb::CommandInfo(
648 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "unlock" ) ),
650 getCppuVoidType() );
651 nPos++;
653 return aCmdInfo;
656 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */