1 17 18 package org.alfresco.web.app.servlet; 19 20 import java.util.Locale ; 21 import java.util.StringTokenizer ; 22 23 30 class AcceptLanguage 31 { 32 34 private String m_language; 35 36 38 private float m_quality = 1.0f; 39 40 46 public AcceptLanguage(String lang, float quality) 47 { 48 50 m_language = lang.replace('-', '_'); 51 m_quality = quality; 52 } 53 54 59 public final String getLanguage() 60 { 61 return m_language; 62 } 63 64 69 public final float getQuality() 70 { 71 return m_quality; 72 } 73 74 79 public final Locale createLocale() 80 { 81 return createLocale(getLanguage()); 82 } 83 84 90 public final static Locale createLocale(String locName) 91 { 92 Locale locale = null; 93 94 StringTokenizer t = new StringTokenizer (locName, "_"); 95 int tokens = t.countTokens(); 96 if (tokens == 1) 97 { 98 locale = new Locale (locName); 99 } 100 else if (tokens == 2) 101 { 102 locale = new Locale (t.nextToken(), t.nextToken()); 103 } 104 else if (tokens == 3) 105 { 106 locale = new Locale (t.nextToken(), t.nextToken(), t.nextToken()); 107 } 108 109 return locale; 110 } 111 112 117 public String toString() 118 { 119 StringBuilder str = new StringBuilder (); 120 121 str.append("["); 122 str.append(getLanguage()); 123 str.append(","); 124 str.append(getQuality()); 125 str.append("]"); 126 127 return str.toString(); 128 } 129 } 130 | Popular Tags |