at.spardat.xma.util.Util Maven / Gradle / Ivy
The 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
*******************************************************************************/
package at.spardat.xma.util;
import java.util.ArrayList;
import java.util.List;
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 "";
}
public static List getLanguages(String[] locales) {
// convert to language list
List languages = new ArrayList(locales.length);
for(int i=0;i