All Downloads are FREE. Search and download functionalities are using the official Maven repository.

at.spardat.xma.util.Util Maven / Gradle / Ivy

There is a newer version: 6.0.2
Show newest version
/*******************************************************************************
 * Copyright (c) 2003, 2007 s IT Solutions AT Spardat GmbH .
 * 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:
 *     s IT Solutions AT Spardat GmbH - initial API and implementation
 *******************************************************************************/

/*
 * @(#) $Id: Util.java 2089 2007-11-28 13:56:13Z s3460 $
 *
 * 
 * 
 * 
 *
 */
package at.spardat.xma.util;

import java.util.Locale;
import java.util.StringTokenizer;

/**
 * diverse utility methods
 * @author s2877  
 */
public class Util {

    /**
     * Helper method to convert a locale-string to a Locale-object.
     */
    public static Locale parseLocale (String loc) {    
        if (loc == null) return null;
        StringTokenizer     tokizer = new StringTokenizer (loc, "_",true);
        String language = nextLocaleToken(tokizer);
        String country  = nextLocaleToken(tokizer);
        String variant  = nextLocaleToken(tokizer);
        return new Locale (language, country, variant);
    }

    private static String nextLocaleToken(StringTokenizer tokizer) {
        if (tokizer.hasMoreTokens()) {
            String tok = tokizer.nextToken();
            if(!"_".equals(tok)) {
                if (tokizer.hasMoreTokens()) tokizer.nextToken();
                return tok;
            }
        }
        return "";
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy