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 isnt 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_AUTHENTICATIONHANDLER(); 89 static const ::rtl::OUString& PROP_JUMPMARK(); 90 static const ::rtl::OUString& PROP_MACROEXECUTIONMODE(); 91 static const ::rtl::OUString& PROP_MEDIATYPE(); 92 static const ::rtl::OUString& PROP_MINIMIZED(); 93 static const ::rtl::OUString& PROP_NOAUTOSAVE(); 94 static const ::rtl::OUString& PROP_OPENNEWVIEW(); 95 static const ::rtl::OUString& PROP_OUTPUTSTREAM(); 96 static const ::rtl::OUString& PROP_PASSWORD(); 97 static const ::rtl::OUString& PROP_PATTERN(); 98 static const ::rtl::OUString& PROP_POSSIZE(); 99 static const ::rtl::OUString& PROP_POSTDATA(); 100 static const ::rtl::OUString& PROP_POSTSTRING(); 101 static const ::rtl::OUString& PROP_PREVIEW(); 102 static const ::rtl::OUString& PROP_READONLY(); 103 static const ::rtl::OUString& PROP_REFERRER(); 104 static const ::rtl::OUString& PROP_SALVAGEDFILE(); 105 static const ::rtl::OUString& PROP_SILENT(); 106 static const ::rtl::OUString& PROP_STATUSINDICATOR(); 107 static const ::rtl::OUString& PROP_STREAM(); 108 static const ::rtl::OUString& PROP_STREAMFOROUTPUT(); 109 static const ::rtl::OUString& PROP_TEMPLATENAME(); 110 static const ::rtl::OUString& PROP_TEMPLATEREGIONNAME(); 111 static const ::rtl::OUString& PROP_TITLE(); 112 static const ::rtl::OUString& PROP_TYPENAME(); 113 static const ::rtl::OUString& PROP_UCBCONTENT(); 114 static const ::rtl::OUString& PROP_UPDATEDOCMODE(); 115 static const ::rtl::OUString& PROP_URL(); 116 static const ::rtl::OUString& PROP_VERSION(); 117 static const ::rtl::OUString& PROP_VIEWID(); 118 static const ::rtl::OUString& PROP_REPAIRPACKAGE(); 119 static const ::rtl::OUString& PROP_DOCUMENTTITLE(); 120 static const ::rtl::OUString& PROP_MODEL(); 121 static const ::rtl::OUString& PROP_VIEWONLY(); 122 static const ::rtl::OUString& PROP_DOCUMENTBASEURL(); 123 static const ::rtl::OUString& PROP_VIEWCONTROLLERNAME(); 124 125 //------------------------------------------- 126 // interface 127 public: 128 //--------------------------------------- 129 /** @short these ctors do nothing - excepting that they forward 130 the given parameters to the base class ctors. 131 132 @descr The ctros must be overwritten to resolve conflicts with 133 the default ctors of the compiler :-(. 134 */ 135 MediaDescriptor(); 136 MediaDescriptor(const ::com::sun::star::uno::Any& aSource); 137 MediaDescriptor(const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& lSource); 138 MediaDescriptor(const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >& lSource); 139 140 //--------------------------------------- 141 /** @short it checks if the descriptor already has a valid 142 InputStream item and creates a new one, if not. 143 144 @descr This method uses the current items of this MediaDescriptor, 145 to open the stream (as e.g. URL, ReadOnly, PostData etcpp.). 146 It creates a seekable stream and put it into the descriptor. 147 148 A might existing InteractionHandler will be used automaticly, 149 to solve problems! 150 151 In case of local file the system file locking is used. 152 153 @return TRUE, if the stream was already part of the descriptor or could 154 be created as new item. FALSE otherwhise. 155 */ 156 sal_Bool addInputStream(); 157 158 //--------------------------------------- 159 /** @short it checks if the descriptor already has a valid 160 InputStream item and creates a new one, if not. 161 162 @descr This method uses the current items of this MediaDescriptor, 163 to open the stream (as e.g. URL, ReadOnly, PostData etcpp.). 164 It creates a seekable stream and put it into the descriptor. 165 166 A might existing InteractionHandler will be used automaticly, 167 to solve problems! 168 169 In case of local file the system file locking is used based on 170 configuration settings. 171 172 @return TRUE, if the stream was already part of the descriptor or could 173 be created as new item. FALSE otherwhise. 174 */ 175 sal_Bool addInputStreamOwnLock(); 176 177 //--------------------------------------- 178 /** @short it checks if the descriptor describes a readonly stream. 179 180 @descr The descriptor itself isnt changed doing so. 181 It's only checked if the stream seems to be based 182 of a real readonly file. 183 184 @Attention 185 We dont check the property "ReadOnly" here. Because 186 this property can be set from outside and overwrites 187 the readonly state of the stream. 188 If e.g. the stream could be opened read/write ... 189 but "ReadOnly" property is set to TRUE, this means: 190 show a readonly UI on top of this read/write stream. 191 192 @return TRUE, if the stream must be interpreted as readonly ... 193 FALSE otherwhise. 194 */ 195 sal_Bool isStreamReadOnly() const; 196 197 //--------------------------------------- 198 /** Returns a value from the sequence contained in the property 199 'ComponentData' of this media descriptor. 200 201 @descr The property 'ComponentData' should be empty, or should 202 contain a value of type sequence<com.sun.star.beans.NamedValue> 203 or sequence<com.sun.star.beans.PropertyValue>. 204 205 @return The value with the specified name, if existing in the 206 sequence of the 'ComponentData' property, otherwise an empty 207 Any. 208 */ 209 ::com::sun::star::uno::Any getComponentDataEntry( 210 const ::rtl::OUString& rName ) const; 211 212 //--------------------------------------- 213 /** Inserts a value into the sequence contained in the property 214 'ComponentData' of the media descriptor. 215 216 @descr The property 'ComponentData' should be empty, or should 217 contain a value of type sequence<com.sun.star.beans.NamedValue> 218 or sequence<com.sun.star.beans.PropertyValue>. The passed value 219 will be inserted into the sequence, or, if already existing, 220 will be overwritten. 221 222 @param rName The name of the value to be inserted into the 223 sequence of the 'ComponentData' property. 224 225 @param rValue The value to be inserted into the sequence of the 226 'ComponentData' property. 227 */ 228 void setComponentDataEntry( 229 const ::rtl::OUString& rName, 230 const ::com::sun::star::uno::Any& rValue ); 231 232 //--------------------------------------- 233 /** Removes a value from the sequence contained in the property 234 'ComponentData' of the media descriptor. 235 236 @descr The property 'ComponentData' should be empty, or should 237 contain a value of type sequence<com.sun.star.beans.NamedValue> 238 or sequence<com.sun.star.beans.PropertyValue>. The value with 239 the passed name will be removed from the sequence, if existing. 240 241 @param rName The name of the value to be removed from the sequence 242 of the 'ComponentData' property. 243 */ 244 void clearComponentDataEntry( 245 const ::rtl::OUString& rName ); 246 247 //------------------------------------------- 248 // helper 249 private: 250 251 //--------------------------------------- 252 /** @short tries to open a stream by using the given PostData stream. 253 254 @descr The stream is used directly ... 255 256 The MediaDescriptor itself is changed inside this method. 257 Means: the stream is added internal and not returned by a value. 258 259 @param _rxPostData 260 the PostData stream. 261 262 @return TRUE if the stream could be added successfully. 263 Note: If FALSE is returned, the error was already handled inside! 264 265 @throw [css::uno::RuntimeException] 266 if the MediaDescriptor seems to be invalid! 267 268 @throw [css::lang::IllegalArgumentException] 269 if the given PostData stream is <NULL/>. 270 */ 271 COMPHELPER_DLLPRIVATE sal_Bool impl_openStreamWithPostData( 272 const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& _rxPostData 273 ) throw(::com::sun::star::uno::RuntimeException); 274 275 //--------------------------------------- 276 /** @short tries to open a stream by using the given URL. 277 278 @descr First it tries to open the content in r/w mode (if its 279 allowed to do so). Only in case its not allowed or it failed 280 the stream will be tried to open in readonly mode. 281 282 The MediaDescriptor itself is changed inside this method. 283 Means: the stream is added internal and not returned by a value. 284 285 @param sURL 286 the URL for open. 287 288 @param bLockFile 289 specifies whether the file should be locked 290 291 @return TRUE if the stream could be added successfully. 292 Note: If FALSE is returned, the error was already handled inside! 293 294 @throw [css::uno::RuntimeException] 295 if the MediaDescriptor seems to be invalid! 296 */ 297 COMPHELPER_DLLPRIVATE sal_Bool impl_openStreamWithURL( 298 const ::rtl::OUString& sURL, 299 sal_Bool bLockFile 300 ) throw(::com::sun::star::uno::RuntimeException); 301 302 //--------------------------------------- 303 /** @short some URL parts can make trouble for opening streams (e.g. jumpmarks.) 304 An URL should be "normalized" before its used. 305 306 @param sURL 307 the original URL (e.g. including a jumpmark) 308 309 @return [string] 310 the "normalized" URL (e.g. without jumpmark) 311 */ 312 COMPHELPER_DLLPRIVATE ::rtl::OUString impl_normalizeURL(const ::rtl::OUString& sURL); 313 314 //--------------------------------------- 315 /** @short it checks if the descriptor already has a valid 316 InputStream item and creates a new one, if not. 317 318 @descr This method uses the current items of this MediaDescriptor, 319 to open the stream (as e.g. URL, ReadOnly, PostData etcpp.). 320 It creates a seekable stream and put it into the descriptor. 321 322 A might existing InteractionHandler will be used automaticly, 323 to solve problems! 324 325 @param bLockFile 326 specifies whether the file should be locked 327 328 @return TRUE, if the stream was already part of the descriptor or could 329 be created as new item. FALSE otherwhise. 330 */ 331 COMPHELPER_DLLPRIVATE sal_Bool impl_addInputStream( sal_Bool bLockFile ); 332 }; 333 334 } // namespace comphelper 335 336 #endif // _COMPHELPER_MEDIADESCRIPTOR_HXX_ 337