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 jalview.util.UrlLink;
25 import java.util.ArrayList;
26 import java.util.HashMap;
27 import java.util.List;
28 import java.util.Map.Entry;
29 import java.util.Vector;
30 import java.util.regex.Pattern;
33 * Leaf node of UrlProvider composite
39 public class UrlProviderImpl implements UrlProviderI
41 private static final Pattern MIRIAM_PATTERN = Pattern
42 .compile("^MIR:\\d{8}$");
44 // minimum length of substitution in url link string
45 protected static final int MIN_SUBST_LENGTH = 4;
47 protected String defaultUrl;
50 public Vector<String> getLinksForMenu()
52 // TODO Auto-generated method stub
57 public String getDefaultUrl(String seqid)
59 // TODO Auto-generated method stub
64 public String getDefaultTarget(String seqid)
66 // TODO Auto-generated method stub
70 protected String getDefaultUrl(String seqid, HashMap<String, UrlLink> urls)
72 if (seqid.length() < MIN_SUBST_LENGTH)
76 else if (defaultUrl == null)
83 UrlLink urlLink = urls.get(defaultUrl);
84 String[] defaultUrls = urlLink.makeUrls(seqid, true);
85 if (defaultUrls == null || defaultUrls[0] == null
86 || defaultUrls[0].length() < MIN_SUBST_LENGTH)
92 // just take first URL made from regex
100 public boolean setDefaultUrl(String id)
102 // TODO Auto-generated method stub
107 public String writeUrlsAsString(boolean selected)
109 // TODO Auto-generated method stub
114 public String chooseDefaultUrl()
116 // TODO Auto-generated method stub
121 public List<UrlLinkDisplay> getLinksForTable()
126 protected ArrayList<UrlLinkDisplay> getLinksForTable(
127 HashMap<String, UrlLink> urls, ArrayList<String> selectedUrls,
130 ArrayList<UrlLinkDisplay> displayLinks = new ArrayList<UrlLinkDisplay>();
131 for (Entry<String, UrlLink> entry : urls.entrySet())
133 String key = entry.getKey();
134 boolean isDefault = (key.equals(defaultUrl));
136 if (selectedUrls != null)
138 isSelected = selectedUrls.contains(key);
142 isSelected = selected;
144 String displayLink = entry.getValue().getUrlWithToken();
145 displayLinks.add(new UrlLinkDisplay(key, entry.getValue().getLabel(),
146 displayLink, isSelected, isDefault));
152 public void setUrlData(List<UrlLinkDisplay> links)
154 // deliberately left empty
157 protected boolean isMiriamId(String id)
159 return MIRIAM_PATTERN.matcher(id).matches();
163 public boolean isUserEntry(String id)
165 return !isMiriamId(id);
169 public String getDefaultUrlId()
171 // TODO Auto-generated method stub