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 __FRAMEWORK_CLASSES_PROTOCOLHANDLERCACHE_HXX_ 29 #define __FRAMEWORK_CLASSES_PROTOCOLHANDLERCACHE_HXX_ 30 31 //_________________________________________________________________________________________________________________ 32 // my own includes 33 //_________________________________________________________________________________________________________________ 34 35 #include <general.h> 36 #include <stdtypes.h> 37 #include <macros/debug.hxx> 38 39 //_________________________________________________________________________________________________________________ 40 // interface includes 41 //_________________________________________________________________________________________________________________ 42 #include <com/sun/star/util/URL.hpp> 43 44 //_________________________________________________________________________________________________________________ 45 // other includes 46 //_________________________________________________________________________________________________________________ 47 48 #include <unotools/configitem.hxx> 49 #include <rtl/ustring.hxx> 50 #include <fwidllapi.h> 51 52 //_________________________________________________________________________________________________________________ 53 // namespace 54 //_________________________________________________________________________________________________________________ 55 56 namespace framework{ 57 58 //_________________________________________________________________________________________________________________ 59 // exported const 60 //_________________________________________________________________________________________________________________ 61 62 #define PACKAGENAME_PROTOCOLHANDLER DECLARE_ASCII("Office.ProtocolHandler" ) /// name of our configuration package 63 64 #define CFG_PATH_SEPERATOR DECLARE_ASCII("/" ) /// seperator for configuration pathes 65 #define CFG_ENCODING_OPEN DECLARE_ASCII("[\'" ) /// used to start encoding of set names 66 #define CFG_ENCODING_CLOSE DECLARE_ASCII("\']" ) /// used to finish encoding of set names 67 68 #define SETNAME_HANDLER DECLARE_ASCII("HandlerSet" ) /// name of configuration set inside package 69 #define PROPERTY_PROTOCOLS DECLARE_ASCII("Protocols" ) /// properties of a protocol handler 70 71 //_________________________________________________________________________________________________________________ 72 73 /** 74 Programmer can register his own services to handle different protocols. 75 Don't forget: It doesn't mean "handling of documents" ... these services could handle protocols ... 76 e.g. "mailto:", "file://", ".java:" 77 This struct holds the information about one such registered protocol handler. 78 A list of handler objects is defined as ProtocolHandlerHash. see below 79 */ 80 struct FWI_DLLPUBLIC ProtocolHandler 81 { 82 /* member */ 83 public: 84 85 /// the uno implementation name of this handler 86 ::rtl::OUString m_sUNOName; 87 /// list of URL pattern which defines the protocols which this handler is registered for 88 OUStringList m_lProtocols; 89 }; 90 91 //_________________________________________________________________________________________________________________ 92 93 /** 94 This hash use registered pattern of all protocol handlers as keys and provide her 95 uno implementation names as value. Overloading of the index operator makes it possible 96 to search for a key by using a full qualified URL on list of all possible pattern keys. 97 */ 98 class FWI_DLLPUBLIC PatternHash : public BaseHash< ::rtl::OUString > 99 { 100 /* interface */ 101 public: 102 103 PatternHash::iterator findPatternKey( const ::rtl::OUString& sURL ); 104 }; 105 106 //_________________________________________________________________________________________________________________ 107 108 /** 109 This hash holds protocol handler structs by her names. 110 */ 111 typedef BaseHash< ProtocolHandler > HandlerHash; 112 113 //_________________________________________________________________________________________________________________ 114 115 /** 116 @short this hash makes it easy to find a protocol handler by using his uno implementation name. 117 @descr It holds two lists of informations: 118 - first holds all handler by her uno implementation names and 119 can be used to get her other properties 120 - another one maps her registered pattern to her uno names to 121 perform search on such data 122 But this lists a static for all instances of this class. So it's possible to 123 create new objects without opening configuration twice and free memory automaticly 124 if last object will gone. 125 126 @attention We implement a singleton concept - so we doesn't need any mutex member here. 127 Because to safe access on static member we must use a static global lock 128 here too. 129 130 @devstatus ready to use 131 @threadsafe yes 132 133 @modified 30.04.2002 11:19, as96863 134 */ 135 136 class HandlerCFGAccess; 137 class FWI_DLLPUBLIC HandlerCache 138 { 139 /* member */ 140 private: 141 142 /// list of all registered handler registered by her uno implementation names 143 static HandlerHash* m_pHandler; 144 /// maps URL pattern to handler names 145 static PatternHash* m_pPattern; 146 /// informs about config updates 147 static HandlerCFGAccess* m_pConfig; 148 /// ref count to construct/destruct internal member lists on demand by using singleton mechanism 149 static sal_Int32 m_nRefCount; 150 151 /* interface */ 152 public: 153 154 HandlerCache(); 155 virtual ~HandlerCache(); 156 157 sal_Bool search( const ::rtl::OUString& sURL, ProtocolHandler* pReturn ) const; 158 sal_Bool search( const css::util::URL& aURL, ProtocolHandler* pReturn ) const; 159 sal_Bool exists( const ::rtl::OUString& sURL ) const; 160 161 void takeOver(HandlerHash* pHandler, PatternHash* pPattern); 162 }; 163 164 //_________________________________________________________________________________________________________________ 165 166 /** 167 @short implements configuration access for handler configuration 168 @descr We use the ConfigItem mechanism to read/write values from/to configuration. 169 We set a data container pointer for filling or reading ... this class use it temp. 170 After successfuly calling of read(), we can use filled container directly or merge it with an existing one. 171 After successfuly calling of write() all values of given data container are flushed to our configuration - 172 but current implementation doesn't support writeing realy. 173 174 @base ::utl::ConfigItem 175 base mechanism for configuration access 176 177 @devstatus ready to use 178 @threadsafe no 179 180 @modified 30.04.2002 09:58, as96863 181 */ 182 class FWI_DLLPUBLIC HandlerCFGAccess : public ::utl::ConfigItem 183 { 184 private: 185 HandlerCache* m_pCache; 186 187 /* interface */ 188 public: 189 HandlerCFGAccess( const ::rtl::OUString& sPackage ); 190 void read ( HandlerHash** ppHandler , 191 PatternHash** ppPattern ); 192 193 void setCache(HandlerCache* pCache) {m_pCache = pCache;}; 194 virtual void Notify(const css::uno::Sequence< rtl::OUString >& lPropertyNames); 195 virtual void Commit(); 196 }; 197 198 } // namespace framework 199 200 #endif // #ifndef __FRAMEWORK_CLASSES_PROTOCOLHANDLERCACHE_HXX_ 201