⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 countrylist.java.txt

📁 刚开始学习看的
💻 TXT
字号:
/*
 * Copyright 2002-2005 the original author or authors.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.swato.json_rpc.demo;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;

import javax.servlet.http.HttpServletRequest;

import org.swato.json_rpc.servlet.RequestAware;

/**
 * @author Zhijie Chen (zigzag.chen@gmail.com)
 */
public class CountryList implements RequestAware {
    final String EMPTY = "";

    private HttpServletRequest m_request = null;

    public List getCountryList(String language) {
        Locale locale = new Locale(language.toLowerCase(),language.toLowerCase());
        final Locale[] available = Locale.getAvailableLocales();
        List countries = new ArrayList();

        for (int i = 0; i < available.length; i++) {
            final String iso = available[i].getCountry();
            final String name = available[i].getDisplayCountry(locale);

            if (!EMPTY.equals(iso) && !EMPTY.equals(name)) {
                if (!countries.contains(name)) {
                    countries.add(name);
                }
            }
        }
        return countries;
    }

    public List getCountryList() {
        return getCountryList(m_request.getLocale().getDisplayLanguage());
    }

    public Object[] getLanguageOptions() {
        if (m_request == null)
            return null;
        final Locale[] available = Locale.getAvailableLocales();
        List languages = new ArrayList();
        for (int i = 0; i < available.length; i++) {
            Locale locale = available[i];
            String iso = available[i].getLanguage();
            String name = available[i]
                    .getDisplayLanguage(m_request.getLocale());
            LabelValueBean option = new LabelValueBean();
            option.setValue(iso);
            option.setLabel(name);
            if (!EMPTY.equals(iso) && !EMPTY.equals(name)
                    && !languages.contains(option)) {
                languages.add(option);
            }
        }
        Object[] languagesArray = languages.toArray();
        Arrays.sort(languagesArray, LabelValueBean.CASE_INSENSITIVE_ORDER);
        return languagesArray;
    }

    /*
     * (non-Javadoc)
     * 
     * @see org.swato.json_rpc.servlet.RequestAware#setRequest(javax.servlet.http.HttpServletRequest)
     */

    public void setRequest(HttpServletRequest request) {
        m_request = request;
    }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -