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.
24 import static jalview.util.UrlConstants.DB_ACCESSION;
25 import static jalview.util.UrlConstants.EMBLEBI_STRING;
26 import static jalview.util.UrlConstants.SEQUENCE_ID;
27 import static jalview.util.UrlConstants.SRS_STRING;
29 import java.util.HashMap;
30 import java.util.Iterator;
32 import java.util.StringTokenizer;
33 import java.util.Vector;
37 * Implements the UrlProviderI interface for a UrlProvider object which serves
38 * custom URLs defined by the user
43 public class CustomUrlProvider implements UrlProviderI
46 private HashMap<String, UrlLink> urls;
48 public CustomUrlProvider(String cachedUrlList)
52 StringTokenizer st = new StringTokenizer(cachedUrlList, "|");
53 while (st.hasMoreElements())
55 String name = st.nextToken();
56 String url = st.nextToken();
57 // check for '|' within a regex
58 int rxstart = url.indexOf("$" + DB_ACCESSION + "$");
61 rxstart = url.indexOf("$" + SEQUENCE_ID + "$");
63 while (rxstart == -1 && url.indexOf("/=$") == -1)
65 url = url + "|" + st.nextToken();
67 urls.put(name, new UrlLink(url));
68 // sequenceURLLinks.addElement(name + "|" + url);
70 } catch (Exception ex)
72 System.out.println(ex + "\nError parsing sequence links");
75 // upgrade old SRS link
76 String srs_key = SRS_STRING.split("\\|")[0];
77 if (urls.containsKey(srs_key))
80 urls.put(EMBLEBI_STRING.split("//|")[0],
81 new UrlLink(EMBLEBI_STRING.split("//|")[1]));
86 public HashMap<String, UrlLink> getUrlLinks()
88 // TODO Auto-generated method stub
93 public void getLinksForDisplay(Vector<String> nameLinks,
94 Vector<String> urlLinks)
96 Iterator<Map.Entry<String, UrlLink>> it = urls.entrySet().iterator();
99 Map.Entry<String, UrlLink> pair = it.next();
100 nameLinks.addElement(pair.getKey());
101 urlLinks.addElement(pair.getValue().toString()); // TODO check this is
107 public String getDefaultUrl()
109 // TODO Auto-generated method stub
114 public void setDefaultUrl(String id)
116 // TODO Auto-generated method stub
121 public String writeUrlsAsString()
123 StringBuffer links = new StringBuffer();
126 for (UrlLink link : urls.values())
128 links.append(link.toString());
133 links.setLength(links.length() - 1);
139 return links.toString();
143 public void setUrlLinks(String cachedUrl)
145 // TODO Auto-generated method stub, maybe don't need this? watch out for
146 // superclass interactions
151 public void setUrlLinks(HashMap<String, UrlLink> links)
153 // TODO Auto-generated method stub