1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_SFX2_DOCFILE_HXX
21 #define INCLUDED_SFX2_DOCFILE_HXX
23 #include <com/sun/star/io/XSeekable.hpp>
24 #include <sal/config.h>
25 #include <sfx2/dllapi.h>
26 #include <sfx2/signaturestate.hxx>
27 #include <svl/lockfilecommon.hxx>
28 #include <sal/types.h>
29 #include <com/sun/star/util/RevisionTag.hpp>
30 #include <com/sun/star/util/DateTime.hpp>
31 #include <com/sun/star/io/XOutputStream.hpp>
32 #include <com/sun/star/io/XInputStream.hpp>
33 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
34 #include <com/sun/star/lang/XServiceInfo.hpp>
35 #include <com/sun/star/ucb/XContent.hpp>
36 #include <com/sun/star/ucb/XCommandEnvironment.hpp>
37 #include <com/sun/star/task/XInteractionHandler.hpp>
38 #include <com/sun/star/embed/XStorage.hpp>
39 #include <com/sun/star/beans/PropertyValue.hpp>
40 #include <cppuhelper/weak.hxx>
41 #include <rtl/ustring.hxx>
42 #include <svl/lstner.hxx>
43 #include <tools/link.hxx>
44 #include <tools/stream.hxx>
45 #include <ucbhelper/content.hxx>
47 class SvKeyValueIterator
;
48 class SfxObjectFactory
;
58 class SFX2_DLLPUBLIC SfxMedium
: public SvRefBase
62 SAL_DLLPRIVATE
void SetIsRemote_Impl();
63 SAL_DLLPRIVATE
void CloseInStream_Impl();
64 SAL_DLLPRIVATE
bool CloseOutStream_Impl();
65 SAL_DLLPRIVATE
void CloseStreams_Impl();
66 DECL_DLLPRIVATE_STATIC_LINK( SfxMedium
, UCBHdl_Impl
, sal_uInt32
* );
68 SAL_DLLPRIVATE
void SetEncryptionDataToStorage_Impl();
74 * @param pSet Takes ownership
76 SfxMedium( const OUString
&rName
,
78 const SfxFilter
*pFilter
= 0,
79 SfxItemSet
*pSet
= 0 );
81 * @param pSet Takes ownership
83 SfxMedium( const OUString
&rName
,
84 const OUString
&rReferer
,
86 const SfxFilter
*pFilter
= 0,
87 SfxItemSet
*pSet
= 0 );
90 * @param pSet does NOT take ownership
92 SfxMedium( const css::uno::Reference
< css::embed::XStorage
>& xStorage
,
93 const OUString
& rBaseURL
,
94 const SfxItemSet
* pSet
=0 );
96 * @param pSet does NOT take ownership
98 SfxMedium( const css::uno::Reference
< css::embed::XStorage
>& xStorage
,
99 const OUString
& rBaseURL
,
100 const OUString
& rTypeName
,
101 const SfxItemSet
* pSet
=0 );
102 SfxMedium( const css::uno::Sequence
< css::beans::PropertyValue
>& aArgs
);
104 virtual ~SfxMedium();
106 void UseInteractionHandler( bool );
107 css::uno::Reference
< css::task::XInteractionHandler
>
108 GetInteractionHandler();
110 void setStreamToLoadFrom(
111 const css::uno::Reference
<css::io::XInputStream
>& xInputStream
,
114 void SetLoadTargetFrame(SfxFrame
* pFrame
);
115 SfxFrame
* GetLoadTargetFrame() const;
117 void SetFilter(const SfxFilter
*pFlt
, bool bResetOrig
= false);
118 const SfxFilter
* GetFilter() const;
119 const SfxFilter
* GetOrigFilter( bool bNotCurrent
= false ) const;
120 const OUString
& GetOrigURL() const;
122 SfxItemSet
* GetItemSet() const;
124 void CloseAndRelease();
126 void CompleteReOpen();
127 const OUString
& GetName() const;
128 const INetURLObject
& GetURLObject() const;
130 void CheckFileDate( const css::util::DateTime
& aInitDate
);
131 SAL_WARN_UNUSED_RESULT
bool DocNeedsFileDateCheck() const;
132 css::util::DateTime
GetInitFileDate( bool bIgnoreOldValue
);
134 css::uno::Reference
< css::ucb::XContent
> GetContent() const;
135 const OUString
& GetPhysicalName() const;
136 SAL_WARN_UNUSED_RESULT
bool IsRemote() const;
137 SAL_WARN_UNUSED_RESULT
bool IsOpen() const; // { return aStorage.Is() || pInStream; }
138 void Download( const Link
<>& aLink
= Link
<>());
139 void SetDoneLink( const Link
<>& rLink
);
141 sal_uInt32
GetErrorCode() const;
142 sal_uInt32
GetError() const
143 { return ERRCODE_TOERROR(GetErrorCode()); }
144 sal_uInt32
GetLastStorageCreationState();
146 void SetError( sal_uInt32 nError
, const OUString
& aLogMessage
);
148 void AddLog( const OUString
& aMessage
);
150 void CloseInStream();
151 bool CloseOutStream();
155 StreamMode
GetOpenMode() const;
156 void SetOpenMode( StreamMode nStorOpen
, bool bDontClose
= false );
158 SvStream
* GetInStream();
159 SvStream
* GetOutStream();
164 sal_Int8
ShowLockedDocumentDialog( const LockFileEntry
& aData
, bool bIsLoading
, bool bOwnLock
);
165 void LockOrigFileOnDemand( bool bLoading
, bool bNoUI
);
166 void UnlockFile( bool bReleaseLockStream
);
168 css::uno::Reference
< css::embed::XStorage
> GetStorage( bool bCreateTempIfNo
= true );
169 css::uno::Reference
< css::embed::XStorage
> GetOutputStorage();
171 SAL_WARN_UNUSED_RESULT
bool UsesCache() const;
172 void SetUsesCache( bool );
173 SAL_WARN_UNUSED_RESULT
bool IsExpired() const;
174 void SetName( const OUString
& rName
, bool bSetOrigURL
= false );
175 SAL_WARN_UNUSED_RESULT
bool IsAllowedForExternalBrowser() const;
176 SAL_WARN_UNUSED_RESULT
long GetFileVersion() const;
178 const css::uno::Sequence
< css::util::RevisionTag
>&
179 GetVersionList( bool _bNoReload
= false );
180 SAL_WARN_UNUSED_RESULT
bool IsReadOnly() const;
182 // Whether the medium had originally been opened r/o, independent of later
183 // changes via SetOpenMode; used to keep track of the "true" state of the
184 // medium across toggles via SID_EDITDOC (which do change SetOpenMode):
185 SAL_WARN_UNUSED_RESULT
bool IsOriginallyReadOnly() const;
187 css::uno::Reference
< css::io::XInputStream
> GetInputStream();
189 void CreateTempFile( bool bReplace
= true );
190 void CreateTempFileNoCopy();
191 OUString
SwitchDocumentToTempFile();
192 bool SwitchDocumentToFile( const OUString
& aURL
);
194 OUString
GetBaseURL( bool bForSaving
=false );
195 void SetInCheckIn( bool bInCheckIn
);
197 bool IsSkipImages( );
199 SAL_DLLPRIVATE
bool HasStorage_Impl() const;
201 SAL_DLLPRIVATE
void StorageBackup_Impl();
202 SAL_DLLPRIVATE OUString
GetBackup_Impl();
204 SAL_DLLPRIVATE
css::uno::Reference
< css::embed::XStorage
> GetZipStorageToSign_Impl( bool bReadOnly
= true );
205 SAL_DLLPRIVATE
void CloseZipStorage_Impl();
207 // the storage that will be returned by the medium on GetStorage request
208 SAL_DLLPRIVATE
void SetStorage_Impl( const css::uno::Reference
< css::embed::XStorage
>& xNewStorage
);
210 SAL_DLLPRIVATE
css::uno::Reference
< css::io::XInputStream
> GetInputStream_Impl();
211 SAL_DLLPRIVATE
void CloseAndReleaseStreams_Impl();
212 SAL_DLLPRIVATE sal_uInt16
AddVersion_Impl( css::util::RevisionTag
& rVersion
);
213 SAL_DLLPRIVATE
bool TransferVersionList_Impl( SfxMedium
& rMedium
);
214 SAL_DLLPRIVATE
bool SaveVersionList_Impl( bool bUseXML
);
215 SAL_DLLPRIVATE
bool RemoveVersion_Impl( const OUString
& rVersion
);
217 SAL_DLLPRIVATE
void SetExpired_Impl( const DateTime
& rDateTime
);
218 SAL_DLLPRIVATE SvKeyValueIterator
* GetHeaderAttributes_Impl();
220 // Diese Protokolle liefern MIME Typen
221 SAL_DLLPRIVATE
bool SupportsMIME_Impl() const;
223 SAL_DLLPRIVATE
void Init_Impl();
224 SAL_DLLPRIVATE
void ForceSynchronStream_Impl( bool bSynchron
);
226 SAL_DLLPRIVATE
void GetLockingStream_Impl();
227 SAL_DLLPRIVATE
void GetMedium_Impl();
228 SAL_DLLPRIVATE
bool TryDirectTransfer( const OUString
& aURL
, SfxItemSet
& aTargetSet
);
229 SAL_DLLPRIVATE
void Transfer_Impl();
230 SAL_DLLPRIVATE
void CreateFileStream();
231 SAL_DLLPRIVATE
void SetUpdatePickList(bool);
232 SAL_DLLPRIVATE
bool IsUpdatePickList() const;
234 SAL_DLLPRIVATE
void SetLongName(const OUString
&rName
);
235 SAL_DLLPRIVATE
const OUString
& GetLongName() const;
236 SAL_DLLPRIVATE ErrCode
CheckOpenMode_Impl( bool bSilent
, bool bAllowRO
= true );
237 SAL_DLLPRIVATE
bool IsPreview_Impl();
238 SAL_DLLPRIVATE
void ClearBackup_Impl();
239 SAL_DLLPRIVATE
void Done_Impl( ErrCode
);
240 SAL_DLLPRIVATE
void SetPhysicalName_Impl(const OUString
& rName
);
241 SAL_DLLPRIVATE
void CanDisposeStorage_Impl( bool bDisposeStorage
);
242 SAL_DLLPRIVATE
bool WillDisposeStorageOnClose_Impl();
244 SAL_DLLPRIVATE
void DoBackup_Impl();
245 SAL_DLLPRIVATE
void DoInternalBackup_Impl( const ::ucbhelper::Content
& aOriginalContent
);
246 SAL_DLLPRIVATE
void DoInternalBackup_Impl( const ::ucbhelper::Content
& aOriginalContent
,
247 const OUString
& aPrefix
,
248 const OUString
& aExtension
,
249 const OUString
& aDestDir
);
251 SAL_DLLPRIVATE
bool UseBackupToRestore_Impl( ::ucbhelper::Content
& aOriginalContent
,
252 const css::uno::Reference
< css::ucb::XCommandEnvironment
>& xComEnv
);
254 SAL_DLLPRIVATE
bool StorageCommit_Impl();
256 SAL_DLLPRIVATE
bool TransactedTransferForFS_Impl( const INetURLObject
& aSource
,
257 const INetURLObject
& aDest
,
258 const css::uno::Reference
< css::ucb::XCommandEnvironment
>& xComEnv
);
260 SAL_DLLPRIVATE
bool SignContents_Impl( bool bScriptingContent
, const OUString
& aODFVersion
, bool bHasValidDocumentSignature
);
262 // the following two methods must be used and make sense only during saving currently
263 // TODO/LATER: in future the signature state should be controlled by the medium not by the document
264 // in this case the methods will be used generally, and might need to be renamed
265 SAL_DLLPRIVATE SignatureState
GetCachedSignatureState_Impl();
266 SAL_DLLPRIVATE
void SetCachedSignatureState_Impl( SignatureState nState
);
268 static css::uno::Sequence
< css::util::RevisionTag
> GetVersionList(
269 const css::uno::Reference
< css::embed::XStorage
>& xStorage
);
270 static OUString
CreateTempCopyWithExt( const OUString
& aURL
);
271 static bool CallApproveHandler(const css::uno::Reference
< css::task::XInteractionHandler
>& xHandler
, const css::uno::Any
& rRequest
, bool bAllowAbort
);
273 static bool SetWritableForUserOnly( const OUString
& aURL
);
274 static sal_uInt32
CreatePasswordToModifyHash( const OUString
& aPasswd
, bool bWriter
);
277 typedef tools::SvRef
<SfxMedium
> SfxMediumRef
;
281 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */