/* * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) * Copyright (C) $$Year-Rel$$ The Jalview Authors * * This file is part of Jalview. * * Jalview is free software: you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation, either version 3 * of the License, or (at your option) any later version. * * Jalview is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty * of MERCHANTABILITY or FITNESS FOR A PARTICULAR * PURPOSE. See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Jalview. If not, see . * The Jalview Authors are detailed in the 'AUTHORS' file. */ package jalview.urls; import static jalview.util.UrlConstants.SEP; import java.util.ArrayList; import java.util.List; import java.util.Vector; /** * * Implements the UrlProviderI interface for a composite UrlProvider object * * @author $author$ * @version $Revision$ */ public class UrlProvider implements UrlProviderI { // List of actual URL link providers private List providers; // Specific reference to custom URL link provider private UrlProviderI customProvider; /** * Constructor for UrlProvider composite * * @param defaultUrlString * id of default url * @param allProviders * list of UrlProviders this provider gives access to */ public UrlProvider(String defaultUrlString, List allProviders) { providers = allProviders; customProvider = findCustomProvider(); // check that the defaultUrl still exists if (!setDefaultUrl(defaultUrlString)) { chooseDefaultUrl(); } } /* * Store ref to custom url provider */ private UrlProviderI findCustomProvider() { for (UrlProviderI p : providers) { if (p.getClass().equals(CustomUrlProvider.class)) { return p; } } System.out .println("Error initialising UrlProvider - no custom url provider"); return null; } @Override public boolean setDefaultUrl(String id) { boolean outcome = false; for (UrlProviderI p : providers) { if (p.setDefaultUrl(id)) { outcome = true; } } return outcome; } @Override public String writeUrlsAsString(boolean selected) { String result = ""; for (UrlProviderI p : providers) { String next = p.writeUrlsAsString(selected); if (!next.isEmpty()) { result += next; result += SEP; } } // remove last sep if (!result.isEmpty()) { result = result.substring(0, result.length() - 1); } return result; } @Override public Vector getLinksForMenu() { Vector fullLinks = new Vector(); for (UrlProviderI p : providers) { List links = p.getLinksForMenu(); if (links != null) { // will obliterate links with same keys from different providers // must have checks in place to prevent user from duplicating ids fullLinks.addAll(links); } } return fullLinks; } @Override public List getLinksForTable() { ArrayList displayLinks = new ArrayList(); for (UrlProviderI p : providers) { displayLinks.addAll(p.getLinksForTable()); } return displayLinks; } @Override public void setUrlData(List links) { for (UrlProviderI p : providers) { p.setDefaultUrl(null); p.setUrlData(links); } } @Override public String getDefaultUrl(String seqid) { String link = null; for (UrlProviderI p : providers) { if (p.getDefaultUrl(seqid) == null) { continue; } else { link = p.getDefaultUrl(seqid); break; } } return link; } @Override public String getDefaultUrlId() { String id = null; for (UrlProviderI p : providers) { if (p.getDefaultUrlId() == null) { continue; } else { id = p.getDefaultUrlId(); break; } } return id; } @Override public String getDefaultTarget(String seqid) { String target = null; for (UrlProviderI p : providers) { if (p.getDefaultTarget(seqid) == null) { continue; } else { target = p.getDefaultTarget(seqid); break; } } return target; } @Override public String chooseDefaultUrl() { // choose a custom url default return customProvider.chooseDefaultUrl(); } @Override public boolean isUserEntry(String id) { return customProvider.isUserEntry(id); } }