fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / ucb / source / ucp / webdav-neon / webdavcontentcaps.cxx
blob31561a1da3309da98b6c5e417ff2307e33bea00e
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/PropertyCommandArgument.hpp>
45 #include <com/sun/star/ucb/TransferInfo.hpp>
46 #include <com/sun/star/uno/Sequence.hxx>
47 #include <com/sun/star/util/DateTime.hpp>
48 #include <com/sun/star/ucb/Link.hpp>
49 #include <com/sun/star/ucb/Lock.hpp>
50 #include <com/sun/star/ucb/LockEntry.hpp>
51 #include "webdavcontent.hxx"
52 #include "webdavprovider.hxx"
53 #include "DAVSession.hxx"
54 #include "ContentProperties.hxx"
56 using namespace com::sun::star;
57 using namespace webdav_ucp;
61 // ContentProvider implementation.
65 bool ContentProvider::getProperty(
66 const OUString & rPropName, beans::Property & rProp, bool bStrict )
68 if ( !m_pProps )
70 osl::MutexGuard aGuard( m_aMutex );
71 if ( !m_pProps )
73 m_pProps = new PropertyMap;
76 // Fill map of known properties...
79 // Mandatory UCB properties.
80 m_pProps->insert(
81 beans::Property(
82 OUString( "ContentType" ),
83 -1,
84 cppu::UnoType<OUString>::get(),
85 beans::PropertyAttribute::BOUND
86 | beans::PropertyAttribute::READONLY ) );
88 m_pProps->insert(
89 beans::Property(
90 OUString( "IsDocument" ),
91 -1,
92 cppu::UnoType<bool>::get(),
93 beans::PropertyAttribute::BOUND
94 | beans::PropertyAttribute::READONLY ) );
96 m_pProps->insert(
97 beans::Property(
98 OUString( "IsFolder" ),
99 -1,
100 cppu::UnoType<bool>::get(),
101 beans::PropertyAttribute::BOUND
102 | beans::PropertyAttribute::READONLY ) );
104 m_pProps->insert(
105 beans::Property(
106 OUString( "Title" ),
108 cppu::UnoType<OUString>::get(),
109 beans::PropertyAttribute::BOUND ) );
111 // Optional UCB properties.
113 m_pProps->insert(
114 beans::Property(
115 OUString( "DateCreated" ),
117 cppu::UnoType<util::DateTime>::get(),
118 beans::PropertyAttribute::BOUND
119 | beans::PropertyAttribute::READONLY ) );
121 m_pProps->insert(
122 beans::Property(
123 OUString( "DateModified" ),
125 cppu::UnoType<util::DateTime>::get(),
126 beans::PropertyAttribute::BOUND
127 | beans::PropertyAttribute::READONLY ) );
129 m_pProps->insert(
130 beans::Property(
131 OUString( "MediaType" ),
133 cppu::UnoType<OUString>::get(),
134 beans::PropertyAttribute::BOUND
135 | beans::PropertyAttribute::READONLY ) );
137 m_pProps->insert(
138 beans::Property(
139 OUString( "Size" ),
141 cppu::UnoType<sal_Int64>::get(),
142 beans::PropertyAttribute::BOUND
143 | beans::PropertyAttribute::READONLY ) );
145 m_pProps->insert(
146 beans::Property(
147 OUString( "BaseURI" ),
149 cppu::UnoType<OUString>::get(),
150 beans::PropertyAttribute::BOUND
151 | beans::PropertyAttribute::READONLY ) );
153 m_pProps->insert(
154 beans::Property(
155 OUString(
156 "CreatableContentsInfo" ),
158 cppu::UnoType<
159 uno::Sequence< ucb::ContentInfo >>::get(),
160 beans::PropertyAttribute::BOUND
161 | beans::PropertyAttribute::READONLY ) );
163 // Standard DAV properties.
165 m_pProps->insert(
166 beans::Property(
167 DAVProperties::CREATIONDATE,
169 cppu::UnoType<OUString>::get(),
170 beans::PropertyAttribute::BOUND
171 | beans::PropertyAttribute::READONLY ) );
173 m_pProps->insert(
174 beans::Property(
175 DAVProperties::DISPLAYNAME,
177 cppu::UnoType<OUString>::get(),
178 beans::PropertyAttribute::BOUND ) );
180 m_pProps->insert(
181 beans::Property(
182 DAVProperties::GETCONTENTLANGUAGE,
184 cppu::UnoType<OUString>::get(),
185 beans::PropertyAttribute::BOUND
186 | beans::PropertyAttribute::READONLY ) );
188 m_pProps->insert(
189 beans::Property(
190 DAVProperties::GETCONTENTLENGTH,
192 cppu::UnoType<OUString>::get(),
193 beans::PropertyAttribute::BOUND
194 | beans::PropertyAttribute::READONLY ) );
196 m_pProps->insert(
197 beans::Property(
198 DAVProperties::GETCONTENTTYPE ,
200 cppu::UnoType<OUString>::get(),
201 beans::PropertyAttribute::BOUND
202 | beans::PropertyAttribute::READONLY ) );
204 m_pProps->insert(
205 beans::Property(
206 DAVProperties::GETETAG,
208 cppu::UnoType<OUString>::get(),
209 beans::PropertyAttribute::BOUND
210 | beans::PropertyAttribute::READONLY ) );
212 m_pProps->insert(
213 beans::Property(
214 DAVProperties::GETLASTMODIFIED,
216 cppu::UnoType<OUString>::get(),
217 beans::PropertyAttribute::BOUND
218 | beans::PropertyAttribute::READONLY ) );
220 m_pProps->insert(
221 beans::Property(
222 DAVProperties::LOCKDISCOVERY,
224 cppu::UnoType<
225 uno::Sequence< ucb::Lock >>::get(),
226 beans::PropertyAttribute::BOUND
227 | beans::PropertyAttribute::READONLY ) );
229 m_pProps->insert(
230 beans::Property(
231 DAVProperties::RESOURCETYPE,
233 cppu::UnoType<OUString>::get(),
234 beans::PropertyAttribute::BOUND
235 | beans::PropertyAttribute::READONLY ) );
237 m_pProps->insert(
238 beans::Property(
239 DAVProperties::SOURCE,
241 cppu::UnoType<uno::Sequence< ucb::Link >>::get(),
242 beans::PropertyAttribute::BOUND ) );
244 m_pProps->insert(
245 beans::Property(
246 DAVProperties::SUPPORTEDLOCK,
248 cppu::UnoType<uno::Sequence< ucb::LockEntry >>::get(),
249 beans::PropertyAttribute::BOUND
250 | beans::PropertyAttribute::READONLY ) );
252 m_pProps->insert(
253 beans::Property(
254 DAVProperties::EXECUTABLE,
256 cppu::UnoType<OUString>::get(),
257 beans::PropertyAttribute::BOUND ) );
262 // Lookup property.
265 beans::Property aProp;
266 aProp.Name = rPropName;
267 const PropertyMap::const_iterator it = m_pProps->find( aProp );
268 if ( it != m_pProps->end() )
270 rProp = (*it);
272 else
274 if ( bStrict )
275 return false;
277 // All unknown props are treated as:
278 rProp = beans::Property(
279 rPropName,
280 - 1,
281 cppu::UnoType<OUString>::get(),
282 beans::PropertyAttribute::BOUND );
285 return true;
290 // Content implementation.
294 // virtual
295 uno::Sequence< beans::Property > Content::getProperties(
296 const uno::Reference< ucb::XCommandEnvironment > & xEnv )
298 bool bTransient;
299 std::unique_ptr< DAVResourceAccess > xResAccess;
300 std::unique_ptr< ContentProperties > xCachedProps;
301 rtl::Reference< ContentProvider > xProvider;
304 osl::Guard< osl::Mutex > aGuard( m_aMutex );
306 bTransient = m_bTransient;
307 xResAccess.reset( new DAVResourceAccess( *m_xResAccess.get() ) );
308 if ( m_xCachedProps.get() )
309 xCachedProps.reset(
310 new ContentProperties( *m_xCachedProps.get() ) );
311 xProvider.set( m_pProvider );
314 typedef std::set< OUString > StringSet;
315 StringSet aPropSet;
317 // No server access for just created (not yet committed) objects.
318 // Only a minimal set of properties supported at this stage.
319 if ( !bTransient )
321 // Obtain all properties supported for this resource from server.
324 std::vector< DAVResourceInfo > props;
325 xResAccess->PROPFIND( DAVZERO, props, xEnv );
327 // Note: vector always contains exactly one resource info, because
328 // we used a depth of DAVZERO for PROPFIND.
329 aPropSet.insert( (*props.begin()).properties.begin(),
330 (*props.begin()).properties.end() );
332 catch ( DAVException const & )
337 // Add DAV properties, map DAV properties to UCB properties.
338 bool bHasCreationDate = false; // creationdate <-> DateCreated
339 bool bHasGetLastModified = false; // getlastmodified <-> DateModified
340 bool bHasGetContentType = false; // getcontenttype <-> MediaType
341 bool bHasGetContentLength = false; // getcontentlength <-> Size
343 bool bHasContentType = false;
344 bool bHasIsDocument = false;
345 bool bHasIsFolder = false;
346 bool bHasTitle = false;
347 bool bHasBaseURI = false;
348 bool bHasDateCreated = false;
349 bool bHasDateModified = false;
350 bool bHasMediaType = false;
351 bool bHasSize = false;
352 bool bHasCreatableInfos = false;
355 std::set< OUString >::const_iterator it = aPropSet.begin();
356 std::set< OUString >::const_iterator end = aPropSet.end();
357 while ( it != end )
359 if ( !bHasCreationDate &&
360 ( (*it) == DAVProperties::CREATIONDATE ) )
362 bHasCreationDate = true;
364 else if ( !bHasGetLastModified &&
365 ( (*it) == DAVProperties::GETLASTMODIFIED ) )
367 bHasGetLastModified = true;
369 else if ( !bHasGetContentType &&
370 ( (*it) == DAVProperties::GETCONTENTTYPE ) )
372 bHasGetContentType = true;
374 else if ( !bHasGetContentLength &&
375 ( (*it) == DAVProperties::GETCONTENTLENGTH ) )
377 bHasGetContentLength = true;
379 else if ( !bHasContentType && (*it) == "ContentType" )
381 bHasContentType = true;
383 else if ( !bHasIsDocument && (*it) == "IsDocument" )
385 bHasIsDocument = true;
387 else if ( !bHasIsFolder && (*it) == "IsFolder" )
389 bHasIsFolder = true;
391 else if ( !bHasTitle && (*it) == "Title" )
393 bHasTitle = true;
395 else if ( !bHasBaseURI && (*it) == "BaseURI" )
397 bHasBaseURI = true;
399 else if ( !bHasDateCreated && (*it) == "DateCreated" )
401 bHasDateCreated = true;
403 else if ( !bHasDateModified && (*it) == "DateModified" )
405 bHasDateModified = true;
407 else if ( !bHasMediaType && (*it) == "MediaType" )
409 bHasMediaType = true;
411 else if ( !bHasSize && (*it) == "Size" )
413 bHasSize = true;
415 else if ( !bHasCreatableInfos && (*it) == "CreatableContentsInfo" )
417 bHasCreatableInfos = true;
419 ++it;
423 // Add mandatory properties.
424 if ( !bHasContentType )
425 aPropSet.insert(
426 OUString( "ContentType" ) );
428 if ( !bHasIsDocument )
429 aPropSet.insert(
430 OUString( "IsDocument" ) );
432 if ( !bHasIsFolder )
433 aPropSet.insert(
434 OUString( "IsFolder" ) );
436 if ( !bHasTitle )
438 // Always present since it can be calculated from content's URI.
439 aPropSet.insert(
440 OUString( "Title" ) );
443 // Add optional properties.
445 if ( !bHasBaseURI )
447 // Always present since it can be calculated from content's URI.
448 aPropSet.insert(
449 OUString( "BaseURI" ) );
452 if ( !bHasDateCreated && bHasCreationDate )
453 aPropSet.insert(
454 OUString( "DateCreated" ) );
456 if ( !bHasDateModified && bHasGetLastModified )
457 aPropSet.insert(
458 OUString( "DateModified" ) );
460 if ( !bHasMediaType && bHasGetContentType )
461 aPropSet.insert(
462 OUString( "MediaType" ) );
464 if ( !bHasSize && bHasGetContentLength )
465 aPropSet.insert(
466 OUString( "Size" ) );
468 if ( !bHasCreatableInfos )
469 aPropSet.insert(
470 OUString(
471 "CreatableContentsInfo" ) );
473 // Add cached properties, if present and still missing.
474 if ( xCachedProps.get() )
476 const std::set< OUString >::const_iterator set_end
477 = aPropSet.end();
479 const std::unique_ptr< PropertyValueMap > & xProps
480 = xCachedProps->getProperties();
482 PropertyValueMap::const_iterator map_it = xProps->begin();
483 const PropertyValueMap::const_iterator map_end = xProps->end();
485 while ( map_it != map_end )
487 if ( aPropSet.find( (*map_it).first ) == set_end )
488 aPropSet.insert( (*map_it).first );
490 ++map_it;
494 // std::set -> uno::Sequence
495 sal_Int32 nCount = aPropSet.size();
496 uno::Sequence< beans::Property > aProperties( nCount );
498 std::set< OUString >::const_iterator it = aPropSet.begin();
499 beans::Property aProp;
501 for ( sal_Int32 n = 0; n < nCount; ++n, ++it )
503 xProvider->getProperty( (*it), aProp );
504 aProperties[ n ] = aProp;
507 return aProperties;
511 // virtual
512 uno::Sequence< ucb::CommandInfo > Content::getCommands(
513 const uno::Reference< ucb::XCommandEnvironment > & xEnv )
515 osl::Guard< osl::Mutex > aGuard( m_aMutex );
517 uno::Sequence< ucb::CommandInfo > aCmdInfo( 10 );
520 // Mandatory commands
523 aCmdInfo[ 0 ] =
524 ucb::CommandInfo(
525 OUString( "getCommandInfo" ),
527 cppu::UnoType<void>::get() );
528 aCmdInfo[ 1 ] =
529 ucb::CommandInfo(
530 OUString( "getPropertySetInfo" ),
532 cppu::UnoType<void>::get() );
533 aCmdInfo[ 2 ] =
534 ucb::CommandInfo(
535 OUString( "getPropertyValues" ),
537 cppu::UnoType<uno::Sequence< beans::Property >>::get() );
538 aCmdInfo[ 3 ] =
539 ucb::CommandInfo(
540 OUString( "setPropertyValues" ),
542 cppu::UnoType<uno::Sequence< beans::PropertyValue >>::get() );
545 // Optional standard commands
548 aCmdInfo[ 4 ] =
549 ucb::CommandInfo(
550 OUString( "delete" ),
552 cppu::UnoType<bool>::get() );
553 aCmdInfo[ 5 ] =
554 ucb::CommandInfo(
555 OUString( "insert" ),
557 cppu::UnoType<ucb::InsertCommandArgument>::get() );
558 aCmdInfo[ 6 ] =
559 ucb::CommandInfo(
560 OUString( "open" ),
562 cppu::UnoType<ucb::OpenCommandArgument2>::get() );
565 // New commands
568 aCmdInfo[ 7 ] =
569 ucb::CommandInfo(
570 OUString( "post" ),
572 cppu::UnoType<ucb::PostCommandArgument2>::get() );
573 aCmdInfo[ 8 ] =
574 ucb::CommandInfo(
575 OUString( "addProperty" ),
577 cppu::UnoType<ucb::PropertyCommandArgument>::get() );
578 aCmdInfo[ 9 ] =
579 ucb::CommandInfo(
580 OUString( "removeProperty" ),
582 cppu::UnoType<rtl::OUString>::get() );
584 bool bFolder = false;
588 bFolder = isFolder( xEnv );
590 catch ( uno::Exception const & )
592 return aCmdInfo;
595 bool bSupportsLocking = supportsExclusiveWriteLock( xEnv );
597 sal_Int32 nPos = aCmdInfo.getLength();
598 sal_Int32 nMoreCmds = ( bFolder ? 2 : 0 ) + ( bSupportsLocking ? 2 : 0 );
599 if ( nMoreCmds )
600 aCmdInfo.realloc( nPos + nMoreCmds );
601 else
602 return aCmdInfo;
604 if ( bFolder )
607 // Optional standard commands
610 aCmdInfo[ nPos ] =
611 ucb::CommandInfo(
612 OUString( "transfer" ),
614 cppu::UnoType<ucb::TransferInfo>::get() );
615 nPos++;
616 aCmdInfo[ nPos ] =
617 ucb::CommandInfo(
618 OUString(
619 "createNewContent" ),
621 cppu::UnoType<ucb::ContentInfo>::get() );
622 nPos++;
624 else
626 // no document-only commands at the moment.
629 if ( bSupportsLocking )
631 aCmdInfo[ nPos ] =
632 ucb::CommandInfo(
633 OUString( "lock" ),
635 cppu::UnoType<void>::get() );
636 nPos++;
637 aCmdInfo[ nPos ] =
638 ucb::CommandInfo(
639 OUString( "unlock" ),
641 cppu::UnoType<void>::get() );
642 nPos++;
644 return aCmdInfo;
647 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */