Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #ifndef INCLUDED_FRAMEWORK_INC_CLASSES_PROTOCOLHANDLERCACHE_HXX
21 : #define INCLUDED_FRAMEWORK_INC_CLASSES_PROTOCOLHANDLERCACHE_HXX
22 :
23 : #include <general.h>
24 : #include <stdtypes.h>
25 :
26 : #include <com/sun/star/util/URL.hpp>
27 :
28 : #include <unotools/configitem.hxx>
29 : #include <rtl/ustring.hxx>
30 : #include <fwidllapi.h>
31 :
32 : namespace framework{
33 :
34 : #define PACKAGENAME_PROTOCOLHANDLER DECLARE_ASCII("Office.ProtocolHandler" ) /// name of our configuration package
35 :
36 : #define CFG_PATH_SEPARATOR DECLARE_ASCII("/" ) /// separator for configuration paths
37 :
38 : #define PROPERTY_PROTOCOLS DECLARE_ASCII("Protocols" ) /// properties of a protocol handler
39 :
40 : /**
41 : Programmer can register his own services to handle different protocols.
42 : Don't forget: It doesn't mean "handling of documents" ... these services could handle protocols ...
43 : e.g. "mailto:", "file://", ".java:"
44 : This struct holds the information about one such registered protocol handler.
45 : A list of handler objects is defined as ProtocolHandlerHash. see below
46 : */
47 105979 : struct FWI_DLLPUBLIC ProtocolHandler
48 : {
49 : /* member */
50 : public:
51 :
52 : /// the uno implementation name of this handler
53 : OUString m_sUNOName;
54 : /// list of URL pattern which defines the protocols which this handler is registered for
55 : OUStringList m_lProtocols;
56 : };
57 :
58 : /**
59 : This hash use registered pattern of all protocol handlers as keys and provide her
60 : uno implementation names as value. Overloading of the index operator makes it possible
61 : to search for a key by using a full qualified URL on list of all possible pattern keys.
62 : */
63 413 : class FWI_DLLPUBLIC PatternHash : public BaseHash< OUString >
64 : {
65 : /* interface */
66 : public:
67 :
68 : PatternHash::iterator findPatternKey( const OUString& sURL );
69 : };
70 :
71 : /**
72 : This hash holds protocol handler structs by her names.
73 : */
74 : typedef BaseHash< ProtocolHandler > HandlerHash;
75 :
76 : /**
77 : @short this hash makes it easy to find a protocol handler by using his uno implementation name.
78 : @descr It holds two lists of information:
79 : - first holds all handler by her uno implementation names and
80 : can be used to get her other properties
81 : - another one maps her registered pattern to her uno names to
82 : perform search on such data
83 : But this lists a static for all instances of this class. So it's possible to
84 : create new objects without opening configuration twice and free memory automatically
85 : if last object will gone.
86 :
87 : @attention We implement a singleton concept - so we don't need any mutex member here.
88 : Because to safe access on static member we must use a static global lock
89 : here too.
90 :
91 : @devstatus ready to use
92 : @threadsafe yes
93 : */
94 :
95 : class HandlerCFGAccess;
96 : class FWI_DLLPUBLIC HandlerCache
97 : {
98 : /* member */
99 : private:
100 :
101 : /// list of all registered handler registered by her uno implementation names
102 : static HandlerHash* m_pHandler;
103 : /// maps URL pattern to handler names
104 : static PatternHash* m_pPattern;
105 : /// informs about config updates
106 : static HandlerCFGAccess* m_pConfig;
107 : /// ref count to construct/destruct internal member lists on demand by using singleton mechanism
108 : static sal_Int32 m_nRefCount;
109 :
110 : /* interface */
111 : public:
112 :
113 : HandlerCache();
114 : virtual ~HandlerCache();
115 :
116 : bool search( const OUString& sURL, ProtocolHandler* pReturn ) const;
117 : bool search( const css::util::URL& aURL, ProtocolHandler* pReturn ) const;
118 :
119 : void takeOver(HandlerHash* pHandler, PatternHash* pPattern);
120 : };
121 :
122 : /**
123 : @short implements configuration access for handler configuration
124 : @descr We use the ConfigItem mechanism to read/write values from/to configuration.
125 : We set a data container pointer for filling or reading ... this class use it temp.
126 : After successfully calling of read(), we can use filled container directly or merge it with an existing one.
127 : After successfully calling of write() all values of given data container are flushed to our configuration -
128 : but current implementation doesn't support writing really.
129 :
130 : @base ::utl::ConfigItem
131 : base mechanism for configuration access
132 :
133 : @devstatus ready to use
134 : @threadsafe no
135 : */
136 404 : class FWI_DLLPUBLIC HandlerCFGAccess : public ::utl::ConfigItem
137 : {
138 : private:
139 : HandlerCache* m_pCache;
140 :
141 : virtual void ImplCommit() SAL_OVERRIDE;
142 :
143 : /* interface */
144 : public:
145 : HandlerCFGAccess( const OUString& sPackage );
146 : void read ( HandlerHash** ppHandler ,
147 : PatternHash** ppPattern );
148 :
149 413 : void setCache(HandlerCache* pCache) {m_pCache = pCache;};
150 : virtual void Notify(const css::uno::Sequence< OUString >& lPropertyNames) SAL_OVERRIDE;
151 : };
152 :
153 : } // namespace framework
154 :
155 : #endif // INCLUDED_FRAMEWORK_INC_CLASSES_PROTOCOLHANDLERCACHE_HXX
156 :
157 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|