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