2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 package complex
.dispatches
;
20 // __________ Imports __________
22 // structs, const, ...
23 import com
.sun
.star
.beans
.PropertyValue
;
26 import com
.sun
.star
.frame
.DispatchDescriptor
;
27 import com
.sun
.star
.frame
.XDispatch
;
28 import com
.sun
.star
.frame
.XDispatchProvider
;
29 import com
.sun
.star
.frame
.XDispatchProviderInterceptor
;
30 import com
.sun
.star
.frame
.XInterceptorInfo
;
31 import com
.sun
.star
.frame
.XStatusListener
;
37 import com
.sun
.star
.util
.URL
;
39 // __________ Implementation __________
42 * implements a configurable interceptor for dispatch events.
44 public class Interceptor
implements XDispatch
,
45 XDispatchProviderInterceptor
,
50 /** contains the list of interception URL schema's (wildcards are allowed there!)
51 supported by this interceptor. It can be set from outside.
52 If no external URLs are set, the default "*" is used instead.
53 That would have the same effect as if this implementation would not support the
54 interface XInterceptorInfo !
56 private String
[] m_lURLs4InterceptionInfo
= null;
60 /** These URL's will be blocked by this interceptor.
61 Can be set from outside. Every queryDispatch() for these
62 set of URL's will be answered with an empty dispatch object!
63 If no external URLs are set the default "*" is used instead.
64 So every incoming URL will be blocked .-)
66 private String
[] m_lURLs4Blocking
= null;
70 /** Every dispatch interceptor knows it's master and slave interceptor
71 of the dispatch chain. These values must be stupid handled .-)
72 They have to be set and reset in case the right interface methods are called.
73 Nothing more. It's not allowed to dispose() it.
74 The slave can be used inside queryDispatch() to forward requests,
75 which are not handled by this interceptor instance.
77 private XDispatchProvider m_xSlave
= null;
78 private XDispatchProvider m_xMaster
= null;
82 /** counts calls of setSlave...().
83 So the outside API test can use this value to know if this interceptor
84 was really added to the interceptor chain of OOo.
86 private int m_nRegistrationCount
= 0;
90 /** indicates if this interceptor object is currently part of the interceptor
91 chain of OOo. Only true if a valid slave or master dispatch is set on this
94 private boolean m_bIsRegistered
= false;
99 /** XInterceptorInfo */
100 public synchronized String
[] getInterceptedURLs()
102 return impl_getURLs4InterceptionInfo();
107 /** XDispatchProviderInterceptor */
108 public synchronized XDispatchProvider
getSlaveDispatchProvider()
110 System
.out
.println("Interceptor.getSlaveDispatchProvider() called");
116 /** XDispatchProviderInterceptor */
117 public synchronized XDispatchProvider
getMasterDispatchProvider()
119 System
.out
.println("Interceptor.getMasterDispatchProvider() called");
125 /** XDispatchProviderInterceptor */
126 public synchronized void setSlaveDispatchProvider(XDispatchProvider xSlave
)
128 System
.out
.println("Interceptor.setSlaveDispatchProvider("+xSlave
+") called");
132 ++m_nRegistrationCount
;
133 m_bIsRegistered
= true;
137 m_bIsRegistered
= false;
145 /** XDispatchProviderInterceptor */
146 public synchronized void setMasterDispatchProvider(XDispatchProvider xMaster
)
148 System
.out
.println("Interceptor.setMasterDispatchProvider("+xMaster
+") called");
154 /** XDispatchProvider
156 public synchronized XDispatch
queryDispatch(URL aURL
,
157 String sTargetFrameName
,
160 System
.out
.println("Interceptor.queryDispatch('"+aURL
.Complete
+"', '"+sTargetFrameName
+"', "+nSearchFlags
+") called");
162 if (impl_isBlockedURL(aURL
.Complete
))
164 System
.out
.println("Interceptor.queryDispatch(): URL blocked => returns NULL");
168 if (m_xSlave
!= null)
170 System
.out
.println("Interceptor.queryDispatch(): ask slave ...");
171 return m_xSlave
.queryDispatch(aURL
, sTargetFrameName
, nSearchFlags
);
174 System
.out
.println("Interceptor.queryDispatch(): no idea => returns this");
180 /** XDispatchProvider
182 public XDispatch
[] queryDispatches(DispatchDescriptor
[] lRequests
)
185 int c
= lRequests
.length
;
187 XDispatch
[] lResults
= new XDispatch
[c
];
190 lResults
[i
] = queryDispatch(lRequests
[i
].FeatureURL
,
191 lRequests
[i
].FrameName
,
192 lRequests
[i
].SearchFlags
);
202 public synchronized void dispatch(URL aURL
,
203 PropertyValue
[] lArguments
)
205 System
.out
.println("Interceptor.dispatch('"+aURL
.Complete
+"') called");
212 public synchronized void addStatusListener(XStatusListener xListener
,
213 com
.sun
.star
.util
.URL aURL
)
215 System
.out
.println("Interceptor.addStatusListener(..., '"+aURL
.Complete
+"') called");
222 public synchronized void removeStatusListener(XStatusListener xListener
,
223 com
.sun
.star
.util
.URL aURL
)
225 System
.out
.println("Interceptor.removeStatusListener(..., '"+aURL
.Complete
+"') called");
230 public synchronized int getRegistrationCount()
232 return m_nRegistrationCount
;
237 public synchronized boolean isRegistered()
239 return m_bIsRegistered
;
243 /** set a new list of URL's, which should be blocked by this interceptor.
244 (that's why it's necessary to call this impl-method before the interceptor
245 is used at the OOo API!)
247 public synchronized void setURLs4URLs4Blocking(String
[] lURLs
)
249 m_lURLs4Blocking
= lURLs
;
254 /** must be used internal to access the member m_lURLs4InterceptionInfo
256 - and to make sure it's initialized on demand
258 private synchronized String
[] impl_getURLs4InterceptionInfo()
260 if (m_lURLs4InterceptionInfo
== null)
262 m_lURLs4InterceptionInfo
= new String
[] { "*" };
265 return m_lURLs4InterceptionInfo
;
270 /** must be used internal to access the member m_lURLs4Blocking
272 - and to make sure it's initialized on demand
274 private synchronized String
[] impl_getURLs4Blocking()
276 if (m_lURLs4Blocking
== null)
278 m_lURLs4Blocking
= new String
[] { "*" };
281 return m_lURLs4Blocking
;
285 private boolean impl_isBlockedURL(String sURL
)
287 String
[] lBlockedURLs
= impl_getURLs4Blocking();
289 int c
= lBlockedURLs
.length
;
293 if (impl_match(sURL
, lBlockedURLs
[i
]))
304 private boolean impl_match(String sVal1
, String sVal2
)
306 // TODO implement wildcard match
307 return (sVal1
.equals(sVal2
));