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_UNOTOOLS_MEDIADESCRIPTOR_HXX
21 #define INCLUDED_UNOTOOLS_MEDIADESCRIPTOR_HXX
23 #include <sal/config.h>
27 #include <comphelper/docpasswordrequest.hxx>
28 #include <comphelper/sequenceashashmap.hxx>
29 #include <rtl/ustring.hxx>
30 #include <unotools/unotoolsdllapi.h>
32 namespace com::sun::star::io
{
35 namespace comphelper
{ class IDocPasswordVerifier
; }
39 /** @short can be used to work with a css::document::MediaDescriptor
42 @descr It wraps an unordered_map around the Sequence< css::beans::PropertyValue >, which
43 represent the MediaDescriptor item.
44 Further this helper defines often used functions (as e.g. open of the required streams,
45 consistent checks etcpp.) and it defines all usable property names.
47 @attention This class isn't threadsafe and must be guarded from outside!
49 class UNOTOOLS_DLLPUBLIC MediaDescriptor
: public comphelper::SequenceAsHashMap
53 /** @short these methods can be used to get the different property names
54 as static const OUString values.
56 @descr Because definition and declaration of static const class members
57 does not work as expected under windows (under unix it works as well)
58 these way must be used :-(
60 static constexpr OUStringLiteral PROP_ABORTED
= u
"Aborted";
61 static constexpr OUStringLiteral PROP_ASTEMPLATE
= u
"AsTemplate";
62 static constexpr OUStringLiteral PROP_COMPONENTDATA
= u
"ComponentData";
63 static constexpr OUStringLiteral PROP_DOCUMENTSERVICE
= u
"DocumentService";
64 static constexpr OUStringLiteral PROP_ENCRYPTIONDATA
= u
"EncryptionData";
65 static constexpr OUStringLiteral PROP_FILENAME
= u
"FileName";
66 static constexpr OUStringLiteral PROP_FILTERNAME
= u
"FilterName";
67 static constexpr OUStringLiteral PROP_FILTERPROVIDER
= u
"FilterProvider";
68 static constexpr OUStringLiteral PROP_FILTEROPTIONS
= u
"FilterOptions";
69 static constexpr OUStringLiteral PROP_FRAME
= u
"Frame";
70 static constexpr OUStringLiteral PROP_FRAMENAME
= u
"FrameName";
71 static constexpr OUStringLiteral PROP_HIDDEN
= u
"Hidden";
72 static constexpr OUStringLiteral PROP_INPUTSTREAM
= u
"InputStream";
73 static constexpr OUStringLiteral PROP_INTERACTIONHANDLER
= u
"InteractionHandler";
74 static constexpr OUStringLiteral PROP_AUTHENTICATIONHANDLER
= u
"AuthenticationHandler";
75 static constexpr OUStringLiteral PROP_JUMPMARK
= u
"JumpMark";
76 static constexpr OUStringLiteral PROP_MACROEXECUTIONMODE
= u
"MacroExecutionMode";
77 static constexpr OUStringLiteral PROP_MEDIATYPE
= u
"MediaType";
78 static constexpr OUStringLiteral PROP_MINIMIZED
= u
"Minimized";
79 static constexpr OUStringLiteral PROP_NOAUTOSAVE
= u
"NoAutoSave";
80 static constexpr OUStringLiteral PROP_OPENNEWVIEW
= u
"OpenNewView";
81 static constexpr OUStringLiteral PROP_OUTPUTSTREAM
= u
"OutputStream";
82 static constexpr OUStringLiteral PROP_PASSWORD
= u
"Password";
83 static constexpr OUStringLiteral PROP_POSTDATA
= u
"PostData";
84 static constexpr OUStringLiteral PROP_PREVIEW
= u
"Preview";
85 static constexpr OUStringLiteral PROP_READONLY
= u
"ReadOnly";
86 static constexpr OUStringLiteral PROP_REFERRER
= u
"Referer";
87 static constexpr OUStringLiteral PROP_REPLACEABLE
= u
"Replaceable";
88 static constexpr OUStringLiteral PROP_SALVAGEDFILE
= u
"SalvagedFile";
89 static constexpr OUStringLiteral PROP_SILENT
= u
"Silent";
90 static constexpr OUStringLiteral PROP_STATUSINDICATOR
= u
"StatusIndicator";
91 static constexpr OUStringLiteral PROP_STREAM
= u
"Stream";
92 static constexpr OUStringLiteral PROP_STREAMFOROUTPUT
= u
"StreamForOutput";
93 static constexpr OUStringLiteral PROP_TEMPLATENAME
= u
"TemplateName";
94 static constexpr OUStringLiteral PROP_TITLE
= u
"Title";
95 static constexpr OUStringLiteral PROP_TYPENAME
= u
"TypeName";
96 static constexpr OUStringLiteral PROP_UCBCONTENT
= u
"UCBContent";
97 static constexpr OUStringLiteral PROP_UPDATEDOCMODE
= u
"UpdateDocMode";
98 static constexpr OUStringLiteral PROP_URL
= u
"URL";
99 static constexpr OUStringLiteral PROP_VERSION
= u
"Version";
100 static constexpr OUStringLiteral PROP_DOCUMENTTITLE
= u
"DocumentTitle";
101 static constexpr OUStringLiteral PROP_MODEL
= u
"Model";
102 static constexpr OUStringLiteral PROP_VIEWONLY
= u
"ViewOnly";
103 static constexpr OUStringLiteral PROP_DOCUMENTBASEURL
= u
"DocumentBaseURL";
104 static constexpr OUStringLiteral PROP_SUGGESTEDSAVEASNAME
= u
"SuggestedSaveAsName";
109 /** @short these ctors do nothing - excepting that they forward
110 the given parameters to the base class ctors.
112 @descr The ctors must be overwritten to resolve conflicts with
113 the default ctors of the compiler :-(.
116 MediaDescriptor(const css::uno::Sequence
< css::beans::PropertyValue
>& lSource
);
118 /** @short it checks if the descriptor already has a valid
119 InputStream item and creates a new one, if not.
121 @descr This method uses the current items of this MediaDescriptor,
122 to open the stream (as e.g. URL, ReadOnly, PostData etcpp.).
123 It creates a seekable stream and put it into the descriptor.
125 A might existing InteractionHandler will be used automatically,
128 In case of local file the system file locking is used.
130 @return TRUE, if the stream was already part of the descriptor or could
131 be created as new item. FALSE otherwise.
133 bool addInputStream();
135 /** @short it checks if the descriptor already has a valid
136 InputStream item and creates a new one, if not.
138 @descr This method uses the current items of this MediaDescriptor,
139 to open the stream (as e.g. URL, ReadOnly, PostData etcpp.).
140 It creates a seekable stream and put it into the descriptor.
142 A might existing InteractionHandler will be used automatically,
145 In case of local file the system file locking is used based on
146 configuration settings.
148 @return TRUE, if the stream was already part of the descriptor or could
149 be created as new item. FALSE otherwise.
151 bool addInputStreamOwnLock();
153 /** @short it checks if the descriptor describes a readonly stream.
155 @descr The descriptor itself isn't changed doing so.
156 It's only checked if the stream seems to be based
157 of a real readonly file.
160 We don't check the property "ReadOnly" here. Because
161 this property can be set from outside and overwrites
162 the readonly state of the stream.
163 If e.g. the stream could be opened read/write ...
164 but "ReadOnly" property is set to TRUE, this means:
165 show a readonly UI on top of this read/write stream.
167 @return TRUE, if the stream must be interpreted as readonly ...
170 bool isStreamReadOnly() const;
172 /** Returns a value from the sequence contained in the property
173 'ComponentData' of this media descriptor.
175 @descr The property 'ComponentData' should be empty, or should
176 contain a value of type sequence<com.sun.star.beans.NamedValue>
177 or sequence<com.sun.star.beans.PropertyValue>.
179 @return The value with the specified name, if existing in the
180 sequence of the 'ComponentData' property, otherwise an empty
183 css::uno::Any
getComponentDataEntry(
184 const OUString
& rName
) const;
186 /** Inserts a value into the sequence contained in the property
187 'ComponentData' of the media descriptor.
189 @descr The property 'ComponentData' should be empty, or should
190 contain a value of type sequence<com.sun.star.beans.NamedValue>
191 or sequence<com.sun.star.beans.PropertyValue>. The passed value
192 will be inserted into the sequence, or, if already existing,
195 @param rName The name of the value to be inserted into the
196 sequence of the 'ComponentData' property.
198 @param rValue The value to be inserted into the sequence of the
199 'ComponentData' property.
201 void setComponentDataEntry(
202 const OUString
& rName
,
203 const css::uno::Any
& rValue
);
205 /** Removes a value from the sequence contained in the property
206 'ComponentData' of the media descriptor.
208 @descr The property 'ComponentData' should be empty, or should
209 contain a value of type sequence<com.sun.star.beans.NamedValue>
210 or sequence<com.sun.star.beans.PropertyValue>. The value with
211 the passed name will be removed from the sequence, if existing.
213 @param rName The name of the value to be removed from the sequence
214 of the 'ComponentData' property.
216 void clearComponentDataEntry(
217 const OUString
& rName
);
219 /** This helper function tries to find a password for the document
220 described by this media descriptor.
222 First, the list of default passwords will be tried if provided. This
223 is needed by import filters for external file formats that have to
224 check a predefined password in some cases without asking the user
225 for a password. Every password is checked using the passed password
228 If not successful, this media descriptor is asked for a password,
229 that has been set e.g. by an API call to load a document. If
230 existing, the password is checked using the passed password
233 If still not successful, the interaction handler contained in this
234 media descriptor is used to request a password from the user. This
235 will be repeated until the passed password verifier validates the
236 entered password, or if the user chooses to cancel password input.
238 If a valid password (that is not contained in the passed list of
239 default passwords) was found, it will be inserted into the
240 "Password" property of this descriptor.
243 The password verifier used to check every processed password.
246 The password request type that will be passed to the
247 DocPasswordRequest object created internally. See
248 docpasswordrequest.hxx for more details.
250 @param pDefaultPasswords
251 If not null, contains default passwords that will be tried before a
252 password will be requested from the media descriptor or the user.
255 If not empty, contains the password that has been validated by the
256 passed password verifier. If empty, no valid password has been
257 found, or the user has chosen to cancel password input.
259 css::uno::Sequence
< css::beans::NamedValue
> requestAndVerifyDocPassword(
260 comphelper::IDocPasswordVerifier
& rVerifier
,
261 comphelper::DocPasswordRequestType eRequestType
,
262 const ::std::vector
< OUString
>* pDefaultPasswords
);
267 /** @short tries to open a stream by using the given PostData stream.
269 @descr The stream is used directly ...
271 The MediaDescriptor itself is changed inside this method.
272 Means: the stream is added internal and not returned by a value.
277 @return TRUE if the stream could be added successfully.
278 Note: If FALSE is returned, the error was already handled inside!
280 @throw [css::uno::RuntimeException]
281 if the MediaDescriptor seems to be invalid!
283 @throw [css::lang::IllegalArgumentException]
284 if the given PostData stream is <NULL/>.
286 SAL_DLLPRIVATE
bool impl_openStreamWithPostData(
287 const css::uno::Reference
< css::io::XInputStream
>& _rxPostData
290 /** @short tries to open a stream by using the given URL.
292 @descr First it tries to open the content in r/w mode (if its
293 allowed to do so). Only in case it's not allowed or it failed
294 the stream will be tried to open in readonly mode.
296 The MediaDescriptor itself is changed inside this method.
297 Means: the stream is added internal and not returned by a value.
303 specifies whether the file should be locked
305 @return TRUE if the stream could be added successfully.
306 Note: If FALSE is returned, the error was already handled inside!
308 @throw [css::uno::RuntimeException]
309 if the MediaDescriptor seems to be invalid!
311 SAL_DLLPRIVATE
bool impl_openStreamWithURL(
312 const OUString
& sURL
,
316 /** @short it checks if the descriptor already has a valid
317 InputStream item and creates a new one, if not.
319 @descr This method uses the current items of this MediaDescriptor,
320 to open the stream (as e.g. URL, ReadOnly, PostData etcpp.).
321 It creates a seekable stream and put it into the descriptor.
323 A might existing InteractionHandler will be used automatically,
327 specifies whether the file should be locked
329 @return TRUE, if the stream was already part of the descriptor or could
330 be created as new item. FALSE otherwise.
332 SAL_DLLPRIVATE
bool impl_addInputStream( bool bLockFile
);
339 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */