1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.xnap.plugin.opennap.net;
21
22 import java.util.Hashtable;
23 import java.util.Iterator;
24
25 import org.xnap.plugin.opennap.OpenNapPlugin;
26 import org.xnap.search.MediaType;
27 import org.xnap.search.Search;
28 import org.xnap.search.SearchFilter;
29 import org.xnap.search.SearchManager;
30 import org.xnap.search.SearchProvider;
31
32 public class OpenNapSearchManager implements SearchProvider {
33
34
35
36
37
38
39
40 private Hashtable mediaTypeByRealm = new Hashtable();
41
42
43
44 public OpenNapSearchManager()
45 {
46 mediaTypeByRealm.put("audio", SearchManager.MEDIA_AUDIO);
47 mediaTypeByRealm.put("video", SearchManager.MEDIA_VIDEO);
48 mediaTypeByRealm.put("image", SearchManager.MEDIA_IMAGES);
49 mediaTypeByRealm.put("application", SearchManager.MEDIA_SOFTWARE);
50 mediaTypeByRealm.put("text", SearchManager.MEDIA_DOCUMENTS);
51 }
52
53
54
55 public MediaType getMediaType(String realm)
56 {
57 return (MediaType)mediaTypeByRealm.get(realm);
58 }
59
60 public String getRealm(MediaType mt)
61 {
62 for (Iterator i = mediaTypeByRealm.keySet().iterator(); i.hasNext();) {
63 String realm = (String)i.next();
64 if (mediaTypeByRealm.get(realm) == mt) {
65 return realm;
66 }
67 }
68 return null;
69 }
70
71 public MediaType[] getSupportedMediaTypes()
72 {
73 return new MediaType[] {
74 SearchManager.MEDIA_ANYTHING, SearchManager.MEDIA_AUDIO,
75 SearchManager.MEDIA_DOCUMENTS, SearchManager.MEDIA_IMAGES,
76 SearchManager.MEDIA_SOFTWARE, SearchManager.MEDIA_VIDEO,
77 };
78 }
79
80 public String getName()
81 {
82 return OpenNapPlugin.getInstance().getInfo().getName();
83 }
84
85 /***
86 * Returns true, if realm is a valid OpenNap realm.
87 */
88 public boolean isRealm(String realm)
89 {
90 return mediaTypeByRealm.containsKey(realm);
91 }
92
93 /***
94 * Invoked when a search is requested.
95 */
96 public Search search(SearchFilter filter)
97 {
98
99
100
101
102 OpenNapPlugin.getInstance().getInfo().setDisableable(false);
103
104 OpenNapServer s = (OpenNapServer)filter.get("nap.server");
105 if (s != null) {
106 return new OpenNapSearch(filter, OpenNapSearch.PRIORITY_HIGH,
107 new OpenNapServer[] { s });
108 }
109 else {
110 return new OpenNapSearch
111 (filter, OpenNapSearch.PRIORITY_HIGH,
112 OpenNapPlugin.getServerManager().getConnectedServers());
113 }
114 }
115
116 }