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 SETNAME_HANDLER DECLARE_ASCII("HandlerSet" ) /// name of configuration set inside package
39 : #define PROPERTY_PROTOCOLS DECLARE_ASCII("Protocols" ) /// properties of a protocol handler
40 :
41 : /**
42 : Programmer can register his own services to handle different protocols.
43 : Don't forget: It doesn't mean "handling of documents" ... these services could handle protocols ...
44 : e.g. "mailto:", "file://", ".java:"
45 : This struct holds the information about one such registered protocol handler.
46 : A list of handler objects is defined as ProtocolHandlerHash. see below
47 : */
48 170447 : struct FWI_DLLPUBLIC ProtocolHandler
49 : {
50 : /* member */
51 : public:
52 :
53 : /// the uno implementation name of this handler
54 : OUString m_sUNOName;
55 : /// list of URL pattern which defines the protocols which this handler is registered for
56 : OUStringList m_lProtocols;
57 : };
58 :
59 : /**
60 : This hash use registered pattern of all protocol handlers as keys and provide her
61 : uno implementation names as value. Overloading of the index operator makes it possible
62 : to search for a key by using a full qualified URL on list of all possible pattern keys.
63 : */
64 610 : class FWI_DLLPUBLIC PatternHash : public BaseHash< OUString >
65 : {
66 : /* interface */
67 : public:
68 :
69 : PatternHash::iterator findPatternKey( const OUString& sURL );
70 : };
71 :
72 : /**
73 : This hash holds protocol handler structs by her names.
74 : */
75 : typedef BaseHash< ProtocolHandler > HandlerHash;
76 :
77 : /**
78 : @short this hash makes it easy to find a protocol handler by using his uno implementation name.
79 : @descr It holds two lists of information:
80 : - first holds all handler by her uno implementation names and
81 : can be used to get her other properties
82 : - another one maps her registered pattern to her uno names to
83 : perform search on such data
84 : But this lists a static for all instances of this class. So it's possible to
85 : create new objects without opening configuration twice and free memory automatically
86 : if last object will gone.
87 :
88 : @attention We implement a singleton concept - so we don't need any mutex member here.
89 : Because to safe access on static member we must use a static global lock
90 : here too.
91 :
92 : @devstatus ready to use
93 : @threadsafe yes
94 : */
95 :
96 : class HandlerCFGAccess;
97 : class FWI_DLLPUBLIC HandlerCache
98 : {
99 : /* member */
100 : private:
101 :
102 : /// list of all registered handler registered by her uno implementation names
103 : static HandlerHash* m_pHandler;
104 : /// maps URL pattern to handler names
105 : static PatternHash* m_pPattern;
106 : /// informs about config updates
107 : static HandlerCFGAccess* m_pConfig;
108 : /// ref count to construct/destruct internal member lists on demand by using singleton mechanism
109 : static sal_Int32 m_nRefCount;
110 :
111 : /* interface */
112 : public:
113 :
114 : HandlerCache();
115 : virtual ~HandlerCache();
116 :
117 : bool search( const OUString& sURL, ProtocolHandler* pReturn ) const;
118 : bool search( const css::util::URL& aURL, ProtocolHandler* pReturn ) const;
119 :
120 : void takeOver(HandlerHash* pHandler, PatternHash* pPattern);
121 : };
122 :
123 : /**
124 : @short implements configuration access for handler configuration
125 : @descr We use the ConfigItem mechanism to read/write values from/to configuration.
126 : We set a data container pointer for filling or reading ... this class use it temp.
127 : After successfully calling of read(), we can use filled container directly or merge it with an existing one.
128 : After successfully calling of write() all values of given data container are flushed to our configuration -
129 : but current implementation doesn't support writing really.
130 :
131 : @base ::utl::ConfigItem
132 : base mechanism for configuration access
133 :
134 : @devstatus ready to use
135 : @threadsafe no
136 : */
137 602 : class FWI_DLLPUBLIC HandlerCFGAccess : public ::utl::ConfigItem
138 : {
139 : private:
140 : HandlerCache* m_pCache;
141 :
142 : /* interface */
143 : public:
144 : HandlerCFGAccess( const OUString& sPackage );
145 : void read ( HandlerHash** ppHandler ,
146 : PatternHash** ppPattern );
147 :
148 610 : void setCache(HandlerCache* pCache) {m_pCache = pCache;};
149 : virtual void Notify(const css::uno::Sequence< OUString >& lPropertyNames) SAL_OVERRIDE;
150 : virtual void Commit() 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: */
|