public boolean canHandle(DownloadLink link) { if (plugin == null) { return false; } final PluginForHost linkPlugin = link.getDefaultPlugin(); boolean canHandle = linkPlugin == null ? true : linkPlugin.allowHandle(link, plugin); if (canHandle) { canHandle = plugin.canHandle(link, account) && plugin.enoughTrafficFor(link, account); } if (canHandle && ACCOUNTTYPE.MULTI.equals(getType()) && getAccount() != null) { final AccountInfo ai = getAccount().getAccountInfo(); /* verify again because plugins can modify list on runtime */ if (ai != null) { Object multiHostSupport = ai.getProperty("multiHostSupport", null); if (multiHostSupport != null && multiHostSupport instanceof List) { canHandle = ((List<Object>) multiHostSupport).contains(link.getHost()); } } } return canHandle; }
/** * Returns configuration from for the specified Account/Hoster combination. * * @param account Account for which the configuration should be retrieved. * @param link Link (used to extract the hoster) for which the configuration should be extracted. * If null, a global setting will be returned instead of a hoster specific one. * @param key Name of the setting which should be retrieved. * @return retrieved configuration value */ private Object getHosterSetting(Account account, DownloadLink link, String key) { AccountInfo ai = account.getAccountInfo(); Map<String, Object> clientConfiguration = (Map<String, Object>) ai.getProperty(CLIENT_CONFIGURATION_KEY); if (clientConfiguration == null) { return null; } if (link == null) { return clientConfiguration.get(key); } else { Map<String, Object> allHostersSettings = (Map<String, Object>) clientConfiguration.get("supported_hosters"); if (allHostersSettings != null) { Map<String, Object> hosterSettings = (Map<String, Object>) allHostersSettings.get(link.getHost()); if (hosterSettings != null) { return hosterSettings.get(key); } } } return null; }