1/* 2 * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23/* 24 * 25 */ 26 27package com.foo; 28 29import java.text.*; 30import java.text.spi.*; 31import java.util.*; 32 33import com.foobar.Utils; 34 35public class CollatorProviderImpl extends CollatorProvider { 36 37 static Locale[] avail = { 38 Locale.JAPAN, 39 new Locale("ja", "JP", "osaka"), 40 new Locale("ja", "JP", "kyoto"), 41 new Locale("xx", "YY", "ZZZZ")}; 42 43 static String[] dialect = { 44 "\u3067\u3059\u3002", 45 "\u3084\u3002", 46 "\u3069\u3059\u3002", 47 "-xx-YY-ZZZZ" 48 }; 49 50 public Locale[] getAvailableLocales() { 51 return avail; 52 } 53 54 public Collator getInstance(Locale locale) { 55 for (int i = 0; i < avail.length; i ++) { 56 if (Utils.supportsLocale(avail[i], locale)) { 57 RuleBasedCollator ja = (RuleBasedCollator)Collator.getInstance(Locale.JAPANESE); 58 try { 59 return new RuleBasedCollator(ja.getRules()+"& Z < "+dialect[i]); 60 } catch (ParseException pe) { 61System.err.println(pe+ja.getRules()+"& Z < "+dialect[i]); 62 return ja; 63 } 64 } 65 } 66 throw new IllegalArgumentException("locale is not supported: "+locale); 67 } 68} 69