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;
27 import java.util.Vector;
31 * Implements the UrlProviderI interface for a composite UrlProvider object
36 public class UrlProvider implements UrlProviderI
38 // List of actual URL link providers
39 private List<UrlProviderI> providers;
41 // Specific reference to custom URL link provider
42 private UrlProviderI customProvider;
45 * Constructor for UrlProvider composite
47 * @param defaultUrlString
50 * list of UrlProviders this provider gives access to
52 public UrlProvider(String defaultUrlString,
53 List<UrlProviderI> allProviders)
55 providers = allProviders;
57 customProvider = findCustomProvider();
59 // check that the defaultUrl still exists
60 if (!contains(defaultUrlString))
62 // if the defaultUrl can't be found in any of the providers
63 // set up a custom default url
68 setDefaultUrl(defaultUrlString);
73 * Store ref to custom url provider
75 private UrlProviderI findCustomProvider()
77 for (UrlProviderI p : providers)
79 if (p.getClass().equals(CustomUrlProvider.class))
86 .println("Error initialising UrlProvider - no custom url provider");
91 public boolean setDefaultUrl(String id)
93 boolean outcome = false;
94 for (UrlProviderI p : providers)
96 if (p.setDefaultUrl(id))
103 throw new IllegalArgumentException();
109 public boolean contains(String id)
111 boolean outcome = false;
112 for (UrlProviderI p : providers)
123 public String writeUrlsAsString(boolean selected)
126 for (UrlProviderI p : providers)
128 String next = p.writeUrlsAsString(selected);
136 if (!result.isEmpty())
138 result = result.substring(0, result.length() - 1);
144 public Vector<String> getLinksForMenu()
146 Vector<String> fullLinks = new Vector<String>();
147 for (UrlProviderI p : providers)
149 List<String> links = p.getLinksForMenu();
152 // will obliterate links with same keys from different providers
153 // must have checks in place to prevent user from duplicating ids
154 fullLinks.addAll(links);
161 public List<UrlLinkDisplay> getLinksForTable()
163 ArrayList<UrlLinkDisplay> displayLinks = new ArrayList<UrlLinkDisplay>();
164 for (UrlProviderI p : providers)
166 displayLinks.addAll(p.getLinksForTable());
172 public void setUrlData(List<UrlLinkDisplay> links)
174 for (UrlProviderI p : providers)
181 public String getDefaultUrl(String seqid)
184 for (UrlProviderI p : providers)
186 if (p.getDefaultUrl(seqid) == null)
192 link = p.getDefaultUrl(seqid);
200 public String getDefaultUrlId()
203 for (UrlProviderI p : providers)
205 if (p.getDefaultUrlId() == null)
211 id = p.getDefaultUrlId();
219 public String getDefaultTarget(String seqid)
221 String target = null;
222 for (UrlProviderI p : providers)
224 if (p.getDefaultTarget(seqid) == null)
230 target = p.getDefaultTarget(seqid);
238 public String chooseDefaultUrl()
240 // choose a custom url default
241 return customProvider.chooseDefaultUrl();
245 public boolean isUserEntry(String id)
247 return customProvider.isUserEntry(id);