Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #ifndef INCLUDED_SFX2_DOCFILE_HXX
21 : #define INCLUDED_SFX2_DOCFILE_HXX
22 :
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>
46 :
47 : class SvKeyValueIterator;
48 : class SfxObjectFactory;
49 : class SfxFilter;
50 : class SfxMedium_Impl;
51 : class INetURLObject;
52 : class SfxObjectShell;
53 : class SfxFrame;
54 : class Timer;
55 : class SfxItemSet;
56 : class DateTime;
57 :
58 : class SFX2_DLLPUBLIC SfxMedium : public SvRefBase
59 : {
60 : SfxMedium_Impl* pImp;
61 :
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 * );
67 :
68 : SAL_DLLPRIVATE void SetEncryptionDataToStorage_Impl();
69 :
70 : public:
71 :
72 : SfxMedium();
73 : /**
74 : * @param pSet Takes ownership
75 : */
76 : SfxMedium( const OUString &rName,
77 : StreamMode nOpenMode,
78 : const SfxFilter *pFilter = 0,
79 : SfxItemSet *pSet = 0 );
80 : /**
81 : * @param pSet Takes ownership
82 : */
83 : SfxMedium( const OUString &rName,
84 : const OUString &rReferer,
85 : StreamMode nOpenMode,
86 : const SfxFilter *pFilter = 0,
87 : SfxItemSet *pSet = 0 );
88 :
89 : /**
90 : * @param pSet does NOT take ownership
91 : */
92 : SfxMedium( const css::uno::Reference< css::embed::XStorage >& xStorage,
93 : const OUString& rBaseURL,
94 : const SfxItemSet* pSet=0 );
95 : /**
96 : * @param pSet does NOT take ownership
97 : */
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 );
103 :
104 : virtual ~SfxMedium();
105 :
106 : void UseInteractionHandler( bool );
107 : css::uno::Reference< css::task::XInteractionHandler >
108 : GetInteractionHandler();
109 :
110 : void setStreamToLoadFrom(
111 : const css::uno::Reference<css::io::XInputStream>& xInputStream,
112 : bool bIsReadOnly);
113 :
114 : void SetLoadTargetFrame(SfxFrame* pFrame );
115 : SfxFrame* GetLoadTargetFrame() const;
116 :
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;
121 :
122 : SfxItemSet * GetItemSet() const;
123 : void Close();
124 : void CloseAndRelease();
125 : void ReOpen();
126 : void CompleteReOpen();
127 : const OUString& GetName() const;
128 : const INetURLObject& GetURLObject() const;
129 :
130 : void CheckFileDate( const css::util::DateTime& aInitDate );
131 : SAL_WARN_UNUSED_RESULT bool DocNeedsFileDateCheck() const;
132 : css::util::DateTime GetInitFileDate( bool bIgnoreOldValue );
133 :
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 );
140 :
141 : sal_uInt32 GetErrorCode() const;
142 57027 : sal_uInt32 GetError() const
143 57027 : { return ERRCODE_TOERROR(GetErrorCode()); }
144 : sal_uInt32 GetLastStorageCreationState();
145 :
146 : void SetError( sal_uInt32 nError, const OUString& aLogMessage );
147 :
148 : void AddLog( const OUString& aMessage );
149 :
150 : void CloseInStream();
151 : bool CloseOutStream();
152 :
153 : void CloseStorage();
154 :
155 : StreamMode GetOpenMode() const;
156 : void SetOpenMode( StreamMode nStorOpen, bool bDontClose = false );
157 :
158 : SvStream* GetInStream();
159 : SvStream* GetOutStream();
160 :
161 : bool Commit();
162 : bool IsStorage();
163 :
164 : sal_Int8 ShowLockedDocumentDialog( const LockFileEntry& aData, bool bIsLoading, bool bOwnLock );
165 : void LockOrigFileOnDemand( bool bLoading, bool bNoUI );
166 : void UnlockFile( bool bReleaseLockStream );
167 :
168 : css::uno::Reference< css::embed::XStorage > GetStorage( bool bCreateTempIfNo = true );
169 : css::uno::Reference< css::embed::XStorage > GetOutputStorage();
170 : void ResetError();
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;
177 :
178 : const css::uno::Sequence < css::util::RevisionTag >&
179 : GetVersionList( bool _bNoReload = false );
180 : SAL_WARN_UNUSED_RESULT bool IsReadOnly() const;
181 :
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;
186 :
187 : css::uno::Reference< css::io::XInputStream > GetInputStream();
188 :
189 : void CreateTempFile( bool bReplace = true );
190 : void CreateTempFileNoCopy();
191 : OUString SwitchDocumentToTempFile();
192 : bool SwitchDocumentToFile( const OUString& aURL );
193 :
194 : OUString GetBaseURL( bool bForSaving=false );
195 : void SetInCheckIn( bool bInCheckIn );
196 : bool IsInCheckIn( );
197 : bool IsSkipImages( );
198 :
199 : SAL_DLLPRIVATE bool HasStorage_Impl() const;
200 :
201 : SAL_DLLPRIVATE void StorageBackup_Impl();
202 : SAL_DLLPRIVATE OUString GetBackup_Impl();
203 :
204 : SAL_DLLPRIVATE css::uno::Reference< css::embed::XStorage > GetZipStorageToSign_Impl( bool bReadOnly = true );
205 : SAL_DLLPRIVATE void CloseZipStorage_Impl();
206 :
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 );
209 :
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 );
216 :
217 : SAL_DLLPRIVATE void SetExpired_Impl( const DateTime& rDateTime );
218 : SAL_DLLPRIVATE SvKeyValueIterator* GetHeaderAttributes_Impl();
219 :
220 : // Diese Protokolle liefern MIME Typen
221 : SAL_DLLPRIVATE bool SupportsMIME_Impl() const;
222 :
223 : SAL_DLLPRIVATE void Init_Impl();
224 : SAL_DLLPRIVATE void ForceSynchronStream_Impl( bool bSynchron );
225 :
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;
233 :
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();
243 :
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 );
250 :
251 : SAL_DLLPRIVATE bool UseBackupToRestore_Impl( ::ucbhelper::Content& aOriginalContent,
252 : const css::uno::Reference< css::ucb::XCommandEnvironment >& xComEnv );
253 :
254 : SAL_DLLPRIVATE bool StorageCommit_Impl();
255 :
256 : SAL_DLLPRIVATE bool TransactedTransferForFS_Impl( const INetURLObject& aSource,
257 : const INetURLObject& aDest,
258 : const css::uno::Reference< css::ucb::XCommandEnvironment >& xComEnv );
259 :
260 : SAL_DLLPRIVATE bool SignContents_Impl( bool bScriptingContent, const OUString& aODFVersion, bool bHasValidDocumentSignature );
261 :
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 );
267 :
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);
272 :
273 : static bool SetWritableForUserOnly( const OUString& aURL );
274 : static sal_uInt32 CreatePasswordToModifyHash( const OUString& aPasswd, bool bWriter );
275 : };
276 :
277 : typedef tools::SvRef<SfxMedium> SfxMediumRef;
278 :
279 : #endif
280 :
281 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|