12f86921cSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 32f86921cSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 42f86921cSAndrew Rist * or more contributor license agreements. See the NOTICE file 52f86921cSAndrew Rist * distributed with this work for additional information 62f86921cSAndrew Rist * regarding copyright ownership. The ASF licenses this file 72f86921cSAndrew Rist * to you under the Apache License, Version 2.0 (the 82f86921cSAndrew Rist * "License"); you may not use this file except in compliance 92f86921cSAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 112f86921cSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 132f86921cSAndrew Rist * Unless required by applicable law or agreed to in writing, 142f86921cSAndrew Rist * software distributed under the License is distributed on an 152f86921cSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 162f86921cSAndrew Rist * KIND, either express or implied. See the License for the 172f86921cSAndrew Rist * specific language governing permissions and limitations 182f86921cSAndrew Rist * under the License. 19cdf0e10cSrcweir * 202f86921cSAndrew Rist *************************************************************/ 212f86921cSAndrew Rist 222f86921cSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25*421ed02eSdamjan #include "precompiled_webdav.hxx" 26cdf0e10cSrcweir /************************************************************************** 27cdf0e10cSrcweir TODO 28cdf0e10cSrcweir ************************************************************************** 29cdf0e10cSrcweir 30cdf0e10cSrcweir *************************************************************************/ 31cdf0e10cSrcweir 32cdf0e10cSrcweir #include <set> 33cdf0e10cSrcweir #include <com/sun/star/beans/Property.hpp> 34cdf0e10cSrcweir #include <com/sun/star/beans/PropertyAttribute.hpp> 35cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp> 36cdf0e10cSrcweir #include <com/sun/star/ucb/CommandInfo.hpp> 37cdf0e10cSrcweir #include <com/sun/star/ucb/ContentInfo.hpp> 38cdf0e10cSrcweir #include <com/sun/star/ucb/OpenCommandArgument2.hpp> 39cdf0e10cSrcweir #include <com/sun/star/ucb/InsertCommandArgument.hpp> 40cdf0e10cSrcweir #include <com/sun/star/ucb/PostCommandArgument2.hpp> 4106594b87SAriel Constenla-Haile #include <com/sun/star/ucb/PropertyCommandArgument.hpp> 42cdf0e10cSrcweir #include <com/sun/star/ucb/TransferInfo.hpp> 43cdf0e10cSrcweir #include <com/sun/star/uno/Sequence.hxx> 44cdf0e10cSrcweir #include <com/sun/star/util/DateTime.hpp> 45cdf0e10cSrcweir #include <com/sun/star/ucb/Lock.hpp> 46cdf0e10cSrcweir #include <com/sun/star/ucb/LockEntry.hpp> 47cdf0e10cSrcweir #include "webdavcontent.hxx" 48cdf0e10cSrcweir #include "webdavprovider.hxx" 49cdf0e10cSrcweir #include "DAVSession.hxx" 50cdf0e10cSrcweir #include "ContentProperties.hxx" 51cdf0e10cSrcweir 52cdf0e10cSrcweir using namespace com::sun::star; 5359ddfc10SAndre Fischer using namespace http_dav_ucp; 54cdf0e10cSrcweir 55cdf0e10cSrcweir //========================================================================= 56cdf0e10cSrcweir // 57cdf0e10cSrcweir // ContentProvider implementation. 58cdf0e10cSrcweir // 59cdf0e10cSrcweir //========================================================================= 60cdf0e10cSrcweir 61cdf0e10cSrcweir bool ContentProvider::getProperty( 62cdf0e10cSrcweir const rtl::OUString & rPropName, beans::Property & rProp, bool bStrict ) 63cdf0e10cSrcweir { 64cdf0e10cSrcweir if ( !m_pProps ) 65cdf0e10cSrcweir { 66cdf0e10cSrcweir osl::MutexGuard aGuard( m_aMutex ); 67cdf0e10cSrcweir if ( !m_pProps ) 68cdf0e10cSrcweir { 69cdf0e10cSrcweir m_pProps = new PropertyMap; 70cdf0e10cSrcweir 71cdf0e10cSrcweir ////////////////////////////////////////////////////////////// 72cdf0e10cSrcweir // Fill map of known properties... 73cdf0e10cSrcweir ////////////////////////////////////////////////////////////// 74cdf0e10cSrcweir 75cdf0e10cSrcweir // Mandatory UCB properties. 76cdf0e10cSrcweir m_pProps->insert( 77cdf0e10cSrcweir beans::Property( 78cdf0e10cSrcweir rtl::OUString( 79cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM( "ContentType" ) ), 80cdf0e10cSrcweir -1, 81cdf0e10cSrcweir getCppuType( static_cast< const rtl::OUString * >( 0 ) ), 82cdf0e10cSrcweir beans::PropertyAttribute::BOUND 83cdf0e10cSrcweir | beans::PropertyAttribute::READONLY ) ); 84cdf0e10cSrcweir 85cdf0e10cSrcweir m_pProps->insert( 86cdf0e10cSrcweir beans::Property( 87cdf0e10cSrcweir rtl::OUString( 88cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM( "IsDocument" ) ), 89cdf0e10cSrcweir -1, 90cdf0e10cSrcweir getCppuBooleanType(), 91cdf0e10cSrcweir beans::PropertyAttribute::BOUND 92cdf0e10cSrcweir | beans::PropertyAttribute::READONLY ) ); 93cdf0e10cSrcweir 94cdf0e10cSrcweir m_pProps->insert( 95cdf0e10cSrcweir beans::Property( 96cdf0e10cSrcweir rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IsFolder" ) ), 97cdf0e10cSrcweir -1, 98cdf0e10cSrcweir getCppuBooleanType(), 99cdf0e10cSrcweir beans::PropertyAttribute::BOUND 100cdf0e10cSrcweir | beans::PropertyAttribute::READONLY ) ); 101cdf0e10cSrcweir 102cdf0e10cSrcweir m_pProps->insert( 103cdf0e10cSrcweir beans::Property( 104cdf0e10cSrcweir rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Title" ) ), 105cdf0e10cSrcweir -1, 106cdf0e10cSrcweir getCppuType( static_cast< const rtl::OUString * >( 0 ) ), 107cdf0e10cSrcweir beans::PropertyAttribute::BOUND ) ); 108cdf0e10cSrcweir 109cdf0e10cSrcweir // Optional UCB properties. 110cdf0e10cSrcweir 111cdf0e10cSrcweir m_pProps->insert( 112cdf0e10cSrcweir beans::Property( 113cdf0e10cSrcweir rtl::OUString( 114cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM( "DateCreated" ) ), 115cdf0e10cSrcweir -1, 116cdf0e10cSrcweir getCppuType( static_cast< const util::DateTime * >( 0 ) ), 117cdf0e10cSrcweir beans::PropertyAttribute::BOUND 118cdf0e10cSrcweir | beans::PropertyAttribute::READONLY ) ); 119cdf0e10cSrcweir 120cdf0e10cSrcweir m_pProps->insert( 121cdf0e10cSrcweir beans::Property( 122cdf0e10cSrcweir rtl::OUString( 123cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM( "DateModified" ) ), 124cdf0e10cSrcweir -1, 125cdf0e10cSrcweir getCppuType( static_cast< const util::DateTime * >( 0 ) ), 126cdf0e10cSrcweir beans::PropertyAttribute::BOUND 127cdf0e10cSrcweir | beans::PropertyAttribute::READONLY ) ); 128cdf0e10cSrcweir 129cdf0e10cSrcweir m_pProps->insert( 130cdf0e10cSrcweir beans::Property( 131cdf0e10cSrcweir rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MediaType" ) ), 132cdf0e10cSrcweir -1, 133cdf0e10cSrcweir getCppuType( static_cast< const rtl::OUString * >( 0 ) ), 134cdf0e10cSrcweir beans::PropertyAttribute::BOUND 135cdf0e10cSrcweir | beans::PropertyAttribute::READONLY ) ); 136cdf0e10cSrcweir 137cdf0e10cSrcweir m_pProps->insert( 138cdf0e10cSrcweir beans::Property( 139cdf0e10cSrcweir rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Size" ) ), 140cdf0e10cSrcweir -1, 141cdf0e10cSrcweir getCppuType( static_cast< const sal_Int64 * >( 0 ) ), 142cdf0e10cSrcweir beans::PropertyAttribute::BOUND 143cdf0e10cSrcweir | beans::PropertyAttribute::READONLY ) ); 144cdf0e10cSrcweir 145cdf0e10cSrcweir m_pProps->insert( 146cdf0e10cSrcweir beans::Property( 147cdf0e10cSrcweir rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "BaseURI" ) ), 148cdf0e10cSrcweir -1, 149cdf0e10cSrcweir getCppuType( static_cast< const rtl::OUString * >( 0 ) ), 150cdf0e10cSrcweir beans::PropertyAttribute::BOUND 151cdf0e10cSrcweir | beans::PropertyAttribute::READONLY ) ); 152cdf0e10cSrcweir 153cdf0e10cSrcweir m_pProps->insert( 154cdf0e10cSrcweir beans::Property( 155cdf0e10cSrcweir rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( 156cdf0e10cSrcweir "CreatableContentsInfo" ) ), 157cdf0e10cSrcweir -1, 158cdf0e10cSrcweir getCppuType( static_cast< 159cdf0e10cSrcweir const uno::Sequence< ucb::ContentInfo > * >( 0 ) ), 160cdf0e10cSrcweir beans::PropertyAttribute::BOUND 161cdf0e10cSrcweir | beans::PropertyAttribute::READONLY ) ); 162cdf0e10cSrcweir 163cdf0e10cSrcweir // Standard DAV properties. 164cdf0e10cSrcweir 165cdf0e10cSrcweir m_pProps->insert( 166cdf0e10cSrcweir beans::Property( 167cdf0e10cSrcweir DAVProperties::CREATIONDATE, 168cdf0e10cSrcweir -1, 169cdf0e10cSrcweir getCppuType( static_cast< const rtl::OUString * >( 0 ) ), 170cdf0e10cSrcweir beans::PropertyAttribute::BOUND 171cdf0e10cSrcweir | beans::PropertyAttribute::READONLY ) ); 172cdf0e10cSrcweir 173cdf0e10cSrcweir m_pProps->insert( 174cdf0e10cSrcweir beans::Property( 175cdf0e10cSrcweir DAVProperties::DISPLAYNAME, 176cdf0e10cSrcweir -1, 177cdf0e10cSrcweir getCppuType( static_cast< const rtl::OUString * >( 0 ) ), 178cdf0e10cSrcweir beans::PropertyAttribute::BOUND ) ); 179cdf0e10cSrcweir 180cdf0e10cSrcweir m_pProps->insert( 181cdf0e10cSrcweir beans::Property( 182cdf0e10cSrcweir DAVProperties::GETCONTENTLANGUAGE, 183cdf0e10cSrcweir -1, 184cdf0e10cSrcweir getCppuType( static_cast< const rtl::OUString * >( 0 ) ), 185cdf0e10cSrcweir beans::PropertyAttribute::BOUND 186cdf0e10cSrcweir | beans::PropertyAttribute::READONLY ) ); 187cdf0e10cSrcweir 188cdf0e10cSrcweir m_pProps->insert( 189cdf0e10cSrcweir beans::Property( 190cdf0e10cSrcweir DAVProperties::GETCONTENTLENGTH, 191cdf0e10cSrcweir -1, 192cdf0e10cSrcweir getCppuType( static_cast< const rtl::OUString * >( 0 ) ), 193cdf0e10cSrcweir beans::PropertyAttribute::BOUND 194cdf0e10cSrcweir | beans::PropertyAttribute::READONLY ) ); 195cdf0e10cSrcweir 196cdf0e10cSrcweir m_pProps->insert( 197cdf0e10cSrcweir beans::Property( 198cdf0e10cSrcweir DAVProperties::GETCONTENTTYPE , 199cdf0e10cSrcweir -1, 200cdf0e10cSrcweir getCppuType( static_cast< const rtl::OUString * >( 0 ) ), 201cdf0e10cSrcweir beans::PropertyAttribute::BOUND 202cdf0e10cSrcweir | beans::PropertyAttribute::READONLY ) ); 203cdf0e10cSrcweir 204cdf0e10cSrcweir m_pProps->insert( 205cdf0e10cSrcweir beans::Property( 206cdf0e10cSrcweir DAVProperties::GETETAG, 207cdf0e10cSrcweir -1, 208cdf0e10cSrcweir getCppuType( static_cast< const rtl::OUString * >( 0 ) ), 209cdf0e10cSrcweir beans::PropertyAttribute::BOUND 210cdf0e10cSrcweir | beans::PropertyAttribute::READONLY ) ); 211cdf0e10cSrcweir 212cdf0e10cSrcweir m_pProps->insert( 213cdf0e10cSrcweir beans::Property( 214cdf0e10cSrcweir DAVProperties::GETLASTMODIFIED, 215cdf0e10cSrcweir -1, 216cdf0e10cSrcweir getCppuType( static_cast< const rtl::OUString * >( 0 ) ), 217cdf0e10cSrcweir beans::PropertyAttribute::BOUND 218cdf0e10cSrcweir | beans::PropertyAttribute::READONLY ) ); 219cdf0e10cSrcweir 220cdf0e10cSrcweir m_pProps->insert( 221cdf0e10cSrcweir beans::Property( 222cdf0e10cSrcweir DAVProperties::LOCKDISCOVERY, 223cdf0e10cSrcweir -1, 224cdf0e10cSrcweir getCppuType( static_cast< 225cdf0e10cSrcweir const uno::Sequence< ucb::Lock > * >( 0 ) ), 226cdf0e10cSrcweir beans::PropertyAttribute::BOUND 227cdf0e10cSrcweir | beans::PropertyAttribute::READONLY ) ); 228cdf0e10cSrcweir 229cdf0e10cSrcweir m_pProps->insert( 230cdf0e10cSrcweir beans::Property( 231cdf0e10cSrcweir DAVProperties::RESOURCETYPE, 232cdf0e10cSrcweir -1, 233cdf0e10cSrcweir getCppuType( static_cast< const rtl::OUString * >( 0 ) ), 234cdf0e10cSrcweir beans::PropertyAttribute::BOUND 235cdf0e10cSrcweir | beans::PropertyAttribute::READONLY ) ); 236cdf0e10cSrcweir 237cdf0e10cSrcweir m_pProps->insert( 238cdf0e10cSrcweir beans::Property( 239cdf0e10cSrcweir DAVProperties::SUPPORTEDLOCK, 240cdf0e10cSrcweir -1, 241cdf0e10cSrcweir getCppuType( static_cast< 242cdf0e10cSrcweir const uno::Sequence< 243cdf0e10cSrcweir ucb::LockEntry > * >( 0 ) ), 244cdf0e10cSrcweir beans::PropertyAttribute::BOUND 245cdf0e10cSrcweir | beans::PropertyAttribute::READONLY ) ); 246cdf0e10cSrcweir 247cdf0e10cSrcweir m_pProps->insert( 248cdf0e10cSrcweir beans::Property( 249cdf0e10cSrcweir DAVProperties::EXECUTABLE, 250cdf0e10cSrcweir -1, 251cdf0e10cSrcweir getCppuType( static_cast< const rtl::OUString * >( 0 ) ), 252cdf0e10cSrcweir beans::PropertyAttribute::BOUND ) ); 253cdf0e10cSrcweir } 254cdf0e10cSrcweir } 255cdf0e10cSrcweir 256cdf0e10cSrcweir ////////////////////////////////////////////////////////////// 257cdf0e10cSrcweir // Lookup property. 258cdf0e10cSrcweir ////////////////////////////////////////////////////////////// 259cdf0e10cSrcweir 260cdf0e10cSrcweir beans::Property aProp; 261cdf0e10cSrcweir aProp.Name = rPropName; 262cdf0e10cSrcweir const PropertyMap::const_iterator it = m_pProps->find( aProp ); 263cdf0e10cSrcweir if ( it != m_pProps->end() ) 264cdf0e10cSrcweir { 265cdf0e10cSrcweir rProp = (*it); 266cdf0e10cSrcweir } 267cdf0e10cSrcweir else 268cdf0e10cSrcweir { 269cdf0e10cSrcweir if ( bStrict ) 270cdf0e10cSrcweir return false; 271cdf0e10cSrcweir 272cdf0e10cSrcweir // All unknown props are treated as: 273cdf0e10cSrcweir rProp = beans::Property( 274cdf0e10cSrcweir rPropName, 275cdf0e10cSrcweir - 1, 276cdf0e10cSrcweir getCppuType( static_cast< const rtl::OUString * >( 0 ) ), 277cdf0e10cSrcweir beans::PropertyAttribute::BOUND ); 278cdf0e10cSrcweir } 279cdf0e10cSrcweir 280cdf0e10cSrcweir return true; 281cdf0e10cSrcweir } 282cdf0e10cSrcweir 283cdf0e10cSrcweir //========================================================================= 284cdf0e10cSrcweir // 285cdf0e10cSrcweir // Content implementation. 286cdf0e10cSrcweir // 287cdf0e10cSrcweir //========================================================================= 288cdf0e10cSrcweir 289cdf0e10cSrcweir // virtual 290cdf0e10cSrcweir uno::Sequence< beans::Property > Content::getProperties( 291cdf0e10cSrcweir const uno::Reference< ucb::XCommandEnvironment > & xEnv ) 292cdf0e10cSrcweir { 293cdf0e10cSrcweir sal_Bool bTransient; 294cdf0e10cSrcweir std::auto_ptr< DAVResourceAccess > xResAccess; 295cdf0e10cSrcweir std::auto_ptr< ContentProperties > xCachedProps; 296cdf0e10cSrcweir rtl::Reference< ContentProvider > xProvider; 297cdf0e10cSrcweir 298cdf0e10cSrcweir { 299cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_aMutex ); 300cdf0e10cSrcweir 301cdf0e10cSrcweir bTransient = m_bTransient; 302cdf0e10cSrcweir xResAccess.reset( new DAVResourceAccess( *m_xResAccess.get() ) ); 303cdf0e10cSrcweir if ( m_xCachedProps.get() ) 304cdf0e10cSrcweir xCachedProps.reset( 305cdf0e10cSrcweir new ContentProperties( *m_xCachedProps.get() ) ); 306cdf0e10cSrcweir xProvider.set( m_pProvider ); 307cdf0e10cSrcweir } 308cdf0e10cSrcweir 309cdf0e10cSrcweir typedef std::set< rtl::OUString > StringSet; 310cdf0e10cSrcweir StringSet aPropSet; 311cdf0e10cSrcweir 312cdf0e10cSrcweir // No server access for just created (not yet committed) objects. 313cdf0e10cSrcweir // Only a minimal set of properties supported at this stage. 314cdf0e10cSrcweir if ( !bTransient ) 315cdf0e10cSrcweir { 316cdf0e10cSrcweir // Obtain all properties supported for this resource from server. 317cdf0e10cSrcweir try 318cdf0e10cSrcweir { 319cdf0e10cSrcweir std::vector< DAVResourceInfo > props; 320cdf0e10cSrcweir xResAccess->PROPFIND( DAVZERO, props, xEnv ); 321cdf0e10cSrcweir 322cdf0e10cSrcweir // Note: vector always contains exactly one resource info, because 323cdf0e10cSrcweir // we used a depth of DAVZERO for PROPFIND. 324cdf0e10cSrcweir aPropSet.insert( (*props.begin()).properties.begin(), 325cdf0e10cSrcweir (*props.begin()).properties.end() ); 326cdf0e10cSrcweir } 327cdf0e10cSrcweir catch ( DAVException const & ) 328cdf0e10cSrcweir { 329cdf0e10cSrcweir } 330cdf0e10cSrcweir } 331cdf0e10cSrcweir 332cdf0e10cSrcweir // Add DAV properties, map DAV properties to UCB properties. 333cdf0e10cSrcweir sal_Bool bHasCreationDate = sal_False; // creationdate <-> DateCreated 334cdf0e10cSrcweir sal_Bool bHasGetLastModified = sal_False; // getlastmodified <-> DateModified 335cdf0e10cSrcweir sal_Bool bHasGetContentType = sal_False; // getcontenttype <-> MediaType 336cdf0e10cSrcweir sal_Bool bHasGetContentLength = sal_False; // getcontentlength <-> Size 337cdf0e10cSrcweir 338cdf0e10cSrcweir sal_Bool bHasContentType = sal_False; 339cdf0e10cSrcweir sal_Bool bHasIsDocument = sal_False; 340cdf0e10cSrcweir sal_Bool bHasIsFolder = sal_False; 341cdf0e10cSrcweir sal_Bool bHasTitle = sal_False; 342cdf0e10cSrcweir sal_Bool bHasBaseURI = sal_False; 343cdf0e10cSrcweir sal_Bool bHasDateCreated = sal_False; 344cdf0e10cSrcweir sal_Bool bHasDateModified = sal_False; 345cdf0e10cSrcweir sal_Bool bHasMediaType = sal_False; 346cdf0e10cSrcweir sal_Bool bHasSize = sal_False; 347cdf0e10cSrcweir sal_Bool bHasCreatableInfos = sal_False; 348cdf0e10cSrcweir 349cdf0e10cSrcweir { 350cdf0e10cSrcweir std::set< rtl::OUString >::const_iterator it = aPropSet.begin(); 351cdf0e10cSrcweir std::set< rtl::OUString >::const_iterator end = aPropSet.end(); 352cdf0e10cSrcweir while ( it != end ) 353cdf0e10cSrcweir { 354cdf0e10cSrcweir if ( !bHasCreationDate && 355cdf0e10cSrcweir ( (*it) == DAVProperties::CREATIONDATE ) ) 356cdf0e10cSrcweir { 357cdf0e10cSrcweir bHasCreationDate = sal_True; 358cdf0e10cSrcweir } 359cdf0e10cSrcweir else if ( !bHasGetLastModified && 360cdf0e10cSrcweir ( (*it) == DAVProperties::GETLASTMODIFIED ) ) 361cdf0e10cSrcweir { 362cdf0e10cSrcweir bHasGetLastModified = sal_True; 363cdf0e10cSrcweir } 364cdf0e10cSrcweir else if ( !bHasGetContentType && 365cdf0e10cSrcweir ( (*it) == DAVProperties::GETCONTENTTYPE ) ) 366cdf0e10cSrcweir { 367cdf0e10cSrcweir bHasGetContentType = sal_True; 368cdf0e10cSrcweir } 369cdf0e10cSrcweir else if ( !bHasGetContentLength && 370cdf0e10cSrcweir ( (*it) == DAVProperties::GETCONTENTLENGTH ) ) 371cdf0e10cSrcweir { 372cdf0e10cSrcweir bHasGetContentLength = sal_True; 373cdf0e10cSrcweir } 374cdf0e10cSrcweir else if ( !bHasContentType && 375cdf0e10cSrcweir (*it).equalsAsciiL( 376cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( "ContentType" ) ) ) 377cdf0e10cSrcweir { 378cdf0e10cSrcweir bHasContentType = sal_True; 379cdf0e10cSrcweir } 380cdf0e10cSrcweir else if ( !bHasIsDocument && 381cdf0e10cSrcweir (*it).equalsAsciiL( 382cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( "IsDocument" ) ) ) 383cdf0e10cSrcweir { 384cdf0e10cSrcweir bHasIsDocument = sal_True; 385cdf0e10cSrcweir } 386cdf0e10cSrcweir else if ( !bHasIsFolder && 387cdf0e10cSrcweir (*it).equalsAsciiL( 388cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( "IsFolder" ) ) ) 389cdf0e10cSrcweir { 390cdf0e10cSrcweir bHasIsFolder = sal_True; 391cdf0e10cSrcweir } 392cdf0e10cSrcweir else if ( !bHasTitle && 393cdf0e10cSrcweir (*it).equalsAsciiL( 394cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( "Title" ) ) ) 395cdf0e10cSrcweir { 396cdf0e10cSrcweir bHasTitle = sal_True; 397cdf0e10cSrcweir } 398cdf0e10cSrcweir else if ( !bHasBaseURI && 399cdf0e10cSrcweir (*it).equalsAsciiL( 400cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( "BaseURI" ) ) ) 401cdf0e10cSrcweir { 402cdf0e10cSrcweir bHasBaseURI = sal_True; 403cdf0e10cSrcweir } 404cdf0e10cSrcweir else if ( !bHasDateCreated && 405cdf0e10cSrcweir (*it).equalsAsciiL( 406cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( "DateCreated" ) ) ) 407cdf0e10cSrcweir { 408cdf0e10cSrcweir bHasDateCreated = sal_True; 409cdf0e10cSrcweir } 410cdf0e10cSrcweir else if ( !bHasDateModified && 411cdf0e10cSrcweir (*it).equalsAsciiL( 412cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( "DateModified" ) ) ) 413cdf0e10cSrcweir { 414cdf0e10cSrcweir bHasDateModified = sal_True; 415cdf0e10cSrcweir } 416cdf0e10cSrcweir else if ( !bHasMediaType && 417cdf0e10cSrcweir (*it).equalsAsciiL( 418cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( "MediaType" ) ) ) 419cdf0e10cSrcweir { 420cdf0e10cSrcweir bHasMediaType = sal_True; 421cdf0e10cSrcweir } 422cdf0e10cSrcweir else if ( !bHasSize && 423cdf0e10cSrcweir (*it).equalsAsciiL( 424cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( "Size" ) ) ) 425cdf0e10cSrcweir { 426cdf0e10cSrcweir bHasSize = sal_True; 427cdf0e10cSrcweir } 428cdf0e10cSrcweir else if ( !bHasCreatableInfos && 429cdf0e10cSrcweir (*it).equalsAsciiL( 430cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( 431cdf0e10cSrcweir "CreatableContentsInfo" ) ) ) 432cdf0e10cSrcweir { 433cdf0e10cSrcweir bHasCreatableInfos = sal_True; 434cdf0e10cSrcweir } 435cdf0e10cSrcweir it++; 436cdf0e10cSrcweir } 437cdf0e10cSrcweir } 438cdf0e10cSrcweir 439cdf0e10cSrcweir // Add mandatory properties. 440cdf0e10cSrcweir if ( !bHasContentType ) 441cdf0e10cSrcweir aPropSet.insert( 442cdf0e10cSrcweir rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ContentType" ) ) ); 443cdf0e10cSrcweir 444cdf0e10cSrcweir if ( !bHasIsDocument ) 445cdf0e10cSrcweir aPropSet.insert( 446cdf0e10cSrcweir rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IsDocument" ) ) ); 447cdf0e10cSrcweir 448cdf0e10cSrcweir if ( !bHasIsFolder ) 449cdf0e10cSrcweir aPropSet.insert( 450cdf0e10cSrcweir rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IsFolder" ) ) ); 451cdf0e10cSrcweir 452cdf0e10cSrcweir if ( !bHasTitle ) 453cdf0e10cSrcweir { 454cdf0e10cSrcweir // Always present since it can be calculated from content's URI. 455cdf0e10cSrcweir aPropSet.insert( 456cdf0e10cSrcweir rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Title" ) ) ); 457cdf0e10cSrcweir } 458cdf0e10cSrcweir 459cdf0e10cSrcweir // Add optional properties. 460cdf0e10cSrcweir 461cdf0e10cSrcweir if ( !bHasBaseURI ) 462cdf0e10cSrcweir { 463cdf0e10cSrcweir // Always present since it can be calculated from content's URI. 464cdf0e10cSrcweir aPropSet.insert( 465cdf0e10cSrcweir rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "BaseURI" ) ) ); 466cdf0e10cSrcweir } 467cdf0e10cSrcweir 468cdf0e10cSrcweir if ( !bHasDateCreated && bHasCreationDate ) 469cdf0e10cSrcweir aPropSet.insert( 470cdf0e10cSrcweir rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DateCreated" ) ) ); 471cdf0e10cSrcweir 472cdf0e10cSrcweir if ( !bHasDateModified && bHasGetLastModified ) 473cdf0e10cSrcweir aPropSet.insert( 474cdf0e10cSrcweir rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DateModified" ) ) ); 475cdf0e10cSrcweir 476cdf0e10cSrcweir if ( !bHasMediaType && bHasGetContentType ) 477cdf0e10cSrcweir aPropSet.insert( 478cdf0e10cSrcweir rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MediaType" ) ) ); 479cdf0e10cSrcweir 480cdf0e10cSrcweir if ( !bHasSize && bHasGetContentLength ) 481cdf0e10cSrcweir aPropSet.insert( 482cdf0e10cSrcweir rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Size" ) ) ); 483cdf0e10cSrcweir 484cdf0e10cSrcweir if ( !bHasCreatableInfos ) 485cdf0e10cSrcweir aPropSet.insert( 486cdf0e10cSrcweir rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( 487cdf0e10cSrcweir "CreatableContentsInfo" ) ) ); 488cdf0e10cSrcweir 489cdf0e10cSrcweir // Add cached properties, if present and still missing. 490cdf0e10cSrcweir if ( xCachedProps.get() ) 491cdf0e10cSrcweir { 492cdf0e10cSrcweir const std::set< rtl::OUString >::const_iterator set_end 493cdf0e10cSrcweir = aPropSet.end(); 494cdf0e10cSrcweir 495cdf0e10cSrcweir const std::auto_ptr< PropertyValueMap > & xProps 496cdf0e10cSrcweir = xCachedProps->getProperties(); 497cdf0e10cSrcweir 498cdf0e10cSrcweir PropertyValueMap::const_iterator map_it = xProps->begin(); 499cdf0e10cSrcweir const PropertyValueMap::const_iterator map_end = xProps->end(); 500cdf0e10cSrcweir 501cdf0e10cSrcweir while ( map_it != map_end ) 502cdf0e10cSrcweir { 503cdf0e10cSrcweir if ( aPropSet.find( (*map_it).first ) == set_end ) 504cdf0e10cSrcweir aPropSet.insert( (*map_it).first ); 505cdf0e10cSrcweir 506cdf0e10cSrcweir ++map_it; 507cdf0e10cSrcweir } 508cdf0e10cSrcweir } 509cdf0e10cSrcweir 510cdf0e10cSrcweir // std::set -> uno::Sequence 511cdf0e10cSrcweir sal_Int32 nCount = aPropSet.size(); 512cdf0e10cSrcweir uno::Sequence< beans::Property > aProperties( nCount ); 513cdf0e10cSrcweir 514cdf0e10cSrcweir std::set< rtl::OUString >::const_iterator it = aPropSet.begin(); 515cdf0e10cSrcweir beans::Property aProp; 516cdf0e10cSrcweir 517cdf0e10cSrcweir for ( sal_Int32 n = 0; n < nCount; ++n, ++it ) 518cdf0e10cSrcweir { 519cdf0e10cSrcweir xProvider->getProperty( (*it), aProp ); 520cdf0e10cSrcweir aProperties[ n ] = aProp; 521cdf0e10cSrcweir } 522cdf0e10cSrcweir 523cdf0e10cSrcweir return aProperties; 524cdf0e10cSrcweir } 525cdf0e10cSrcweir 526cdf0e10cSrcweir //========================================================================= 527cdf0e10cSrcweir // virtual 528cdf0e10cSrcweir uno::Sequence< ucb::CommandInfo > Content::getCommands( 529cdf0e10cSrcweir const uno::Reference< ucb::XCommandEnvironment > & xEnv ) 530cdf0e10cSrcweir { 531cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_aMutex ); 532cdf0e10cSrcweir 53306594b87SAriel Constenla-Haile uno::Sequence< ucb::CommandInfo > aCmdInfo( 10 ); 534cdf0e10cSrcweir 535cdf0e10cSrcweir /////////////////////////////////////////////////////////////// 536cdf0e10cSrcweir // Mandatory commands 537cdf0e10cSrcweir /////////////////////////////////////////////////////////////// 538cdf0e10cSrcweir 539cdf0e10cSrcweir aCmdInfo[ 0 ] = 540cdf0e10cSrcweir ucb::CommandInfo( 541cdf0e10cSrcweir rtl::OUString( 542cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM( "getCommandInfo" ) ), 543cdf0e10cSrcweir -1, 544cdf0e10cSrcweir getCppuVoidType() ); 545cdf0e10cSrcweir aCmdInfo[ 1 ] = 546cdf0e10cSrcweir ucb::CommandInfo( 547cdf0e10cSrcweir rtl::OUString( 548cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM( "getPropertySetInfo" ) ), 549cdf0e10cSrcweir -1, 550cdf0e10cSrcweir getCppuVoidType() ); 551cdf0e10cSrcweir aCmdInfo[ 2 ] = 552cdf0e10cSrcweir ucb::CommandInfo( 553cdf0e10cSrcweir rtl::OUString( 554cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM( "getPropertyValues" ) ), 555cdf0e10cSrcweir -1, 556cdf0e10cSrcweir getCppuType( static_cast< 557cdf0e10cSrcweir uno::Sequence< beans::Property > * >( 0 ) ) ); 558cdf0e10cSrcweir aCmdInfo[ 3 ] = 559cdf0e10cSrcweir ucb::CommandInfo( 560cdf0e10cSrcweir rtl::OUString( 561cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM( "setPropertyValues" ) ), 562cdf0e10cSrcweir -1, 563cdf0e10cSrcweir getCppuType( static_cast< 564cdf0e10cSrcweir uno::Sequence< beans::PropertyValue > * >( 0 ) ) ); 565cdf0e10cSrcweir 566cdf0e10cSrcweir /////////////////////////////////////////////////////////////// 567cdf0e10cSrcweir // Optional standard commands 568cdf0e10cSrcweir /////////////////////////////////////////////////////////////// 569cdf0e10cSrcweir 570cdf0e10cSrcweir aCmdInfo[ 4 ] = 571cdf0e10cSrcweir ucb::CommandInfo( 572cdf0e10cSrcweir rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "delete" ) ), 573cdf0e10cSrcweir -1, 574cdf0e10cSrcweir getCppuBooleanType() ); 575cdf0e10cSrcweir aCmdInfo[ 5 ] = 576cdf0e10cSrcweir ucb::CommandInfo( 577cdf0e10cSrcweir rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "insert" ) ), 578cdf0e10cSrcweir -1, 579cdf0e10cSrcweir getCppuType( static_cast< 580cdf0e10cSrcweir ucb::InsertCommandArgument * >( 0 ) ) ); 581cdf0e10cSrcweir aCmdInfo[ 6 ] = 582cdf0e10cSrcweir ucb::CommandInfo( 583cdf0e10cSrcweir rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "open" ) ), 584cdf0e10cSrcweir -1, 585cdf0e10cSrcweir getCppuType( static_cast< 586cdf0e10cSrcweir ucb::OpenCommandArgument2 * >( 0 ) ) ); 587cdf0e10cSrcweir 588cdf0e10cSrcweir /////////////////////////////////////////////////////////////// 589cdf0e10cSrcweir // New commands 590cdf0e10cSrcweir /////////////////////////////////////////////////////////////// 591cdf0e10cSrcweir 592cdf0e10cSrcweir aCmdInfo[ 7 ] = 593cdf0e10cSrcweir ucb::CommandInfo( 594cdf0e10cSrcweir rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "post" ) ), 595cdf0e10cSrcweir -1, 596cdf0e10cSrcweir getCppuType( static_cast< 597cdf0e10cSrcweir ucb::PostCommandArgument2 * >( 0 ) ) ); 59806594b87SAriel Constenla-Haile aCmdInfo[ 8 ] = 59906594b87SAriel Constenla-Haile ucb::CommandInfo( 60006594b87SAriel Constenla-Haile rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "addProperty" ) ), 60106594b87SAriel Constenla-Haile -1, 60206594b87SAriel Constenla-Haile getCppuType( static_cast< 60306594b87SAriel Constenla-Haile ucb::PropertyCommandArgument * >( 0 ) ) ); 60406594b87SAriel Constenla-Haile aCmdInfo[ 9 ] = 60506594b87SAriel Constenla-Haile ucb::CommandInfo( 60606594b87SAriel Constenla-Haile rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "removeProperty" ) ), 60706594b87SAriel Constenla-Haile -1, 60806594b87SAriel Constenla-Haile getCppuType( static_cast< 60906594b87SAriel Constenla-Haile rtl::OUString * >( 0 ) ) ); 610cdf0e10cSrcweir 611cdf0e10cSrcweir sal_Bool bFolder = sal_False; 612cdf0e10cSrcweir 613cdf0e10cSrcweir try 614cdf0e10cSrcweir { 615cdf0e10cSrcweir bFolder = isFolder( xEnv ); 616cdf0e10cSrcweir } 617cdf0e10cSrcweir catch ( uno::Exception const & ) 618cdf0e10cSrcweir { 619cdf0e10cSrcweir return aCmdInfo; 620cdf0e10cSrcweir } 621cdf0e10cSrcweir 622cdf0e10cSrcweir sal_Bool bSupportsLocking = supportsExclusiveWriteLock( xEnv ); 623cdf0e10cSrcweir 624cdf0e10cSrcweir sal_Int32 nPos = aCmdInfo.getLength(); 625cdf0e10cSrcweir sal_Int32 nMoreCmds = ( bFolder ? 2 : 0 ) + ( bSupportsLocking ? 2 : 0 ); 626cdf0e10cSrcweir if ( nMoreCmds ) 627cdf0e10cSrcweir aCmdInfo.realloc( nPos + nMoreCmds ); 628cdf0e10cSrcweir else 629cdf0e10cSrcweir return aCmdInfo; 630cdf0e10cSrcweir 631cdf0e10cSrcweir if ( bFolder ) 632cdf0e10cSrcweir { 633cdf0e10cSrcweir /////////////////////////////////////////////////////////////// 634cdf0e10cSrcweir // Optional standard commands 635cdf0e10cSrcweir /////////////////////////////////////////////////////////////// 636cdf0e10cSrcweir 637cdf0e10cSrcweir aCmdInfo[ nPos ] = 638cdf0e10cSrcweir ucb::CommandInfo( 639cdf0e10cSrcweir rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "transfer" ) ), 640cdf0e10cSrcweir -1, 641cdf0e10cSrcweir getCppuType( static_cast< ucb::TransferInfo * >( 0 ) ) ); 642cdf0e10cSrcweir nPos++; 643cdf0e10cSrcweir aCmdInfo[ nPos ] = 644cdf0e10cSrcweir ucb::CommandInfo( 645cdf0e10cSrcweir rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( 646cdf0e10cSrcweir "createNewContent" ) ), 647cdf0e10cSrcweir -1, 648cdf0e10cSrcweir getCppuType( static_cast< ucb::ContentInfo * >( 0 ) ) ); 649cdf0e10cSrcweir nPos++; 650cdf0e10cSrcweir } 651cdf0e10cSrcweir else 652cdf0e10cSrcweir { 653cdf0e10cSrcweir // no document-only commands at the moment. 654cdf0e10cSrcweir } 655cdf0e10cSrcweir 656cdf0e10cSrcweir if ( bSupportsLocking ) 657cdf0e10cSrcweir { 658cdf0e10cSrcweir aCmdInfo[ nPos ] = 659cdf0e10cSrcweir ucb::CommandInfo( 660cdf0e10cSrcweir rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "lock" ) ), 661cdf0e10cSrcweir -1, 662cdf0e10cSrcweir getCppuVoidType() ); 663cdf0e10cSrcweir nPos++; 664cdf0e10cSrcweir aCmdInfo[ nPos ] = 665cdf0e10cSrcweir ucb::CommandInfo( 666cdf0e10cSrcweir rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "unlock" ) ), 667cdf0e10cSrcweir -1, 668cdf0e10cSrcweir getCppuVoidType() ); 669cdf0e10cSrcweir nPos++; 670cdf0e10cSrcweir } 671cdf0e10cSrcweir return aCmdInfo; 672cdf0e10cSrcweir } 673