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