1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 #ifndef _PKGCONTENT_HXX 29 #define _PKGCONTENT_HXX 30 31 #include <list> 32 #include <rtl/ref.hxx> 33 34 #include <com/sun/star/ucb/InteractiveBadTransferURLException.hpp> 35 #include <com/sun/star/ucb/XContentCreator.hpp> 36 #include <ucbhelper/contenthelper.hxx> 37 #include "pkguri.hxx" 38 39 namespace com { namespace sun { namespace star { 40 namespace beans 41 { 42 struct Property; 43 struct PropertyValue; 44 } 45 namespace container 46 { 47 class XHierarchicalNameAccess; 48 class XEnumeration; 49 } 50 namespace io 51 { 52 class XInputStream; 53 } 54 namespace sdbc 55 { 56 class XRow; 57 } 58 namespace ucb 59 { 60 struct OpenCommandArgument2; 61 struct TransferInfo; 62 } 63 } } } 64 65 namespace package_ucp 66 { 67 68 //========================================================================= 69 70 // UNO service name for the content. 71 #define PACKAGE_FOLDER_CONTENT_SERVICE_NAME \ 72 "com.sun.star.ucb.PackageFolderContent" 73 #define PACKAGE_STREAM_CONTENT_SERVICE_NAME \ 74 "com.sun.star.ucb.PackageStreamContent" 75 76 //========================================================================= 77 78 struct ContentProperties 79 { 80 ::rtl::OUString aTitle; // Title 81 ::rtl::OUString aContentType; // ContentType 82 sal_Bool bIsDocument; // IsDocument 83 sal_Bool bIsFolder; // IsFolder 84 ::rtl::OUString aMediaType; // MediaType 85 com::sun::star::uno::Sequence < 86 sal_Int8 > aEncryptionKey; // EncryptionKey 87 sal_Int64 nSize; // Size 88 sal_Bool bCompressed; // Compressed 89 sal_Bool bEncrypted; // Encrypted 90 sal_Bool bHasEncryptedEntries; // HasEncryptedEntries 91 92 ContentProperties() 93 : bIsDocument( sal_True ), bIsFolder( sal_False ), nSize( 0 ), 94 bCompressed( sal_True ), bEncrypted( sal_False ), 95 bHasEncryptedEntries( sal_False ) {} 96 97 ContentProperties( const ::rtl::OUString& rContentType ); 98 99 com::sun::star::uno::Sequence< com::sun::star::ucb::ContentInfo > 100 getCreatableContentsInfo( PackageUri const & rUri ) const; 101 }; 102 103 //========================================================================= 104 105 class ContentProvider; 106 107 class Content : public ::ucbhelper::ContentImplHelper, 108 public com::sun::star::ucb::XContentCreator 109 { 110 enum ContentState { TRANSIENT, // created via CreateNewContent, 111 // but did not process "insert" yet 112 PERSISTENT, // processed "insert" 113 DEAD // processed "delete" 114 }; 115 116 PackageUri m_aUri; 117 ContentProperties m_aProps; 118 ContentState m_eState; 119 com::sun::star::uno::Reference< 120 com::sun::star::container::XHierarchicalNameAccess > m_xPackage; 121 ContentProvider* m_pProvider; 122 sal_uInt32 m_nModifiedProps; 123 124 private: 125 Content( const com::sun::star::uno::Reference< 126 com::sun::star::lang::XMultiServiceFactory >& rxSMgr, 127 ContentProvider* pProvider, 128 const com::sun::star::uno::Reference< 129 com::sun::star::ucb::XContentIdentifier >& Identifier, 130 const ::com::sun::star::uno::Reference< 131 com::sun::star::container::XHierarchicalNameAccess >& Package, 132 const PackageUri& rUri, 133 const ContentProperties& rProps ); 134 Content( const com::sun::star::uno::Reference< 135 com::sun::star::lang::XMultiServiceFactory >& rxSMgr, 136 ContentProvider* pProvider, 137 const com::sun::star::uno::Reference< 138 com::sun::star::ucb::XContentIdentifier >& Identifier, 139 const com::sun::star::uno::Reference< 140 com::sun::star::container::XHierarchicalNameAccess >& Package, 141 const PackageUri& rUri, 142 const com::sun::star::ucb::ContentInfo& Info ); 143 144 virtual com::sun::star::uno::Sequence< com::sun::star::beans::Property > 145 getProperties( const com::sun::star::uno::Reference< 146 com::sun::star::ucb::XCommandEnvironment > & xEnv ); 147 virtual com::sun::star::uno::Sequence< com::sun::star::ucb::CommandInfo > 148 getCommands( const com::sun::star::uno::Reference< 149 com::sun::star::ucb::XCommandEnvironment > & xEnv ); 150 virtual ::rtl::OUString getParentURL(); 151 152 static ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRow > 153 getPropertyValues( const ::com::sun::star::uno::Reference< 154 ::com::sun::star::lang::XMultiServiceFactory >& rSMgr, 155 const ::com::sun::star::uno::Sequence< 156 ::com::sun::star::beans::Property >& rProperties, 157 const ContentProperties& rData, 158 const rtl::Reference< 159 ::ucbhelper::ContentProviderImplHelper >& rProvider, 160 const ::rtl::OUString& rContentId ); 161 162 ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRow > 163 getPropertyValues( const ::com::sun::star::uno::Sequence< 164 ::com::sun::star::beans::Property >& rProperties ); 165 ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any > 166 setPropertyValues( const ::com::sun::star::uno::Sequence< 167 ::com::sun::star::beans::PropertyValue >& rValues, 168 const ::com::sun::star::uno::Reference< 169 ::com::sun::star::ucb::XCommandEnvironment > & xEnv ) 170 throw( ::com::sun::star::uno::Exception ); 171 172 com::sun::star::uno::Reference< 173 com::sun::star::container::XHierarchicalNameAccess > 174 getPackage( const PackageUri& rURI ); 175 com::sun::star::uno::Reference< 176 com::sun::star::container::XHierarchicalNameAccess > 177 getPackage(); 178 179 static sal_Bool 180 loadData( ContentProvider* pProvider, 181 const PackageUri& rURI, 182 ContentProperties& rProps, 183 com::sun::star::uno::Reference< 184 com::sun::star::container::XHierarchicalNameAccess > & 185 rxPackage ); 186 static sal_Bool 187 hasData( ContentProvider* pProvider, 188 const PackageUri& rURI, 189 com::sun::star::uno::Reference< 190 com::sun::star::container::XHierarchicalNameAccess > & 191 rxPackage ); 192 193 sal_Bool 194 hasData( const PackageUri& rURI ); 195 sal_Bool 196 renameData( const com::sun::star::uno::Reference< 197 com::sun::star::ucb::XContentIdentifier >& xOldId, 198 const com::sun::star::uno::Reference< 199 com::sun::star::ucb::XContentIdentifier >& xNewId ); 200 sal_Bool 201 storeData( const com::sun::star::uno::Reference< 202 com::sun::star::io::XInputStream >& xStream ); 203 sal_Bool 204 removeData(); 205 206 sal_Bool 207 flushData(); 208 209 typedef rtl::Reference< Content > ContentRef; 210 typedef std::list< ContentRef > ContentRefList; 211 void queryChildren( ContentRefList& rChildren ); 212 213 sal_Bool 214 exchangeIdentity( const ::com::sun::star::uno::Reference< 215 ::com::sun::star::ucb::XContentIdentifier >& xNewId ); 216 217 ::com::sun::star::uno::Any 218 open( const ::com::sun::star::ucb::OpenCommandArgument2& rArg, 219 const ::com::sun::star::uno::Reference< 220 ::com::sun::star::ucb::XCommandEnvironment > & xEnv ) 221 throw( ::com::sun::star::uno::Exception ); 222 223 void insert( const ::com::sun::star::uno::Reference< 224 ::com::sun::star::io::XInputStream >& xStream, 225 sal_Int32 nNameClashResolve, 226 const ::com::sun::star::uno::Reference< 227 ::com::sun::star::ucb::XCommandEnvironment > & xEnv ) 228 throw( ::com::sun::star::uno::Exception ); 229 230 void destroy( sal_Bool bDeletePhysical, 231 const ::com::sun::star::uno::Reference< 232 ::com::sun::star::ucb::XCommandEnvironment > & xEnv ) 233 throw( ::com::sun::star::uno::Exception ); 234 235 void transfer( const ::com::sun::star::ucb::TransferInfo& rInfo, 236 const ::com::sun::star::uno::Reference< 237 ::com::sun::star::ucb::XCommandEnvironment > & xEnv ) 238 throw( ::com::sun::star::uno::Exception ); 239 240 ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > 241 getInputStream(); 242 243 sal_Bool isFolder() const { return m_aProps.bIsFolder; } 244 245 public: 246 // Create existing content. Fail, if not already exists. 247 static Content* create( 248 const com::sun::star::uno::Reference< 249 com::sun::star::lang::XMultiServiceFactory >& rxSMgr, 250 ContentProvider* pProvider, 251 const com::sun::star::uno::Reference< 252 com::sun::star::ucb::XContentIdentifier >& Identifier ); 253 254 // Create new content. Fail, if already exists. 255 static Content* create( 256 const com::sun::star::uno::Reference< 257 com::sun::star::lang::XMultiServiceFactory >& rxSMgr, 258 ContentProvider* pProvider, 259 const com::sun::star::uno::Reference< 260 com::sun::star::ucb::XContentIdentifier >& Identifier, 261 const com::sun::star::ucb::ContentInfo& Info ); 262 263 virtual ~Content(); 264 265 // XInterface 266 XINTERFACE_DECL() 267 268 // XTypeProvider 269 XTYPEPROVIDER_DECL() 270 271 // XServiceInfo 272 virtual ::rtl::OUString SAL_CALL 273 getImplementationName() 274 throw( ::com::sun::star::uno::RuntimeException ); 275 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL 276 getSupportedServiceNames() 277 throw( ::com::sun::star::uno::RuntimeException ); 278 279 // XContent 280 virtual rtl::OUString SAL_CALL 281 getContentType() 282 throw( com::sun::star::uno::RuntimeException ); 283 284 // XCommandProcessor 285 virtual com::sun::star::uno::Any SAL_CALL 286 execute( const com::sun::star::ucb::Command& aCommand, 287 sal_Int32 CommandId, 288 const com::sun::star::uno::Reference< 289 com::sun::star::ucb::XCommandEnvironment >& Environment ) 290 throw( com::sun::star::uno::Exception, 291 com::sun::star::ucb::CommandAbortedException, 292 com::sun::star::uno::RuntimeException ); 293 virtual void SAL_CALL 294 abort( sal_Int32 CommandId ) 295 throw( com::sun::star::uno::RuntimeException ); 296 297 ////////////////////////////////////////////////////////////////////// 298 // Additional interfaces 299 ////////////////////////////////////////////////////////////////////// 300 301 // XContentCreator 302 virtual com::sun::star::uno::Sequence< 303 com::sun::star::ucb::ContentInfo > SAL_CALL 304 queryCreatableContentsInfo() 305 throw( com::sun::star::uno::RuntimeException ); 306 virtual com::sun::star::uno::Reference< 307 com::sun::star::ucb::XContent > SAL_CALL 308 createNewContent( const com::sun::star::ucb::ContentInfo& Info ) 309 throw( com::sun::star::uno::RuntimeException ); 310 311 ////////////////////////////////////////////////////////////////////// 312 // Non-interface methods. 313 ////////////////////////////////////////////////////////////////////// 314 315 // Called from resultset data supplier. 316 static ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRow > 317 getPropertyValues( const ::com::sun::star::uno::Reference< 318 ::com::sun::star::lang::XMultiServiceFactory >& rSMgr, 319 const ::com::sun::star::uno::Sequence< 320 ::com::sun::star::beans::Property >& rProperties, 321 ContentProvider* pProvider, 322 const ::rtl::OUString& rContentId ); 323 324 // Called from resultset data supplier. 325 ::com::sun::star::uno::Reference< 326 ::com::sun::star::container::XEnumeration > 327 getIterator(); 328 329 static ::rtl::OUString 330 getContentType( const ::rtl::OUString& aScheme, sal_Bool bFolder ); 331 }; 332 333 } 334 335 #endif 336