1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: protocolhandlercache.hxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef __FRAMEWORK_CLASSES_PROTOCOLHANDLERCACHE_HXX_
32 #define __FRAMEWORK_CLASSES_PROTOCOLHANDLERCACHE_HXX_
34 //_________________________________________________________________________________________________________________
36 //_________________________________________________________________________________________________________________
40 #include <macros/debug.hxx>
42 //_________________________________________________________________________________________________________________
44 //_________________________________________________________________________________________________________________
45 #include <com/sun/star/util/URL.hpp>
47 //_________________________________________________________________________________________________________________
49 //_________________________________________________________________________________________________________________
51 #include <unotools/configitem.hxx>
52 #include <rtl/ustring.hxx>
54 //_________________________________________________________________________________________________________________
56 //_________________________________________________________________________________________________________________
60 //_________________________________________________________________________________________________________________
62 //_________________________________________________________________________________________________________________
64 #define PACKAGENAME_PROTOCOLHANDLER DECLARE_ASCII("Office.ProtocolHandler" ) /// name of our configuration package
66 #define CFG_PATH_SEPERATOR DECLARE_ASCII("/" ) /// seperator for configuration pathes
67 #define CFG_ENCODING_OPEN DECLARE_ASCII("[\'" ) /// used to start encoding of set names
68 #define CFG_ENCODING_CLOSE DECLARE_ASCII("\']" ) /// used to finish encoding of set names
70 #define SETNAME_HANDLER DECLARE_ASCII("HandlerSet" ) /// name of configuration set inside package
71 #define PROPERTY_PROTOCOLS DECLARE_ASCII("Protocols" ) /// properties of a protocol handler
73 //_________________________________________________________________________________________________________________
76 Programmer can register his own services to handle different protocols.
77 Don't forget: It doesn't mean "handling of documents" ... these services could handle protocols ...
78 e.g. "mailto:", "file://", ".java:"
79 This struct holds the information about one such registered protocol handler.
80 A list of handler objects is defined as ProtocolHandlerHash. see below
82 struct ProtocolHandler
87 /// the uno implementation name of this handler
88 ::rtl::OUString m_sUNOName
;
89 /// list of URL pattern which defines the protocols which this handler is registered for
90 OUStringList m_lProtocols
;
93 //_________________________________________________________________________________________________________________
96 This hash use registered pattern of all protocol handlers as keys and provide her
97 uno implementation names as value. Overloading of the index operator makes it possible
98 to search for a key by using a full qualified URL on list of all possible pattern keys.
100 class PatternHash
: public BaseHash
< ::rtl::OUString
>
105 PatternHash::iterator
findPatternKey( const ::rtl::OUString
& sURL
);
108 //_________________________________________________________________________________________________________________
111 This hash holds protocol handler structs by her names.
113 typedef BaseHash
< ProtocolHandler
> HandlerHash
;
115 //_________________________________________________________________________________________________________________
118 @short this hash makes it easy to find a protocol handler by using his uno implementation name.
119 @descr It holds two lists of informations:
120 - first holds all handler by her uno implementation names and
121 can be used to get her other properties
122 - another one maps her registered pattern to her uno names to
123 perform search on such data
124 But this lists a static for all instances of this class. So it's possible to
125 create new objects without opening configuration twice and free memory automaticly
126 if last object will gone.
128 @attention We implement a singleton concept - so we doesn't need any mutex member here.
129 Because to safe access on static member we must use a static global lock
132 @devstatus ready to use
135 @modified 30.04.2002 11:19, as96863
138 class HandlerCFGAccess
;
144 /// list of all registered handler registered by her uno implementation names
145 static HandlerHash
* m_pHandler
;
146 /// maps URL pattern to handler names
147 static PatternHash
* m_pPattern
;
148 /// informs about config updates
149 static HandlerCFGAccess
* m_pConfig
;
150 /// ref count to construct/destruct internal member lists on demand by using singleton mechanism
151 static sal_Int32 m_nRefCount
;
157 virtual ~HandlerCache();
159 sal_Bool
search( const ::rtl::OUString
& sURL
, ProtocolHandler
* pReturn
) const;
160 sal_Bool
search( const css::util::URL
& aURL
, ProtocolHandler
* pReturn
) const;
161 sal_Bool
exists( const ::rtl::OUString
& sURL
) const;
163 void takeOver(HandlerHash
* pHandler
, PatternHash
* pPattern
);
166 //_________________________________________________________________________________________________________________
169 @short implements configuration access for handler configuration
170 @descr We use the ConfigItem mechanism to read/write values from/to configuration.
171 We set a data container pointer for filling or reading ... this class use it temp.
172 After successfuly calling of read(), we can use filled container directly or merge it with an existing one.
173 After successfuly calling of write() all values of given data container are flushed to our configuration -
174 but current implementation doesn't support writeing realy.
176 @base ::utl::ConfigItem
177 base mechanism for configuration access
179 @devstatus ready to use
182 @modified 30.04.2002 09:58, as96863
184 class HandlerCFGAccess
: public ::utl::ConfigItem
187 HandlerCache
* m_pCache
;
191 HandlerCFGAccess( const ::rtl::OUString
& sPackage
);
192 void read ( HandlerHash
** ppHandler
,
193 PatternHash
** ppPattern
);
195 void setCache(HandlerCache
* pCache
) {m_pCache
= pCache
;};
196 virtual void Notify(const css::uno::Sequence
< rtl::OUString
>& lPropertyNames
);
199 } // namespace framework
201 #endif // #ifndef __FRAMEWORK_CLASSES_PROTOCOLHANDLERCACHE_HXX_