/** * This method try to retrieve the protocol indicated by the given URL string. * * @param urlString to be analysed * @return found {@code Protocol} or {@code null} */ public static Protocol getFrom(final String urlString) { if (HTTP.isTheSame(urlString)) { return HTTP; } else if (HTTPS.isTheSame(urlString)) { return HTTPS; } else if (LDAP.isTheSame(urlString)) { return LDAP; } else if (FTP.isTheSame(urlString)) { return FTP; } else if (FILE.isTheSame(urlString)) { return FILE; } return null; }
/** * if {@code preferredProtocol} is set then the list of urls is prioritize. * NOTE: This is not standard conformant! However in the major number of cases LDAP is much slower then HTTP! * * @param urls * {@code List} of urls to prioritize */ private void prioritize(final List<String> urls) { if (preferredProtocol != null) { final List<String> priorityUrls = new ArrayList<String>(); for (final String url : urls) { if (preferredProtocol.isTheSame(url)) { priorityUrls.add(url); } } urls.removeAll(priorityUrls); for (int ii = priorityUrls.size() - 1; ii >= 0; ii--) { urls.add(0, priorityUrls.get(ii)); } } }