1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 #ifndef _WEBDAV_UCP_CONTENT_HXX 25 #define _WEBDAV_UCP_CONTENT_HXX 26 27 #include <memory> 28 #include <list> 29 #include <rtl/ref.hxx> 30 #include <com/sun/star/ucb/ContentCreationException.hpp> 31 #include <com/sun/star/ucb/XContentCreator.hpp> 32 #include <ucbhelper/contenthelper.hxx> 33 #include "DAVResourceAccess.hxx" 34 #include "PropertyMap.hxx" 35 36 namespace com { namespace sun { namespace star { namespace beans { 37 struct Property; 38 struct PropertyValue; 39 } } } } 40 41 namespace com { namespace sun { namespace star { namespace io { 42 class XInputStream; 43 } } } } 44 45 namespace com { namespace sun { namespace star { namespace sdbc { 46 class XRow; 47 } } } } 48 49 namespace com { namespace sun { namespace star { namespace ucb { 50 struct OpenCommandArgument2; 51 struct PostCommandArgument2; 52 struct TransferInfo; 53 } } } } 54 55 namespace http_dav_ucp 56 { 57 58 //========================================================================= 59 60 // UNO service name for the content. 61 #define WEBDAV_CONTENT_SERVICE_NAME "com.sun.star.ucb.WebDAVContent" 62 63 //========================================================================= 64 65 class ContentProvider; 66 class ContentProperties; 67 class CachableContentProperties; 68 69 class Content : public ::ucbhelper::ContentImplHelper, 70 public com::sun::star::ucb::XContentCreator 71 { 72 enum ResourceType 73 { 74 UNKNOWN, 75 NON_DAV, 76 DAV 77 }; 78 79 std::auto_ptr< DAVResourceAccess > m_xResAccess; 80 std::auto_ptr< CachableContentProperties > 81 m_xCachedProps; // locally cached props 82 rtl::OUString m_aEscapedTitle; 83 ResourceType m_eResourceType; 84 ContentProvider* m_pProvider; // No need for a ref, base class holds object 85 bool m_bTransient; 86 bool m_bCollection; 87 bool m_bDidGetOrHead; 88 std::vector< rtl::OUString > m_aFailedPropNames; 89 90 private: 91 virtual com::sun::star::uno::Sequence< com::sun::star::beans::Property > 92 getProperties( const com::sun::star::uno::Reference< 93 com::sun::star::ucb::XCommandEnvironment > & xEnv ); 94 virtual com::sun::star::uno::Sequence< com::sun::star::ucb::CommandInfo > 95 getCommands( const com::sun::star::uno::Reference< 96 com::sun::star::ucb::XCommandEnvironment > & xEnv ); 97 virtual ::rtl::OUString getParentURL(); 98 99 sal_Bool isFolder( const ::com::sun::star::uno::Reference< 100 ::com::sun::star::ucb::XCommandEnvironment >& xEnv ) 101 throw ( ::com::sun::star::uno::Exception ); 102 103 ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRow > 104 getPropertyValues( const ::com::sun::star::uno::Sequence< 105 ::com::sun::star::beans::Property >& rProperties, 106 const ::com::sun::star::uno::Reference< 107 ::com::sun::star::ucb::XCommandEnvironment >& xEnv ) 108 throw ( ::com::sun::star::uno::Exception ); 109 110 ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any > 111 setPropertyValues( const ::com::sun::star::uno::Sequence< 112 ::com::sun::star::beans::PropertyValue >& rValues, 113 const ::com::sun::star::uno::Reference< 114 ::com::sun::star::ucb::XCommandEnvironment >& xEnv ) 115 throw ( ::com::sun::star::uno::Exception ); 116 117 typedef rtl::Reference< Content > ContentRef; 118 typedef std::list< ContentRef > ContentRefList; 119 void queryChildren( ContentRefList& rChildren); 120 121 sal_Bool 122 exchangeIdentity( const ::com::sun::star::uno::Reference< 123 ::com::sun::star::ucb::XContentIdentifier >& xNewId ); 124 125 const rtl::OUString 126 getBaseURI( const std::auto_ptr< DAVResourceAccess > & rResAccess ); 127 128 const ResourceType & 129 getResourceType( const ::com::sun::star::uno::Reference< 130 ::com::sun::star::ucb::XCommandEnvironment >& xEnv ) 131 throw ( ::com::sun::star::uno::Exception ); 132 133 const ResourceType & 134 getResourceType( const ::com::sun::star::uno::Reference< 135 ::com::sun::star::ucb::XCommandEnvironment >& xEnv, 136 const std::auto_ptr< DAVResourceAccess > & rResAccess ) 137 throw ( ::com::sun::star::uno::Exception ); 138 139 // Command "open" 140 com::sun::star::uno::Any open( 141 const com::sun::star::ucb::OpenCommandArgument2 & rArg, 142 const com::sun::star::uno::Reference< 143 com::sun::star::ucb::XCommandEnvironment > & xEnv ) 144 throw( ::com::sun::star::uno::Exception ); 145 146 // Command "post" 147 void post( const com::sun::star::ucb::PostCommandArgument2 & rArg, 148 const com::sun::star::uno::Reference< 149 com::sun::star::ucb::XCommandEnvironment > & xEnv ) 150 throw( ::com::sun::star::uno::Exception ); 151 152 // Command "insert" 153 void insert( const ::com::sun::star::uno::Reference< 154 ::com::sun::star::io::XInputStream > & xInputStream, 155 sal_Bool bReplaceExisting, 156 const com::sun::star::uno::Reference< 157 com::sun::star::ucb::XCommandEnvironment >& Environment ) 158 throw( ::com::sun::star::uno::Exception ); 159 160 // Command "transfer" 161 void transfer( const ::com::sun::star::ucb::TransferInfo & rArgs, 162 const com::sun::star::uno::Reference< 163 com::sun::star::ucb::XCommandEnvironment >& Environment ) 164 throw( ::com::sun::star::uno::Exception ); 165 166 // Command "delete" 167 void destroy( sal_Bool bDeletePhysical ) 168 throw( ::com::sun::star::uno::Exception ); 169 170 // Command "lock" 171 void lock( const com::sun::star::uno::Reference< 172 com::sun::star::ucb::XCommandEnvironment >& Environment ) 173 throw( ::com::sun::star::uno::Exception ); 174 175 // Command "unlock" 176 void unlock( const com::sun::star::uno::Reference< 177 com::sun::star::ucb::XCommandEnvironment >& Environment ) 178 throw( ::com::sun::star::uno::Exception ); 179 180 ::com::sun::star::uno::Any MapDAVException( const DAVException & e, 181 sal_Bool bWrite ); 182 void cancelCommandExecution( 183 const DAVException & e, 184 const ::com::sun::star::uno::Reference< 185 com::sun::star::ucb::XCommandEnvironment > & xEnv, 186 sal_Bool bWrite = sal_False ) 187 throw( ::com::sun::star::uno::Exception ); 188 189 static bool shouldAccessNetworkAfterException( const DAVException & e ); 190 191 bool supportsExclusiveWriteLock( 192 const com::sun::star::uno::Reference< 193 com::sun::star::ucb::XCommandEnvironment >& Environment ); 194 195 public: 196 Content( const ::com::sun::star::uno::Reference< 197 ::com::sun::star::lang::XMultiServiceFactory >& rxSMgr, 198 ContentProvider* pProvider, 199 const ::com::sun::star::uno::Reference< 200 ::com::sun::star::ucb::XContentIdentifier >& Identifier, 201 rtl::Reference< DAVSessionFactory > const & rSessionFactory ) 202 throw ( ::com::sun::star::ucb::ContentCreationException ); 203 Content( const ::com::sun::star::uno::Reference< 204 ::com::sun::star::lang::XMultiServiceFactory >& rxSMgr, 205 ContentProvider* pProvider, 206 const ::com::sun::star::uno::Reference< 207 ::com::sun::star::ucb::XContentIdentifier >& Identifier, 208 rtl::Reference< DAVSessionFactory > const & rSessionFactory, 209 sal_Bool isCollection ) 210 throw ( ::com::sun::star::ucb::ContentCreationException ); 211 virtual ~Content(); 212 213 // XInterface 214 XINTERFACE_DECL() 215 216 // XTypeProvider 217 XTYPEPROVIDER_DECL() 218 219 // XServiceInfo 220 virtual ::rtl::OUString SAL_CALL 221 getImplementationName() 222 throw( ::com::sun::star::uno::RuntimeException ); 223 224 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL 225 getSupportedServiceNames() 226 throw( ::com::sun::star::uno::RuntimeException ); 227 228 // XContent 229 virtual rtl::OUString SAL_CALL 230 getContentType() 231 throw( com::sun::star::uno::RuntimeException ); 232 233 // XCommandProcessor 234 virtual com::sun::star::uno::Any SAL_CALL 235 execute( const com::sun::star::ucb::Command& aCommand, 236 sal_Int32 CommandId, 237 const com::sun::star::uno::Reference< 238 com::sun::star::ucb::XCommandEnvironment >& Environment ) 239 throw( com::sun::star::uno::Exception, 240 com::sun::star::ucb::CommandAbortedException, 241 com::sun::star::uno::RuntimeException ); 242 virtual void SAL_CALL 243 abort( sal_Int32 CommandId ) 244 throw( com::sun::star::uno::RuntimeException ); 245 246 // XPropertyContainer 247 virtual void SAL_CALL 248 addProperty( const rtl::OUString& Name, 249 sal_Int16 Attributes, 250 const com::sun::star::uno::Any& DefaultValue ) 251 throw( com::sun::star::beans::PropertyExistException, 252 com::sun::star::beans::IllegalTypeException, 253 com::sun::star::lang::IllegalArgumentException, 254 com::sun::star::uno::RuntimeException ); 255 256 virtual void SAL_CALL 257 removeProperty( const rtl::OUString& Name ) 258 throw( com::sun::star::beans::UnknownPropertyException, 259 com::sun::star::beans::NotRemoveableException, 260 com::sun::star::uno::RuntimeException ); 261 262 ////////////////////////////////////////////////////////////////////// 263 // Additional interfaces 264 ////////////////////////////////////////////////////////////////////// 265 266 // XContentCreator 267 virtual com::sun::star::uno::Sequence< 268 com::sun::star::ucb::ContentInfo > SAL_CALL 269 queryCreatableContentsInfo() 270 throw( com::sun::star::uno::RuntimeException ); 271 virtual com::sun::star::uno::Reference< 272 com::sun::star::ucb::XContent > SAL_CALL 273 createNewContent( const com::sun::star::ucb::ContentInfo& Info ) 274 throw( com::sun::star::uno::RuntimeException ); 275 276 ////////////////////////////////////////////////////////////////////// 277 // Non-interface methods. 278 ////////////////////////////////////////////////////////////////////// 279 280 DAVResourceAccess & getResourceAccess() { return *m_xResAccess; } 281 282 // Called from resultset data supplier. 283 static ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRow > 284 getPropertyValues( const ::com::sun::star::uno::Reference< 285 ::com::sun::star::lang::XMultiServiceFactory >& rSMgr, 286 const ::com::sun::star::uno::Sequence< 287 ::com::sun::star::beans::Property >& rProperties, 288 const ContentProperties& rData, 289 const rtl::Reference< 290 ::ucbhelper::ContentProviderImplHelper >& rProvider, 291 const ::rtl::OUString& rContentId ); 292 }; 293 294 } 295 296 #endif 297