*/
public Enumeration getLocales()
{
// TODO: cache result
String al = getHeader(ACCEPT_LANGUAGE);
TreeSet ts = new TreeSet();
if (al != null)
{
// System.err.println("Accept lang:"+al);
StringTokenizer st = new StringTokenizer(al, ";", false);
try
{
while (st.hasMoreTokens())
{
String langs = st.nextToken(";");
// System.err.println("Langs:"+langs);
String q = st.nextToken(";=");
// System.err.println("q:"+q);
q = st.nextToken("=,");
// System.err.println("q:"+q);
float w = 0;
try
{
w = Float.valueOf(q).floatValue();
}
catch (NumberFormatException nfe)
{
}
if (w > 0)
{
StringTokenizer lst = new StringTokenizer(langs, ", ", false);
while (lst.hasMoreTokens())
{
String lan = lst.nextToken();
int di = lan.indexOf('-');
if (di < 0)
ts.add(new LocaleWithWeight(new Locale(lan.trim()) /* 1.4 */, w));
else
ts.add(new LocaleWithWeight(new Locale(lan.substring(0, di), lan.substring(di + 1)
.trim().toUpperCase()), w));
}
}
}
}
catch (NoSuchElementException ncee)
{
// can't parse
}
}
if (ts.size() == 0)
ts.add(new LocaleWithWeight(Locale.getDefault(), 1));
return new AcceptLocaleEnumeration(ts);
}