Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.util.Locale;

public class Main {
    private static final String DOT_CO[] = { "bw", "jp", "in", "id", "il", "jp", "ke", "kr", "ma", "mz", "nz", "th",
            "tz", "ug", "uk", "ve", "za", "zm", "zw" };
    private static final String DOT_COM[] = { "af", "ar", "au", "bh", "bd", "br", "co", "ec", "eg", "et", "gh",
            "hk", "kw", "lb", "ly", "my", "mt", "mx", "na", "ng", "pk", "pe", "pr", "qa", "sl", "sg", "tr", "tw",
            "ua", "vn" };

    public static String getTOSLink() {
        return constructLink(Locale.getDefault(), "/tospage");
    }

    private static String constructLink(Locale locale, String path) {
        String domain = locale.getCountry().toLowerCase();

        // ISO-3166-to-TLD exceptions...
        if (domain.equals("us")) {
            domain = "com";
        } else if (domain.equals("ao")) {
            domain = "it.ao";
        } else if (domain.equals("gb")) {
            domain = "co.uk";
        } else {
            for (int i = 0; i < DOT_COM.length; i++) {
                if (domain.equals(DOT_COM[i])) {
                    domain = "com." + domain;
                    break;
                }
            }
            for (int i = 0; i < DOT_CO.length; i++) {
                if (domain.equals(DOT_CO[i])) {
                    domain = "co." + domain;
                    break;
                }
            }
            if (locale.toString().equals(Locale.CANADA_FRENCH.toString())) {
                path += "?hl=fr";
            }
        }

        return "http://m.google." + domain + path;
    }
}