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);
58 customProvider = new CustomUrlProvider(cachedUrlList);
59 providers.add(idProvider);
60 providers.add(customProvider);
62 // check that the defaultUrl still exists
63 if (!setDefaultUrl(defaultUrlString))
70 * Construct URL provider from a map of (label,url) pairs, and set default URL
72 * @param defaultUrlString
73 * id of the current default URL
75 * vector of (label, url) pairs
77 public UrlProvider(String defaultUrlString, Map<String, String> urlList)
79 // create all the UrlProviders we need
80 providers = new ArrayList<UrlProviderI>();
82 UrlProviderI idProvider = new IdentifiersUrlProvider(urlList);
83 customProvider = new CustomUrlProvider(urlList);
84 providers.add(idProvider);
85 providers.add(customProvider);
87 // check that the defaultUrl still exists
88 if (!setDefaultUrl(defaultUrlString))
95 public String getDefaultUrl()
97 String defaultUrl = null;
98 for (UrlProviderI p : providers)
100 defaultUrl = p.getDefaultUrl();
101 if (defaultUrl != null)
107 // no provider has a default set, just choose one
108 if (defaultUrl == null)
110 defaultUrl = chooseDefaultUrl();
116 public boolean setDefaultUrl(String id)
118 for (UrlProviderI p : providers)
120 if (p.setDefaultUrl(id))
129 public String writeUrlsAsString()
132 for (UrlProviderI p : providers)
134 result += p.writeUrlsAsString();
140 public Vector<String> getLinksForDisplay()
142 Vector<String> fullLinks = new Vector<String>();
143 for (UrlProviderI p : providers)
145 List<String> links = p.getLinksForDisplay();
148 // will obliterate links with same keys from different providers
149 // must have checks in place to prevent user from duplicating ids
150 fullLinks.addAll(links);
157 public String getDefaultUrl(String seqid)
160 for (UrlProviderI p : providers)
162 if (p.getDefaultUrl(seqid) == null)
168 link = p.getDefaultUrl(seqid);
176 public String getDefaultTarget(String seqid)
178 String target = null;
179 for (UrlProviderI p : providers)
181 if (p.getDefaultTarget(seqid) == null)
187 target = p.getDefaultTarget(seqid);
195 public void setUrlLinks(Vector<String> names, Vector<String> urls)
197 // only allow custom urls to be updated by user
198 customProvider.setUrlLinks(names, urls);
202 public String chooseDefaultUrl()
204 // choose a custom url default
205 return customProvider.chooseDefaultUrl();