J. Duke | 319a3b9 | 2007-12-01 00:00:00 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (c) 2007 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
| 20 | * CA 95054 USA or visit www.sun.com if you need additional information or |
| 21 | * have any questions. |
| 22 | */ |
| 23 | /* |
| 24 | * |
| 25 | */ |
| 26 | |
| 27 | package com.foo; |
| 28 | |
| 29 | import java.text.*; |
| 30 | import java.text.spi.*; |
| 31 | import java.util.*; |
| 32 | import com.foobar.Utils; |
| 33 | |
| 34 | public class BreakIteratorProviderImpl extends BreakIteratorProvider { |
| 35 | |
| 36 | static Locale[] avail = { |
| 37 | Locale.JAPAN, |
| 38 | new Locale("ja", "JP", "osaka"), |
| 39 | new Locale("ja", "JP", "kyoto"), |
| 40 | new Locale("xx", "YY")}; |
| 41 | |
| 42 | static String[] dialect = { |
| 43 | "\u3067\u3059\u3002", |
| 44 | "\u3084\u3002", |
| 45 | "\u3069\u3059\u3002", |
| 46 | "-xx-YY" |
| 47 | }; |
| 48 | |
| 49 | static enum Type {CHARACTER, LINE, SENTENCE, WORD}; |
| 50 | |
| 51 | public Locale[] getAvailableLocales() { |
| 52 | return avail; |
| 53 | } |
| 54 | |
| 55 | public BreakIterator getCharacterInstance(Locale locale) { |
| 56 | for (int i = 0; i < avail.length; i ++) { |
| 57 | if (Utils.supportsLocale(avail[i], locale)) { |
| 58 | return new FooBreakIterator(Type.CHARACTER, i); |
| 59 | } |
| 60 | } |
| 61 | throw new IllegalArgumentException("locale is not supported: "+locale); |
| 62 | } |
| 63 | |
| 64 | public BreakIterator getLineInstance(Locale locale) { |
| 65 | for (int i = 0; i < avail.length; i ++) { |
| 66 | if (Utils.supportsLocale(avail[i], locale)) { |
| 67 | return new FooBreakIterator(Type.LINE, i); |
| 68 | } |
| 69 | } |
| 70 | throw new IllegalArgumentException("locale is not supported: "+locale); |
| 71 | } |
| 72 | |
| 73 | public BreakIterator getSentenceInstance(Locale locale) { |
| 74 | for (int i = 0; i < avail.length; i ++) { |
| 75 | if (Utils.supportsLocale(avail[i], locale)) { |
| 76 | return new FooBreakIterator(Type.SENTENCE, i); |
| 77 | } |
| 78 | } |
| 79 | throw new IllegalArgumentException("locale is not supported: "+locale); |
| 80 | } |
| 81 | |
| 82 | public BreakIterator getWordInstance(Locale locale) { |
| 83 | for (int i = 0; i < avail.length; i ++) { |
| 84 | if (Utils.supportsLocale(avail[i], locale)) { |
| 85 | return new FooBreakIterator(Type.WORD, i); |
| 86 | } |
| 87 | } |
| 88 | throw new IllegalArgumentException("locale is not supported: "+locale); |
| 89 | } |
| 90 | |
| 91 | // dummy implementation |
| 92 | class FooBreakIterator extends BreakIterator { |
| 93 | public FooBreakIterator(Type t, int index) { |
| 94 | super(); |
| 95 | } |
| 96 | |
| 97 | public int current() { |
| 98 | return 0; |
| 99 | } |
| 100 | |
| 101 | public int first() { |
| 102 | return 0; |
| 103 | } |
| 104 | |
| 105 | public int following(int offset) { |
| 106 | return 0; |
| 107 | } |
| 108 | |
| 109 | public CharacterIterator getText() { |
| 110 | return null; |
| 111 | } |
| 112 | |
| 113 | public boolean isBoundary(int offset) { |
| 114 | return true; |
| 115 | } |
| 116 | |
| 117 | public int last() { |
| 118 | return 0; |
| 119 | } |
| 120 | |
| 121 | public int next() { |
| 122 | return 0; |
| 123 | } |
| 124 | |
| 125 | public int next(int n) { |
| 126 | return 0; |
| 127 | } |
| 128 | |
| 129 | public int preceding(int offset) { |
| 130 | return 0; |
| 131 | } |
| 132 | |
| 133 | public int previous() { |
| 134 | return 0; |
| 135 | } |
| 136 | |
| 137 | public void setText(CharacterIterator ci) { |
| 138 | } |
| 139 | } |
| 140 | } |