Branch data 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 _COMPHELPER_MEDIADESCRIPTOR_HXX_
21 : : #define _COMPHELPER_MEDIADESCRIPTOR_HXX_
22 : :
23 : : #include <comphelper/sequenceashashmap.hxx>
24 : : #include <rtl/ustring.hxx>
25 : : #include "comphelper/comphelperdllapi.h"
26 : :
27 : : namespace com { namespace sun { namespace star { namespace io {
28 : : class XInputStream;
29 : : } } } }
30 : :
31 : : namespace comphelper{
32 : :
33 : : /** @short can be used to work with a <type scope="::com::sun::star::document">MediaDescriptor</type>
34 : : struct.
35 : :
36 : : @descr It wraps a ::boost::unordered_map around the Sequence< css::beans::PropertyValue >, which
37 : : represent the MediaDescriptor item.
38 : : Further this helper defines often used functions (as e.g. open of the required streams,
39 : : consistent checks etcpp.) and it defines all useable property names.
40 : :
41 : : @attention This class isnt threadsafe and must be guarded from outside!
42 : : */
43 : 10291 : class COMPHELPER_DLLPUBLIC MediaDescriptor : public SequenceAsHashMap
44 : : {
45 : : public:
46 : :
47 : : //---------------------------------------
48 : : /** @short these methods can be used to get the different property names
49 : : as static const OUString values.
50 : :
51 : : @descr Because definition and declaration of static const class members
52 : : does not work as expected under windows (under unix it works as well)
53 : : these way must be used :-(
54 : : */
55 : : static const ::rtl::OUString& PROP_ABORTED();
56 : : static const ::rtl::OUString& PROP_ASTEMPLATE();
57 : : static const ::rtl::OUString& PROP_COMPONENTDATA();
58 : : static const ::rtl::OUString& PROP_DOCUMENTSERVICE();
59 : : static const ::rtl::OUString& PROP_ENCRYPTIONDATA();
60 : : static const ::rtl::OUString& PROP_FILENAME();
61 : : static const ::rtl::OUString& PROP_FILTERNAME();
62 : : static const ::rtl::OUString& PROP_FILTEROPTIONS();
63 : : static const ::rtl::OUString& PROP_FRAME();
64 : : static const ::rtl::OUString& PROP_FRAMENAME();
65 : : static const ::rtl::OUString& PROP_HIDDEN();
66 : : static const ::rtl::OUString& PROP_INPUTSTREAM();
67 : : static const ::rtl::OUString& PROP_INTERACTIONHANDLER();
68 : : static const ::rtl::OUString& PROP_JUMPMARK();
69 : : static const ::rtl::OUString& PROP_MACROEXECUTIONMODE();
70 : : static const ::rtl::OUString& PROP_MEDIATYPE();
71 : : static const ::rtl::OUString& PROP_MINIMIZED();
72 : : static const ::rtl::OUString& PROP_NOAUTOSAVE();
73 : : static const ::rtl::OUString& PROP_OPENNEWVIEW();
74 : : static const ::rtl::OUString& PROP_OUTPUTSTREAM();
75 : : static const ::rtl::OUString& PROP_PASSWORD();
76 : : static const ::rtl::OUString& PROP_POSTDATA();
77 : : static const ::rtl::OUString& PROP_PREVIEW();
78 : : static const ::rtl::OUString& PROP_READONLY();
79 : : static const ::rtl::OUString& PROP_REFERRER();
80 : : static const ::rtl::OUString& PROP_SALVAGEDFILE();
81 : : static const ::rtl::OUString& PROP_STATUSINDICATOR();
82 : : static const ::rtl::OUString& PROP_STREAM();
83 : : static const ::rtl::OUString& PROP_STREAMFOROUTPUT();
84 : : static const ::rtl::OUString& PROP_TEMPLATENAME();
85 : : static const ::rtl::OUString& PROP_TITLE();
86 : : static const ::rtl::OUString& PROP_TYPENAME();
87 : : static const ::rtl::OUString& PROP_UCBCONTENT();
88 : : static const ::rtl::OUString& PROP_UPDATEDOCMODE();
89 : : static const ::rtl::OUString& PROP_URL();
90 : : static const ::rtl::OUString& PROP_VERSION();
91 : : static const ::rtl::OUString& PROP_DOCUMENTTITLE();
92 : : static const ::rtl::OUString& PROP_MODEL();
93 : : static const ::rtl::OUString& PROP_VIEWONLY();
94 : : static const ::rtl::OUString& PROP_DOCUMENTBASEURL();
95 : :
96 : : //-------------------------------------------
97 : : // interface
98 : : public:
99 : : //---------------------------------------
100 : : /** @short these ctors do nothing - excepting that they forward
101 : : the given parameters to the base class ctors.
102 : :
103 : : @descr The ctros must be overwritten to resolve conflicts with
104 : : the default ctors of the compiler :-(.
105 : : */
106 : : MediaDescriptor();
107 : : MediaDescriptor(const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& lSource);
108 : :
109 : : //---------------------------------------
110 : : /** @short it checks if the descriptor already has a valid
111 : : InputStream item and creates a new one, if not.
112 : :
113 : : @descr This method uses the current items of this MediaDescriptor,
114 : : to open the stream (as e.g. URL, ReadOnly, PostData etcpp.).
115 : : It creates a seekable stream and put it into the descriptor.
116 : :
117 : : A might existing InteractionHandler will be used automaticly,
118 : : to solve problems!
119 : :
120 : : In case of local file the system file locking is used.
121 : :
122 : : @return TRUE, if the stream was already part of the descriptor or could
123 : : be created as new item. FALSE otherwhise.
124 : : */
125 : : sal_Bool addInputStream();
126 : :
127 : : //---------------------------------------
128 : : /** @short it checks if the descriptor already has a valid
129 : : InputStream item and creates a new one, if not.
130 : :
131 : : @descr This method uses the current items of this MediaDescriptor,
132 : : to open the stream (as e.g. URL, ReadOnly, PostData etcpp.).
133 : : It creates a seekable stream and put it into the descriptor.
134 : :
135 : : A might existing InteractionHandler will be used automaticly,
136 : : to solve problems!
137 : :
138 : : In case of local file the system file locking is used based on
139 : : configuration settings.
140 : :
141 : : @return TRUE, if the stream was already part of the descriptor or could
142 : : be created as new item. FALSE otherwhise.
143 : : */
144 : : sal_Bool addInputStreamOwnLock();
145 : :
146 : : //---------------------------------------
147 : : /** @short it checks if the descriptor describes a readonly stream.
148 : :
149 : : @descr The descriptor itself isnt changed doing so.
150 : : It's only checked if the stream seems to be based
151 : : of a real readonly file.
152 : :
153 : : @Attention
154 : : We dont check the property "ReadOnly" here. Because
155 : : this property can be set from outside and overwrites
156 : : the readonly state of the stream.
157 : : If e.g. the stream could be opened read/write ...
158 : : but "ReadOnly" property is set to TRUE, this means:
159 : : show a readonly UI on top of this read/write stream.
160 : :
161 : : @return TRUE, if the stream must be interpreted as readonly ...
162 : : FALSE otherwhise.
163 : : */
164 : : sal_Bool isStreamReadOnly() const;
165 : :
166 : : //---------------------------------------
167 : : /** Returns a value from the sequence contained in the property
168 : : 'ComponentData' of this media descriptor.
169 : :
170 : : @descr The property 'ComponentData' should be empty, or should
171 : : contain a value of type sequence<com.sun.star.beans.NamedValue>
172 : : or sequence<com.sun.star.beans.PropertyValue>.
173 : :
174 : : @return The value with the specified name, if existing in the
175 : : sequence of the 'ComponentData' property, otherwise an empty
176 : : Any.
177 : : */
178 : : ::com::sun::star::uno::Any getComponentDataEntry(
179 : : const ::rtl::OUString& rName ) const;
180 : :
181 : : //---------------------------------------
182 : : /** Inserts a value into the sequence contained in the property
183 : : 'ComponentData' of the media descriptor.
184 : :
185 : : @descr The property 'ComponentData' should be empty, or should
186 : : contain a value of type sequence<com.sun.star.beans.NamedValue>
187 : : or sequence<com.sun.star.beans.PropertyValue>. The passed value
188 : : will be inserted into the sequence, or, if already existing,
189 : : will be overwritten.
190 : :
191 : : @param rName The name of the value to be inserted into the
192 : : sequence of the 'ComponentData' property.
193 : :
194 : : @param rValue The value to be inserted into the sequence of the
195 : : 'ComponentData' property.
196 : : */
197 : : void setComponentDataEntry(
198 : : const ::rtl::OUString& rName,
199 : : const ::com::sun::star::uno::Any& rValue );
200 : :
201 : : //---------------------------------------
202 : : /** Removes a value from the sequence contained in the property
203 : : 'ComponentData' of the media descriptor.
204 : :
205 : : @descr The property 'ComponentData' should be empty, or should
206 : : contain a value of type sequence<com.sun.star.beans.NamedValue>
207 : : or sequence<com.sun.star.beans.PropertyValue>. The value with
208 : : the passed name will be removed from the sequence, if existing.
209 : :
210 : : @param rName The name of the value to be removed from the sequence
211 : : of the 'ComponentData' property.
212 : : */
213 : : void clearComponentDataEntry(
214 : : const ::rtl::OUString& rName );
215 : :
216 : : //-------------------------------------------
217 : : // helper
218 : : private:
219 : :
220 : : //---------------------------------------
221 : : /** @short tries to open a stream by using the given PostData stream.
222 : :
223 : : @descr The stream is used directly ...
224 : :
225 : : The MediaDescriptor itself is changed inside this method.
226 : : Means: the stream is added internal and not returned by a value.
227 : :
228 : : @param _rxPostData
229 : : the PostData stream.
230 : :
231 : : @return TRUE if the stream could be added successfully.
232 : : Note: If FALSE is returned, the error was already handled inside!
233 : :
234 : : @throw [css::uno::RuntimeException]
235 : : if the MediaDescriptor seems to be invalid!
236 : :
237 : : @throw [css::lang::IllegalArgumentException]
238 : : if the given PostData stream is <NULL/>.
239 : : */
240 : : COMPHELPER_DLLPRIVATE sal_Bool impl_openStreamWithPostData(
241 : : const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& _rxPostData
242 : : ) throw(::com::sun::star::uno::RuntimeException);
243 : :
244 : : //---------------------------------------
245 : : /** @short tries to open a stream by using the given URL.
246 : :
247 : : @descr First it tries to open the content in r/w mode (if its
248 : : allowed to do so). Only in case its not allowed or it failed
249 : : the stream will be tried to open in readonly mode.
250 : :
251 : : The MediaDescriptor itself is changed inside this method.
252 : : Means: the stream is added internal and not returned by a value.
253 : :
254 : : @param sURL
255 : : the URL for open.
256 : :
257 : : @param bLockFile
258 : : specifies whether the file should be locked
259 : :
260 : : @return TRUE if the stream could be added successfully.
261 : : Note: If FALSE is returned, the error was already handled inside!
262 : :
263 : : @throw [css::uno::RuntimeException]
264 : : if the MediaDescriptor seems to be invalid!
265 : : */
266 : : COMPHELPER_DLLPRIVATE sal_Bool impl_openStreamWithURL(
267 : : const ::rtl::OUString& sURL,
268 : : sal_Bool bLockFile
269 : : ) throw(::com::sun::star::uno::RuntimeException);
270 : :
271 : : //---------------------------------------
272 : : /** @short some URL parts can make trouble for opening streams (e.g. jumpmarks.)
273 : : An URL should be "normalized" before its used.
274 : :
275 : : @param sURL
276 : : the original URL (e.g. including a jumpmark)
277 : :
278 : : @return [string]
279 : : the "normalized" URL (e.g. without jumpmark)
280 : : */
281 : : COMPHELPER_DLLPRIVATE ::rtl::OUString impl_normalizeURL(const ::rtl::OUString& sURL);
282 : :
283 : : //---------------------------------------
284 : : /** @short it checks if the descriptor already has a valid
285 : : InputStream item and creates a new one, if not.
286 : :
287 : : @descr This method uses the current items of this MediaDescriptor,
288 : : to open the stream (as e.g. URL, ReadOnly, PostData etcpp.).
289 : : It creates a seekable stream and put it into the descriptor.
290 : :
291 : : A might existing InteractionHandler will be used automaticly,
292 : : to solve problems!
293 : :
294 : : @param bLockFile
295 : : specifies whether the file should be locked
296 : :
297 : : @return TRUE, if the stream was already part of the descriptor or could
298 : : be created as new item. FALSE otherwhise.
299 : : */
300 : : COMPHELPER_DLLPRIVATE sal_Bool impl_addInputStream( sal_Bool bLockFile );
301 : : };
302 : :
303 : : } // namespace comphelper
304 : :
305 : : #endif // _COMPHELPER_MEDIADESCRIPTOR_HXX_
306 : :
307 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|