fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / ucb / source / ucp / webdav / webdavcontentcaps.cxx
blobf075ba0d6665c5ed59ebae3cb3bea2baf4b67aad
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
20 #include <set>
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 )
51 if ( !m_pProps )
53 osl::MutexGuard aGuard( m_aMutex );
54 if ( !m_pProps )
56 m_pProps = new PropertyMap;
58 //////////////////////////////////////////////////////////////
59 // Fill map of known properties...
60 //////////////////////////////////////////////////////////////
62 // Mandatory UCB properties.
63 m_pProps->insert(
64 beans::Property(
65 OUString( "ContentType" ),
66 -1,
67 getCppuType( static_cast< const OUString * >( 0 ) ),
68 beans::PropertyAttribute::BOUND
69 | beans::PropertyAttribute::READONLY ) );
71 m_pProps->insert(
72 beans::Property(
73 OUString( "IsDocument" ),
74 -1,
75 getCppuBooleanType(),
76 beans::PropertyAttribute::BOUND
77 | beans::PropertyAttribute::READONLY ) );
79 m_pProps->insert(
80 beans::Property(
81 OUString( "IsFolder" ),
82 -1,
83 getCppuBooleanType(),
84 beans::PropertyAttribute::BOUND
85 | beans::PropertyAttribute::READONLY ) );
87 m_pProps->insert(
88 beans::Property(
89 OUString( "Title" ),
90 -1,
91 getCppuType( static_cast< const OUString * >( 0 ) ),
92 beans::PropertyAttribute::BOUND ) );
94 // Optional UCB properties.
96 m_pProps->insert(
97 beans::Property(
98 OUString( "DateCreated" ),
99 -1,
100 getCppuType( static_cast< const util::DateTime * >( 0 ) ),
101 beans::PropertyAttribute::BOUND
102 | beans::PropertyAttribute::READONLY ) );
104 m_pProps->insert(
105 beans::Property(
106 OUString( "DateModified" ),
108 getCppuType( static_cast< const util::DateTime * >( 0 ) ),
109 beans::PropertyAttribute::BOUND
110 | beans::PropertyAttribute::READONLY ) );
112 m_pProps->insert(
113 beans::Property(
114 OUString( "MediaType" ),
116 getCppuType( static_cast< const OUString * >( 0 ) ),
117 beans::PropertyAttribute::BOUND
118 | beans::PropertyAttribute::READONLY ) );
120 m_pProps->insert(
121 beans::Property(
122 OUString( "Size" ),
124 getCppuType( static_cast< const sal_Int64 * >( 0 ) ),
125 beans::PropertyAttribute::BOUND
126 | beans::PropertyAttribute::READONLY ) );
128 m_pProps->insert(
129 beans::Property(
130 OUString( "BaseURI" ),
132 getCppuType( static_cast< const OUString * >( 0 ) ),
133 beans::PropertyAttribute::BOUND
134 | beans::PropertyAttribute::READONLY ) );
136 m_pProps->insert(
137 beans::Property(
138 OUString(
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.
148 m_pProps->insert(
149 beans::Property(
150 DAVProperties::CREATIONDATE,
152 getCppuType( static_cast< const OUString * >( 0 ) ),
153 beans::PropertyAttribute::BOUND
154 | beans::PropertyAttribute::READONLY ) );
156 m_pProps->insert(
157 beans::Property(
158 DAVProperties::DISPLAYNAME,
160 getCppuType( static_cast< const OUString * >( 0 ) ),
161 beans::PropertyAttribute::BOUND ) );
163 m_pProps->insert(
164 beans::Property(
165 DAVProperties::GETCONTENTLANGUAGE,
167 getCppuType( static_cast< const OUString * >( 0 ) ),
168 beans::PropertyAttribute::BOUND
169 | beans::PropertyAttribute::READONLY ) );
171 m_pProps->insert(
172 beans::Property(
173 DAVProperties::GETCONTENTLENGTH,
175 getCppuType( static_cast< const OUString * >( 0 ) ),
176 beans::PropertyAttribute::BOUND
177 | beans::PropertyAttribute::READONLY ) );
179 m_pProps->insert(
180 beans::Property(
181 DAVProperties::GETCONTENTTYPE ,
183 getCppuType( static_cast< const OUString * >( 0 ) ),
184 beans::PropertyAttribute::BOUND
185 | beans::PropertyAttribute::READONLY ) );
187 m_pProps->insert(
188 beans::Property(
189 DAVProperties::GETETAG,
191 getCppuType( static_cast< const OUString * >( 0 ) ),
192 beans::PropertyAttribute::BOUND
193 | beans::PropertyAttribute::READONLY ) );
195 m_pProps->insert(
196 beans::Property(
197 DAVProperties::GETLASTMODIFIED,
199 getCppuType( static_cast< const OUString * >( 0 ) ),
200 beans::PropertyAttribute::BOUND
201 | beans::PropertyAttribute::READONLY ) );
203 m_pProps->insert(
204 beans::Property(
205 DAVProperties::LOCKDISCOVERY,
207 getCppuType( static_cast<
208 const uno::Sequence< ucb::Lock > * >( 0 ) ),
209 beans::PropertyAttribute::BOUND
210 | beans::PropertyAttribute::READONLY ) );
212 m_pProps->insert(
213 beans::Property(
214 DAVProperties::RESOURCETYPE,
216 getCppuType( static_cast< const OUString * >( 0 ) ),
217 beans::PropertyAttribute::BOUND
218 | beans::PropertyAttribute::READONLY ) );
220 m_pProps->insert(
221 beans::Property(
222 DAVProperties::SUPPORTEDLOCK,
224 getCppuType( static_cast<
225 const uno::Sequence<
226 ucb::LockEntry > * >( 0 ) ),
227 beans::PropertyAttribute::BOUND
228 | beans::PropertyAttribute::READONLY ) );
230 m_pProps->insert(
231 beans::Property(
232 DAVProperties::EXECUTABLE,
234 getCppuType( static_cast< const OUString * >( 0 ) ),
235 beans::PropertyAttribute::BOUND ) );
239 //////////////////////////////////////////////////////////////
240 // Lookup property.
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() )
248 rProp = (*it);
250 else
252 if ( bStrict )
253 return false;
255 // All unknown props are treated as:
256 rProp = beans::Property(
257 rPropName,
258 - 1,
259 getCppuType( static_cast< const OUString * >( 0 ) ),
260 beans::PropertyAttribute::BOUND );
263 return true;
266 //=========================================================================
268 // Content implementation.
270 //=========================================================================
272 // virtual
273 uno::Sequence< beans::Property > Content::getProperties(
274 const uno::Reference< ucb::XCommandEnvironment > & xEnv )
276 sal_Bool bTransient;
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() )
287 xCachedProps.reset(
288 new ContentProperties( *m_xCachedProps.get() ) );
289 xProvider.set( m_pProvider );
292 typedef std::set< OUString > StringSet;
293 StringSet aPropSet;
295 // No server access for just created (not yet committed) objects.
296 // Only a minimal set of properties supported at this stage.
297 if ( !bTransient )
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();
335 while ( it != 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" )
391 bHasSize = sal_True;
393 else if ( !bHasCreatableInfos && (*it) == "CreatableContentsInfo" )
395 bHasCreatableInfos = sal_True;
397 ++it;
401 // Add mandatory properties.
402 if ( !bHasContentType )
403 aPropSet.insert(
404 OUString( "ContentType" ) );
406 if ( !bHasIsDocument )
407 aPropSet.insert(
408 OUString( "IsDocument" ) );
410 if ( !bHasIsFolder )
411 aPropSet.insert(
412 OUString( "IsFolder" ) );
414 if ( !bHasTitle )
416 // Always present since it can be calculated from content's URI.
417 aPropSet.insert(
418 OUString( "Title" ) );
421 // Add optional properties.
423 if ( !bHasBaseURI )
425 // Always present since it can be calculated from content's URI.
426 aPropSet.insert(
427 OUString( "BaseURI" ) );
430 if ( !bHasDateCreated && bHasCreationDate )
431 aPropSet.insert(
432 OUString( "DateCreated" ) );
434 if ( !bHasDateModified && bHasGetLastModified )
435 aPropSet.insert(
436 OUString( "DateModified" ) );
438 if ( !bHasMediaType && bHasGetContentType )
439 aPropSet.insert(
440 OUString( "MediaType" ) );
442 if ( !bHasSize && bHasGetContentLength )
443 aPropSet.insert(
444 OUString( "Size" ) );
446 if ( !bHasCreatableInfos )
447 aPropSet.insert(
448 OUString(
449 "CreatableContentsInfo" ) );
451 // Add cached properties, if present and still missing.
452 if ( xCachedProps.get() )
454 const std::set< OUString >::const_iterator set_end
455 = aPropSet.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 );
468 ++map_it;
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;
485 return aProperties;
488 //=========================================================================
489 // virtual
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 ///////////////////////////////////////////////////////////////
501 aCmdInfo[ 0 ] =
502 ucb::CommandInfo(
503 OUString( "getCommandInfo" ),
505 getCppuVoidType() );
506 aCmdInfo[ 1 ] =
507 ucb::CommandInfo(
508 OUString( "getPropertySetInfo" ),
510 getCppuVoidType() );
511 aCmdInfo[ 2 ] =
512 ucb::CommandInfo(
513 OUString( "getPropertyValues" ),
515 getCppuType( static_cast<
516 uno::Sequence< beans::Property > * >( 0 ) ) );
517 aCmdInfo[ 3 ] =
518 ucb::CommandInfo(
519 OUString( "setPropertyValues" ),
521 getCppuType( static_cast<
522 uno::Sequence< beans::PropertyValue > * >( 0 ) ) );
524 ///////////////////////////////////////////////////////////////
525 // Optional standard commands
526 ///////////////////////////////////////////////////////////////
528 aCmdInfo[ 4 ] =
529 ucb::CommandInfo(
530 OUString( "delete" ),
532 getCppuBooleanType() );
533 aCmdInfo[ 5 ] =
534 ucb::CommandInfo(
535 OUString( "insert" ),
537 getCppuType( static_cast<
538 ucb::InsertCommandArgument * >( 0 ) ) );
539 aCmdInfo[ 6 ] =
540 ucb::CommandInfo(
541 OUString( "open" ),
543 getCppuType( static_cast<
544 ucb::OpenCommandArgument2 * >( 0 ) ) );
546 ///////////////////////////////////////////////////////////////
547 // New commands
548 ///////////////////////////////////////////////////////////////
550 aCmdInfo[ 7 ] =
551 ucb::CommandInfo(
552 OUString( "post" ),
554 getCppuType( static_cast<
555 ucb::PostCommandArgument2 * >( 0 ) ) );
557 sal_Bool bFolder = sal_False;
561 bFolder = isFolder( xEnv );
563 catch ( uno::Exception const & )
565 return aCmdInfo;
568 sal_Bool bSupportsLocking = supportsExclusiveWriteLock( xEnv );
570 sal_Int32 nPos = aCmdInfo.getLength();
571 sal_Int32 nMoreCmds = ( bFolder ? 2 : 0 ) + ( bSupportsLocking ? 2 : 0 );
572 if ( nMoreCmds )
573 aCmdInfo.realloc( nPos + nMoreCmds );
574 else
575 return aCmdInfo;
577 if ( bFolder )
579 ///////////////////////////////////////////////////////////////
580 // Optional standard commands
581 ///////////////////////////////////////////////////////////////
583 aCmdInfo[ nPos ] =
584 ucb::CommandInfo(
585 OUString( "transfer" ),
587 getCppuType( static_cast< ucb::TransferInfo * >( 0 ) ) );
588 nPos++;
589 aCmdInfo[ nPos ] =
590 ucb::CommandInfo(
591 OUString(
592 "createNewContent" ),
594 getCppuType( static_cast< ucb::ContentInfo * >( 0 ) ) );
595 nPos++;
597 else
599 // no document-only commands at the moment.
602 if ( bSupportsLocking )
604 aCmdInfo[ nPos ] =
605 ucb::CommandInfo(
606 OUString( "lock" ),
608 getCppuVoidType() );
609 nPos++;
610 aCmdInfo[ nPos ] =
611 ucb::CommandInfo(
612 OUString( "unlock" ),
614 getCppuVoidType() );
615 nPos++;
617 return aCmdInfo;
620 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */