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 144 void setStreamToLoadFrom(const com::sun::star::uno::Reference<com::sun::star::io::XInputStream>& xInputStream,sal_Bool bIsReadOnly ) 145 { m_xInputStreamToLoadFrom = xInputStream; m_bIsReadOnly = bIsReadOnly; } 146 147 void SetLoadTargetFrame(SfxFrame* pFrame ); 148 SfxFrame* GetLoadTargetFrame() const; 149 150 void SetReferer( const String& rRefer ); 151 const String& GetReferer( ) const; 152 sal_Bool Exists( sal_Bool bForceSession = sal_True ); 153 void SetFilter(const SfxFilter *pFlt, sal_Bool bResetOrig = sal_False); 154 const SfxFilter * GetFilter() const { return pFilter; } 155 const SfxFilter * GetOrigFilter( sal_Bool bNotCurrent = sal_False ) const; 156 const String& GetOrigURL() const; 157 158 SfxItemSet * GetItemSet() const; 159 void SetItemSet(SfxItemSet *pSet); 160 void Close(); 161 void CloseAndRelease(); 162 void ReOpen(); 163 void CompleteReOpen(); 164 const String& GetName() const {return aLogicName;} 165 #if defined SINIX && defined GCC && defined C272 166 const INetURLObject& GetURLObject(); 167 #else 168 const INetURLObject& GetURLObject() const; 169 #endif 170 171 void CheckFileDate( const ::com::sun::star::util::DateTime& aInitDate ); 172 sal_Bool DocNeedsFileDateCheck(); 173 ::com::sun::star::util::DateTime GetInitFileDate( sal_Bool bIgnoreOldValue ); 174 175 ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XContent > GetContent() const; 176 const String& GetPhysicalName() const; 177 void SetTemporary( sal_Bool bTemp ); 178 sal_Bool IsTemporary() const; 179 sal_Bool IsRemote(); 180 sal_Bool IsOpen() const; // { return aStorage.Is() || pInStream; } 181 void StartDownload(); 182 void DownLoad( const Link& aLink = Link()); 183 void SetDoneLink( const Link& rLink ); 184 Link GetDoneLink( ) const; 185 void SetDataAvailableLink( const Link& rLink ); 186 Link GetDataAvailableLink( ) const; 187 188 sal_uInt32 GetMIMEAndRedirect( String& ); 189 sal_uInt32 GetErrorCode() const; 190 sal_uInt32 GetError() const 191 { return ERRCODE_TOERROR(GetErrorCode()); } 192 sal_uInt32 GetLastStorageCreationState(); 193 194 void SetError( sal_uInt32 nError, const ::rtl::OUString& aLogMessage ); 195 196 void AddLog( const ::rtl::OUString& aMessage ); 197 198 void CloseInStream(); 199 sal_Bool CloseOutStream(); 200 201 sal_Bool IsRoot() const { return bRoot; } 202 void CloseStorage(); 203 204 StreamMode GetOpenMode() const { return nStorOpenMode; } 205 void SetOpenMode( StreamMode nStorOpen, sal_Bool bDirect, sal_Bool bDontClose = sal_False ); 206 sal_Bool IsDirect() const { return bDirect? sal_True: sal_False; } 207 208 SvStream* GetInStream(); 209 SvStream* GetOutStream(); 210 211 sal_Bool Commit(); 212 sal_Bool IsStorage(); 213 214 sal_Int8 ShowLockedDocumentDialog( const ::com::sun::star::uno::Sequence< ::rtl::OUString >& aData, sal_Bool bIsLoading, sal_Bool bOwnLock ); 215 sal_Bool LockOrigFileOnDemand( sal_Bool bLoading, sal_Bool bNoUI ); 216 void UnlockFile( sal_Bool bReleaseLockStream ); 217 218 ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage > GetStorage( sal_Bool bCreateTempIfNo = sal_True ); 219 ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage > GetOutputStorage(); 220 void ResetError(); 221 sal_Bool UsesCache() const; 222 void SetUsesCache( sal_Bool ); 223 sal_Bool IsExpired() const; 224 void SetName( const String& rName, sal_Bool bSetOrigURL = sal_False ); 225 sal_Bool IsAllowedForExternalBrowser() const; 226 long GetFileVersion() const; 227 228 const com::sun::star::uno::Sequence < com::sun::star::util::RevisionTag >& 229 GetVersionList( bool _bNoReload = false ); 230 sal_Bool IsReadOnly(); 231 232 ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > GetInputStream(); 233 234 void CreateTempFile( sal_Bool bReplace = sal_True ); 235 void CreateTempFileNoCopy(); 236 ::rtl::OUString SwitchDocumentToTempFile(); 237 sal_Bool SwitchDocumentToFile( ::rtl::OUString aURL ); 238 239 ::rtl::OUString GetCharset(); 240 void SetCharset( ::rtl::OUString ); 241 ::rtl::OUString GetBaseURL( bool bForSaving=false ); 242 243 #if _SOLAR__PRIVATE 244 SAL_DLLPRIVATE sal_Bool HasStorage_Impl() const; 245 246 SAL_DLLPRIVATE void StorageBackup_Impl(); 247 SAL_DLLPRIVATE ::rtl::OUString GetBackup_Impl(); 248 249 SAL_DLLPRIVATE ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage > GetZipStorageToSign_Impl( sal_Bool bReadOnly = sal_True ); 250 SAL_DLLPRIVATE void CloseZipStorage_Impl(); 251 252 // the storage that will be returned by the medium on GetStorage request 253 SAL_DLLPRIVATE void SetStorage_Impl( const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xNewStorage ); 254 255 SAL_DLLPRIVATE ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > GetInputStream_Impl(); 256 SAL_DLLPRIVATE void CloseAndReleaseStreams_Impl(); 257 SAL_DLLPRIVATE void RefreshName_Impl(); 258 SAL_DLLPRIVATE sal_uInt16 AddVersion_Impl( com::sun::star::util::RevisionTag& rVersion ); 259 SAL_DLLPRIVATE sal_Bool TransferVersionList_Impl( SfxMedium& rMedium ); 260 SAL_DLLPRIVATE sal_Bool SaveVersionList_Impl( sal_Bool bUseXML ); 261 SAL_DLLPRIVATE sal_Bool RemoveVersion_Impl( const ::rtl::OUString& rVersion ); 262 263 SAL_DLLPRIVATE void SetExpired_Impl( const DateTime& rDateTime ); 264 SAL_DLLPRIVATE SvKeyValueIterator* GetHeaderAttributes_Impl(); 265 SAL_DLLPRIVATE const String& GetPreRedirectedURL() const; 266 SAL_DLLPRIVATE void SetOrigFilter_Impl( const SfxFilter* pFilter ); 267 268 // Diese Protokolle liefern MIME Typen 269 SAL_DLLPRIVATE sal_Bool SupportsMIME_Impl() const; 270 271 SAL_DLLPRIVATE void Init_Impl(); 272 SAL_DLLPRIVATE void ForceSynchronStream_Impl( sal_Bool bSynchron ); 273 274 SAL_DLLPRIVATE void GetLockingStream_Impl(); 275 SAL_DLLPRIVATE void GetMedium_Impl(); 276 SAL_DLLPRIVATE sal_Bool TryDirectTransfer( const ::rtl::OUString& aURL, SfxItemSet& aTargetSet ); 277 SAL_DLLPRIVATE void Transfer_Impl(); 278 SAL_DLLPRIVATE void CreateFileStream(); 279 SAL_DLLPRIVATE void SetUpdatePickList(sal_Bool); 280 SAL_DLLPRIVATE sal_Bool IsUpdatePickList() const; 281 282 //REMOVE void SetStorage_Impl( SvStorage* pStor ); 283 SAL_DLLPRIVATE void SetLongName(const String &rName) 284 { aLongName = rName; } 285 SAL_DLLPRIVATE const String & GetLongName() const { return aLongName; } 286 SAL_DLLPRIVATE ErrCode CheckOpenMode_Impl( sal_Bool bSilent, sal_Bool bAllowRO = sal_True ); 287 SAL_DLLPRIVATE sal_Bool IsDownloadDone_Impl(); 288 SAL_DLLPRIVATE sal_Bool IsPreview_Impl(); 289 SAL_DLLPRIVATE void ClearBackup_Impl(); 290 SAL_DLLPRIVATE void Done_Impl( ErrCode ); 291 SAL_DLLPRIVATE void DataAvailable_Impl(); 292 SAL_DLLPRIVATE void Cancel_Impl(); 293 SAL_DLLPRIVATE void SetPhysicalName_Impl(const String& rName); 294 SAL_DLLPRIVATE void CanDisposeStorage_Impl( sal_Bool bDisposeStorage ); 295 SAL_DLLPRIVATE sal_Bool WillDisposeStorageOnClose_Impl(); 296 297 SAL_DLLPRIVATE void DoBackup_Impl(); 298 SAL_DLLPRIVATE void DoInternalBackup_Impl( const ::ucbhelper::Content& aOriginalContent ); 299 SAL_DLLPRIVATE void DoInternalBackup_Impl( const ::ucbhelper::Content& aOriginalContent, 300 const String& aPrefix, 301 const String& aExtension, 302 const String& aDestDir ); 303 304 SAL_DLLPRIVATE sal_Bool UseBackupToRestore_Impl( ::ucbhelper::Content& aOriginalContent, 305 const ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XCommandEnvironment >& xComEnv ); 306 307 SAL_DLLPRIVATE sal_Bool StorageCommit_Impl(); 308 309 SAL_DLLPRIVATE sal_Bool TransactedTransferForFS_Impl( const INetURLObject& aSource, 310 const INetURLObject& aDest, 311 const ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XCommandEnvironment >& xComEnv ); 312 313 SAL_DLLPRIVATE sal_Bool SignContents_Impl( sal_Bool bScriptingContent, const ::rtl::OUString& aODFVersion, sal_Bool bHasValidDocumentSignature ); 314 315 // the following two methods must be used and make sence only during saving currently 316 // TODO/LATER: in future the signature state should be controlled by the medium not by the document 317 // in this case the methods will be used generally, and might need to be renamed 318 SAL_DLLPRIVATE sal_uInt16 GetCachedSignatureState_Impl(); 319 SAL_DLLPRIVATE void SetCachedSignatureState_Impl( sal_uInt16 nState ); 320 #endif 321 322 static com::sun::star::uno::Sequence < com::sun::star::util::RevisionTag > GetVersionList( 323 const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xStorage ); 324 static ::rtl::OUString CreateTempCopyWithExt( const ::rtl::OUString& aURL ); 325 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 ); 326 327 static sal_Bool SetWritableForUserOnly( const ::rtl::OUString& aURL ); 328 static sal_uInt32 CreatePasswordToModifyHash( const ::rtl::OUString& aPasswd, sal_Bool bWriter ); 329 }; 330 331 SV_DECL_IMPL_REF( SfxMedium ) 332 SV_DECL_COMPAT_WEAK( SfxMedium ) 333 334 #ifndef SFXMEDIUM_LIST 335 #define SFXMEDIUM_LIST 336 DECLARE_LIST( SfxMediumList, SfxMedium* ) 337 #endif 338 339 #endif 340 341