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