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