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 __FRAMEWORK_SERVICES_FRAMELOADERFACTORY_HXX_ 25 #define __FRAMEWORK_SERVICES_FRAMELOADERFACTORY_HXX_ 26 27 //_________________________________________________________________________________________________________________ 28 // my own includes 29 //_________________________________________________________________________________________________________________ 30 31 #include <classes/filtercache.hxx> 32 #include <threadhelp/threadhelpbase.hxx> 33 #include <macros/generic.hxx> 34 #include <macros/debug.hxx> 35 #include <macros/xinterface.hxx> 36 #include <macros/xtypeprovider.hxx> 37 #include <macros/xserviceinfo.hxx> 38 #include <general.h> 39 40 //_________________________________________________________________________________________________________________ 41 // interface includes 42 //_________________________________________________________________________________________________________________ 43 #include <com/sun/star/beans/PropertyValue.hpp> 44 #include <com/sun/star/lang/XInitialization.hpp> 45 #include <com/sun/star/lang/WrappedTargetException.hpp> 46 #include <com/sun/star/container/XNameAccess.hpp> 47 #include <com/sun/star/container/NoSuchElementException.hpp> 48 #include <com/sun/star/io/XInputStream.hpp> 49 50 //_________________________________________________________________________________________________________________ 51 // other includes 52 //_________________________________________________________________________________________________________________ 53 #include <cppuhelper/implbase3.hxx> 54 55 //_________________________________________________________________________________________________________________ 56 // namespace 57 //_________________________________________________________________________________________________________________ 58 59 namespace framework{ 60 61 //_________________________________________________________________________________________________________________ 62 // exported const 63 //_________________________________________________________________________________________________________________ 64 65 //_________________________________________________________________________________________________________________ 66 // exported definitions 67 //_________________________________________________________________________________________________________________ 68 69 struct tIMPLExtractedArguments 70 { 71 ::rtl::OUString sMimeType ; 72 sal_Int32 nFlags ; 73 ::rtl::OUString sFilterName ; 74 sal_Int32 nClipboardFormat ; 75 ::rtl::OUString sDetectService ; 76 css::uno::Reference< css::io::XInputStream > xInputStream ; 77 78 sal_Int32 nValidMask ; 79 }; 80 81 /*-************************************************************************************************************//** 82 @short factory to create frameloader-objects 83 @descr These class can be used to create new loader for specified contents. 84 We use cached values of the registry to lay down, which frameloader match 85 a given URL or filtername. To do this, we use the XMultiServiceFactory-interface. 86 87 @ATTENTION In a specialmode of these implementation we support a simple filterdetection. 88 But there is no special interface. You must call some existing methods in another context! 89 see createInstanceWithArguments() fo rfurther informations! 90 91 @implements XInterface 92 XTypeProvider 93 XServiceInfo 94 XMultiServiceFactory 95 XNameAccess 96 XElementAccess 97 @base ThreadHelpBase 98 OWeakObject 99 100 @devstatus deprecated 101 *//*-*************************************************************************************************************/ 102 103 class FrameLoaderFactory : public ThreadHelpBase , // Struct for right initialization of mutex member! Mst first of baseclasses 104 public ::cppu::WeakImplHelper3< ::com::sun::star::lang::XServiceInfo,::com::sun::star::lang::XMultiServiceFactory,::com::sun::star::container::XNameAccess > 105 { 106 //------------------------------------------------------------------------------------------------------------- 107 // public methods 108 //------------------------------------------------------------------------------------------------------------- 109 110 public: 111 112 //--------------------------------------------------------------------------------------------------------- 113 // constructor / destructor 114 //--------------------------------------------------------------------------------------------------------- 115 116 /*-****************************************************************************************************//** 117 @short standard constructor 118 @descr Initialize a new instance and fill the registrycache with values. 119 To do this - xFactory must be valid! 120 121 @seealso class RegistryCache 122 @seealso member m_aRegistryCache 123 124 @param "xFactory", factory which has created us. 125 @return - 126 127 @onerror An ASSERTION is thrown in debug version, if xFactory is invalid or cache can't filled. 128 *//*-*****************************************************************************************************/ 129 130 FrameLoaderFactory( const css::uno::Reference< css::lang::XMultiServiceFactory >& xFactory ); 131 132 /*-****************************************************************************************************//** 133 @short standard destructor to delete instance 134 @descr We use it to clear our cache. 135 136 @seealso class RegistryCache 137 138 @param - 139 @return - 140 141 @onerror - 142 *//*-*****************************************************************************************************/ 143 144 virtual ~FrameLoaderFactory(); 145 146 //--------------------------------------------------------------------------------------------------------- 147 // XInterface, XTypeProvider, XServiceInfo 148 //--------------------------------------------------------------------------------------------------------- 149 150 DECLARE_XSERVICEINFO 151 152 //--------------------------------------------------------------------------------------------------------- 153 // XMultiServiceFactory 154 //--------------------------------------------------------------------------------------------------------- 155 156 /*-****************************************************************************************************//** 157 @short create a new frameloder (without arguments!) 158 @descr We search for an agreement between given type name and our cache-content. 159 If we found some information, we create the registered frameloader for these type. 160 Otherwise - we return NULL. 161 We search from begin to end of internal loader list! 162 163 @seealso method impl_createFrameLoader() 164 @seealso method createInstanceWithArguments() 165 166 @param "sTypeName", type name of a document to filter, open or save. 167 @return A reference to a new created frameloader. 168 169 @onerror A null reference is returned. 170 *//*-*****************************************************************************************************/ 171 172 virtual css::uno::Reference< css::uno::XInterface > SAL_CALL createInstance( const ::rtl::OUString& sTypeName ) throw( css::uno::Exception , 173 css::uno::RuntimeException ); 174 175 /*-****************************************************************************************************//** 176 @short create a new frameloder 177 @descr We search for an agreement between given type name and our cache-content. 178 If we found some information, we create the registered frameloader for these type. 179 Otherwise - we return NULL. 180 You can give us some optional arguments to influence our search! 181 182 @seealso method impl_createFrameLoader() 183 @seealso method createInstance() 184 185 @param "sTypeName", type name of a document to filter, open or save. 186 @param "seqArguments", list of optional arguments for initializing of new frameloader. 187 @return A reference to a new created frameloader. 188 189 @onerror A null reference is returned. 190 *//*-*****************************************************************************************************/ 191 192 virtual css::uno::Reference< css::uno::XInterface > SAL_CALL createInstanceWithArguments( const ::rtl::OUString& sTypeName , 193 const css::uno::Sequence< css::uno::Any >& seqArguments) throw( css::uno::Exception , 194 css::uno::RuntimeException); 195 196 /*-****************************************************************************************************//** 197 @short not supported 198 @descr Please use XNameAccess instead of these! 199 200 @seealso - 201 202 @param - 203 @return - 204 205 @onerror - 206 *//*-*****************************************************************************************************/ 207 208 virtual css::uno::Sequence< ::rtl::OUString > SAL_CALL getAvailableServiceNames() throw( css::uno::RuntimeException ); 209 210 //--------------------------------------------------------------------------------------------------------- 211 // XNameAccess 212 //--------------------------------------------------------------------------------------------------------- 213 214 /*-****************************************************************************************************//** 215 @short return properties of registered frame loader specified by his implementation name 216 @descr Use these method to get all informations about our internal loader cache 217 and a special frame loader. 218 We return a Sequence< PropertyValue > in an Any packed as result. 219 220 structure of return value: 221 [0].Name = "Types" 222 [0].Value = list of supported types of these loader as [sequence< oustring >] 223 224 [1].Name = "UIName" 225 [1].Value = localized name of loader as [string] 226 227 @seealso method getElementNames() 228 @seealso method hasByName() 229 230 @param "sName", the name of searched frame loader (use getElementNames() to get it!) 231 @return A Sequence< PropertyValue > packed in an Any. 232 233 @onerror If given name not exist a NoSuchElementException is thrown. 234 *//*-*****************************************************************************************************/ 235 236 virtual css::uno::Any SAL_CALL getByName( const ::rtl::OUString& sName ) throw( css::container::NoSuchElementException , 237 css::lang::WrappedTargetException , 238 css::uno::RuntimeException ); 239 240 /*-****************************************************************************************************//** 241 @short return list of all well known loader names from configuration 242 @descr Use these method to get all names of well known loader. 243 You can use it to get the properties of a loader by calling getByName()! 244 245 @seealso method getByName() 246 @seealso method hasByName() 247 248 @param - 249 @return A list of well known loader. Is static at runtime! 250 251 @onerror No error should occur. 252 *//*-*****************************************************************************************************/ 253 254 virtual css::uno::Sequence< ::rtl::OUString > SAL_CALL getElementNames() throw( css::uno::RuntimeException ); 255 256 /*-****************************************************************************************************//** 257 @short check if searched frame loader exist in configuration 258 @descr Normally nobody needs really these method (use getElementNames() in combination with getByName()). 259 We guarantee correctness of these mechanism. There is no reason to check for existing elements then ... 260 but if you have an unknwon name and has no fun to search it in returned sequence ... 261 you can call these ... 262 263 @seealso method getByName() 264 @seealso method getElementNames() 265 266 @param "sName", implementation name of searched frame loader 267 @return sal_True if loader exist, sal_False otherwise. 268 269 @onerror No error should occur. 270 *//*-*****************************************************************************************************/ 271 272 virtual sal_Bool SAL_CALL hasByName( const ::rtl::OUString& sName ) throw( css::uno::RuntimeException ); 273 274 //--------------------------------------------------------------------------------------------------------- 275 // XElementAccess 276 //--------------------------------------------------------------------------------------------------------- 277 278 /*-****************************************************************************************************//** 279 @short return the type of retrun value of method XNameAccess::getByName() 280 @descr In these implementation its a Sequence< PropertyValue > every time! 281 282 @seealso description of interface XNameAccess 283 284 @param - 285 @return Type of Sequence< PropertyValue >. 286 287 @onerror No error should occur. 288 *//*-*****************************************************************************************************/ 289 290 virtual css::uno::Type SAL_CALL getElementType() throw( css::uno::RuntimeException ); 291 292 /*-****************************************************************************************************//** 293 @short return state if informations about frame loader available 294 @descr If these method return false - no information could'nt read from configuration ... 295 I think nothing will work then. Normally we return sal_True! 296 297 @seealso class FilterCache! 298 299 @param - 300 @return sal_True if information available, sal_False otherwise. 301 302 @onerror No error should occur. 303 *//*-*****************************************************************************************************/ 304 305 virtual sal_Bool SAL_CALL hasElements() throw( css::uno::RuntimeException ); 306 307 //------------------------------------------------------------------------------------------------------------- 308 // protected methods 309 //------------------------------------------------------------------------------------------------------------- 310 311 protected: 312 313 //------------------------------------------------------------------------------------------------------------- 314 // private methods 315 //------------------------------------------------------------------------------------------------------------- 316 317 private: 318 319 /*-****************************************************************************************************//** 320 @short try to set configuration properties at created loader 321 @descr We support the old async. loader interface ( XFrameLoader ) and the new one XSynchronousFrameLoader. 322 The new one should implement a property set on which we can set his configuration values! 323 We try to cast given loader to these interface - if it's exist we set the values - otherwise not! 324 325 @seealso service FrameLoader 326 @seealso service SynchronousFrameLoader 327 328 @param "xLoader" loader with generic XInterface! (We don't know before which service type is used!) 329 @param "pLoaderInfo" configuration structure of these loader. 330 @return - 331 332 @onerror No error should occur. 333 *//*-*****************************************************************************************************/ 334 335 void impl_initializeLoader( css::uno::Reference< css::uno::XInterface >& xLoader, const Loader& pLoaderInfo ); 336 337 //------------------------------------------------------------------------------------------------------------- 338 // debug methods 339 // (should be private everyway!) 340 //------------------------------------------------------------------------------------------------------------- 341 342 /*-****************************************************************************************************//** 343 @short debug-method to check incoming parameter of some other mehods of this class 344 @descr The following methods are used to check parameters for other methods 345 of this class. The return value is used directly for an ASSERT(...). 346 347 @seealso ASSERTs in implementation! 348 349 @param references to checking variables 350 @return sal_False ,on invalid parameter 351 @return sal_True ,otherwise 352 353 @onerror - 354 *//*-*****************************************************************************************************/ 355 356 357 #ifdef ENABLE_ASSERTIONS 358 359 private: 360 361 static sal_Bool impldbg_checkParameter_FrameLoaderFactory ( const css::uno::Reference< css::lang::XMultiServiceFactory >& xFactory ); 362 static sal_Bool impldbg_checkParameter_createInstance ( const ::rtl::OUString& sTypeName ); 363 static sal_Bool impldbg_checkParameter_createInstanceWithArguments ( const ::rtl::OUString& sTypeName , 364 const css::uno::Sequence< css::uno::Any >& seqArguments); 365 static sal_Bool impldbg_checkParameter_getByName ( const ::rtl::OUString& sName ); 366 static sal_Bool impldbg_checkParameter_hasByName ( const ::rtl::OUString& sName ); 367 368 #endif // #ifdef ENABLE_ASSERTIONS 369 370 //------------------------------------------------------------------------------------------------------------- 371 // private variables 372 // (should be private everyway!) 373 //------------------------------------------------------------------------------------------------------------- 374 375 private: 376 377 css::uno::Reference< css::lang::XMultiServiceFactory > m_xFactory ; 378 FilterCache m_aCache ; 379 380 }; // class FrameLoaderFactory 381 382 } // namespace framework 383 384 #endif // #ifndef __FRAMEWORK_SERVICES_FRAMELOADERFACTORY_HXX_ 385