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