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