fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / ucb / source / ucp / webdav / webdavcontentcaps.cxx
blobcb85c40851c462c8f75d6693212442cca772a24d
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/PropertyCommandArgument.hpp>
30 #include <com/sun/star/ucb/TransferInfo.hpp>
31 #include <com/sun/star/uno/Sequence.hxx>
32 #include <com/sun/star/util/DateTime.hpp>
33 #include <com/sun/star/ucb/Lock.hpp>
34 #include <com/sun/star/ucb/LockEntry.hpp>
35 #include "webdavcontent.hxx"
36 #include "webdavprovider.hxx"
37 #include "DAVSession.hxx"
38 #include "ContentProperties.hxx"
40 using namespace com::sun::star;
41 using namespace http_dav_ucp;
45 // ContentProvider implementation.
49 bool ContentProvider::getProperty(
50 const OUString & rPropName, beans::Property & rProp, bool bStrict )
52 if ( !m_pProps )
54 osl::MutexGuard aGuard( m_aMutex );
55 if ( !m_pProps )
57 m_pProps = new PropertyMap;
60 // Fill map of known properties...
63 // Mandatory UCB properties.
64 m_pProps->insert(
65 beans::Property(
66 OUString( "ContentType" ),
67 -1,
68 cppu::UnoType<OUString>::get(),
69 beans::PropertyAttribute::BOUND
70 | beans::PropertyAttribute::READONLY ) );
72 m_pProps->insert(
73 beans::Property(
74 OUString( "IsDocument" ),
75 -1,
76 cppu::UnoType<bool>::get(),
77 beans::PropertyAttribute::BOUND
78 | beans::PropertyAttribute::READONLY ) );
80 m_pProps->insert(
81 beans::Property(
82 OUString( "IsFolder" ),
83 -1,
84 cppu::UnoType<bool>::get(),
85 beans::PropertyAttribute::BOUND
86 | beans::PropertyAttribute::READONLY ) );
88 m_pProps->insert(
89 beans::Property(
90 OUString( "Title" ),
91 -1,
92 cppu::UnoType<OUString>::get(),
93 beans::PropertyAttribute::BOUND ) );
95 // Optional UCB properties.
97 m_pProps->insert(
98 beans::Property(
99 OUString( "DateCreated" ),
101 cppu::UnoType<util::DateTime>::get(),
102 beans::PropertyAttribute::BOUND
103 | beans::PropertyAttribute::READONLY ) );
105 m_pProps->insert(
106 beans::Property(
107 OUString( "DateModified" ),
109 cppu::UnoType<util::DateTime>::get(),
110 beans::PropertyAttribute::BOUND
111 | beans::PropertyAttribute::READONLY ) );
113 m_pProps->insert(
114 beans::Property(
115 OUString( "MediaType" ),
117 cppu::UnoType<OUString>::get(),
118 beans::PropertyAttribute::BOUND
119 | beans::PropertyAttribute::READONLY ) );
121 m_pProps->insert(
122 beans::Property(
123 OUString( "Size" ),
125 cppu::UnoType<sal_Int64>::get(),
126 beans::PropertyAttribute::BOUND
127 | beans::PropertyAttribute::READONLY ) );
129 m_pProps->insert(
130 beans::Property(
131 OUString( "BaseURI" ),
133 cppu::UnoType<OUString>::get(),
134 beans::PropertyAttribute::BOUND
135 | beans::PropertyAttribute::READONLY ) );
137 m_pProps->insert(
138 beans::Property(
139 OUString(
140 "CreatableContentsInfo" ),
142 cppu::UnoType<uno::Sequence< ucb::ContentInfo >>::get(),
143 beans::PropertyAttribute::BOUND
144 | beans::PropertyAttribute::READONLY ) );
146 // Standard DAV properties.
148 m_pProps->insert(
149 beans::Property(
150 DAVProperties::CREATIONDATE,
152 cppu::UnoType<OUString>::get(),
153 beans::PropertyAttribute::BOUND
154 | beans::PropertyAttribute::READONLY ) );
156 m_pProps->insert(
157 beans::Property(
158 DAVProperties::DISPLAYNAME,
160 cppu::UnoType<OUString>::get(),
161 beans::PropertyAttribute::BOUND ) );
163 m_pProps->insert(
164 beans::Property(
165 DAVProperties::GETCONTENTLANGUAGE,
167 cppu::UnoType<OUString>::get(),
168 beans::PropertyAttribute::BOUND
169 | beans::PropertyAttribute::READONLY ) );
171 m_pProps->insert(
172 beans::Property(
173 DAVProperties::GETCONTENTLENGTH,
175 cppu::UnoType<OUString>::get(),
176 beans::PropertyAttribute::BOUND
177 | beans::PropertyAttribute::READONLY ) );
179 m_pProps->insert(
180 beans::Property(
181 DAVProperties::GETCONTENTTYPE ,
183 cppu::UnoType<OUString>::get(),
184 beans::PropertyAttribute::BOUND
185 | beans::PropertyAttribute::READONLY ) );
187 m_pProps->insert(
188 beans::Property(
189 DAVProperties::GETETAG,
191 cppu::UnoType<OUString>::get(),
192 beans::PropertyAttribute::BOUND
193 | beans::PropertyAttribute::READONLY ) );
195 m_pProps->insert(
196 beans::Property(
197 DAVProperties::GETLASTMODIFIED,
199 cppu::UnoType<OUString>::get(),
200 beans::PropertyAttribute::BOUND
201 | beans::PropertyAttribute::READONLY ) );
203 m_pProps->insert(
204 beans::Property(
205 DAVProperties::LOCKDISCOVERY,
207 cppu::UnoType<uno::Sequence< ucb::Lock >>::get(),
208 beans::PropertyAttribute::BOUND
209 | beans::PropertyAttribute::READONLY ) );
211 m_pProps->insert(
212 beans::Property(
213 DAVProperties::RESOURCETYPE,
215 cppu::UnoType<OUString>::get(),
216 beans::PropertyAttribute::BOUND
217 | beans::PropertyAttribute::READONLY ) );
219 m_pProps->insert(
220 beans::Property(
221 DAVProperties::SUPPORTEDLOCK,
223 cppu::UnoType<uno::Sequence< ucb::LockEntry >>::get(),
224 beans::PropertyAttribute::BOUND
225 | beans::PropertyAttribute::READONLY ) );
227 m_pProps->insert(
228 beans::Property(
229 DAVProperties::EXECUTABLE,
231 cppu::UnoType<OUString>::get(),
232 beans::PropertyAttribute::BOUND ) );
237 // Lookup property.
240 beans::Property aProp;
241 aProp.Name = rPropName;
242 const PropertyMap::const_iterator it = m_pProps->find( aProp );
243 if ( it != m_pProps->end() )
245 rProp = (*it);
247 else
249 if ( bStrict )
250 return false;
252 // All unknown props are treated as:
253 rProp = beans::Property(
254 rPropName,
255 - 1,
256 cppu::UnoType<OUString>::get(),
257 beans::PropertyAttribute::BOUND );
260 return true;
265 // Content implementation.
269 // virtual
270 uno::Sequence< beans::Property > Content::getProperties(
271 const uno::Reference< ucb::XCommandEnvironment > & xEnv )
273 bool bTransient;
274 boost::scoped_ptr< DAVResourceAccess > xResAccess;
275 boost::scoped_ptr< ContentProperties > xCachedProps;
276 rtl::Reference< ContentProvider > xProvider;
279 osl::Guard< osl::Mutex > aGuard( m_aMutex );
281 bTransient = m_bTransient;
282 xResAccess.reset( new DAVResourceAccess( *m_xResAccess.get() ) );
283 if ( m_xCachedProps.get() )
284 xCachedProps.reset(
285 new ContentProperties( *m_xCachedProps.get() ) );
286 xProvider.set( m_pProvider );
289 typedef std::set< OUString > StringSet;
290 StringSet aPropSet;
292 // No server access for just created (not yet committed) objects.
293 // Only a minimal set of properties supported at this stage.
294 if ( !bTransient )
296 // Obtain all properties supported for this resource from server.
299 std::vector< DAVResourceInfo > props;
300 xResAccess->PROPFIND( DAVZERO, props, xEnv );
302 // Note: vector always contains exactly one resource info, because
303 // we used a depth of DAVZERO for PROPFIND.
304 aPropSet.insert( (*props.begin()).properties.begin(),
305 (*props.begin()).properties.end() );
307 catch ( DAVException const & )
312 // Add DAV properties, map DAV properties to UCB properties.
313 bool bHasCreationDate = false; // creationdate <-> DateCreated
314 bool bHasGetLastModified = false; // getlastmodified <-> DateModified
315 bool bHasGetContentType = false; // getcontenttype <-> MediaType
316 bool bHasGetContentLength = false; // getcontentlength <-> Size
318 bool bHasContentType = false;
319 bool bHasIsDocument = false;
320 bool bHasIsFolder = false;
321 bool bHasTitle = false;
322 bool bHasBaseURI = false;
323 bool bHasDateCreated = false;
324 bool bHasDateModified = false;
325 bool bHasMediaType = false;
326 bool bHasSize = false;
327 bool bHasCreatableInfos = false;
330 std::set< OUString >::const_iterator it = aPropSet.begin();
331 std::set< OUString >::const_iterator end = aPropSet.end();
332 while ( it != end )
334 if ( !bHasCreationDate &&
335 ( (*it) == DAVProperties::CREATIONDATE ) )
337 bHasCreationDate = true;
339 else if ( !bHasGetLastModified &&
340 ( (*it) == DAVProperties::GETLASTMODIFIED ) )
342 bHasGetLastModified = true;
344 else if ( !bHasGetContentType &&
345 ( (*it) == DAVProperties::GETCONTENTTYPE ) )
347 bHasGetContentType = true;
349 else if ( !bHasGetContentLength &&
350 ( (*it) == DAVProperties::GETCONTENTLENGTH ) )
352 bHasGetContentLength = true;
354 else if ( !bHasContentType && (*it) == "ContentType" )
356 bHasContentType = true;
358 else if ( !bHasIsDocument && (*it) == "IsDocument" )
360 bHasIsDocument = true;
362 else if ( !bHasIsFolder && (*it) == "IsFolder" )
364 bHasIsFolder = true;
366 else if ( !bHasTitle && (*it) == "Title" )
368 bHasTitle = true;
370 else if ( !bHasBaseURI && (*it) == "BaseURI" )
372 bHasBaseURI = true;
374 else if ( !bHasDateCreated && (*it) == "DateCreated" )
376 bHasDateCreated = true;
378 else if ( !bHasDateModified && (*it) == "DateModified" )
380 bHasDateModified = true;
382 else if ( !bHasMediaType && (*it) == "MediaType" )
384 bHasMediaType = true;
386 else if ( !bHasSize && (*it) == "Size" )
388 bHasSize = true;
390 else if ( !bHasCreatableInfos && (*it) == "CreatableContentsInfo" )
392 bHasCreatableInfos = true;
394 ++it;
398 // Add mandatory properties.
399 if ( !bHasContentType )
400 aPropSet.insert(
401 OUString( "ContentType" ) );
403 if ( !bHasIsDocument )
404 aPropSet.insert(
405 OUString( "IsDocument" ) );
407 if ( !bHasIsFolder )
408 aPropSet.insert(
409 OUString( "IsFolder" ) );
411 if ( !bHasTitle )
413 // Always present since it can be calculated from content's URI.
414 aPropSet.insert(
415 OUString( "Title" ) );
418 // Add optional properties.
420 if ( !bHasBaseURI )
422 // Always present since it can be calculated from content's URI.
423 aPropSet.insert(
424 OUString( "BaseURI" ) );
427 if ( !bHasDateCreated && bHasCreationDate )
428 aPropSet.insert(
429 OUString( "DateCreated" ) );
431 if ( !bHasDateModified && bHasGetLastModified )
432 aPropSet.insert(
433 OUString( "DateModified" ) );
435 if ( !bHasMediaType && bHasGetContentType )
436 aPropSet.insert(
437 OUString( "MediaType" ) );
439 if ( !bHasSize && bHasGetContentLength )
440 aPropSet.insert(
441 OUString( "Size" ) );
443 if ( !bHasCreatableInfos )
444 aPropSet.insert(
445 OUString(
446 "CreatableContentsInfo" ) );
448 // Add cached properties, if present and still missing.
449 if ( xCachedProps.get() )
451 const std::set< OUString >::const_iterator set_end
452 = aPropSet.end();
454 const boost::scoped_ptr< PropertyValueMap > & xProps
455 = xCachedProps->getProperties();
457 PropertyValueMap::const_iterator map_it = xProps->begin();
458 const PropertyValueMap::const_iterator map_end = xProps->end();
460 while ( map_it != map_end )
462 if ( aPropSet.find( (*map_it).first ) == set_end )
463 aPropSet.insert( (*map_it).first );
465 ++map_it;
469 // std::set -> uno::Sequence
470 sal_Int32 nCount = aPropSet.size();
471 uno::Sequence< beans::Property > aProperties( nCount );
473 std::set< OUString >::const_iterator it = aPropSet.begin();
474 beans::Property aProp;
476 for ( sal_Int32 n = 0; n < nCount; ++n, ++it )
478 xProvider->getProperty( (*it), aProp );
479 aProperties[ n ] = aProp;
482 return aProperties;
486 // virtual
487 uno::Sequence< ucb::CommandInfo > Content::getCommands(
488 const uno::Reference< ucb::XCommandEnvironment > & xEnv )
490 osl::Guard< osl::Mutex > aGuard( m_aMutex );
492 uno::Sequence< ucb::CommandInfo > aCmdInfo( 10 );
495 // Mandatory commands
498 aCmdInfo[ 0 ] =
499 ucb::CommandInfo(
500 OUString( "getCommandInfo" ),
502 cppu::UnoType<void>::get() );
503 aCmdInfo[ 1 ] =
504 ucb::CommandInfo(
505 OUString( "getPropertySetInfo" ),
507 cppu::UnoType<void>::get() );
508 aCmdInfo[ 2 ] =
509 ucb::CommandInfo(
510 OUString( "getPropertyValues" ),
512 cppu::UnoType<uno::Sequence< beans::Property >>::get());
513 aCmdInfo[ 3 ] =
514 ucb::CommandInfo(
515 OUString( "setPropertyValues" ),
517 cppu::UnoType<uno::Sequence< beans::PropertyValue >>::get());
520 // Optional standard commands
523 aCmdInfo[ 4 ] =
524 ucb::CommandInfo(
525 OUString( "delete" ),
527 cppu::UnoType<bool>::get() );
528 aCmdInfo[ 5 ] =
529 ucb::CommandInfo(
530 OUString( "insert" ),
532 cppu::UnoType<ucb::InsertCommandArgument>::get() );
533 aCmdInfo[ 6 ] =
534 ucb::CommandInfo(
535 OUString( "open" ),
537 cppu::UnoType<ucb::OpenCommandArgument2>::get() );
540 // New commands
543 aCmdInfo[ 7 ] =
544 ucb::CommandInfo(
545 OUString( "post" ),
547 cppu::UnoType<ucb::PostCommandArgument2>::get() );
548 aCmdInfo[ 8 ] =
549 ucb::CommandInfo(
550 OUString( "addProperty" ),
552 cppu::UnoType<ucb::PropertyCommandArgument>::get() );
553 aCmdInfo[ 9 ] =
554 ucb::CommandInfo(
555 OUString( "removeProperty" ),
557 cppu::UnoType<rtl::OUString>::get() );
559 bool bFolder = false;
563 bFolder = isFolder( xEnv );
565 catch ( uno::Exception const & )
567 return aCmdInfo;
570 bool bSupportsLocking = supportsExclusiveWriteLock( xEnv );
572 sal_Int32 nPos = aCmdInfo.getLength();
573 sal_Int32 nMoreCmds = ( bFolder ? 2 : 0 ) + ( bSupportsLocking ? 2 : 0 );
574 if ( nMoreCmds )
575 aCmdInfo.realloc( nPos + nMoreCmds );
576 else
577 return aCmdInfo;
579 if ( bFolder )
582 // Optional standard commands
585 aCmdInfo[ nPos ] =
586 ucb::CommandInfo(
587 OUString( "transfer" ),
589 cppu::UnoType<ucb::TransferInfo>::get() );
590 nPos++;
591 aCmdInfo[ nPos ] =
592 ucb::CommandInfo(
593 OUString(
594 "createNewContent" ),
596 cppu::UnoType<ucb::ContentInfo>::get() );
597 nPos++;
599 else
601 // no document-only commands at the moment.
604 if ( bSupportsLocking )
606 aCmdInfo[ nPos ] =
607 ucb::CommandInfo(
608 OUString( "lock" ),
610 cppu::UnoType<void>::get() );
611 nPos++;
612 aCmdInfo[ nPos ] =
613 ucb::CommandInfo(
614 OUString( "unlock" ),
616 cppu::UnoType<void>::get() );
617 nPos++;
619 return aCmdInfo;
622 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */