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.HashMap;
25 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 // Record of default URL
41 private String defaultUrl;
44 * Construct URL provider from string of cached URLs, and set default URL
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 defaultUrl, String cachedUrlList)
54 // create all the UrlProviders we need
55 providers = new ArrayList<UrlProviderI>();
57 UrlProviderI idProvider = new IdentifiersUrlProvider(cachedUrlList);
58 UrlProviderI customProvider = new CustomUrlProvider(cachedUrlList);
59 providers.add(idProvider);
60 providers.add(customProvider);
62 // check that the defaultUrl still exists
66 * Get all the URL links
67 * @return all URL links
70 public HashMap<String, UrlLink> getUrlLinks()
72 HashMap<String, UrlLink> urls = new HashMap<String, UrlLink>();
73 for (UrlProviderI p : providers)
75 urls.putAll(p.getUrlLinks());
82 * @return id of the default URL
85 public String getDefaultUrl()
92 * @param id the id of the URL to set as default
95 public void setDefaultUrl(String id)
101 * Write out all URLs as a string suitable for serialising
102 * @return string representation of available URLs
105 public String writeUrlsAsString()
108 for (UrlProviderI p : providers)
110 result += p.writeUrlsAsString();
116 * Set URL links from string
119 * string representation of URL links, i.e. | separated
122 public void setUrlLinks(String cachedUrl)
124 for (UrlProviderI p : providers)
126 p.setUrlLinks(cachedUrl);
131 * Set URL links from collection
134 * hashmap containing string indexed UrlLinks
137 public void setUrlLinks(HashMap<String, UrlLink> links)
139 for (UrlProviderI p : providers)
141 p.setUrlLinks(links);
146 public void getLinksForDisplay(Vector<String> nameLinks,
147 Vector<String> urlLinks)
149 Vector<String> names = new Vector<String>();
150 Vector<String> links = new Vector<String>();
151 for (UrlProviderI p : providers)
153 p.getLinksForDisplay(names, links);
154 nameLinks.addAll(names);
155 urlLinks.addAll(links);