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 PropertyCommandArgument; 52 struct PostCommandArgument2; 53 struct TransferInfo; 54 } } } } 55 56 namespace http_dav_ucp 57 { 58 59 //========================================================================= 60 61 // UNO service name for the content. 62 #define WEBDAV_CONTENT_SERVICE_NAME "com.sun.star.ucb.WebDAVContent" 63 64 //========================================================================= 65 66 class ContentProvider; 67 class ContentProperties; 68 class CachableContentProperties; 69 70 class Content : public ::ucbhelper::ContentImplHelper, 71 public com::sun::star::ucb::XContentCreator 72 { 73 enum ResourceType 74 { 75 UNKNOWN, 76 NON_DAV, 77 DAV 78 }; 79 80 std::auto_ptr< DAVResourceAccess > m_xResAccess; 81 std::auto_ptr< CachableContentProperties > 82 m_xCachedProps; // locally cached props 83 rtl::OUString m_aEscapedTitle; 84 ResourceType m_eResourceType; 85 ContentProvider* m_pProvider; // No need for a ref, base class holds object 86 // True if the DEV resource is a 'unmapped URL' as it is named in RFC4918 87 bool m_bTransient; 88 bool m_bCollection; 89 bool m_bDidGetOrHead; 90 std::vector< rtl::OUString > m_aFailedPropNames; 91 92 private: 93 virtual com::sun::star::uno::Sequence< com::sun::star::beans::Property > 94 getProperties( const com::sun::star::uno::Reference< 95 com::sun::star::ucb::XCommandEnvironment > & xEnv ); 96 virtual com::sun::star::uno::Sequence< com::sun::star::ucb::CommandInfo > 97 getCommands( const com::sun::star::uno::Reference< 98 com::sun::star::ucb::XCommandEnvironment > & xEnv ); 99 virtual ::rtl::OUString getParentURL(); 100 101 sal_Bool isFolder( const ::com::sun::star::uno::Reference< 102 ::com::sun::star::ucb::XCommandEnvironment >& xEnv ); 103 104 ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRow > 105 getPropertyValues( const ::com::sun::star::uno::Sequence< 106 ::com::sun::star::beans::Property >& rProperties, 107 const ::com::sun::star::uno::Reference< 108 ::com::sun::star::ucb::XCommandEnvironment >& xEnv ); 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 116 typedef rtl::Reference< Content > ContentRef; 117 typedef std::list< ContentRef > ContentRefList; 118 void queryChildren( ContentRefList& rChildren); 119 120 sal_Bool 121 exchangeIdentity( const ::com::sun::star::uno::Reference< 122 ::com::sun::star::ucb::XContentIdentifier >& xNewId ); 123 124 const rtl::OUString 125 getBaseURI( const std::auto_ptr< DAVResourceAccess > & rResAccess ); 126 127 const ResourceType & 128 getResourceType( const ::com::sun::star::uno::Reference< 129 ::com::sun::star::ucb::XCommandEnvironment >& xEnv ); 130 131 const ResourceType & 132 getResourceType( const ::com::sun::star::uno::Reference< 133 ::com::sun::star::ucb::XCommandEnvironment >& xEnv, 134 const std::auto_ptr< DAVResourceAccess > & rResAccess ); 135 136 /// Command "open" 137 com::sun::star::uno::Any open( 138 const com::sun::star::ucb::OpenCommandArgument2 & rArg, 139 const com::sun::star::uno::Reference< 140 com::sun::star::ucb::XCommandEnvironment > & xEnv ); 141 142 /// Command "post" 143 void post( const com::sun::star::ucb::PostCommandArgument2 & rArg, 144 const com::sun::star::uno::Reference< 145 com::sun::star::ucb::XCommandEnvironment > & xEnv ); 146 147 /// Command "insert" 148 void insert( const ::com::sun::star::uno::Reference< 149 ::com::sun::star::io::XInputStream > & xInputStream, 150 sal_Bool bReplaceExisting, 151 const com::sun::star::uno::Reference< 152 com::sun::star::ucb::XCommandEnvironment >& Environment ); 153 154 /// Command "transfer" 155 void transfer( const ::com::sun::star::ucb::TransferInfo & rArgs, 156 const com::sun::star::uno::Reference< 157 com::sun::star::ucb::XCommandEnvironment >& Environment ); 158 159 /// Command "delete" 160 void destroy( sal_Bool bDeletePhysical ); 161 162 /// Command "lock" 163 void lock( const com::sun::star::uno::Reference< 164 com::sun::star::ucb::XCommandEnvironment >& Environment ); 165 166 /// Command "unlock" 167 void unlock( const com::sun::star::uno::Reference< 168 com::sun::star::ucb::XCommandEnvironment >& Environment ); 169 170 ::com::sun::star::uno::Any MapDAVException( const DAVException & e, 171 sal_Bool bWrite ); 172 void cancelCommandExecution( 173 const DAVException & e, 174 const ::com::sun::star::uno::Reference< 175 com::sun::star::ucb::XCommandEnvironment > & xEnv, 176 sal_Bool bWrite = sal_False ); 177 178 static bool shouldAccessNetworkAfterException( const DAVException & e ); 179 180 bool supportsExclusiveWriteLock( 181 const com::sun::star::uno::Reference< 182 com::sun::star::ucb::XCommandEnvironment >& Environment ); 183 184 /// XPropertyContainer replacement 185 void addProperty( const com::sun::star::ucb::PropertyCommandArgument &aCmdArg, 186 const com::sun::star::uno::Reference< 187 com::sun::star::ucb::XCommandEnvironment >& Environment ); 188 189 void removeProperty( const rtl::OUString& Name, 190 const com::sun::star::uno::Reference< 191 com::sun::star::ucb::XCommandEnvironment >& Environment ); 192 public: 193 Content( const ::com::sun::star::uno::Reference< 194 ::com::sun::star::lang::XMultiServiceFactory >& rxSMgr, 195 ContentProvider* pProvider, 196 const ::com::sun::star::uno::Reference< 197 ::com::sun::star::ucb::XContentIdentifier >& Identifier, 198 rtl::Reference< DAVSessionFactory > const & rSessionFactory ); 199 Content( const ::com::sun::star::uno::Reference< 200 ::com::sun::star::lang::XMultiServiceFactory >& rxSMgr, 201 ContentProvider* pProvider, 202 const ::com::sun::star::uno::Reference< 203 ::com::sun::star::ucb::XContentIdentifier >& Identifier, 204 rtl::Reference< DAVSessionFactory > const & rSessionFactory, 205 sal_Bool isCollection ); 206 virtual ~Content(); 207 208 /// XInterface 209 XINTERFACE_DECL() 210 211 /// XTypeProvider 212 XTYPEPROVIDER_DECL() 213 214 /// XServiceInfo 215 virtual ::rtl::OUString SAL_CALL 216 getImplementationName(); 217 218 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL 219 getSupportedServiceNames(); 220 221 /// XContent 222 virtual rtl::OUString SAL_CALL 223 getContentType(); 224 225 /// XCommandProcessor 226 virtual com::sun::star::uno::Any SAL_CALL 227 execute( const com::sun::star::ucb::Command& aCommand, 228 sal_Int32 CommandId, 229 const com::sun::star::uno::Reference< 230 com::sun::star::ucb::XCommandEnvironment >& Environment ); 231 virtual void SAL_CALL 232 abort( sal_Int32 CommandId ); 233 234 /// XPropertyContainer 235 virtual void SAL_CALL 236 addProperty( const rtl::OUString& Name, 237 sal_Int16 Attributes, 238 const com::sun::star::uno::Any& DefaultValue ); 239 240 virtual void SAL_CALL 241 removeProperty( const rtl::OUString& Name ); 242 243 ////////////////////////////////////////////////////////////////////// 244 // Additional interfaces 245 ////////////////////////////////////////////////////////////////////// 246 247 // XContentCreator 248 virtual com::sun::star::uno::Sequence< 249 com::sun::star::ucb::ContentInfo > SAL_CALL 250 queryCreatableContentsInfo(); 251 virtual com::sun::star::uno::Reference< 252 com::sun::star::ucb::XContent > SAL_CALL 253 createNewContent( const com::sun::star::ucb::ContentInfo& Info ); 254 255 ////////////////////////////////////////////////////////////////////// 256 // Non-interface methods. 257 ////////////////////////////////////////////////////////////////////// 258 getResourceAccess()259 DAVResourceAccess & getResourceAccess() { return *m_xResAccess; } 260 261 /** Called from resultset data supplier. */ 262 static ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRow > 263 getPropertyValues( const ::com::sun::star::uno::Reference< 264 ::com::sun::star::lang::XMultiServiceFactory >& rSMgr, 265 const ::com::sun::star::uno::Sequence< 266 ::com::sun::star::beans::Property >& rProperties, 267 const ContentProperties& rData, 268 const rtl::Reference< 269 ::ucbhelper::ContentProviderImplHelper >& rProvider, 270 const ::rtl::OUString& rContentId ); 271 272 /** returns the owner of current resource lock */ 273 rtl::OUString getLockOwner( const uno::Reference< ucb::XCommandEnvironment >& Environment ); 274 }; 275 276 } 277 278 #endif 279