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 static jalview.util.UrlConstants.SEP;
25 import java.util.ArrayList;
26 import java.util.List;
28 import java.util.Vector;
32 * Implements the UrlProviderI interface for a composite UrlProvider object
37 public class UrlProvider implements UrlProviderI
39 // List of actual URL link providers
40 private List<UrlProviderI> providers;
42 // Specific reference to custom URL link provider
43 private UrlProviderI customProvider;
46 * Construct URL provider from string of cached URLs, and set default URL
48 * @param defaultUrlString
49 * id of the current default URL
50 * @param cachedUrlList
51 * string listing current active URLs, expected to be custom URLs
52 * separated by |, or ids of URLs
54 public UrlProvider(String defaultUrlString, String cachedUrlList)
56 // create all the UrlProviders we need
57 providers = new ArrayList<UrlProviderI>();
59 UrlProviderI idProvider = new IdentifiersUrlProvider(cachedUrlList,
61 customProvider = new CustomUrlProvider(cachedUrlList);
62 providers.add(idProvider);
63 providers.add(customProvider);
65 // check that the defaultUrl still exists
66 if (!setDefaultUrl(defaultUrlString))
73 * Construct URL provider from a map of (label,url) pairs, and set default URL
75 * @param defaultUrlString
76 * id of the current default URL
78 * vector of (label, url) pairs
80 public UrlProvider(String defaultUrlString, Map<String, String> urlList)
82 // create all the UrlProviders we need
83 providers = new ArrayList<UrlProviderI>();
85 UrlProviderI idProvider = new IdentifiersUrlProvider(null,
87 customProvider = new CustomUrlProvider(urlList);
88 providers.add(idProvider);
89 providers.add(customProvider);
91 // check that the defaultUrl still exists
92 if (!setDefaultUrl(defaultUrlString))
99 public String getDefaultUrl()
101 String defaultUrl = null;
102 for (UrlProviderI p : providers)
104 defaultUrl = p.getDefaultUrl();
105 if (defaultUrl != null)
111 // no provider has a default set, just choose one
112 if (defaultUrl == null)
114 defaultUrl = chooseDefaultUrl();
120 public boolean setDefaultUrl(String id)
122 for (UrlProviderI p : providers)
124 if (p.setDefaultUrl(id))
133 public String writeUrlsAsString()
136 for (UrlProviderI p : providers)
138 result += p.writeUrlsAsString();
142 result = result.substring(0, result.length() - 1);
147 public Vector<String> getLinksForDisplay()
149 Vector<String> fullLinks = new Vector<String>();
150 for (UrlProviderI p : providers)
152 List<String> links = p.getLinksForDisplay();
155 // will obliterate links with same keys from different providers
156 // must have checks in place to prevent user from duplicating ids
157 fullLinks.addAll(links);
164 public List<UrlLinkDisplay> getLinksForTable()
166 ArrayList<UrlLinkDisplay> displayLinks = new ArrayList<UrlLinkDisplay>();
167 for (UrlProviderI p : providers)
169 displayLinks.addAll(p.getLinksForTable());
175 public void setUrlData(List<UrlLinkDisplay> links)
177 for (UrlProviderI p : providers)
184 public String getDefaultUrl(String seqid)
187 for (UrlProviderI p : providers)
189 if (p.getDefaultUrl(seqid) == null)
195 link = p.getDefaultUrl(seqid);
203 public String getDefaultTarget(String seqid)
205 String target = null;
206 for (UrlProviderI p : providers)
208 if (p.getDefaultTarget(seqid) == null)
214 target = p.getDefaultTarget(seqid);
222 public void setUrlLinks(Vector<String> names, Vector<String> urls)
224 // only allow custom urls to be updated by user
225 customProvider.setUrlLinks(names, urls);
229 public String chooseDefaultUrl()
231 // choose a custom url default
232 return customProvider.chooseDefaultUrl();
236 public boolean isUserEntry(String id)
238 return customProvider.isUserEntry(id);