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 #ifndef _SFXDOCFILE_HXX 24 #define _SFXDOCFILE_HXX 25 26 #include <com/sun/star/io/XSeekable.hpp> 27 #include "sal/config.h" 28 #include "sfx2/dllapi.h" 29 #include "sal/types.h" 30 #include <com/sun/star/util/RevisionTag.hpp> 31 #include <com/sun/star/util/DateTime.hpp> 32 #include <com/sun/star/io/XOutputStream.hpp> 33 #include <com/sun/star/io/XInputStream.hpp> 34 #include <com/sun/star/lang/XMultiServiceFactory.hpp> 35 #include <com/sun/star/lang/XServiceInfo.hpp> 36 #include <com/sun/star/ucb/XContent.hpp> 37 #include <com/sun/star/ucb/XCommandEnvironment.hpp> 38 #include <com/sun/star/task/XInteractionHandler.hpp> 39 #include <com/sun/star/embed/XStorage.hpp> 40 #include <com/sun/star/beans/PropertyValue.hpp> 41 #include <tools/stream.hxx> 42 #include <tools/string.hxx> 43 #include <tools/list.hxx> 44 #include <svl/lstner.hxx> 45 46 #include <tools/globname.hxx> 47 #include <cppuhelper/weak.hxx> 48 #include <ucbhelper/content.hxx> 49 50 class SvKeyValueIterator; 51 class SfxObjectFactory; 52 class SfxFilter; 53 class SfxMedium_Impl; 54 class INetURLObject; 55 class SfxObjectShell; 56 class SfxFrame; 57 class Timer; 58 class SfxItemSet; 59 class DateTime; 60 class SvStringsDtor; 61 62 #define S2BS(s) ByteString( s, RTL_TEXTENCODING_MS_1252 ) 63 64 //____________________________________________________________________________________________________________________________________ 65 // defines for namespaces 66 //____________________________________________________________________________________________________________________________________ 67 68 #define OUSTRING ::rtl::OUString 69 #define XMULTISERVICEFACTORY ::com::sun::star::lang::XMultiServiceFactory 70 #define XSERVICEINFO ::com::sun::star::lang::XServiceInfo 71 #define OWEAKOBJECT ::cppu::OWeakObject 72 #define REFERENCE ::com::sun::star::uno::Reference 73 #define XINTERFACE ::com::sun::star::uno::XInterface 74 #define EXCEPTION ::com::sun::star::uno::Exception 75 #define RUNTIMEEXCEPTION ::com::sun::star::uno::RuntimeException 76 #define ANY ::com::sun::star::uno::Any 77 78 class SFX2_DLLPUBLIC SfxMedium : public SvRefBase 79 { 80 sal_uInt32 eError; 81 sal_Bool bDirect:1, 82 bRoot:1, 83 bSetFilter:1, 84 bTriedStorage; 85 StreamMode nStorOpenMode; 86 INetURLObject* pURLObj; 87 String aName; 88 SvGlobalName aFilterClass; 89 SvStream* pInStream; 90 SvStream* pOutStream; 91 //REMOVE SvStorageRef aStorage; 92 const SfxFilter* pFilter; 93 SfxItemSet* pSet; 94 SfxMedium_Impl* pImp; 95 String aLogicName; 96 String aLongName; 97 sal_Bool bRemote; 98 99 sal_Bool m_bIsReadOnly; 100 com::sun::star::uno::Reference<com::sun::star::io::XInputStream> 101 m_xInputStreamToLoadFrom; 102 103 #if _SOLAR__PRIVATE 104 SAL_DLLPRIVATE void SetIsRemote_Impl(); 105 SAL_DLLPRIVATE void CloseInStream_Impl(); 106 SAL_DLLPRIVATE sal_Bool CloseOutStream_Impl(); 107 SAL_DLLPRIVATE void CloseStreams_Impl(); 108 DECL_DLLPRIVATE_STATIC_LINK( SfxMedium, UCBHdl_Impl, sal_uInt32 * ); 109 110 SAL_DLLPRIVATE void SetEncryptionDataToStorage_Impl(); 111 #endif 112 113 public: 114 115 SvCompatWeakHdl* GetHdl(); 116 117 SfxMedium(); 118 SfxMedium( const String &rName, 119 StreamMode nOpenMode, 120 sal_Bool bDirect=sal_False, 121 const SfxFilter *pFilter = 0, 122 SfxItemSet *pSet = 0 ); 123 124 SfxMedium( const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xStorage, 125 const String& rBaseURL, 126 const SfxItemSet* pSet=0, 127 sal_Bool bRoot = sal_False ); 128 129 SfxMedium( const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xStorage, 130 const String& rBaseURL, 131 const String& rTypeName, 132 const SfxItemSet* pSet=0, 133 sal_Bool bRoot = sal_False ); 134 135 SfxMedium( const SfxMedium &rMedium, sal_Bool bCreateTemporary = sal_False ); 136 SfxMedium( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aArgs ); 137 138 ~SfxMedium(); 139 140 void UseInteractionHandler( sal_Bool ); 141 ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler > 142 GetInteractionHandler(); 143 ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler > 144 GetAuthenticationInteractionHandler(); 145 setStreamToLoadFrom(const com::sun::star::uno::Reference<com::sun::star::io::XInputStream> & xInputStream,sal_Bool bIsReadOnly)146 void setStreamToLoadFrom(const com::sun::star::uno::Reference<com::sun::star::io::XInputStream>& xInputStream,sal_Bool bIsReadOnly ) 147 { m_xInputStreamToLoadFrom = xInputStream; m_bIsReadOnly = bIsReadOnly; } 148 149 void SetLoadTargetFrame(SfxFrame* pFrame ); 150 SfxFrame* GetLoadTargetFrame() const; 151 152 void SetReferer( const String& rRefer ); 153 const String& GetReferer( ) const; 154 sal_Bool Exists( sal_Bool bForceSession = sal_True ); 155 void SetFilter(const SfxFilter *pFlt, sal_Bool bResetOrig = sal_False); GetFilter() const156 const SfxFilter * GetFilter() const { return pFilter; } 157 const SfxFilter * GetOrigFilter( sal_Bool bNotCurrent = sal_False ) const; 158 const String& GetOrigURL() const; 159 160 SfxItemSet * GetItemSet() const; 161 void SetItemSet(SfxItemSet *pSet); 162 void Close(); 163 void CloseAndRelease(); 164 void ReOpen(); 165 void CompleteReOpen(); GetName() const166 const String& GetName() const {return aLogicName;} 167 #if defined SINIX && defined GCC && defined C272 168 const INetURLObject& GetURLObject(); 169 #else 170 const INetURLObject& GetURLObject() const; 171 #endif 172 173 void CheckFileDate( const ::com::sun::star::util::DateTime& aInitDate ); 174 sal_Bool DocNeedsFileDateCheck(); 175 ::com::sun::star::util::DateTime GetInitFileDate( sal_Bool bIgnoreOldValue ); 176 177 ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XContent > GetContent() const; 178 const String& GetPhysicalName() const; 179 void SetTemporary( sal_Bool bTemp ); 180 sal_Bool IsTemporary() const; 181 sal_Bool IsRemote(); 182 sal_Bool IsOpen() const; // { return aStorage.Is() || pInStream; } 183 void StartDownload(); 184 void DownLoad( const Link& aLink = Link()); 185 void SetDoneLink( const Link& rLink ); 186 Link GetDoneLink( ) const; 187 void SetDataAvailableLink( const Link& rLink ); 188 Link GetDataAvailableLink( ) const; 189 190 sal_uInt32 GetMIMEAndRedirect( String& ); 191 sal_uInt32 GetErrorCode() const; GetError() const192 sal_uInt32 GetError() const 193 { return ERRCODE_TOERROR(GetErrorCode()); } 194 sal_uInt32 GetLastStorageCreationState(); 195 196 void SetError( sal_uInt32 nError, const ::rtl::OUString& aLogMessage ); 197 198 void AddLog( const ::rtl::OUString& aMessage ); 199 200 void CloseInStream(); 201 sal_Bool CloseOutStream(); 202 IsRoot() const203 sal_Bool IsRoot() const { return bRoot; } 204 void CloseStorage(); 205 GetOpenMode() const206 StreamMode GetOpenMode() const { return nStorOpenMode; } 207 void SetOpenMode( StreamMode nStorOpen, sal_Bool bDirect, sal_Bool bDontClose = sal_False ); IsDirect() const208 sal_Bool IsDirect() const { return bDirect? sal_True: sal_False; } 209 210 SvStream* GetInStream(); 211 SvStream* GetOutStream(); 212 213 sal_Bool Commit(); 214 sal_Bool IsStorage(); 215 216 //->i126305 217 sal_Int8 ShowLockedWebDAVDocumentDialog( const ::com::sun::star::uno::Sequence< ::rtl::OUString >& aData, sal_Bool bIsLoading ); 218 //<-i126305 219 sal_Int8 ShowLockedDocumentDialog( const ::com::sun::star::uno::Sequence< ::rtl::OUString >& aData, sal_Bool bIsLoading, sal_Bool bOwnLock ); 220 sal_Bool LockOrigFileOnDemand( sal_Bool bLoading, sal_Bool bNoUI ); 221 void UnlockFile( sal_Bool bReleaseLockStream ); 222 223 ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage > GetStorage( sal_Bool bCreateTempIfNo = sal_True ); 224 ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage > GetOutputStorage(); 225 void ResetError(); 226 sal_Bool UsesCache() const; 227 void SetUsesCache( sal_Bool ); 228 sal_Bool IsExpired() const; 229 void SetName( const String& rName, sal_Bool bSetOrigURL = sal_False ); 230 sal_Bool IsAllowedForExternalBrowser() const; 231 long GetFileVersion() const; 232 233 const com::sun::star::uno::Sequence < com::sun::star::util::RevisionTag >& 234 GetVersionList( bool _bNoReload = false ); 235 sal_Bool IsReadOnly(); 236 237 ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > GetInputStream(); 238 239 void CreateTempFile( sal_Bool bReplace = sal_True ); 240 void CreateTempFileNoCopy(); 241 ::rtl::OUString SwitchDocumentToTempFile(); 242 sal_Bool SwitchDocumentToFile( ::rtl::OUString aURL ); 243 244 ::rtl::OUString GetCharset(); 245 void SetCharset( ::rtl::OUString ); 246 ::rtl::OUString GetBaseURL( bool bForSaving=false ); 247 248 #if _SOLAR__PRIVATE 249 SAL_DLLPRIVATE sal_Bool HasStorage_Impl() const; 250 251 SAL_DLLPRIVATE void StorageBackup_Impl(); 252 SAL_DLLPRIVATE ::rtl::OUString GetBackup_Impl(); 253 254 SAL_DLLPRIVATE ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage > GetZipStorageToSign_Impl( sal_Bool bReadOnly = sal_True ); 255 SAL_DLLPRIVATE void CloseZipStorage_Impl(); 256 257 // the storage that will be returned by the medium on GetStorage request 258 SAL_DLLPRIVATE void SetStorage_Impl( const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xNewStorage ); 259 260 SAL_DLLPRIVATE ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > GetInputStream_Impl(); 261 SAL_DLLPRIVATE void CloseAndReleaseStreams_Impl(); 262 SAL_DLLPRIVATE void RefreshName_Impl(); 263 SAL_DLLPRIVATE sal_uInt16 AddVersion_Impl( com::sun::star::util::RevisionTag& rVersion ); 264 SAL_DLLPRIVATE sal_Bool TransferVersionList_Impl( SfxMedium& rMedium ); 265 SAL_DLLPRIVATE sal_Bool SaveVersionList_Impl( sal_Bool bUseXML ); 266 SAL_DLLPRIVATE sal_Bool RemoveVersion_Impl( const ::rtl::OUString& rVersion ); 267 268 SAL_DLLPRIVATE void SetExpired_Impl( const DateTime& rDateTime ); 269 SAL_DLLPRIVATE SvKeyValueIterator* GetHeaderAttributes_Impl(); 270 SAL_DLLPRIVATE const String& GetPreRedirectedURL() const; 271 SAL_DLLPRIVATE void SetOrigFilter_Impl( const SfxFilter* pFilter ); 272 273 // Diese Protokolle liefern MIME Typen 274 SAL_DLLPRIVATE sal_Bool SupportsMIME_Impl() const; 275 276 SAL_DLLPRIVATE void Init_Impl(); 277 SAL_DLLPRIVATE void ForceSynchronStream_Impl( sal_Bool bSynchron ); 278 279 SAL_DLLPRIVATE void GetLockingStream_Impl(); 280 SAL_DLLPRIVATE void GetMedium_Impl(); 281 SAL_DLLPRIVATE sal_Bool TryDirectTransfer( const ::rtl::OUString& aURL, SfxItemSet& aTargetSet ); 282 SAL_DLLPRIVATE void Transfer_Impl(); 283 SAL_DLLPRIVATE void CreateFileStream(); 284 SAL_DLLPRIVATE void SetUpdatePickList(sal_Bool); 285 SAL_DLLPRIVATE sal_Bool IsUpdatePickList() const; 286 287 //REMOVE void SetStorage_Impl( SvStorage* pStor ); SetLongName(const String & rName)288 SAL_DLLPRIVATE void SetLongName(const String &rName) 289 { aLongName = rName; } GetLongName() const290 SAL_DLLPRIVATE const String & GetLongName() const { return aLongName; } 291 SAL_DLLPRIVATE ErrCode CheckOpenMode_Impl( sal_Bool bSilent, sal_Bool bAllowRO = sal_True ); 292 SAL_DLLPRIVATE sal_Bool IsDownloadDone_Impl(); 293 SAL_DLLPRIVATE sal_Bool IsPreview_Impl(); 294 SAL_DLLPRIVATE void ClearBackup_Impl(); 295 SAL_DLLPRIVATE void Done_Impl( ErrCode ); 296 SAL_DLLPRIVATE void DataAvailable_Impl(); 297 SAL_DLLPRIVATE void Cancel_Impl(); 298 SAL_DLLPRIVATE void SetPhysicalName_Impl(const String& rName); 299 SAL_DLLPRIVATE void CanDisposeStorage_Impl( sal_Bool bDisposeStorage ); 300 SAL_DLLPRIVATE sal_Bool WillDisposeStorageOnClose_Impl(); 301 302 SAL_DLLPRIVATE void DoBackup_Impl(); 303 SAL_DLLPRIVATE void DoInternalBackup_Impl( const ::ucbhelper::Content& aOriginalContent ); 304 SAL_DLLPRIVATE void DoInternalBackup_Impl( const ::ucbhelper::Content& aOriginalContent, 305 const String& aPrefix, 306 const String& aExtension, 307 const String& aDestDir ); 308 309 SAL_DLLPRIVATE sal_Bool UseBackupToRestore_Impl( ::ucbhelper::Content& aOriginalContent, 310 const ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XCommandEnvironment >& xComEnv ); 311 312 SAL_DLLPRIVATE sal_Bool StorageCommit_Impl(); 313 314 SAL_DLLPRIVATE sal_Bool TransactedTransferForFS_Impl( const INetURLObject& aSource, 315 const INetURLObject& aDest, 316 const ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XCommandEnvironment >& xComEnv ); 317 318 SAL_DLLPRIVATE sal_Bool SignContents_Impl( sal_Bool bScriptingContent, const ::rtl::OUString& aODFVersion, sal_Bool bHasValidDocumentSignature ); 319 320 // the following two methods must be used and make sense only during saving currently 321 // TODO/LATER: in future the signature state should be controlled by the medium not by the document 322 // in this case the methods will be used generally, and might need to be renamed 323 SAL_DLLPRIVATE sal_uInt16 GetCachedSignatureState_Impl(); 324 SAL_DLLPRIVATE void SetCachedSignatureState_Impl( sal_uInt16 nState ); 325 #endif 326 327 static com::sun::star::uno::Sequence < com::sun::star::util::RevisionTag > GetVersionList( 328 const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xStorage ); 329 static ::rtl::OUString CreateTempCopyWithExt( const ::rtl::OUString& aURL ); 330 static sal_Bool CallApproveHandler( const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler >& xHandler, ::com::sun::star::uno::Any aRequest, sal_Bool bAllowAbort ); 331 332 static sal_Bool SetWritableForUserOnly( const ::rtl::OUString& aURL ); 333 static sal_uInt32 CreatePasswordToModifyHash( const ::rtl::OUString& aPasswd, sal_Bool bWriter ); 334 }; 335 336 SV_DECL_IMPL_REF( SfxMedium ) 337 SV_DECL_COMPAT_WEAK( SfxMedium ) 338 339 #ifndef SFXMEDIUM_LIST 340 #define SFXMEDIUM_LIST 341 DECLARE_LIST( SfxMediumList, SfxMedium* ) 342 #endif 343 344 #endif 345 346