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 INCLUDED_TDOC_CONTENT_HXX 29 #define INCLUDED_TDOC_CONTENT_HXX 30 31 #include <ucbhelper/contenthelper.hxx> 32 #include <com/sun/star/task/DocumentPasswordRequest.hpp> 33 #include <com/sun/star/ucb/XContentCreator.hpp> 34 #include <com/sun/star/ucb/CommandFailedException.hpp> 35 #include "tdoc_provider.hxx" 36 37 #define NO_STREAM_CREATION_WITHIN_DOCUMENT_ROOT 1 38 39 namespace com { namespace sun { namespace star { 40 namespace sdbc { class XRow; } 41 namespace io { class XInputStream; class XOutputStream; } 42 namespace beans { struct PropertyValue; } 43 namespace ucb { struct OpenCommandArgument2; struct TransferInfo; 44 struct ContentInfo; } 45 } } } 46 47 namespace tdoc_ucp 48 { 49 50 //========================================================================= 51 52 #define TDOC_ROOT_CONTENT_SERVICE_NAME \ 53 "com.sun.star.ucb.TransientDocumentsRootContent" 54 #define TDOC_DOCUMENT_CONTENT_SERVICE_NAME \ 55 "com.sun.star.ucb.TransientDocumentsDocumentContent" 56 #define TDOC_FOLDER_CONTENT_SERVICE_NAME \ 57 "com.sun.star.ucb.TransientDocumentsFolderContent" 58 #define TDOC_STREAM_CONTENT_SERVICE_NAME \ 59 "com.sun.star.ucb.TransientDocumentsStreamContent" 60 61 //========================================================================= 62 63 enum ContentType { STREAM, FOLDER, DOCUMENT, ROOT }; 64 65 class ContentProperties 66 { 67 public: 68 ContentProperties() 69 {} 70 71 ContentProperties( const ContentType & rType, const rtl::OUString & rTitle ) 72 : m_eType( rType ), 73 m_aContentType( rType == STREAM 74 ? rtl::OUString::createFromAscii( TDOC_STREAM_CONTENT_TYPE ) 75 : rType == FOLDER 76 ? rtl::OUString::createFromAscii( TDOC_FOLDER_CONTENT_TYPE ) 77 : rType == DOCUMENT 78 ? rtl::OUString::createFromAscii( TDOC_DOCUMENT_CONTENT_TYPE ) 79 : rtl::OUString::createFromAscii( TDOC_ROOT_CONTENT_TYPE ) ), 80 m_aTitle( rTitle ) 81 {} 82 83 ContentType getType() const { return m_eType; } 84 85 // Properties 86 87 const rtl::OUString & getContentType() const { return m_aContentType; } 88 89 bool getIsFolder() const { return m_eType > STREAM; } 90 bool getIsDocument() const { return !getIsFolder(); } 91 92 const rtl::OUString & getTitle() const { return m_aTitle; } 93 void setTitle( const rtl::OUString & rTitle ) { m_aTitle = rTitle; } 94 95 com::sun::star::uno::Sequence< com::sun::star::ucb::ContentInfo > 96 getCreatableContentsInfo() const; 97 98 bool isContentCreator() const; 99 100 private: 101 ContentType m_eType; 102 rtl::OUString m_aContentType; 103 rtl::OUString m_aTitle; 104 }; 105 106 //========================================================================= 107 108 class Content : public ::ucbhelper::ContentImplHelper, 109 public com::sun::star::ucb::XContentCreator 110 { 111 enum ContentState { TRANSIENT, // created via createNewContent, 112 // but did not process "insert" yet 113 PERSISTENT, // processed "insert" 114 DEAD // processed "delete" / document was closed 115 }; 116 117 ContentProperties m_aProps; 118 ContentState m_eState; 119 ContentProvider* m_pProvider; 120 121 private: 122 Content( const com::sun::star::uno::Reference< 123 com::sun::star::lang::XMultiServiceFactory >& rxSMgr, 124 ContentProvider* pProvider, 125 const com::sun::star::uno::Reference< 126 com::sun::star::ucb::XContentIdentifier >& Identifier, 127 const ContentProperties & rProps ); 128 Content( const com::sun::star::uno::Reference< 129 com::sun::star::lang::XMultiServiceFactory >& rxSMgr, 130 ContentProvider* pProvider, 131 const com::sun::star::uno::Reference< 132 com::sun::star::ucb::XContentIdentifier >& Identifier, 133 const com::sun::star::ucb::ContentInfo& Info ); 134 135 virtual com::sun::star::uno::Sequence< com::sun::star::beans::Property > 136 getProperties( const com::sun::star::uno::Reference< 137 com::sun::star::ucb::XCommandEnvironment > & xEnv ); 138 virtual com::sun::star::uno::Sequence< com::sun::star::ucb::CommandInfo > 139 getCommands( const com::sun::star::uno::Reference< 140 com::sun::star::ucb::XCommandEnvironment > & xEnv ); 141 virtual ::rtl::OUString getParentURL(); 142 143 static bool hasData( ContentProvider* pProvider, const Uri & rUri ); 144 bool hasData( const Uri & rUri ) { return hasData( m_pProvider, rUri ); } 145 146 static bool loadData( ContentProvider* pProvider, 147 const Uri & rUri, 148 ContentProperties& rProps ); 149 bool storeData( const com::sun::star::uno::Reference< 150 com::sun::star::io::XInputStream >& xData, 151 const com::sun::star::uno::Reference< 152 com::sun::star::ucb::XCommandEnvironment >& xEnv ) 153 throw ( ::com::sun::star::ucb::CommandFailedException, 154 ::com::sun::star::task::DocumentPasswordRequest ); 155 bool renameData( const com::sun::star::uno::Reference< 156 com::sun::star::ucb::XContentIdentifier >& xOldId, 157 const com::sun::star::uno::Reference< 158 com::sun::star::ucb::XContentIdentifier >& xNewId ); 159 bool removeData(); 160 161 bool copyData( const Uri & rSourceUri, const rtl::OUString & rNewName ); 162 163 ::com::sun::star::uno::Reference< 164 ::com::sun::star::ucb::XContentIdentifier > 165 makeNewIdentifier( const rtl::OUString& rTitle ); 166 167 typedef rtl::Reference< Content > ContentRef; 168 typedef std::list< ContentRef > ContentRefList; 169 void queryChildren( ContentRefList& rChildren ); 170 171 sal_Bool exchangeIdentity( 172 const ::com::sun::star::uno::Reference< 173 ::com::sun::star::ucb::XContentIdentifier >& xNewId ); 174 175 ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRow > 176 getPropertyValues( const ::com::sun::star::uno::Sequence< 177 ::com::sun::star::beans::Property >& rProperties ); 178 ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any > 179 setPropertyValues( 180 const ::com::sun::star::uno::Sequence< 181 ::com::sun::star::beans::PropertyValue >& rValues, 182 const ::com::sun::star::uno::Reference< 183 ::com::sun::star::ucb::XCommandEnvironment > & xEnv ) 184 throw( ::com::sun::star::uno::Exception ); 185 186 com::sun::star::uno::Any 187 open( const ::com::sun::star::ucb::OpenCommandArgument2& rArg, 188 const ::com::sun::star::uno::Reference< 189 ::com::sun::star::ucb::XCommandEnvironment >& xEnv ) 190 throw( ::com::sun::star::uno::Exception ); 191 192 void insert( const ::com::sun::star::uno::Reference< 193 ::com::sun::star::io::XInputStream >& xData, 194 sal_Int32 nNameClashResolve, 195 const ::com::sun::star::uno::Reference< 196 ::com::sun::star::ucb::XCommandEnvironment > & xEnv ) 197 throw( ::com::sun::star::uno::Exception ); 198 199 void destroy( sal_Bool bDeletePhysical, 200 const ::com::sun::star::uno::Reference< 201 ::com::sun::star::ucb::XCommandEnvironment > & xEnv ) 202 throw( ::com::sun::star::uno::Exception ); 203 204 void transfer( const ::com::sun::star::ucb::TransferInfo& rInfo, 205 const ::com::sun::star::uno::Reference< 206 ::com::sun::star::ucb::XCommandEnvironment > & xEnv ) 207 throw( ::com::sun::star::uno::Exception ); 208 209 static ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRow > 210 getPropertyValues( const ::com::sun::star::uno::Reference< 211 ::com::sun::star::lang::XMultiServiceFactory >& rSMgr, 212 const ::com::sun::star::uno::Sequence< 213 ::com::sun::star::beans::Property >& rProperties, 214 const ContentProperties& rData, 215 ContentProvider* pProvider, 216 const ::rtl::OUString& rContentId ); 217 218 219 static bool commitStorage( 220 const com::sun::star::uno::Reference< 221 com::sun::star::embed::XStorage > & xStorage ); 222 223 static bool closeOutputStream( 224 const com::sun::star::uno::Reference< 225 com::sun::star::io::XOutputStream > & xOut ); 226 227 ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > 228 getInputStream( const ::com::sun::star::uno::Reference< 229 ::com::sun::star::ucb::XCommandEnvironment > & 230 xEnv ) 231 throw ( ::com::sun::star::ucb::CommandFailedException, 232 ::com::sun::star::task::DocumentPasswordRequest ); 233 234 ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream > 235 getTruncatedOutputStream( 236 const ::com::sun::star::uno::Reference< 237 ::com::sun::star::ucb::XCommandEnvironment > & xEnv ) 238 throw ( ::com::sun::star::ucb::CommandFailedException, 239 ::com::sun::star::task::DocumentPasswordRequest ); 240 241 ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XContent > 242 queryChildContent( const rtl::OUString & rRelativeChildUri ); 243 244 ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream > 245 getStream( const ::com::sun::star::uno::Reference< 246 ::com::sun::star::ucb::XCommandEnvironment > & xEnv ) 247 throw ( ::com::sun::star::ucb::CommandFailedException, 248 ::com::sun::star::task::DocumentPasswordRequest ); 249 250 public: 251 // Create existing content. Fail, if not already exists. 252 static Content* create( 253 const com::sun::star::uno::Reference< 254 com::sun::star::lang::XMultiServiceFactory >& rxSMgr, 255 ContentProvider* pProvider, 256 const com::sun::star::uno::Reference< 257 com::sun::star::ucb::XContentIdentifier >& Identifier ); 258 259 // Create new content. Fail, if already exists. 260 static Content* create( 261 const com::sun::star::uno::Reference< 262 com::sun::star::lang::XMultiServiceFactory >& rxSMgr, 263 ContentProvider* pProvider, 264 const com::sun::star::uno::Reference< 265 com::sun::star::ucb::XContentIdentifier >& Identifier, 266 const com::sun::star::ucb::ContentInfo& Info ); 267 268 virtual ~Content(); 269 270 // XInterface 271 XINTERFACE_DECL() 272 273 // XTypeProvider 274 XTYPEPROVIDER_DECL() 275 276 // XServiceInfo 277 virtual ::rtl::OUString SAL_CALL 278 getImplementationName() 279 throw( ::com::sun::star::uno::RuntimeException ); 280 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL 281 getSupportedServiceNames() 282 throw( ::com::sun::star::uno::RuntimeException ); 283 284 // XContent 285 virtual rtl::OUString SAL_CALL 286 getContentType() 287 throw( com::sun::star::uno::RuntimeException ); 288 virtual com::sun::star::uno::Reference< 289 com::sun::star::ucb::XContentIdentifier > SAL_CALL 290 getIdentifier() 291 throw( com::sun::star::uno::RuntimeException ); 292 293 // XCommandProcessor 294 virtual com::sun::star::uno::Any SAL_CALL 295 execute( const com::sun::star::ucb::Command& aCommand, 296 sal_Int32 CommandId, 297 const com::sun::star::uno::Reference< 298 com::sun::star::ucb::XCommandEnvironment >& Environment ) 299 throw( com::sun::star::uno::Exception, 300 com::sun::star::ucb::CommandAbortedException, 301 com::sun::star::uno::RuntimeException ); 302 virtual void SAL_CALL 303 abort( sal_Int32 CommandId ) 304 throw( com::sun::star::uno::RuntimeException ); 305 306 ////////////////////////////////////////////////////////////////////// 307 // Additional interfaces 308 ////////////////////////////////////////////////////////////////////// 309 310 // XContentCreator 311 virtual com::sun::star::uno::Sequence< 312 com::sun::star::ucb::ContentInfo > SAL_CALL 313 queryCreatableContentsInfo() 314 throw( com::sun::star::uno::RuntimeException ); 315 virtual com::sun::star::uno::Reference< 316 com::sun::star::ucb::XContent > SAL_CALL 317 createNewContent( const com::sun::star::ucb::ContentInfo& Info ) 318 throw( com::sun::star::uno::RuntimeException ); 319 320 ////////////////////////////////////////////////////////////////////// 321 // Non-interface methods. 322 ////////////////////////////////////////////////////////////////////// 323 324 static ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRow > 325 getPropertyValues( const ::com::sun::star::uno::Reference< 326 ::com::sun::star::lang::XMultiServiceFactory >& rSMgr, 327 const ::com::sun::star::uno::Sequence< 328 ::com::sun::star::beans::Property >& rProperties, 329 ContentProvider* pProvider, 330 const ::rtl::OUString& rContentId ); 331 332 void notifyDocumentClosed(); 333 void notifyChildRemoved( const rtl::OUString & rRelativeChildUri ); 334 void notifyChildInserted( const rtl::OUString & rRelativeChildUri ); 335 336 rtl::Reference< ContentProvider > getContentProvider() const 337 { return rtl::Reference< ContentProvider >( m_pProvider ); } 338 }; 339 340 } // namespace tdoc_ucp 341 342 #endif /* !INCLUDED_TDOC_CONTENT_HXX */ 343