01: /**
02: * RimfaxeLocale.java
03: *
04: *
05: * Copyright (c) 2003 Rimfaxe ApS (www.rimfaxe.com).
06: * All rights reserved.
07: *
08: * This package is written by Lars Andersen <lars@rimfaxe.com>
09: * and licensed by Rimfaxe ApS.
10: *
11: * Redistribution and use in source and binary forms, with or without
12: * modification, are permitted provided that the following conditions
13: * are met:
14: *
15: * 1. Redistributions of source code must retain the above copyright
16: * notice, this list of conditions and the following disclaimer.
17: *
18: * 2. Redistributions in binary form must reproduce the above copyright
19: * notice, this list of conditions and the following disclaimer in
20: * the documentation and/or other materials provided with the
21: * distribution.
22: *
23: * 3. The end-user documentation included with the redistribution, if
24: * any, must include the following acknowlegement:
25: * "This product includes software developed by Rimfaxe ApS
26: (www.rimfaxe.com)"
27: * Alternately, this acknowlegement may appear in the software itself,
28: * if and wherever such third-party acknowlegements normally appear.
29: *
30: * 4. The names "Rimfaxe", "Rimfaxe Software", "Lars Andersen" and
31: * "Rimfaxe WebServer" must not be used to endorse or promote products
32: * derived from this software without prior written permission. For written
33: * permission, please contact info@rimfaxe.com
34: *
35: * 5. Products derived from this software may not be called "Rimfaxe"
36: * nor may "Rimfaxe" appear in their names without prior written
37: * permission of the Rimfaxe ApS.
38: *
39: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
40: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
42: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
43: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
44: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
45: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
46: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
47: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
48: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
49: * SUCH DAMAGE.
50: *
51: */package com.rimfaxe.webserver.servletapi;
52:
53: import java.util.*;
54:
55: public class RimfaxeLocale {
56:
57: protected double quality;
58: protected Locale locale;
59:
60: public double getLanguageQuality() {
61: return quality;
62: }
63:
64: public Locale getLocale() {
65: return locale;
66: }
67:
68: /**
69: * Construct a locale from language, country and quality.
70: */
71: public RimfaxeLocale(String language, String country, double quality) {
72: this .locale = new Locale(language, country);
73: this .quality = quality;
74: }
75:
76: /**
77: * Construct a locale from string encoded value.
78: */
79: public RimfaxeLocale(String enc) {
80: StringTokenizer tkz = new StringTokenizer(enc, " ;", false);
81:
82: this .locale = new Locale(tkz.nextToken());
83: this .quality = 1.0D;
84:
85: try {
86: if (tkz.hasMoreTokens()) {
87: String q_str = tkz.nextToken();
88: if (q_str.startsWith("q=")) {
89: if (q_str.length() > 2) {
90: Double q_d = new Double(q_str.substring(2));
91: this .quality = q_d.doubleValue();
92: }
93: }
94: }
95: } catch (Exception e) {
96: }
97:
98: }
99: }
|