bump product version to 6.3.0.0.beta1
[LibreOffice.git] / include / unotools / mediadescriptor.hxx
blobb568bd770f3a5b9741569bf760d37f6031f1aab8
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
25 #include <vector>
27 #include <comphelper/docpasswordrequest.hxx>
28 #include <comphelper/sequenceashashmap.hxx>
29 #include <rtl/ustring.hxx>
30 #include <unotools/unotoolsdllapi.h>
32 namespace com { namespace sun { namespace star { namespace io {
33 class XInputStream;
34 } } } }
35 namespace comphelper { class IDocPasswordVerifier; }
37 namespace utl {
39 /** @short can be used to work with a css::document::MediaDescriptor
40 struct.
42 @descr It wraps a 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
51 public:
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 const OUString& PROP_ABORTED();
61 static const OUString& PROP_ASTEMPLATE();
62 static const OUString& PROP_COMPONENTDATA();
63 static const OUString& PROP_DOCUMENTSERVICE();
64 static const OUString& PROP_ENCRYPTIONDATA();
65 static const OUString& PROP_FILENAME();
66 static const OUString& PROP_FILTERNAME();
67 static const OUString& PROP_FILTERPROVIDER();
68 static const OUString& PROP_FILTEROPTIONS();
69 static const OUString& PROP_FRAME();
70 static const OUString& PROP_FRAMENAME();
71 static const OUString& PROP_HIDDEN();
72 static const OUString& PROP_INPUTSTREAM();
73 static const OUString& PROP_INTERACTIONHANDLER();
74 static const OUString& PROP_AUTHENTICATIONHANDLER();
75 static const OUString& PROP_JUMPMARK();
76 static const OUString& PROP_MACROEXECUTIONMODE();
77 static const OUString& PROP_MEDIATYPE();
78 static const OUString& PROP_MINIMIZED();
79 static const OUString& PROP_NOAUTOSAVE();
80 static const OUString& PROP_OPENNEWVIEW();
81 static const OUString& PROP_OUTPUTSTREAM();
82 static const OUString& PROP_PASSWORD();
83 static const OUString& PROP_POSTDATA();
84 static const OUString& PROP_PREVIEW();
85 static const OUString& PROP_READONLY();
86 static const OUString& PROP_REFERRER();
87 static const OUString& PROP_SALVAGEDFILE();
88 static const OUString& PROP_STATUSINDICATOR();
89 static const OUString& PROP_STREAM();
90 static const OUString& PROP_STREAMFOROUTPUT();
91 static const OUString& PROP_TEMPLATENAME();
92 static const OUString& PROP_TITLE();
93 static const OUString& PROP_TYPENAME();
94 static const OUString& PROP_UCBCONTENT();
95 static const OUString& PROP_UPDATEDOCMODE();
96 static const OUString& PROP_URL();
97 static const OUString& PROP_VERSION();
98 static const OUString& PROP_DOCUMENTTITLE();
99 static const OUString& PROP_MODEL();
100 static const OUString& PROP_VIEWONLY();
101 static const OUString& PROP_DOCUMENTBASEURL();
102 static const OUString& PROP_SUGGESTEDSAVEASNAME();
104 // interface
105 public:
107 /** @short these ctors do nothing - excepting that they forward
108 the given parameters to the base class ctors.
110 @descr The ctors must be overwritten to resolve conflicts with
111 the default ctors of the compiler :-(.
113 MediaDescriptor();
114 MediaDescriptor(const css::uno::Sequence< css::beans::PropertyValue >& lSource);
116 /** @short it checks if the descriptor already has a valid
117 InputStream item and creates a new one, if not.
119 @descr This method uses the current items of this MediaDescriptor,
120 to open the stream (as e.g. URL, ReadOnly, PostData etcpp.).
121 It creates a seekable stream and put it into the descriptor.
123 A might existing InteractionHandler will be used automatically,
124 to solve problems!
126 In case of local file the system file locking is used.
128 @return TRUE, if the stream was already part of the descriptor or could
129 be created as new item. FALSE otherwise.
131 bool addInputStream();
133 /** @short it checks if the descriptor already has a valid
134 InputStream item and creates a new one, if not.
136 @descr This method uses the current items of this MediaDescriptor,
137 to open the stream (as e.g. URL, ReadOnly, PostData etcpp.).
138 It creates a seekable stream and put it into the descriptor.
140 A might existing InteractionHandler will be used automatically,
141 to solve problems!
143 In case of local file the system file locking is used based on
144 configuration settings.
146 @return TRUE, if the stream was already part of the descriptor or could
147 be created as new item. FALSE otherwise.
149 bool addInputStreamOwnLock();
151 /** @short it checks if the descriptor describes a readonly stream.
153 @descr The descriptor itself isn't changed doing so.
154 It's only checked if the stream seems to be based
155 of a real readonly file.
157 @Attention
158 We don't check the property "ReadOnly" here. Because
159 this property can be set from outside and overwrites
160 the readonly state of the stream.
161 If e.g. the stream could be opened read/write ...
162 but "ReadOnly" property is set to TRUE, this means:
163 show a readonly UI on top of this read/write stream.
165 @return TRUE, if the stream must be interpreted as readonly ...
166 FALSE otherwise.
168 bool isStreamReadOnly() const;
170 /** Returns a value from the sequence contained in the property
171 'ComponentData' of this media descriptor.
173 @descr The property 'ComponentData' should be empty, or should
174 contain a value of type sequence<com.sun.star.beans.NamedValue>
175 or sequence<com.sun.star.beans.PropertyValue>.
177 @return The value with the specified name, if existing in the
178 sequence of the 'ComponentData' property, otherwise an empty
179 Any.
181 css::uno::Any getComponentDataEntry(
182 const OUString& rName ) const;
184 /** Inserts a value into the sequence contained in the property
185 'ComponentData' of the media descriptor.
187 @descr The property 'ComponentData' should be empty, or should
188 contain a value of type sequence<com.sun.star.beans.NamedValue>
189 or sequence<com.sun.star.beans.PropertyValue>. The passed value
190 will be inserted into the sequence, or, if already existing,
191 will be overwritten.
193 @param rName The name of the value to be inserted into the
194 sequence of the 'ComponentData' property.
196 @param rValue The value to be inserted into the sequence of the
197 'ComponentData' property.
199 void setComponentDataEntry(
200 const OUString& rName,
201 const css::uno::Any& rValue );
203 /** Removes a value from the sequence contained in the property
204 'ComponentData' of the media descriptor.
206 @descr The property 'ComponentData' should be empty, or should
207 contain a value of type sequence<com.sun.star.beans.NamedValue>
208 or sequence<com.sun.star.beans.PropertyValue>. The value with
209 the passed name will be removed from the sequence, if existing.
211 @param rName The name of the value to be removed from the sequence
212 of the 'ComponentData' property.
214 void clearComponentDataEntry(
215 const OUString& rName );
217 /** This helper function tries to find a password for the document
218 described by this media descriptor.
220 First, the list of default passwords will be tried if provided. This
221 is needed by import filters for external file formats that have to
222 check a predefined password in some cases without asking the user
223 for a password. Every password is checked using the passed password
224 verifier.
226 If not successful, this media descriptor is asked for a password,
227 that has been set e.g. by an API call to load a document. If
228 existing, the password is checked using the passed password
229 verifier.
231 If still not successful, the interaction handler contained in this
232 media descriptor is used to request a password from the user. This
233 will be repeated until the passed password verifier validates the
234 entered password, or if the user chooses to cancel password input.
236 If a valid password (that is not contained in the passed list of
237 default passwords) was found, it will be inserted into the
238 "Password" property of this descriptor.
240 @param rVerifier
241 The password verifier used to check every processed password.
243 @param eRequestType
244 The password request type that will be passed to the
245 DocPasswordRequest object created internally. See
246 docpasswordrequest.hxx for more details.
248 @param pDefaultPasswords
249 If not null, contains default passwords that will be tried before a
250 password will be requested from the media descriptor or the user.
252 @return
253 If not empty, contains the password that has been validated by the
254 passed password verifier. If empty, no valid password has been
255 found, or the user has chosen to cancel password input.
257 css::uno::Sequence< css::beans::NamedValue > requestAndVerifyDocPassword(
258 comphelper::IDocPasswordVerifier& rVerifier,
259 comphelper::DocPasswordRequestType eRequestType,
260 const ::std::vector< OUString >* pDefaultPasswords );
262 // helper
263 private:
265 /** @short tries to open a stream by using the given PostData stream.
267 @descr The stream is used directly ...
269 The MediaDescriptor itself is changed inside this method.
270 Means: the stream is added internal and not returned by a value.
272 @param _rxPostData
273 the PostData stream.
275 @return TRUE if the stream could be added successfully.
276 Note: If FALSE is returned, the error was already handled inside!
278 @throw [css::uno::RuntimeException]
279 if the MediaDescriptor seems to be invalid!
281 @throw [css::lang::IllegalArgumentException]
282 if the given PostData stream is <NULL/>.
284 SAL_DLLPRIVATE bool impl_openStreamWithPostData(
285 const css::uno::Reference< css::io::XInputStream >& _rxPostData
288 /** @short tries to open a stream by using the given URL.
290 @descr First it tries to open the content in r/w mode (if its
291 allowed to do so). Only in case it's not allowed or it failed
292 the stream will be tried to open in readonly mode.
294 The MediaDescriptor itself is changed inside this method.
295 Means: the stream is added internal and not returned by a value.
297 @param sURL
298 the URL for open.
300 @param bLockFile
301 specifies whether the file should be locked
303 @return TRUE if the stream could be added successfully.
304 Note: If FALSE is returned, the error was already handled inside!
306 @throw [css::uno::RuntimeException]
307 if the MediaDescriptor seems to be invalid!
309 SAL_DLLPRIVATE bool impl_openStreamWithURL(
310 const OUString& sURL,
311 bool bLockFile
314 /** @short it checks if the descriptor already has a valid
315 InputStream item and creates a new one, if not.
317 @descr This method uses the current items of this MediaDescriptor,
318 to open the stream (as e.g. URL, ReadOnly, PostData etcpp.).
319 It creates a seekable stream and put it into the descriptor.
321 A might existing InteractionHandler will be used automatically,
322 to solve problems!
324 @param bLockFile
325 specifies whether the file should be locked
327 @return TRUE, if the stream was already part of the descriptor or could
328 be created as new item. FALSE otherwise.
330 SAL_DLLPRIVATE bool impl_addInputStream( bool bLockFile );
335 #endif
337 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */