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