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