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 _SFXDOCFILE_HXX
21 #define _SFXDOCFILE_HXX
23 #include <com/sun/star/io/XSeekable.hpp>
24 #include "sal/config.h"
25 #include "sfx2/dllapi.h"
26 #include "sal/types.h"
27 #include <com/sun/star/util/RevisionTag.hpp>
28 #include <com/sun/star/util/DateTime.hpp>
29 #include <com/sun/star/io/XOutputStream.hpp>
30 #include <com/sun/star/io/XInputStream.hpp>
31 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
32 #include <com/sun/star/lang/XServiceInfo.hpp>
33 #include <com/sun/star/ucb/XContent.hpp>
34 #include <com/sun/star/ucb/XCommandEnvironment.hpp>
35 #include <com/sun/star/task/XInteractionHandler.hpp>
36 #include <com/sun/star/embed/XStorage.hpp>
37 #include <com/sun/star/beans/PropertyValue.hpp>
38 #include <tools/link.hxx>
39 #include <tools/stream.hxx>
40 #include <tools/string.hxx>
41 #include <svl/lstner.hxx>
43 #include <cppuhelper/weak.hxx>
44 #include <ucbhelper/content.hxx>
48 class SvKeyValueIterator
;
49 class SfxObjectFactory
;
59 class SFX2_DLLPUBLIC SfxMedium
: public SvRefBase
63 SAL_DLLPRIVATE
void SetIsRemote_Impl();
64 SAL_DLLPRIVATE
void CloseInStream_Impl();
65 SAL_DLLPRIVATE sal_Bool
CloseOutStream_Impl();
66 SAL_DLLPRIVATE
void CloseStreams_Impl();
67 DECL_DLLPRIVATE_STATIC_LINK( SfxMedium
, UCBHdl_Impl
, sal_uInt32
* );
69 SAL_DLLPRIVATE
void SetEncryptionDataToStorage_Impl();
75 * @param pSet Takes ownership
77 SfxMedium( const String
&rName
,
79 const SfxFilter
*pFilter
= 0,
80 SfxItemSet
*pSet
= 0 );
81 //TODO: the next, non-defined overload is only there to
82 // detect uses of the above (String, StreamMode, etc.)
83 // overload from when it still had an additional third
84 // parameter sal_Bool bDirect, where now a leftover
85 // "false" or "sal_False" could be mistaken for a null
86 // pointer argument for the pFilter parameter; it can be
87 // removed once we are confident all old uses of the
88 // original overload have been adapted (in platform
89 // specific code etc.):
90 SfxMedium(String
const &, StreamMode
, void *)
94 * @param pSet does NOT take ownership
96 SfxMedium( const css::uno::Reference
< css::embed::XStorage
>& xStorage
,
97 const String
& rBaseURL
,
98 const SfxItemSet
* pSet
=0 );
100 * @param pSet does NOT take ownership
102 SfxMedium( const css::uno::Reference
< css::embed::XStorage
>& xStorage
,
103 const String
& rBaseURL
,
104 const String
& rTypeName
,
105 const SfxItemSet
* pSet
=0 );
106 SfxMedium( const css::uno::Sequence
< css::beans::PropertyValue
>& aArgs
);
110 void UseInteractionHandler( sal_Bool
);
111 css::uno::Reference
< css::task::XInteractionHandler
>
112 GetInteractionHandler();
114 void setStreamToLoadFrom(
115 const css::uno::Reference
<css::io::XInputStream
>& xInputStream
,
116 sal_Bool bIsReadOnly
);
118 void SetLoadTargetFrame(SfxFrame
* pFrame
);
119 SfxFrame
* GetLoadTargetFrame() const;
121 void SetFilter(const SfxFilter
*pFlt
, sal_Bool bResetOrig
= sal_False
);
122 const SfxFilter
* GetFilter() const;
123 const SfxFilter
* GetOrigFilter( sal_Bool bNotCurrent
= sal_False
) const;
124 const OUString
& GetOrigURL() const;
126 SfxItemSet
* GetItemSet() const;
128 void CloseAndRelease();
130 void CompleteReOpen();
131 const OUString
& GetName() const;
132 const INetURLObject
& GetURLObject() const;
134 void CheckFileDate( const css::util::DateTime
& aInitDate
);
135 sal_Bool
DocNeedsFileDateCheck();
136 css::util::DateTime
GetInitFileDate( sal_Bool bIgnoreOldValue
);
138 css::uno::Reference
< css::ucb::XContent
> GetContent() const;
139 const OUString
& GetPhysicalName() const;
141 sal_Bool
IsOpen() const; // { return aStorage.Is() || pInStream; }
142 void DownLoad( const Link
& aLink
= Link());
143 void SetDoneLink( const Link
& rLink
);
145 sal_uInt32
GetErrorCode() const;
146 sal_uInt32
GetError() const
147 { return ERRCODE_TOERROR(GetErrorCode()); }
148 sal_uInt32
GetLastStorageCreationState();
150 void SetError( sal_uInt32 nError
, const OUString
& aLogMessage
);
152 void AddLog( const OUString
& aMessage
);
154 void CloseInStream();
155 sal_Bool
CloseOutStream();
159 StreamMode
GetOpenMode() const;
160 void SetOpenMode( StreamMode nStorOpen
, sal_Bool bDontClose
= sal_False
);
162 SvStream
* GetInStream();
163 SvStream
* GetOutStream();
166 sal_Bool
IsStorage();
168 sal_Int8
ShowLockedDocumentDialog( const css::uno::Sequence
< OUString
>& aData
, sal_Bool bIsLoading
, sal_Bool bOwnLock
);
169 bool LockOrigFileOnDemand( sal_Bool bLoading
, sal_Bool bNoUI
);
170 void UnlockFile( sal_Bool bReleaseLockStream
);
172 css::uno::Reference
< css::embed::XStorage
> GetStorage( sal_Bool bCreateTempIfNo
= sal_True
);
173 css::uno::Reference
< css::embed::XStorage
> GetOutputStorage();
175 sal_Bool
UsesCache() const;
176 void SetUsesCache( sal_Bool
);
177 sal_Bool
IsExpired() const;
178 void SetName( const String
& rName
, sal_Bool bSetOrigURL
= sal_False
);
179 sal_Bool
IsAllowedForExternalBrowser() const;
180 long GetFileVersion() const;
182 const css::uno::Sequence
< css::util::RevisionTag
>&
183 GetVersionList( bool _bNoReload
= false );
184 sal_Bool
IsReadOnly();
186 // Whether the medium had originally been opened r/o, independent of later
187 // changes via SetOpenMode; used to keep track of the "true" state of the
188 // medium across toggles via SID_EDITDOC (which do change SetOpenMode):
189 bool IsOriginallyReadOnly() const;
191 css::uno::Reference
< css::io::XInputStream
> GetInputStream();
193 void CreateTempFile( sal_Bool bReplace
= sal_True
);
194 void CreateTempFileNoCopy();
195 OUString
SwitchDocumentToTempFile();
196 sal_Bool
SwitchDocumentToFile( const OUString
& aURL
);
198 OUString
GetBaseURL( bool bForSaving
=false );
199 void SetInCheckIn( bool bInCheckIn
);
202 SAL_DLLPRIVATE sal_Bool
HasStorage_Impl() const;
204 SAL_DLLPRIVATE
void StorageBackup_Impl();
205 SAL_DLLPRIVATE OUString
GetBackup_Impl();
207 SAL_DLLPRIVATE
css::uno::Reference
< css::embed::XStorage
> GetZipStorageToSign_Impl( sal_Bool bReadOnly
= sal_True
);
208 SAL_DLLPRIVATE
void CloseZipStorage_Impl();
210 // the storage that will be returned by the medium on GetStorage request
211 SAL_DLLPRIVATE
void SetStorage_Impl( const css::uno::Reference
< css::embed::XStorage
>& xNewStorage
);
213 SAL_DLLPRIVATE
css::uno::Reference
< css::io::XInputStream
> GetInputStream_Impl();
214 SAL_DLLPRIVATE
void CloseAndReleaseStreams_Impl();
215 SAL_DLLPRIVATE sal_uInt16
AddVersion_Impl( css::util::RevisionTag
& rVersion
);
216 SAL_DLLPRIVATE sal_Bool
TransferVersionList_Impl( SfxMedium
& rMedium
);
217 SAL_DLLPRIVATE sal_Bool
SaveVersionList_Impl( sal_Bool bUseXML
);
218 SAL_DLLPRIVATE sal_Bool
RemoveVersion_Impl( const OUString
& rVersion
);
220 SAL_DLLPRIVATE
void SetExpired_Impl( const DateTime
& rDateTime
);
221 SAL_DLLPRIVATE SvKeyValueIterator
* GetHeaderAttributes_Impl();
223 // Diese Protokolle liefern MIME Typen
224 SAL_DLLPRIVATE sal_Bool
SupportsMIME_Impl() const;
226 SAL_DLLPRIVATE
void Init_Impl();
227 SAL_DLLPRIVATE
void ForceSynchronStream_Impl( sal_Bool bSynchron
);
229 SAL_DLLPRIVATE
void GetLockingStream_Impl();
230 SAL_DLLPRIVATE
void GetMedium_Impl();
231 SAL_DLLPRIVATE sal_Bool
TryDirectTransfer( const OUString
& aURL
, SfxItemSet
& aTargetSet
);
232 SAL_DLLPRIVATE
void Transfer_Impl();
233 SAL_DLLPRIVATE
void CreateFileStream();
234 SAL_DLLPRIVATE
void SetUpdatePickList(sal_Bool
);
235 SAL_DLLPRIVATE sal_Bool
IsUpdatePickList() const;
237 SAL_DLLPRIVATE
void SetLongName(const OUString
&rName
);
238 SAL_DLLPRIVATE
const OUString
& GetLongName() const;
239 SAL_DLLPRIVATE ErrCode
CheckOpenMode_Impl( sal_Bool bSilent
, sal_Bool bAllowRO
= sal_True
);
240 SAL_DLLPRIVATE sal_Bool
IsPreview_Impl();
241 SAL_DLLPRIVATE
void ClearBackup_Impl();
242 SAL_DLLPRIVATE
void Done_Impl( ErrCode
);
243 SAL_DLLPRIVATE
void SetPhysicalName_Impl(const OUString
& rName
);
244 SAL_DLLPRIVATE
void CanDisposeStorage_Impl( sal_Bool bDisposeStorage
);
245 SAL_DLLPRIVATE sal_Bool
WillDisposeStorageOnClose_Impl();
247 SAL_DLLPRIVATE
void DoBackup_Impl();
248 SAL_DLLPRIVATE
void DoInternalBackup_Impl( const ::ucbhelper::Content
& aOriginalContent
);
249 SAL_DLLPRIVATE
void DoInternalBackup_Impl( const ::ucbhelper::Content
& aOriginalContent
,
250 const String
& aPrefix
,
251 const String
& aExtension
,
252 const String
& aDestDir
);
254 SAL_DLLPRIVATE sal_Bool
UseBackupToRestore_Impl( ::ucbhelper::Content
& aOriginalContent
,
255 const css::uno::Reference
< css::ucb::XCommandEnvironment
>& xComEnv
);
257 SAL_DLLPRIVATE sal_Bool
StorageCommit_Impl();
259 SAL_DLLPRIVATE sal_Bool
TransactedTransferForFS_Impl( const INetURLObject
& aSource
,
260 const INetURLObject
& aDest
,
261 const css::uno::Reference
< css::ucb::XCommandEnvironment
>& xComEnv
);
263 SAL_DLLPRIVATE sal_Bool
SignContents_Impl( sal_Bool bScriptingContent
, const OUString
& aODFVersion
, sal_Bool bHasValidDocumentSignature
);
265 // the following two methods must be used and make sence only during saving currently
266 // TODO/LATER: in future the signature state should be controlled by the medium not by the document
267 // in this case the methods will be used generally, and might need to be renamed
268 SAL_DLLPRIVATE sal_uInt16
GetCachedSignatureState_Impl();
269 SAL_DLLPRIVATE
void SetCachedSignatureState_Impl( sal_uInt16 nState
);
271 static css::uno::Sequence
< css::util::RevisionTag
> GetVersionList(
272 const css::uno::Reference
< css::embed::XStorage
>& xStorage
);
273 static OUString
CreateTempCopyWithExt( const OUString
& aURL
);
274 static sal_Bool
CallApproveHandler( const css::uno::Reference
< css::task::XInteractionHandler
>& xHandler
, css::uno::Any aRequest
, sal_Bool bAllowAbort
);
276 static sal_Bool
SetWritableForUserOnly( const OUString
& aURL
);
277 static sal_uInt32
CreatePasswordToModifyHash( const OUString
& aPasswd
, sal_Bool bWriter
);
280 SV_DECL_IMPL_REF( SfxMedium
)
282 typedef ::std::vector
< SfxMedium
* > SfxMediumList
;
286 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */