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/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
)
70 osl::MutexGuard
aGuard( m_aMutex
);
73 m_pProps
= new PropertyMap
;
76 // Fill map of known properties...
79 // Mandatory UCB properties.
82 OUString( "ContentType" ),
84 cppu::UnoType
<OUString
>::get(),
85 beans::PropertyAttribute::BOUND
86 | beans::PropertyAttribute::READONLY
) );
90 OUString( "IsDocument" ),
92 cppu::UnoType
<bool>::get(),
93 beans::PropertyAttribute::BOUND
94 | beans::PropertyAttribute::READONLY
) );
98 OUString( "IsFolder" ),
100 cppu::UnoType
<bool>::get(),
101 beans::PropertyAttribute::BOUND
102 | beans::PropertyAttribute::READONLY
) );
108 cppu::UnoType
<OUString
>::get(),
109 beans::PropertyAttribute::BOUND
) );
111 // Optional UCB properties.
115 OUString( "DateCreated" ),
117 cppu::UnoType
<util::DateTime
>::get(),
118 beans::PropertyAttribute::BOUND
119 | beans::PropertyAttribute::READONLY
) );
123 OUString( "DateModified" ),
125 cppu::UnoType
<util::DateTime
>::get(),
126 beans::PropertyAttribute::BOUND
127 | beans::PropertyAttribute::READONLY
) );
131 OUString( "MediaType" ),
133 cppu::UnoType
<OUString
>::get(),
134 beans::PropertyAttribute::BOUND
135 | beans::PropertyAttribute::READONLY
) );
141 cppu::UnoType
<sal_Int64
>::get(),
142 beans::PropertyAttribute::BOUND
143 | beans::PropertyAttribute::READONLY
) );
147 OUString( "BaseURI" ),
149 cppu::UnoType
<OUString
>::get(),
150 beans::PropertyAttribute::BOUND
151 | beans::PropertyAttribute::READONLY
) );
156 "CreatableContentsInfo" ),
159 uno::Sequence
< ucb::ContentInfo
>>::get(),
160 beans::PropertyAttribute::BOUND
161 | beans::PropertyAttribute::READONLY
) );
163 // Standard DAV properties.
167 DAVProperties::CREATIONDATE
,
169 cppu::UnoType
<OUString
>::get(),
170 beans::PropertyAttribute::BOUND
171 | beans::PropertyAttribute::READONLY
) );
175 DAVProperties::DISPLAYNAME
,
177 cppu::UnoType
<OUString
>::get(),
178 beans::PropertyAttribute::BOUND
) );
182 DAVProperties::GETCONTENTLANGUAGE
,
184 cppu::UnoType
<OUString
>::get(),
185 beans::PropertyAttribute::BOUND
186 | beans::PropertyAttribute::READONLY
) );
190 DAVProperties::GETCONTENTLENGTH
,
192 cppu::UnoType
<OUString
>::get(),
193 beans::PropertyAttribute::BOUND
194 | beans::PropertyAttribute::READONLY
) );
198 DAVProperties::GETCONTENTTYPE
,
200 cppu::UnoType
<OUString
>::get(),
201 beans::PropertyAttribute::BOUND
202 | beans::PropertyAttribute::READONLY
) );
206 DAVProperties::GETETAG
,
208 cppu::UnoType
<OUString
>::get(),
209 beans::PropertyAttribute::BOUND
210 | beans::PropertyAttribute::READONLY
) );
214 DAVProperties::GETLASTMODIFIED
,
216 cppu::UnoType
<OUString
>::get(),
217 beans::PropertyAttribute::BOUND
218 | beans::PropertyAttribute::READONLY
) );
222 DAVProperties::LOCKDISCOVERY
,
225 uno::Sequence
< ucb::Lock
>>::get(),
226 beans::PropertyAttribute::BOUND
227 | beans::PropertyAttribute::READONLY
) );
231 DAVProperties::RESOURCETYPE
,
233 cppu::UnoType
<OUString
>::get(),
234 beans::PropertyAttribute::BOUND
235 | beans::PropertyAttribute::READONLY
) );
239 DAVProperties::SOURCE
,
241 cppu::UnoType
<uno::Sequence
< ucb::Link
>>::get(),
242 beans::PropertyAttribute::BOUND
) );
246 DAVProperties::SUPPORTEDLOCK
,
248 cppu::UnoType
<uno::Sequence
< ucb::LockEntry
>>::get(),
249 beans::PropertyAttribute::BOUND
250 | beans::PropertyAttribute::READONLY
) );
254 DAVProperties::EXECUTABLE
,
256 cppu::UnoType
<OUString
>::get(),
257 beans::PropertyAttribute::BOUND
) );
265 beans::Property aProp
;
266 aProp
.Name
= rPropName
;
267 const PropertyMap::const_iterator it
= m_pProps
->find( aProp
);
268 if ( it
!= m_pProps
->end() )
277 // All unknown props are treated as:
278 rProp
= beans::Property(
281 cppu::UnoType
<OUString
>::get(),
282 beans::PropertyAttribute::BOUND
);
290 // Content implementation.
295 uno::Sequence
< beans::Property
> Content::getProperties(
296 const uno::Reference
< ucb::XCommandEnvironment
> & xEnv
)
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() )
310 new ContentProperties( *m_xCachedProps
.get() ) );
311 xProvider
.set( m_pProvider
);
314 typedef std::set
< OUString
> StringSet
;
317 // No server access for just created (not yet committed) objects.
318 // Only a minimal set of properties supported at this stage.
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();
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" )
391 else if ( !bHasTitle
&& (*it
) == "Title" )
395 else if ( !bHasBaseURI
&& (*it
) == "BaseURI" )
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" )
415 else if ( !bHasCreatableInfos
&& (*it
) == "CreatableContentsInfo" )
417 bHasCreatableInfos
= true;
423 // Add mandatory properties.
424 if ( !bHasContentType
)
426 OUString( "ContentType" ) );
428 if ( !bHasIsDocument
)
430 OUString( "IsDocument" ) );
434 OUString( "IsFolder" ) );
438 // Always present since it can be calculated from content's URI.
440 OUString( "Title" ) );
443 // Add optional properties.
447 // Always present since it can be calculated from content's URI.
449 OUString( "BaseURI" ) );
452 if ( !bHasDateCreated
&& bHasCreationDate
)
454 OUString( "DateCreated" ) );
456 if ( !bHasDateModified
&& bHasGetLastModified
)
458 OUString( "DateModified" ) );
460 if ( !bHasMediaType
&& bHasGetContentType
)
462 OUString( "MediaType" ) );
464 if ( !bHasSize
&& bHasGetContentLength
)
466 OUString( "Size" ) );
468 if ( !bHasCreatableInfos
)
471 "CreatableContentsInfo" ) );
473 // Add cached properties, if present and still missing.
474 if ( xCachedProps
.get() )
476 const std::set
< OUString
>::const_iterator set_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
);
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
;
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
525 OUString( "getCommandInfo" ),
527 cppu::UnoType
<void>::get() );
530 OUString( "getPropertySetInfo" ),
532 cppu::UnoType
<void>::get() );
535 OUString( "getPropertyValues" ),
537 cppu::UnoType
<uno::Sequence
< beans::Property
>>::get() );
540 OUString( "setPropertyValues" ),
542 cppu::UnoType
<uno::Sequence
< beans::PropertyValue
>>::get() );
545 // Optional standard commands
550 OUString( "delete" ),
552 cppu::UnoType
<bool>::get() );
555 OUString( "insert" ),
557 cppu::UnoType
<ucb::InsertCommandArgument
>::get() );
562 cppu::UnoType
<ucb::OpenCommandArgument2
>::get() );
572 cppu::UnoType
<ucb::PostCommandArgument2
>::get() );
575 OUString( "addProperty" ),
577 cppu::UnoType
<ucb::PropertyCommandArgument
>::get() );
580 OUString( "removeProperty" ),
582 cppu::UnoType
<rtl::OUString
>::get() );
584 bool bFolder
= false;
588 bFolder
= isFolder( xEnv
);
590 catch ( uno::Exception
const & )
595 bool bSupportsLocking
= supportsExclusiveWriteLock( xEnv
);
597 sal_Int32 nPos
= aCmdInfo
.getLength();
598 sal_Int32 nMoreCmds
= ( bFolder
? 2 : 0 ) + ( bSupportsLocking
? 2 : 0 );
600 aCmdInfo
.realloc( nPos
+ nMoreCmds
);
607 // Optional standard commands
612 OUString( "transfer" ),
614 cppu::UnoType
<ucb::TransferInfo
>::get() );
619 "createNewContent" ),
621 cppu::UnoType
<ucb::ContentInfo
>::get() );
626 // no document-only commands at the moment.
629 if ( bSupportsLocking
)
635 cppu::UnoType
<void>::get() );
639 OUString( "unlock" ),
641 cppu::UnoType
<void>::get() );
647 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */