2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
23 import java.util.ArrayList;
24 import java.util.List;
26 import java.util.Vector;
30 * Implements the UrlProviderI interface for a composite UrlProvider object
35 public class UrlProvider implements UrlProviderI
37 // List of actual URL link providers
38 private List<UrlProviderI> providers;
40 // Specific reference to custom URL link provider
41 private UrlProviderI customProvider;
44 * Construct URL provider from string of cached URLs, and set default URL
46 * @param defaultUrlString
47 * id of the current default URL
48 * @param cachedUrlList
49 * string listing current active URLs, expected to be custom URLs
50 * separated by |, or ids of URLs
52 public UrlProvider(String defaultUrlString, String cachedUrlList)
54 // create all the UrlProviders we need
55 providers = new ArrayList<UrlProviderI>();
57 UrlProviderI idProvider = new IdentifiersUrlProvider(cachedUrlList,
59 customProvider = new CustomUrlProvider(cachedUrlList);
60 // providers.add(idProvider);
61 providers.add(customProvider);
63 // check that the defaultUrl still exists
64 if (!setDefaultUrl(defaultUrlString))
71 * Construct URL provider from a map of (label,url) pairs, and set default URL
73 * @param defaultUrlString
74 * id of the current default URL
76 * vector of (label, url) pairs
78 public UrlProvider(String defaultUrlString, Map<String, String> urlList)
80 // create all the UrlProviders we need
81 providers = new ArrayList<UrlProviderI>();
83 UrlProviderI idProvider = new IdentifiersUrlProvider(null,
85 customProvider = new CustomUrlProvider(urlList);
86 providers.add(idProvider);
87 providers.add(customProvider);
89 // check that the defaultUrl still exists
90 if (!setDefaultUrl(defaultUrlString))
97 public String getDefaultUrl()
99 String defaultUrl = null;
100 for (UrlProviderI p : providers)
102 defaultUrl = p.getDefaultUrl();
103 if (defaultUrl != null)
109 // no provider has a default set, just choose one
110 if (defaultUrl == null)
112 defaultUrl = chooseDefaultUrl();
118 public boolean setDefaultUrl(String id)
120 for (UrlProviderI p : providers)
122 if (p.setDefaultUrl(id))
131 public String writeUrlsAsString()
134 for (UrlProviderI p : providers)
136 result += p.writeUrlsAsString();
142 public Vector<String> getLinksForDisplay()
144 Vector<String> fullLinks = new Vector<String>();
145 for (UrlProviderI p : providers)
147 List<String> links = p.getLinksForDisplay();
150 // will obliterate links with same keys from different providers
151 // must have checks in place to prevent user from duplicating ids
152 fullLinks.addAll(links);
159 public String getDefaultUrl(String seqid)
162 for (UrlProviderI p : providers)
164 if (p.getDefaultUrl(seqid) == null)
170 link = p.getDefaultUrl(seqid);
178 public String getDefaultTarget(String seqid)
180 String target = null;
181 for (UrlProviderI p : providers)
183 if (p.getDefaultTarget(seqid) == null)
189 target = p.getDefaultTarget(seqid);
197 public void setUrlLinks(Vector<String> names, Vector<String> urls)
199 // only allow custom urls to be updated by user
200 customProvider.setUrlLinks(names, urls);
204 public String chooseDefaultUrl()
206 // choose a custom url default
207 return customProvider.chooseDefaultUrl();