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 _COMPHELPER_MEDIADESCRIPTOR_HXX_
21 #define _COMPHELPER_MEDIADESCRIPTOR_HXX_
23 #include <comphelper/sequenceashashmap.hxx>
24 #include <rtl/ustring.hxx>
25 #include "comphelper/comphelperdllapi.h"
27 namespace com
{ namespace sun
{ namespace star
{ namespace io
{
33 /** @short can be used to work with a <type scope="::com::sun::star::document">MediaDescriptor</type>
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.
41 @attention This class isnt threadsafe and must be guarded from outside!
43 class COMPHELPER_DLLPUBLIC MediaDescriptor
: public SequenceAsHashMap
47 //---------------------------------------
48 /** @short these methods can be used to get the different property names
49 as static const OUString values.
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 :-(
55 static const OUString
& PROP_ABORTED();
56 static const OUString
& PROP_ASTEMPLATE();
57 static const OUString
& PROP_COMPONENTDATA();
58 static const OUString
& PROP_DOCUMENTSERVICE();
59 static const OUString
& PROP_ENCRYPTIONDATA();
60 static const OUString
& PROP_FILENAME();
61 static const OUString
& PROP_FILTERNAME();
62 static const OUString
& PROP_FILTERPROVIDER();
63 static const OUString
& PROP_FILTEROPTIONS();
64 static const OUString
& PROP_FRAME();
65 static const OUString
& PROP_FRAMENAME();
66 static const OUString
& PROP_HIDDEN();
67 static const OUString
& PROP_INPUTSTREAM();
68 static const OUString
& PROP_INTERACTIONHANDLER();
69 static const OUString
& PROP_JUMPMARK();
70 static const OUString
& PROP_MACROEXECUTIONMODE();
71 static const OUString
& PROP_MEDIATYPE();
72 static const OUString
& PROP_MINIMIZED();
73 static const OUString
& PROP_NOAUTOSAVE();
74 static const OUString
& PROP_OPENNEWVIEW();
75 static const OUString
& PROP_OUTPUTSTREAM();
76 static const OUString
& PROP_PASSWORD();
77 static const OUString
& PROP_POSTDATA();
78 static const OUString
& PROP_PREVIEW();
79 static const OUString
& PROP_READONLY();
80 static const OUString
& PROP_REFERRER();
81 static const OUString
& PROP_SALVAGEDFILE();
82 static const OUString
& PROP_STATUSINDICATOR();
83 static const OUString
& PROP_STREAM();
84 static const OUString
& PROP_STREAMFOROUTPUT();
85 static const OUString
& PROP_TEMPLATENAME();
86 static const OUString
& PROP_TITLE();
87 static const OUString
& PROP_TYPENAME();
88 static const OUString
& PROP_UCBCONTENT();
89 static const OUString
& PROP_UPDATEDOCMODE();
90 static const OUString
& PROP_URL();
91 static const OUString
& PROP_VERSION();
92 static const OUString
& PROP_DOCUMENTTITLE();
93 static const OUString
& PROP_MODEL();
94 static const OUString
& PROP_VIEWONLY();
95 static const OUString
& PROP_DOCUMENTBASEURL();
97 static const OUString
& PROP_DEEPDETECTION();
99 //-------------------------------------------
102 //---------------------------------------
103 /** @short these ctors do nothing - excepting that they forward
104 the given parameters to the base class ctors.
106 @descr The ctros must be overwritten to resolve conflicts with
107 the default ctors of the compiler :-(.
110 MediaDescriptor(const ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::PropertyValue
>& lSource
);
112 //---------------------------------------
113 /** @short it checks if the descriptor already has a valid
114 InputStream item and creates a new one, if not.
116 @descr This method uses the current items of this MediaDescriptor,
117 to open the stream (as e.g. URL, ReadOnly, PostData etcpp.).
118 It creates a seekable stream and put it into the descriptor.
120 A might existing InteractionHandler will be used automaticly,
123 In case of local file the system file locking is used.
125 @return TRUE, if the stream was already part of the descriptor or could
126 be created as new item. FALSE otherwise.
128 sal_Bool
addInputStream();
130 //---------------------------------------
131 /** @short it checks if the descriptor already has a valid
132 InputStream item and creates a new one, if not.
134 @descr This method uses the current items of this MediaDescriptor,
135 to open the stream (as e.g. URL, ReadOnly, PostData etcpp.).
136 It creates a seekable stream and put it into the descriptor.
138 A might existing InteractionHandler will be used automaticly,
141 In case of local file the system file locking is used based on
142 configuration settings.
144 @return TRUE, if the stream was already part of the descriptor or could
145 be created as new item. FALSE otherwise.
147 sal_Bool
addInputStreamOwnLock();
149 //---------------------------------------
150 /** @short it checks if the descriptor describes a readonly stream.
152 @descr The descriptor itself isnt changed doing so.
153 It's only checked if the stream seems to be based
154 of a real readonly file.
157 We dont check the property "ReadOnly" here. Because
158 this property can be set from outside and overwrites
159 the readonly state of the stream.
160 If e.g. the stream could be opened read/write ...
161 but "ReadOnly" property is set to TRUE, this means:
162 show a readonly UI on top of this read/write stream.
164 @return TRUE, if the stream must be interpreted as readonly ...
167 sal_Bool
isStreamReadOnly() const;
169 //---------------------------------------
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
181 ::com::sun::star::uno::Any
getComponentDataEntry(
182 const OUString
& rName
) const;
184 //---------------------------------------
185 /** Inserts a value into the sequence contained in the property
186 'ComponentData' of the media descriptor.
188 @descr The property 'ComponentData' should be empty, or should
189 contain a value of type sequence<com.sun.star.beans.NamedValue>
190 or sequence<com.sun.star.beans.PropertyValue>. The passed value
191 will be inserted into the sequence, or, if already existing,
194 @param rName The name of the value to be inserted into the
195 sequence of the 'ComponentData' property.
197 @param rValue The value to be inserted into the sequence of the
198 'ComponentData' property.
200 void setComponentDataEntry(
201 const OUString
& rName
,
202 const ::com::sun::star::uno::Any
& rValue
);
204 //---------------------------------------
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 //-------------------------------------------
223 //---------------------------------------
224 /** @short tries to open a stream by using the given PostData stream.
226 @descr The stream is used directly ...
228 The MediaDescriptor itself is changed inside this method.
229 Means: the stream is added internal and not returned by a value.
234 @return TRUE if the stream could be added successfully.
235 Note: If FALSE is returned, the error was already handled inside!
237 @throw [css::uno::RuntimeException]
238 if the MediaDescriptor seems to be invalid!
240 @throw [css::lang::IllegalArgumentException]
241 if the given PostData stream is <NULL/>.
243 COMPHELPER_DLLPRIVATE sal_Bool
impl_openStreamWithPostData(
244 const ::com::sun::star::uno::Reference
< ::com::sun::star::io::XInputStream
>& _rxPostData
245 ) throw(::com::sun::star::uno::RuntimeException
);
247 //---------------------------------------
248 /** @short tries to open a stream by using the given URL.
250 @descr First it tries to open the content in r/w mode (if its
251 allowed to do so). Only in case its not allowed or it failed
252 the stream will be tried to open in readonly mode.
254 The MediaDescriptor itself is changed inside this method.
255 Means: the stream is added internal and not returned by a value.
261 specifies whether the file should be locked
263 @return TRUE if the stream could be added successfully.
264 Note: If FALSE is returned, the error was already handled inside!
266 @throw [css::uno::RuntimeException]
267 if the MediaDescriptor seems to be invalid!
269 COMPHELPER_DLLPRIVATE sal_Bool
impl_openStreamWithURL(
270 const OUString
& sURL
,
272 ) throw(::com::sun::star::uno::RuntimeException
);
274 //---------------------------------------
275 /** @short some URL parts can make trouble for opening streams (e.g. jumpmarks.)
276 An URL should be "normalized" before its used.
279 the original URL (e.g. including a jumpmark)
282 the "normalized" URL (e.g. without jumpmark)
284 COMPHELPER_DLLPRIVATE OUString
impl_normalizeURL(const OUString
& sURL
);
286 //---------------------------------------
287 /** @short it checks if the descriptor already has a valid
288 InputStream item and creates a new one, if not.
290 @descr This method uses the current items of this MediaDescriptor,
291 to open the stream (as e.g. URL, ReadOnly, PostData etcpp.).
292 It creates a seekable stream and put it into the descriptor.
294 A might existing InteractionHandler will be used automaticly,
298 specifies whether the file should be locked
300 @return TRUE, if the stream was already part of the descriptor or could
301 be created as new item. FALSE otherwise.
303 COMPHELPER_DLLPRIVATE sal_Bool
impl_addInputStream( sal_Bool bLockFile
);
306 } // namespace comphelper
308 #endif // _COMPHELPER_MEDIADESCRIPTOR_HXX_
310 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */