| /** |
| * |
| * Copyright (c) 2011, 2016 - Loetz GmbH&Co.KG (69115 Heidelberg, Germany) |
| * |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License v1.0 |
| * which accompanies this distribution, and is available at |
| * http://www.eclipse.org/legal/epl-v10.html |
| * |
| * Contributors: |
| * Christophe Loetz (Loetz GmbH&Co.KG) - initial implementation |
| */ |
| package org.eclipse.osbp.wizard.ui.basic; |
| |
| import java.util.Arrays; |
| import java.util.Locale; |
| import java.util.Set; |
| import java.util.TreeSet; |
| |
| public class TopLevelDomain implements Comparable<TopLevelDomain> { |
| |
| private static Set<TopLevelDomain> availables; |
| |
| private static final String DEFAULT_NAME = "org"; |
| private static final TopLevelDomain DEFAULT |
| = new TopLevelDomain(DEFAULT_NAME, "organization", CommonProjectWizardTranslator.instance().getDocumentation(TopLevelDomain.class,"topLevelDomain"+DEFAULT_NAME)); |
| |
| private final String topLevelDomain; |
| private final String nameEnglish; |
| private final String nameNative; |
| |
| public static TopLevelDomain getDefault() { |
| return DEFAULT; |
| } |
| |
| public static Set<TopLevelDomain> getAvailables() { |
| if (availables == null) { |
| availables = new TreeSet<TopLevelDomain>(); |
| availables.add(new TopLevelDomain("biz", "business", CommonProjectWizardTranslator.instance().getDocumentation(TopLevelDomain.class,"topLevelDomainBiz"))); |
| availables.add(new TopLevelDomain("com", "commercial", CommonProjectWizardTranslator.instance().getDocumentation(TopLevelDomain.class,"topLevelDomainCom"))); |
| availables.add(new TopLevelDomain("info", "information", CommonProjectWizardTranslator.instance().getDocumentation(TopLevelDomain.class,"topLevelDomainInfo"))); |
| availables.add(new TopLevelDomain("net", "network", CommonProjectWizardTranslator.instance().getDocumentation(TopLevelDomain.class,"topLevelDomainNet"))); |
| availables.add(getDefault()); |
| Set<String> countries = new TreeSet<String>(); |
| countries.addAll(Arrays.asList(Locale.getISOCountries())); |
| for (String country : countries) { |
| Locale locale = new Locale("", country); |
| availables.add(new TopLevelDomain( |
| country, |
| locale.getDisplayCountry(Locale.ENGLISH), |
| locale.getDisplayCountry(locale) |
| )); |
| } |
| } |
| return availables; |
| } |
| |
| public static TopLevelDomain forLocale() { |
| return forLocale(Locale.getDefault()); |
| } |
| |
| public static TopLevelDomain forLocale(Locale locale) { |
| return forTopLevelDomain(locale.getCountry()); |
| } |
| |
| public static TopLevelDomain forTopLevelDomain(String topLevelDomain) { |
| for (TopLevelDomain search : getAvailables()) { |
| if (search.topLevelDomain.equalsIgnoreCase(topLevelDomain)) { |
| return search; |
| } |
| } |
| return getDefault(); |
| } |
| |
| private TopLevelDomain(String topLevelDomain, String nameEnglish, String nameNative) { |
| this.topLevelDomain = topLevelDomain.toLowerCase(); |
| this.nameEnglish = nameEnglish; |
| this.nameNative = nameNative; |
| } |
| |
| @Override |
| public String toString() { |
| return topLevelDomain+" - "+nameEnglish+" - "+nameNative; |
| } |
| |
| public String getTopLevelDomain() { |
| return topLevelDomain; |
| } |
| |
| public String getEnglishName() { |
| return nameEnglish; |
| } |
| |
| public String getNativeName() { |
| return nameNative; |
| } |
| |
| @Override |
| public int compareTo(TopLevelDomain arg0) { |
| if (arg0 instanceof TopLevelDomain) { |
| return toString().compareTo(arg0.toString()); |
| } |
| else { |
| return 0; |
| } |
| } |
| } |