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 jalview.urls.api.UrlProviderI;
27 import java.util.ArrayList;
28 import java.util.List;
29 import java.util.Vector;
33 * Implements the UrlProviderI interface for a composite UrlProvider object
38 public class UrlProvider implements UrlProviderI
40 // List of actual URL link providers
41 private List<UrlProviderI> providers;
43 // Specific reference to custom URL link provider
44 private UrlProviderI customProvider;
47 * Constructor for UrlProvider composite
49 * @param defaultUrlString
52 * list of UrlProviders this provider gives access to
54 public UrlProvider(String defaultUrlString,
55 List<UrlProviderI> allProviders)
57 providers = allProviders;
59 customProvider = findCustomProvider();
61 // check that the defaultUrl still exists
62 if (!contains(defaultUrlString))
64 // if the defaultUrl can't be found in any of the providers
65 // set up a custom default url
70 setPrimaryUrl(defaultUrlString);
75 * Store ref to custom url provider
77 private UrlProviderI findCustomProvider()
79 for (UrlProviderI p : providers)
81 if (p instanceof CustomUrlProvider)
88 "Error initialising UrlProvider - no custom url provider");
93 public boolean setPrimaryUrl(String id)
95 boolean outcome = false;
96 for (UrlProviderI p : providers)
98 if (p.setPrimaryUrl(id))
105 throw new IllegalArgumentException();
111 public boolean contains(String id)
113 boolean outcome = false;
114 for (UrlProviderI p : providers)
125 public String writeUrlsAsString(boolean selected)
128 for (UrlProviderI p : providers)
130 String next = p.writeUrlsAsString(selected);
138 if (!result.isEmpty())
140 result = result.substring(0, result.length() - 1);
146 public Vector<String> getLinksForMenu()
148 Vector<String> fullLinks = new Vector<String>();
149 for (UrlProviderI p : providers)
151 List<String> links = p.getLinksForMenu();
154 // will obliterate links with same keys from different providers
155 // must have checks in place to prevent user from duplicating ids
156 fullLinks.addAll(links);
163 public List<UrlLinkDisplay> getLinksForTable()
165 ArrayList<UrlLinkDisplay> displayLinks = new ArrayList<UrlLinkDisplay>();
166 for (UrlProviderI p : providers)
168 displayLinks.addAll(p.getLinksForTable());
174 public void setUrlData(List<UrlLinkDisplay> links)
176 for (UrlProviderI p : providers)
183 public String getPrimaryUrl(String seqid)
186 for (UrlProviderI p : providers)
188 if (p.getPrimaryUrl(seqid) == null)
194 link = p.getPrimaryUrl(seqid);
202 public String getPrimaryUrlId()
205 for (UrlProviderI p : providers)
207 if (p.getPrimaryUrlId() == null)
213 id = p.getPrimaryUrlId();
221 public String getPrimaryTarget(String seqid)
223 String target = null;
224 for (UrlProviderI p : providers)
226 if (p.getPrimaryTarget(seqid) == null)
232 target = p.getPrimaryTarget(seqid);
240 public String choosePrimaryUrl()
242 // choose a custom url default
243 return customProvider.choosePrimaryUrl();
247 public boolean isUserEntry(String id)
249 return customProvider.isUserEntry(id);