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