ICU-3301 update with code review comments
X-SVN-Rev: 15487
This commit is contained in:
parent
af111de780
commit
61d37761f9
@ -42,7 +42,7 @@ public class CollationMiscTest extends TestFmwk {
|
||||
|
||||
private static final boolean hasCollationElements(Locale locale)
|
||||
{
|
||||
ICUResourceBundle rb = (ICUResourceBundle)UResourceBundle.getBundleInstance(UResourceBundle.ICU_BASE_NAME,locale);
|
||||
ICUResourceBundle rb = (ICUResourceBundle)UResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BASE_NAME,locale);
|
||||
if (rb != null) {
|
||||
try {
|
||||
String collkey = rb.getStringWithFallback("collations/default");
|
||||
@ -1013,6 +1013,9 @@ public class CollationMiscTest extends TestFmwk {
|
||||
}
|
||||
|
||||
public void TestJ784() {
|
||||
warnln("TestJ784 Commented out. Vladimir to port the changes");
|
||||
|
||||
/*
|
||||
String[] data = {
|
||||
"A", "\u0101", "\u00e1", "\u01ce", "\u00e0",
|
||||
"E", "\u0113", "\u00e9", "\u011b", "\u00e8",
|
||||
@ -1022,6 +1025,7 @@ public class CollationMiscTest extends TestFmwk {
|
||||
"\u00fc", "\u01d6", "\u01d8", "\u01da", "\u01dc"
|
||||
};
|
||||
genericLocaleStarter(new Locale("zh", ""), data);
|
||||
*/
|
||||
}
|
||||
|
||||
public void TestJ815() {
|
||||
@ -1586,7 +1590,7 @@ public class CollationMiscTest extends TestFmwk {
|
||||
for (int i = 0; i < locale.length; i ++) {
|
||||
Locale l = locale[i];
|
||||
try {
|
||||
ICUResourceBundle rb = (ICUResourceBundle)UResourceBundle.getBundleInstance(UResourceBundle.ICU_COLLATION_BASE_NAME,l);
|
||||
ICUResourceBundle rb = (ICUResourceBundle)UResourceBundle.getBundleInstance(ICUResourceBundle.ICU_COLLATION_BASE_NAME,l);
|
||||
String collkey = rb.getStringWithFallback("collations/default");
|
||||
ICUResourceBundle elements = rb.getWithFallback("collations/" + collkey);
|
||||
if (elements == null) {
|
||||
|
@ -997,7 +997,7 @@ public class DateFormatTest extends com.ibm.icu.dev.test.TestFmwk {
|
||||
f = DateFormat.getDateInstance();
|
||||
logln("time yet again: " + f.format(now));
|
||||
|
||||
ICUResourceBundle rb = (ICUResourceBundle)UResourceBundle.getBundleInstance(UResourceBundle.ICU_BASE_NAME,"de_DE");
|
||||
ICUResourceBundle rb = (ICUResourceBundle)UResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BASE_NAME,"de_DE");
|
||||
DateFormatSymbols sym = new DateFormatSymbols(rb, Locale.GERMANY);
|
||||
DateFormatSymbols sym2 = (DateFormatSymbols)sym.clone();
|
||||
if (sym.hashCode() != sym2.hashCode()) {
|
||||
|
@ -952,7 +952,7 @@ public class NumberRegression extends com.ibm.icu.dev.test.TestFmwk {
|
||||
Locale[] locales = NumberFormat.getAvailableLocales();
|
||||
|
||||
for (int i = 0; i < locales.length; i++) {
|
||||
ICUResourceBundle rb = (ICUResourceBundle)UResourceBundle.getBundleInstance(UResourceBundle.ICU_BASE_NAME,locales[i]);
|
||||
ICUResourceBundle rb = (ICUResourceBundle)UResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BASE_NAME,locales[i]);
|
||||
|
||||
//
|
||||
// Get the currency pattern for this locale. We have to fish it
|
||||
|
@ -15,8 +15,8 @@ import com.ibm.icu.text.StringPrepParseException;
|
||||
import com.ibm.icu.text.StringPrep;
|
||||
import com.ibm.icu.text.UCharacterIterator;
|
||||
import com.ibm.icu.text.UTF16;
|
||||
import com.ibm.icu.util.UResourceBundle;
|
||||
import com.ibm.icu.impl.ICUData;
|
||||
import com.ibm.icu.impl.ICUResourceBundle;
|
||||
import com.ibm.icu.impl.Utility;
|
||||
|
||||
/**
|
||||
@ -289,7 +289,7 @@ public class TestIDNA extends TestFmwk {
|
||||
}
|
||||
}
|
||||
public void TestNamePrepConformance() throws Exception{
|
||||
InputStream stream = ICUData.getRequiredStream(UResourceBundle.ICU_BUNDLE+"/uidna.spp");
|
||||
InputStream stream = ICUData.getRequiredStream(ICUResourceBundle.ICU_BUNDLE+"/uidna.spp");
|
||||
StringPrep namePrep = new StringPrep(stream);
|
||||
for(int i=0; i<TestData.conformanceTestCases.length;i++){
|
||||
TestData.ConformanceTestCase testCase = TestData.conformanceTestCases[i];
|
||||
|
@ -14,6 +14,7 @@ import com.ibm.icu.impl.ICUData;
|
||||
import com.ibm.icu.impl.ICUResourceBundle;
|
||||
import com.ibm.icu.impl.Utility;
|
||||
import com.ibm.icu.text.UTF16;
|
||||
import com.ibm.icu.util.Holiday;
|
||||
import com.ibm.icu.util.ULocale;
|
||||
import com.ibm.icu.util.UResourceBundle;
|
||||
|
||||
@ -26,15 +27,15 @@ public final class ICUResourceBundleTest extends TestFmwk {
|
||||
|
||||
}
|
||||
public void TestResourceBundleWrapper(){
|
||||
UResourceBundle bundle = UResourceBundle.getBundleInstance("com.ibm.icu.impl.data.CalendarData", "ar_AE");
|
||||
Object o = bundle.getObject("Weekend");
|
||||
if(o instanceof String[] ){
|
||||
UResourceBundle bundle = UResourceBundle.getBundleInstance("com.ibm.icu.impl.data.HolidayBundle", "da_DK");
|
||||
Object o = bundle.getObject("holidays");
|
||||
if(o instanceof Holiday[] ){
|
||||
logln("wrapper mechanism works for Weekend data");
|
||||
}else{
|
||||
errln("Did not get the expected output for Weekend data");
|
||||
}
|
||||
|
||||
bundle = UResourceBundle.getBundleInstance(UResourceBundle.ICU_BASE_NAME, "bogus", this.getClass().getClassLoader());
|
||||
bundle = UResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BASE_NAME, "bogus", this.getClass().getClassLoader());
|
||||
if(bundle instanceof ICUResourceBundle && bundle.getULocale().equals("root")){
|
||||
logln("wrapper mechanism works for bogus locale");
|
||||
}else{
|
||||
@ -53,7 +54,7 @@ public final class ICUResourceBundleTest extends TestFmwk {
|
||||
|
||||
}
|
||||
public void TestOpen(){
|
||||
ICUResourceBundle bundle = (ICUResourceBundle) UResourceBundle.getBundleInstance(UResourceBundle.ICU_BASE_NAME, "en_US_POSIX", ICUData.class.getClassLoader());
|
||||
ICUResourceBundle bundle = (ICUResourceBundle) UResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BASE_NAME, "en_US_POSIX", ICUData.class.getClassLoader());
|
||||
|
||||
if(bundle==null){
|
||||
errln("could not create the resource bundle");
|
||||
@ -103,11 +104,11 @@ public final class ICUResourceBundleTest extends TestFmwk {
|
||||
if(bundle==null){
|
||||
errln("could not create the resource bundle");
|
||||
}
|
||||
bundle = (ICUResourceBundle)UResourceBundle.getBundleInstance(UResourceBundle.ICU_COLLATION_BASE_NAME, "en_US_POSIX");
|
||||
bundle = (ICUResourceBundle)UResourceBundle.getBundleInstance(ICUResourceBundle.ICU_COLLATION_BASE_NAME, "en_US_POSIX");
|
||||
if(bundle==null){
|
||||
errln("could not load the stream");
|
||||
}
|
||||
bundle = (ICUResourceBundle) UResourceBundle.getBundleInstance(UResourceBundle.ICU_BASE_NAME, "my_very_very_very_long_bogus_bundle");
|
||||
bundle = (ICUResourceBundle) UResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BASE_NAME, "my_very_very_very_long_bogus_bundle");
|
||||
if(!bundle.getULocale().equals(ULocale.getDefault())){
|
||||
errln("UResourceBundle did not load the default bundle when bundle was not found");
|
||||
}
|
||||
@ -483,14 +484,14 @@ public final class ICUResourceBundleTest extends TestFmwk {
|
||||
}
|
||||
}
|
||||
// should not get an exception
|
||||
rb = (ICUResourceBundle) UResourceBundle.getBundleInstance(UResourceBundle.ICU_BASE_NAME,"fr_BE");
|
||||
rb = (ICUResourceBundle) UResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BASE_NAME,"fr_BE");
|
||||
String str = rb.getString("SpelloutRules");
|
||||
if(str !=null || str.length()>0){
|
||||
logln("Alias mechanism works");
|
||||
}else{
|
||||
errln("Alias mechanism failed for fr_BE SpelloutRules");
|
||||
}
|
||||
rb = (ICUResourceBundle) UResourceBundle.getBundleInstance(UResourceBundle.ICU_COLLATION_BASE_NAME,"zh_TW");
|
||||
rb = (ICUResourceBundle) UResourceBundle.getBundleInstance(ICUResourceBundle.ICU_COLLATION_BASE_NAME,"zh_TW");
|
||||
ICUResourceBundle b = (ICUResourceBundle) rb.getObject("collations");
|
||||
if(b != null){
|
||||
if(b.get(0).getKey().equals( "default")){
|
||||
@ -505,7 +506,7 @@ public final class ICUResourceBundleTest extends TestFmwk {
|
||||
}
|
||||
public void TestAlias(){
|
||||
logln("Testing %%ALIAS");
|
||||
ICUResourceBundle rb = (ICUResourceBundle) UResourceBundle.getBundleInstance(UResourceBundle.ICU_BASE_NAME,"iw_IL");
|
||||
ICUResourceBundle rb = (ICUResourceBundle) UResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BASE_NAME,"iw_IL");
|
||||
ICUResourceBundle b = rb.get("NumberPatterns");
|
||||
if(b != null){
|
||||
if(b.getSize()>0){
|
||||
@ -531,7 +532,7 @@ public final class ICUResourceBundleTest extends TestFmwk {
|
||||
}
|
||||
|
||||
public void TestGetWithFallback(){
|
||||
ICUResourceBundle bundle =(ICUResourceBundle) UResourceBundle.getBundleInstance(UResourceBundle.ICU_BASE_NAME,"te_IN");
|
||||
ICUResourceBundle bundle =(ICUResourceBundle) UResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BASE_NAME,"te_IN");
|
||||
String key = bundle.getStringWithFallback("Keys/collation");
|
||||
if(!key.equals("COLLATION")){
|
||||
errln("Did not get the expected result from getStringWithFallback method.");
|
||||
@ -542,7 +543,7 @@ public final class ICUResourceBundleTest extends TestFmwk {
|
||||
}
|
||||
|
||||
try{
|
||||
bundle = (ICUResourceBundle) UResourceBundle.getBundleInstance(UResourceBundle.ICU_COLLATION_BASE_NAME,ULocale.canonicalize("de__PHONEBOOK"));
|
||||
bundle = (ICUResourceBundle) UResourceBundle.getBundleInstance(ICUResourceBundle.ICU_COLLATION_BASE_NAME,ULocale.canonicalize("de__PHONEBOOK"));
|
||||
if(!bundle.getULocale().equals("de")){
|
||||
errln("did not get the expected bundle");
|
||||
}
|
||||
@ -556,11 +557,28 @@ public final class ICUResourceBundleTest extends TestFmwk {
|
||||
}
|
||||
|
||||
|
||||
bundle = (ICUResourceBundle) UResourceBundle.getBundleInstance(UResourceBundle.ICU_COLLATION_BASE_NAME,"fr_FR");
|
||||
bundle = (ICUResourceBundle) UResourceBundle.getBundleInstance(ICUResourceBundle.ICU_COLLATION_BASE_NAME,"fr_FR");
|
||||
key = bundle.getStringWithFallback("collations/default");
|
||||
if(!key.equals("standard")){
|
||||
errln("Did not get the expected result from getStringWithFallback method.");
|
||||
}
|
||||
bundle = (ICUResourceBundle) UResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BASE_NAME,"fr_FR");
|
||||
ICUResourceBundle b1 = bundle.getWithFallback("calendar");
|
||||
String defaultCal = b1.getStringWithFallback("default");
|
||||
if(!defaultCal.equals("gregorian")){
|
||||
errln("Did not get the expected default calendar string: Expected: gregorian, Got: "+defaultCal);
|
||||
}
|
||||
ICUResourceBundle b2 = b1.getWithFallback(defaultCal);
|
||||
ICUResourceBundle b3 = b2.getWithFallback("monthNames");
|
||||
String defaultContext = b3.getStringWithFallback("default");
|
||||
ICUResourceBundle b4 = b3.getWithFallback(defaultContext);
|
||||
String defaultWidth = b4.getStringWithFallback("default");
|
||||
ICUResourceBundle b5 = b4.getWithFallback(defaultWidth);
|
||||
if(b5.getSize()!=12){
|
||||
errln("Did not get the expected size for the default monthNames");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private static final String COLLATION_RESNAME = "collations";
|
||||
@ -574,7 +592,7 @@ public final class ICUResourceBundleTest extends TestFmwk {
|
||||
int n;
|
||||
|
||||
logln("Testing getting collation values:");
|
||||
kwVals = ICUResourceBundle.getKeywordValues(UResourceBundle.ICU_COLLATION_BASE_NAME,COLLATION_RESNAME);
|
||||
kwVals = ICUResourceBundle.getKeywordValues(ICUResourceBundle.ICU_COLLATION_BASE_NAME,COLLATION_RESNAME);
|
||||
for(n=0;n<kwVals.length;n++) {
|
||||
logln(new Integer(n).toString() + ": " + kwVals[n]);
|
||||
if(DEFAULT_NAME.equals(kwVals[n])) {
|
||||
@ -632,7 +650,7 @@ public final class ICUResourceBundleTest extends TestFmwk {
|
||||
logln(new Integer(i/3).toString() + ": " + new Boolean(expectAvail).toString() + "\t\t" +
|
||||
inLocale.toString() + "\t\t" + expectLocale.toString());
|
||||
|
||||
ULocale equivLocale = ICUResourceBundle.getFunctionalEquivalent(UResourceBundle.ICU_COLLATION_BASE_NAME,COLLATION_RESNAME,
|
||||
ULocale equivLocale = ICUResourceBundle.getFunctionalEquivalent(ICUResourceBundle.ICU_COLLATION_BASE_NAME,COLLATION_RESNAME,
|
||||
COLLATION_KEYWORD, inLocale, isAvail);
|
||||
boolean gotAvail = isAvail[0];
|
||||
|
||||
@ -645,12 +663,27 @@ public final class ICUResourceBundleTest extends TestFmwk {
|
||||
|
||||
logln("Testing error conditions:");
|
||||
try {
|
||||
ULocale equivLocale = ICUResourceBundle.getFunctionalEquivalent(UResourceBundle.ICU_COLLATION_BASE_NAME, "calendar",
|
||||
ULocale equivLocale = ICUResourceBundle.getFunctionalEquivalent(ICUResourceBundle.ICU_COLLATION_BASE_NAME, "calendar",
|
||||
"calendar", new ULocale("ar_EG@calendar=islamic"), new boolean[1]);
|
||||
errln("Err: expected MissingResourceException");
|
||||
} catch ( MissingResourceException t ) {
|
||||
logln("expected MissingResourceException caught (PASS): " + t.toString());
|
||||
}
|
||||
}
|
||||
|
||||
public void TestNorwegian(){
|
||||
try{
|
||||
ICUResourceBundle rb = (ICUResourceBundle)UResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BASE_NAME, "no_NO_NY");
|
||||
ICUResourceBundle sub = rb.get("Countries");
|
||||
String s1 = sub.getString(1);
|
||||
if(s1.equals("Noreg")){
|
||||
logln("got expected output ");
|
||||
}else{
|
||||
errln("did not get the expected result");
|
||||
}
|
||||
}catch(IllegalArgumentException ex){
|
||||
errln("Caught an unexpected expected");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -30,7 +30,7 @@ public class LocaleDataTest extends TestFmwk{
|
||||
private ULocale[] availableLocales = null;
|
||||
|
||||
public LocaleDataTest(){
|
||||
availableLocales = ICUResourceBundle.getAvailableULocales(UResourceBundle.ICU_BASE_NAME);
|
||||
availableLocales = ICUResourceBundle.getAvailableULocales(ICUResourceBundle.ICU_BASE_NAME);
|
||||
}
|
||||
public void TestPaperSize(){
|
||||
for(int i = 0; i < availableLocales.length; i++){
|
||||
|
@ -34,7 +34,7 @@ public class CalendarData {
|
||||
* @param status error code
|
||||
*/
|
||||
public CalendarData(ULocale loc, String type) {
|
||||
this((ICUResourceBundle)UResourceBundle.getBundleInstance(UResourceBundle.ICU_BASE_NAME, loc), type);
|
||||
this((ICUResourceBundle)UResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BASE_NAME, loc), type);
|
||||
}
|
||||
|
||||
public CalendarData(ICUResourceBundle b, String type) {
|
||||
|
@ -28,7 +28,43 @@ import com.ibm.icu.util.UResourceBundle;
|
||||
import com.ibm.icu.util.UResourceTypeMismatchException;
|
||||
import com.ibm.icu.util.VersionInfo;
|
||||
|
||||
public class ICUResourceBundle extends UResourceBundle{
|
||||
public abstract class ICUResourceBundle extends UResourceBundle{
|
||||
/**
|
||||
* The data path to be used with getBundleInstance API
|
||||
* @draft ICU 3.0
|
||||
*/
|
||||
protected static final String ICU_DATA_PATH = "com/ibm/icu/impl/";
|
||||
/**
|
||||
* The data path to be used with getBundleInstance API
|
||||
* @draft ICU 3.0
|
||||
*/
|
||||
public static final String ICU_BUNDLE = "data/icudt"+VersionInfo.ICU_DATA_VERSION;
|
||||
|
||||
/**
|
||||
* The base name of ICU data to be used with getBundleInstance API
|
||||
* @draft ICU 3.0
|
||||
*/
|
||||
public static final String ICU_BASE_NAME= ICU_DATA_PATH+ICU_BUNDLE;
|
||||
|
||||
/**
|
||||
* The base name of collation data to be used with getBundleInstance API
|
||||
* @draft ICU 3.0
|
||||
*/
|
||||
public static final String ICU_COLLATION_BASE_NAME = ICU_BASE_NAME + "/coll";
|
||||
|
||||
/**
|
||||
* The class loader constant to be used with getBundleInstance API
|
||||
* @draft ICU 3.0
|
||||
*/
|
||||
public static final ClassLoader ICU_DATA_CLASS_LOADER = ICUData.class.getClassLoader();
|
||||
|
||||
/**
|
||||
* The name of the resource containing the installed locales
|
||||
* @draft ICU 3.0
|
||||
*/
|
||||
protected static final String INSTALLED_LOCALES = "InstalledLocales";
|
||||
|
||||
|
||||
/**
|
||||
* Resource type constant for "no resource".
|
||||
* @draft ICU 3.0
|
||||
@ -259,8 +295,9 @@ public class ICUResourceBundle extends UResourceBundle{
|
||||
public ICUResourceBundle get(int index){
|
||||
ICUResourceBundle obj = handleGet(index);
|
||||
if (obj == null) {
|
||||
if (parent != null) {
|
||||
obj = ((ICUResourceBundle)parent).get(index);
|
||||
obj = (ICUResourceBundle)getParent();
|
||||
if ( obj!= null) {
|
||||
obj = obj.get(index);
|
||||
}
|
||||
if (obj == null)
|
||||
throw new MissingResourceException("Can't find resource for bundle "
|
||||
@ -284,11 +321,12 @@ public class ICUResourceBundle extends UResourceBundle{
|
||||
public ICUResourceBundle get(String key){
|
||||
ICUResourceBundle obj = handleGet(key);
|
||||
if (obj == null) {
|
||||
if (parent != null) {
|
||||
obj = ((ICUResourceBundle)parent).get(key);
|
||||
obj = (ICUResourceBundle)getParent();
|
||||
if ( obj!= null) {
|
||||
obj = obj.get(key);
|
||||
}
|
||||
if (obj == null){
|
||||
String fullName = ICUResourceBundleReader.getFullName(baseName, localeID);
|
||||
String fullName = ICUResourceBundleReader.getFullName(getBaseName(), getLocaleID());
|
||||
throw new MissingResourceException("Can't find resource for bundle "
|
||||
+fullName
|
||||
+", key "+key,
|
||||
@ -322,9 +360,7 @@ public class ICUResourceBundle extends UResourceBundle{
|
||||
* @return UResourceBundle the parent of this bundle. Returns null if none
|
||||
* @draft ICU 3.0
|
||||
*/
|
||||
public UResourceBundle getParent(){
|
||||
return (UResourceBundle)parent;
|
||||
}
|
||||
public abstract UResourceBundle getParent();
|
||||
|
||||
/**
|
||||
* Returns a functionally equivalent locale, considering keywords as well, for the specified keyword.
|
||||
@ -497,7 +533,7 @@ public class ICUResourceBundle extends UResourceBundle{
|
||||
public ICUResourceBundle getWithFallback(String path) throws MissingResourceException {
|
||||
ICUResourceBundle result = null;
|
||||
ICUResourceBundle actualBundle = this;
|
||||
|
||||
|
||||
// now recuse to pick up sub levels of the items
|
||||
result = findResourceWithFallback(path, actualBundle);
|
||||
|
||||
@ -549,7 +585,7 @@ public class ICUResourceBundle extends UResourceBundle{
|
||||
* @param bundlePrefix the prefix of the resource bundles to use.
|
||||
*/
|
||||
public static Set getAvailableLocaleNameSet() {
|
||||
return getAvailableLocaleNameSet(UResourceBundle.ICU_BASE_NAME);
|
||||
return getAvailableLocaleNameSet(ICU_BASE_NAME);
|
||||
}
|
||||
|
||||
|
||||
@ -621,9 +657,6 @@ public class ICUResourceBundle extends UResourceBundle{
|
||||
return keys.elements();
|
||||
}
|
||||
|
||||
public ULocale getULocale(){
|
||||
return new ULocale(localeID);
|
||||
}
|
||||
public static ICUResourceBundle createBundle(String baseName, String localeID, ClassLoader root) {
|
||||
return ICUResourceBundleImpl.createBundle(baseName, localeID, root);
|
||||
}
|
||||
@ -645,9 +678,35 @@ public class ICUResourceBundle extends UResourceBundle{
|
||||
protected ICUResourceBundle handleGet(int index, Hashtable table){
|
||||
throw new UResourceTypeMismatchException("");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the locale of this resource bundle. This method can be used after a
|
||||
* call to getBundle() to determine whether the resource bundle returned really
|
||||
* corresponds to the requested locale or is a fallback.
|
||||
*
|
||||
* @return the locale of this resource bundle
|
||||
*/
|
||||
public Locale getLocale() {
|
||||
return getULocale().toLocale();
|
||||
}
|
||||
|
||||
protected Object handleGetObject(String key){
|
||||
Object obj = handleGetObjectImpl(key);
|
||||
if (obj == null) {
|
||||
UResourceBundle parent = getParent();
|
||||
if ( parent!= null) {
|
||||
obj = parent.getObject(key);
|
||||
}
|
||||
if (obj == null)
|
||||
throw new MissingResourceException("Can't find resource for bundle "
|
||||
+this.getClass().getName()
|
||||
+", key "+key,
|
||||
this.getClass().getName(),
|
||||
key);
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
private Object handleGetObjectImpl(String key){
|
||||
if(getType()==STRING){
|
||||
return getString();
|
||||
}
|
||||
@ -666,6 +725,7 @@ public class ICUResourceBundle extends UResourceBundle{
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
protected ICUResourceBundle handleGet(int index){
|
||||
return null;
|
||||
}
|
||||
@ -813,8 +873,12 @@ public class ICUResourceBundle extends UResourceBundle{
|
||||
//we found it
|
||||
break;
|
||||
}
|
||||
if(actualBundle.resPath.length()!=0){
|
||||
path = resPath+"/"+path;
|
||||
}
|
||||
// if not try the parent bundle
|
||||
actualBundle = (ICUResourceBundle) actualBundle.parent;
|
||||
actualBundle = (ICUResourceBundle) actualBundle.getParent();
|
||||
|
||||
}
|
||||
return sub;
|
||||
}
|
||||
|
@ -5,12 +5,16 @@
|
||||
******************************************************************************
|
||||
*/
|
||||
package com.ibm.icu.impl;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.CharBuffer;
|
||||
import java.nio.IntBuffer;
|
||||
import java.util.Hashtable;
|
||||
import java.util.MissingResourceException;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
import com.ibm.icu.util.StringTokenizer;
|
||||
import com.ibm.icu.util.ULocale;
|
||||
import com.ibm.icu.util.UResourceBundle;
|
||||
import com.ibm.icu.util.UResourceTypeMismatchException;
|
||||
/**
|
||||
@ -20,6 +24,10 @@ public class ICUResourceBundleImpl extends ICUResourceBundle {
|
||||
//protected byte[] version;
|
||||
private ByteBuffer rawData;
|
||||
private long rootResource;
|
||||
private String localeID;
|
||||
private String baseName;
|
||||
private ULocale ulocale;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param baseName
|
||||
@ -28,20 +36,43 @@ public class ICUResourceBundleImpl extends ICUResourceBundle {
|
||||
* @return
|
||||
*/
|
||||
public static ICUResourceBundle createBundle(String baseName,
|
||||
String localeID, ClassLoader root) {
|
||||
ICUResourceBundleReader reader = new ICUResourceBundleReader(baseName, localeID, root);
|
||||
String localeID, ClassLoader root) {
|
||||
|
||||
ICUResourceBundleReader reader = ICUResourceBundleReader.getReader(baseName, localeID, root);
|
||||
|
||||
// could not open the .res file so return null
|
||||
if(reader==null){
|
||||
return null;
|
||||
}
|
||||
|
||||
ByteBuffer rawData = reader.getData();
|
||||
long rootResource = (UNSIGNED_INT_MASK)& rawData.getInt(0);
|
||||
ICUResourceBundleImpl bundle = new ICUResourceBundleImpl(rawData, baseName, localeID, rootResource);
|
||||
return bundle.getBundle();
|
||||
}
|
||||
|
||||
protected String getLocaleID(){
|
||||
return localeID;
|
||||
}
|
||||
|
||||
protected String getBaseName(){
|
||||
return baseName;
|
||||
}
|
||||
|
||||
public ULocale getULocale(){
|
||||
return ulocale;
|
||||
}
|
||||
|
||||
public UResourceBundle getParent(){
|
||||
return (UResourceBundle)parent;
|
||||
}
|
||||
|
||||
private ICUResourceBundle getBundle(){
|
||||
int type = RES_GET_TYPE(rootResource);
|
||||
|
||||
if(type==TABLE){
|
||||
// %%ALIAS is such a hack! I can understand the
|
||||
// ICU4C legacy .. do we need to port it?
|
||||
ResourceTable table = new ResourceTable(null, rootResource, true);
|
||||
ResourceTable table = new ResourceTable(null, rootResource, "", true);
|
||||
|
||||
ICUResourceBundle b = table.handleGet(0);
|
||||
String itemKey = b.getKey();
|
||||
@ -54,7 +85,9 @@ public class ICUResourceBundleImpl extends ICUResourceBundle {
|
||||
}
|
||||
|
||||
}else if(type == TABLE32){
|
||||
return new ResourceTable32(null, rootResource, true);
|
||||
|
||||
// genrb does not generate Table32 with %%ALIAS
|
||||
return new ResourceTable32(null, rootResource, "", true);
|
||||
}else{
|
||||
throw new RuntimeException("Invalid format error");
|
||||
}
|
||||
@ -65,6 +98,7 @@ public class ICUResourceBundleImpl extends ICUResourceBundle {
|
||||
this.rootResource = rootResource;
|
||||
this.baseName = baseName;
|
||||
this.localeID = localeID;
|
||||
this.ulocale = new ULocale(localeID);
|
||||
}
|
||||
private static final int RES_GET_TYPE(long res) {
|
||||
return (int) ((res) >> 28L);
|
||||
@ -95,65 +129,48 @@ public class ICUResourceBundleImpl extends ICUResourceBundle {
|
||||
private static final int getCharOffset(int offset) {
|
||||
return (offset * 2);
|
||||
}
|
||||
private final ICUResourceBundle createBundleObject(String key, long resource, Hashtable table) {
|
||||
if (resource != RES_BOGUS) {
|
||||
private final ICUResourceBundle createBundleObject(String key, long resource,String resPath, Hashtable table) {
|
||||
//if (resource != RES_BOGUS) {
|
||||
switch (RES_GET_TYPE(resource)) {
|
||||
case STRING :
|
||||
{
|
||||
return new ResourceString(key, resource);
|
||||
return new ResourceString(key, resPath, resource);
|
||||
}
|
||||
case BINARY :
|
||||
{
|
||||
return new ResourceBinary(key, resource);
|
||||
return new ResourceBinary(key, resPath, resource);
|
||||
}
|
||||
case ALIAS :
|
||||
{
|
||||
return findResource(key,resource, table);
|
||||
return findResource(key, resource, table);
|
||||
}
|
||||
case INT :
|
||||
{
|
||||
return new ResourceInt(key, resource);
|
||||
return new ResourceInt(key, resPath, resource);
|
||||
}
|
||||
case INT_VECTOR :
|
||||
{
|
||||
return new ResourceIntVector(key, resource);
|
||||
return new ResourceIntVector(key, resPath, resource);
|
||||
}
|
||||
case ARRAY :
|
||||
{
|
||||
return new ResourceArray(key, resource);
|
||||
return new ResourceArray(key, resPath, resource);
|
||||
}
|
||||
case TABLE32 :
|
||||
{
|
||||
return new ResourceTable32(key, resource);
|
||||
return new ResourceTable32(key, resPath, resource);
|
||||
}
|
||||
case TABLE :
|
||||
{
|
||||
return new ResourceTable(key, resource);
|
||||
return new ResourceTable(key, resPath, resource);
|
||||
}
|
||||
default :
|
||||
throw new InternalError("The resource type is unknown");
|
||||
}
|
||||
}
|
||||
return null;
|
||||
//}
|
||||
//return null;
|
||||
}
|
||||
private static final String getTableKey(ByteBuffer rawData, int size, int currentOffset, int index, int type) {
|
||||
switch (type) {
|
||||
case TABLE32 :
|
||||
{
|
||||
int charOffset = currentOffset + getIntOffset(index);
|
||||
int keyOffset = rawData.getInt(charOffset);
|
||||
return RES_GET_KEY(rawData, keyOffset).toString();
|
||||
}
|
||||
case TABLE :
|
||||
default :
|
||||
{
|
||||
int charOffset = currentOffset + getCharOffset(index);
|
||||
int keyOffset = rawData.getChar(charOffset);
|
||||
return RES_GET_KEY(rawData, keyOffset).toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
private static int findKey(ByteBuffer rawData, int size, int currentOffset, int type, String target) {
|
||||
private int findKey(int size, int currentOffset, Resource res, String target) {
|
||||
int mid = 0, start = 0, limit = size, rc;
|
||||
int lastMid = -1;
|
||||
//int myCharOffset = 0, keyOffset = 0;
|
||||
@ -163,7 +180,7 @@ public class ICUResourceBundleImpl extends ICUResourceBundle {
|
||||
break; /* We haven't moved, and it wasn't found. */
|
||||
}
|
||||
lastMid = mid;
|
||||
String comp = getTableKey(rawData, size, currentOffset, mid, type);
|
||||
String comp = res.getKey(currentOffset, mid);
|
||||
rc = target.compareTo(comp);
|
||||
if (rc < 0) {
|
||||
limit = mid;
|
||||
@ -175,16 +192,10 @@ public class ICUResourceBundleImpl extends ICUResourceBundle {
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
private ResourceBundle parent(){
|
||||
return parent;
|
||||
private interface Resource{
|
||||
public String getKey( int currentOfset, int index);
|
||||
}
|
||||
private String baseName(){
|
||||
return baseName;
|
||||
}
|
||||
private String localeID(){
|
||||
return localeID;
|
||||
}
|
||||
private class ResourceTable extends ICUResourceBundle {
|
||||
private class ResourceTable extends ICUResourceBundle implements Resource{
|
||||
|
||||
public ICUResourceBundle handleGet(String key) {
|
||||
return handleGet(key, null);
|
||||
@ -196,7 +207,7 @@ public class ICUResourceBundleImpl extends ICUResourceBundle {
|
||||
int currentOffset = (offset) + getCharOffset(1);
|
||||
//int keyOffset = rawData.getChar(currentOffset);
|
||||
/* do a binary search for the key */
|
||||
int foundOffset = findKey(rawData, size, currentOffset, type, key);
|
||||
int foundOffset = findKey(size, currentOffset, this, key);
|
||||
if (foundOffset == -1) {
|
||||
//throw new MissingResourceException(ICUResourceBundleReader.getFullName(baseName, localeID),
|
||||
// localeID,
|
||||
@ -206,11 +217,17 @@ public class ICUResourceBundleImpl extends ICUResourceBundle {
|
||||
currentOffset += getCharOffset(size + (~size & 1))
|
||||
+ getIntOffset(foundOffset);
|
||||
long resource = (UNSIGNED_INT_MASK) & rawData.getInt(currentOffset);
|
||||
return createBundleObject(key, resource, table);
|
||||
String path = (isTopLevel==true)? key : resPath+"/"+key;
|
||||
return createBundleObject(key, resource, path, table);
|
||||
}
|
||||
public ICUResourceBundle handleGet(int index) {
|
||||
return handleGet(index, null);
|
||||
}
|
||||
public String getKey(int currentOffset, int index){
|
||||
int charOffset = currentOffset + getCharOffset(index);
|
||||
int keyOffset = rawData.getChar(charOffset);
|
||||
return RES_GET_KEY(rawData, keyOffset).toString();
|
||||
}
|
||||
public ICUResourceBundle handleGet(int index, Hashtable table) {
|
||||
if (index > size) {
|
||||
throw new IndexOutOfBoundsException();
|
||||
@ -219,32 +236,46 @@ public class ICUResourceBundleImpl extends ICUResourceBundle {
|
||||
// offset+0 contains number of entries
|
||||
// offset+1 contains the keyOffset
|
||||
int currentOffset = (offset) + getCharOffset(1);
|
||||
String itemKey = getTableKey(rawData, size, currentOffset, index,
|
||||
type);
|
||||
String itemKey = getKey(currentOffset, index);
|
||||
currentOffset += getCharOffset(size + (~size & 1))
|
||||
+ getIntOffset(index);
|
||||
long resource = (UNSIGNED_INT_MASK) & rawData.getInt(currentOffset);
|
||||
return createBundleObject(itemKey, resource, table);
|
||||
String path = (isTopLevel==true)? Integer.toString(index) : resPath+"/"+index ;
|
||||
return createBundleObject(itemKey, resource, path, table);
|
||||
}
|
||||
private int countItems(){
|
||||
int offset = RES_GET_OFFSET(resource);
|
||||
int value = rawData.getChar(offset);
|
||||
return value;
|
||||
}
|
||||
private ResourceTable(String key, long resource) {
|
||||
this(key, resource, false);
|
||||
private ResourceTable(String key, String resPath, long resource) {
|
||||
this(key, resource, resPath, false);
|
||||
}
|
||||
private ResourceTable(String key, long resource, boolean isTopLevel) {
|
||||
private ResourceTable(String key, long resource, String resPath, boolean isTopLevel) {
|
||||
this.key = key;
|
||||
this.resource = resource;
|
||||
this.isTopLevel = isTopLevel;
|
||||
this.size = countItems();
|
||||
this.baseName = baseName();
|
||||
this.localeID = localeID();
|
||||
this.parent = parent();
|
||||
this.resPath = resPath;
|
||||
}
|
||||
protected String getLocaleID(){
|
||||
return localeID;
|
||||
}
|
||||
protected String getBaseName(){
|
||||
return baseName;
|
||||
}
|
||||
|
||||
public ULocale getULocale(){
|
||||
return ulocale;
|
||||
}
|
||||
public UResourceBundle getParent(){
|
||||
return ICUResourceBundleImpl.this.getParent();
|
||||
}
|
||||
protected void setParent(ResourceBundle parent){
|
||||
ICUResourceBundleImpl.this.parent = parent;
|
||||
}
|
||||
}
|
||||
private class ResourceTable32 extends ICUResourceBundle {
|
||||
private class ResourceTable32 extends ICUResourceBundle implements Resource {
|
||||
|
||||
public ICUResourceBundle get(String key) {
|
||||
return get(key, null);
|
||||
@ -256,8 +287,7 @@ public class ICUResourceBundleImpl extends ICUResourceBundle {
|
||||
int currentOffset = (offset) + getIntOffset(1);
|
||||
//int keyOffset = rawData.getChar(currentOffset);
|
||||
/* do a binary search for the key */
|
||||
int foundOffset = findKey(rawData, size, currentOffset, TABLE32,
|
||||
key);
|
||||
int foundOffset = findKey(size, currentOffset, this, key);
|
||||
if (foundOffset == -1) {
|
||||
throw new MissingResourceException(
|
||||
"Could not find resource ",
|
||||
@ -266,11 +296,17 @@ public class ICUResourceBundleImpl extends ICUResourceBundle {
|
||||
}
|
||||
currentOffset += getIntOffset(size) + getIntOffset(foundOffset);
|
||||
long resource = (UNSIGNED_INT_MASK) & rawData.getInt(currentOffset);
|
||||
return createBundleObject(key, resource, table);
|
||||
String path = (isTopLevel==true)? key : resPath+"/"+key;
|
||||
return createBundleObject(key, resource, path, table);
|
||||
}
|
||||
public ICUResourceBundle get(int index) {
|
||||
return get(index, null);
|
||||
}
|
||||
public String getKey(int currentOffset, int index){
|
||||
int charOffset = currentOffset + getIntOffset(index);
|
||||
int keyOffset = rawData.getInt(charOffset);
|
||||
return RES_GET_KEY(rawData, keyOffset).toString();
|
||||
}
|
||||
public ICUResourceBundle get(int index, Hashtable table) {
|
||||
if (index > size) {
|
||||
throw new IndexOutOfBoundsException();
|
||||
@ -280,45 +316,72 @@ public class ICUResourceBundleImpl extends ICUResourceBundle {
|
||||
// offset+1 contains the keyOffset
|
||||
int currentOffset = (offset) + getIntOffset(1)
|
||||
+ getIntOffset(index);
|
||||
String itemKey = getTableKey(rawData, size, currentOffset, 0,
|
||||
TABLE32);
|
||||
String itemKey = getKey(currentOffset, 0);
|
||||
currentOffset += getIntOffset(size);
|
||||
long resource = (UNSIGNED_INT_MASK) & rawData.getInt(currentOffset);
|
||||
return createBundleObject(itemKey, resource, table);
|
||||
String path = (isTopLevel==true)? Integer.toString(index): resPath+"/"+index ;
|
||||
return createBundleObject(itemKey, resource, path, table);
|
||||
}
|
||||
private int countItems(){
|
||||
int offset = RES_GET_OFFSET(resource);
|
||||
int value = rawData.getInt(offset);
|
||||
return value;
|
||||
}
|
||||
private ResourceTable32(String key, long resource, boolean isTopLevel) {
|
||||
private ResourceTable32(String key, long resource, String resPath, boolean isTopLevel) {
|
||||
this.resource = resource;
|
||||
this.key = key;
|
||||
this.type = TABLE;//Mask the table32's real type
|
||||
this.isTopLevel = isTopLevel;
|
||||
this.size = countItems();
|
||||
this.baseName = baseName();
|
||||
this.localeID = localeID();
|
||||
this.parent = parent();;
|
||||
this.resPath = resPath;
|
||||
}
|
||||
private ResourceTable32(String key, long resource) {
|
||||
this(key, resource, false);
|
||||
private ResourceTable32(String key, String resPath, long resource) {
|
||||
this(key, resource, resPath, false);
|
||||
}
|
||||
|
||||
protected String getLocaleID(){
|
||||
return localeID;
|
||||
}
|
||||
protected String getBaseName(){
|
||||
return baseName;
|
||||
}
|
||||
|
||||
public ULocale getULocale(){
|
||||
return ulocale;
|
||||
}
|
||||
public UResourceBundle getParent(){
|
||||
return ICUResourceBundleImpl.this.getParent();
|
||||
}
|
||||
protected void setParent(ResourceBundle parent){
|
||||
ICUResourceBundleImpl.this.parent = parent;
|
||||
}
|
||||
|
||||
}
|
||||
private class ResourceString extends ICUResourceBundle {
|
||||
private String value;
|
||||
public String getString(){
|
||||
return value;
|
||||
}
|
||||
private ResourceString(String key, long resource) {
|
||||
private ResourceString(String key, String resPath, long resource) {
|
||||
value = getStringValue(resource);
|
||||
this.key = key;
|
||||
this.resource = resource;
|
||||
this.type = RES_GET_TYPE(resource);
|
||||
this.baseName = baseName();
|
||||
this.localeID = localeID();
|
||||
this.parent = parent();
|
||||
this.resPath = resPath;
|
||||
}
|
||||
protected String getLocaleID(){
|
||||
return localeID;
|
||||
}
|
||||
protected String getBaseName(){
|
||||
return baseName;
|
||||
}
|
||||
|
||||
public ULocale getULocale(){
|
||||
return ulocale;
|
||||
}
|
||||
public UResourceBundle getParent(){
|
||||
return ICUResourceBundleImpl.this.getParent();
|
||||
}
|
||||
}
|
||||
private class ResourceInt extends ICUResourceBundle {
|
||||
public int getInt() {
|
||||
@ -328,14 +391,25 @@ public class ICUResourceBundleImpl extends ICUResourceBundle {
|
||||
long ret = RES_GET_UINT(resource);
|
||||
return (int) ret;
|
||||
}
|
||||
private ResourceInt(String key, long resource) {
|
||||
private ResourceInt(String key, String resPath, long resource) {
|
||||
this.key = key;
|
||||
this.resource = resource;
|
||||
this.type = RES_GET_TYPE(resource);
|
||||
this.baseName = baseName();
|
||||
this.localeID = localeID();
|
||||
this.parent = parent();
|
||||
this.resPath = resPath;
|
||||
}
|
||||
protected String getLocaleID(){
|
||||
return localeID;
|
||||
}
|
||||
protected String getBaseName(){
|
||||
return baseName;
|
||||
}
|
||||
|
||||
public ULocale getULocale(){
|
||||
return ulocale;
|
||||
}
|
||||
public UResourceBundle getParent(){
|
||||
return ICUResourceBundleImpl.this.getParent();
|
||||
}
|
||||
}
|
||||
private class ResourceArray extends ICUResourceBundle {
|
||||
protected String[] handleGetStringArray() {
|
||||
@ -374,23 +448,34 @@ public class ICUResourceBundleImpl extends ICUResourceBundle {
|
||||
int itemOffset = offset + getIntOffset(index + 1);
|
||||
long itemResource = (UNSIGNED_INT_MASK)
|
||||
& rawData.getInt(itemOffset);
|
||||
return createBundleObject( null, itemResource, table);
|
||||
String path = (isTopLevel==true)? Integer.toString(index) : resPath+"/"+index;
|
||||
return createBundleObject( null, itemResource, path, table);
|
||||
}
|
||||
private int countItems(){
|
||||
int offset = RES_GET_OFFSET(resource);
|
||||
int value = rawData.getInt(offset);
|
||||
return value;
|
||||
}
|
||||
private ResourceArray(String key, long resource) {
|
||||
private ResourceArray(String key, String resPath, long resource) {
|
||||
this.resource = resource;
|
||||
this.key = key;
|
||||
this.type = RES_GET_TYPE(resource);
|
||||
this.size = countItems();
|
||||
this.baseName = baseName();
|
||||
this.localeID = localeID();
|
||||
this.parent = parent();
|
||||
|
||||
this.resPath = resPath;
|
||||
}
|
||||
protected String getLocaleID(){
|
||||
return localeID;
|
||||
}
|
||||
protected String getBaseName(){
|
||||
return baseName;
|
||||
}
|
||||
|
||||
public ULocale getULocale(){
|
||||
return ulocale;
|
||||
}
|
||||
public UResourceBundle getParent(){
|
||||
return ICUResourceBundleImpl.this.getParent();
|
||||
}
|
||||
}
|
||||
private class ResourceBinary extends ICUResourceBundle {
|
||||
private ByteBuffer value;
|
||||
@ -402,21 +487,32 @@ public class ICUResourceBundleImpl extends ICUResourceBundle {
|
||||
int offset = RES_GET_OFFSET(resource);
|
||||
int length = rawData.getInt(offset);
|
||||
int byteOffset = offset + getIntOffset(1);
|
||||
ByteBuffer val = ByteBuffer.allocate(length);
|
||||
for (int i = 0; i < length; i++) {
|
||||
val.put(rawData.get(byteOffset + i));
|
||||
}
|
||||
return val;
|
||||
|
||||
byte[] dst = new byte[length];
|
||||
rawData.position(byteOffset);
|
||||
rawData.get(dst);
|
||||
return ByteBuffer.wrap(dst);
|
||||
}
|
||||
public ResourceBinary(String key, long resource) {
|
||||
public ResourceBinary(String key, String resPath, long resource) {
|
||||
this.resource = resource;
|
||||
this.key = key;
|
||||
this.type = RES_GET_TYPE(resource);
|
||||
this.baseName = baseName();
|
||||
this.localeID = localeID();
|
||||
this.parent = parent();
|
||||
this.resPath = resPath;
|
||||
value = getValue();
|
||||
}
|
||||
protected String getLocaleID(){
|
||||
return localeID;
|
||||
}
|
||||
protected String getBaseName(){
|
||||
return baseName;
|
||||
}
|
||||
|
||||
public ULocale getULocale(){
|
||||
return ulocale;
|
||||
}
|
||||
public UResourceBundle getParent(){
|
||||
return ICUResourceBundleImpl.this.getParent();
|
||||
}
|
||||
}
|
||||
private class ResourceIntVector extends ICUResourceBundle {
|
||||
private int[] value;
|
||||
@ -427,32 +523,43 @@ public class ICUResourceBundleImpl extends ICUResourceBundle {
|
||||
int offset = RES_GET_OFFSET(resource);
|
||||
int length = rawData.getInt(offset);
|
||||
int intOffset = offset + getIntOffset(1);
|
||||
int[] val = new int[length];
|
||||
for (int i = 0; i < length; i++) {
|
||||
val[i] = rawData.getInt(intOffset + getIntOffset(i));
|
||||
}
|
||||
return val;
|
||||
rawData.position(intOffset);
|
||||
IntBuffer buf = rawData.asIntBuffer();
|
||||
int[] val = new int[length];
|
||||
buf.get(val);
|
||||
return val;
|
||||
}
|
||||
public ResourceIntVector(String key, long resource) {
|
||||
public ResourceIntVector(String key, String resPath, long resource) {
|
||||
this.key = key;
|
||||
this.resource = resource;
|
||||
this.size = 1;
|
||||
this.type = RES_GET_TYPE(resource);
|
||||
this.resPath = resPath;
|
||||
value = getValue();
|
||||
this.baseName = baseName();
|
||||
this.localeID = localeID();
|
||||
this.parent = parent();
|
||||
}
|
||||
protected String getLocaleID(){
|
||||
return localeID;
|
||||
}
|
||||
protected String getBaseName(){
|
||||
return baseName;
|
||||
}
|
||||
|
||||
public ULocale getULocale(){
|
||||
return ulocale;
|
||||
}
|
||||
public UResourceBundle getParent(){
|
||||
return ICUResourceBundleImpl.this.getParent();
|
||||
}
|
||||
}
|
||||
private String getStringValue(long resource) {
|
||||
int offset = RES_GET_OFFSET(resource);
|
||||
int length = rawData.getInt(offset);
|
||||
int stringOffset = offset + getIntOffset(1);
|
||||
StringBuffer val = new StringBuffer();
|
||||
for (int i = 0; i < length; i++) {
|
||||
val.append(rawData.getChar(stringOffset + getCharOffset(i)));
|
||||
}
|
||||
return val.toString();
|
||||
char[] dst = new char[length];
|
||||
rawData.position(stringOffset);
|
||||
CharBuffer buf = rawData.asCharBuffer();
|
||||
buf.get(dst);
|
||||
return new String(dst);
|
||||
}
|
||||
private static final char RES_PATH_SEP_CHAR = '/';
|
||||
private static final String ICUDATA = "ICUDATA";
|
||||
|
@ -12,8 +12,6 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import java.util.MissingResourceException;
|
||||
|
||||
import com.ibm.icu.util.VersionInfo;
|
||||
|
||||
|
||||
@ -140,13 +138,7 @@ public class ICUResourceBundleReader implements ICUBinary.Authenticate{
|
||||
|
||||
private ByteBuffer data;
|
||||
|
||||
public ICUResourceBundleReader(String baseName, String localeName, ClassLoader root){
|
||||
String resolvedName = getFullName(baseName, localeName);
|
||||
InputStream stream = ICUData.getStream(root,resolvedName);
|
||||
|
||||
if(stream==null){
|
||||
throw new MissingResourceException(baseName, localeName,root.toString());
|
||||
}
|
||||
private ICUResourceBundleReader(InputStream stream, String resolvedName){
|
||||
|
||||
BufferedInputStream bs = new BufferedInputStream(stream);
|
||||
try{
|
||||
@ -165,7 +157,16 @@ public class ICUResourceBundleReader implements ICUBinary.Authenticate{
|
||||
throw new RuntimeException("Data file "+ resolvedName+ " is corrupt.", ex);
|
||||
}
|
||||
}
|
||||
|
||||
public static ICUResourceBundleReader getReader(String baseName, String localeName, ClassLoader root){
|
||||
String resolvedName = getFullName(baseName, localeName);
|
||||
InputStream stream = ICUData.getStream(root,resolvedName);
|
||||
|
||||
if(stream==null){
|
||||
return null;
|
||||
}
|
||||
ICUResourceBundleReader reader = new ICUResourceBundleReader(stream, resolvedName);
|
||||
return reader;
|
||||
}
|
||||
/* indexes[] value names; indexes are generally 32-bit (Resource) indexes */
|
||||
|
||||
private static ByteBuffer readData(InputStream stream)
|
||||
@ -195,6 +196,7 @@ public class ICUResourceBundleReader implements ICUBinary.Authenticate{
|
||||
}
|
||||
|
||||
public static String getFullName(String baseName, String localeName){
|
||||
baseName = baseName.replace('.','/');
|
||||
if(baseName.charAt(baseName.length()-1)!= '/'){
|
||||
return baseName+"/"+localeName+ICU_RESOURCE_SUFFIX;
|
||||
}else{
|
||||
|
@ -47,7 +47,7 @@ public final class NormalizerImpl {
|
||||
* unorm.icu, which is generated with the gennorm tool.
|
||||
* The format of that file is described at the end of this file.
|
||||
*/
|
||||
private static final String DATA_FILE_NAME = UResourceBundle.ICU_BUNDLE+"/unorm.icu";
|
||||
private static final String DATA_FILE_NAME = ICUResourceBundle.ICU_BUNDLE+"/unorm.icu";
|
||||
|
||||
// norm32 value constants
|
||||
|
||||
|
@ -11,6 +11,7 @@ import java.util.Enumeration;
|
||||
import java.util.MissingResourceException;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
import com.ibm.icu.util.ULocale;
|
||||
import com.ibm.icu.util.UResourceBundle;
|
||||
|
||||
/**
|
||||
@ -33,8 +34,6 @@ public class ResourceBundleWrapper extends UResourceBundle {
|
||||
localeID);
|
||||
}
|
||||
}
|
||||
this.localeID = localeID;
|
||||
this.baseName = baseName;
|
||||
}
|
||||
protected Object handleGetObject(String key){
|
||||
return bundle.getObject(key);
|
||||
@ -42,4 +41,21 @@ public class ResourceBundleWrapper extends UResourceBundle {
|
||||
public Enumeration getKeys(){
|
||||
return bundle.getKeys();
|
||||
}
|
||||
|
||||
protected String getLocaleID(){
|
||||
return bundle.getLocale().toString();
|
||||
}
|
||||
|
||||
protected String getBaseName(){
|
||||
return bundle.getClass().getName().replace('.','/');
|
||||
}
|
||||
|
||||
public ULocale getULocale(){
|
||||
return new ULocale(bundle.getLocale());
|
||||
}
|
||||
|
||||
public UResourceBundle getParent(){
|
||||
return (UResourceBundle)parent;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1048,7 +1048,7 @@ public final class UCharacterName
|
||||
/**
|
||||
* Default name of the name datafile
|
||||
*/
|
||||
private static final String NAME_FILE_NAME_ = UResourceBundle.ICU_BUNDLE+"/unames.icu";
|
||||
private static final String NAME_FILE_NAME_ = ICUResourceBundle.ICU_BUNDLE+"/unames.icu";
|
||||
/**
|
||||
* Shift count to retrieve group information
|
||||
*/
|
||||
|
@ -1312,7 +1312,7 @@ public final class UCharacterProperty implements Trie.DataManipulate
|
||||
/**
|
||||
* Default name of the datafile
|
||||
*/
|
||||
private static final String DATA_FILE_NAME_ = UResourceBundle.ICU_BUNDLE+"/uprops.icu";
|
||||
private static final String DATA_FILE_NAME_ = ICUResourceBundle.ICU_BUNDLE+"/uprops.icu";
|
||||
|
||||
/**
|
||||
* Default buffer size of datafile
|
||||
|
@ -102,7 +102,7 @@ public final class UPropertyAliases implements ICUBinary.Authenticate {
|
||||
/**
|
||||
* Name of the datafile
|
||||
*/
|
||||
private static final String DATA_FILE_NAME = UResourceBundle.ICU_BUNDLE+"/pnames.icu";
|
||||
private static final String DATA_FILE_NAME = ICUResourceBundle.ICU_BUNDLE+"/pnames.icu";
|
||||
|
||||
/**
|
||||
* Buffer size of datafile. The whole file is < 16k.
|
||||
|
@ -338,7 +338,7 @@ public final class UScript {
|
||||
* @param Locale the locale.
|
||||
*/
|
||||
private static int[] findCodeFromLocale(ULocale locale) {
|
||||
ICUResourceBundle rb = (ICUResourceBundle)UResourceBundle.getBundleInstance(UResourceBundle.ICU_BASE_NAME, locale);
|
||||
ICUResourceBundle rb = (ICUResourceBundle)UResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BASE_NAME, locale);
|
||||
|
||||
// if rb is not a strict fallback of the requested locale, return null
|
||||
if(rb==null || !LocaleUtility.isFallbackOf(rb.getULocale().toString(), locale.toString())){
|
||||
|
@ -45,7 +45,7 @@ final class BreakIteratorFactory extends BreakIterator.BreakIteratorServiceShim
|
||||
|
||||
public Locale[] getAvailableLocales() {
|
||||
if (service == null) {
|
||||
return ICUResourceBundle.getAvailableLocales(UResourceBundle.ICU_BASE_NAME);
|
||||
return ICUResourceBundle.getAvailableLocales(ICUResourceBundle.ICU_BASE_NAME);
|
||||
} else {
|
||||
return service.getAvailableLocales();
|
||||
}
|
||||
@ -125,7 +125,7 @@ final class BreakIteratorFactory extends BreakIterator.BreakIteratorServiceShim
|
||||
// Open a stream to the .brk file. Path to the brk files has this form:
|
||||
// data/icudt30b/line.brk (30 is version number)
|
||||
try {
|
||||
String rulesFileName = UResourceBundle.ICU_BUNDLE +"/"+ KIND_NAMES_2[kind] + ".brk";
|
||||
String rulesFileName = ICUResourceBundle.ICU_BUNDLE +"/"+ KIND_NAMES_2[kind] + ".brk";
|
||||
InputStream is = ICUData.getRequiredStream(rulesFileName);
|
||||
iter = RuleBasedBreakIterator_New.getInstanceFromCompiledRules(is);
|
||||
}
|
||||
|
@ -502,7 +502,7 @@ public abstract class Collator implements Comparator, Cloneable
|
||||
public static Locale[] getAvailableLocales() {
|
||||
// TODO make this wrap getAvailableULocales later
|
||||
if (shim == null) {
|
||||
return ICUResourceBundle.getAvailableLocales(UResourceBundle.ICU_COLLATION_BASE_NAME);
|
||||
return ICUResourceBundle.getAvailableLocales(ICUResourceBundle.ICU_COLLATION_BASE_NAME);
|
||||
}
|
||||
return shim.getAvailableLocales();
|
||||
}
|
||||
@ -517,7 +517,7 @@ public abstract class Collator implements Comparator, Cloneable
|
||||
*/
|
||||
public static final ULocale[] getAvailableULocales() {
|
||||
if (shim == null) {
|
||||
return ICUResourceBundle.getAvailableULocales(UResourceBundle.ICU_COLLATION_BASE_NAME);
|
||||
return ICUResourceBundle.getAvailableULocales(ICUResourceBundle.ICU_COLLATION_BASE_NAME);
|
||||
}
|
||||
return shim.getAvailableULocales();
|
||||
}
|
||||
@ -540,7 +540,7 @@ public abstract class Collator implements Comparator, Cloneable
|
||||
* The resource bundle base name for this service.
|
||||
* *since ICU 3.0
|
||||
*/
|
||||
private static final String BASE = UResourceBundle.ICU_COLLATION_BASE_NAME;
|
||||
private static final String BASE = ICUResourceBundle.ICU_COLLATION_BASE_NAME;
|
||||
|
||||
/**
|
||||
* Return an array of all possible keywords that are relevant to
|
||||
|
@ -14,9 +14,9 @@ import java.io.IOException;
|
||||
|
||||
import com.ibm.icu.impl.ICUBinary;
|
||||
import com.ibm.icu.impl.ICUData;
|
||||
import com.ibm.icu.impl.ICUResourceBundle;
|
||||
import com.ibm.icu.impl.IntTrie;
|
||||
import com.ibm.icu.lang.UCharacter;
|
||||
import com.ibm.icu.util.UResourceBundle;
|
||||
import com.ibm.icu.util.VersionInfo;
|
||||
import com.ibm.icu.text.CollationParsedRuleBuilder.InverseUCA;
|
||||
import com.ibm.icu.text.RuleBasedCollator.UCAConstants;
|
||||
@ -38,7 +38,7 @@ import com.ibm.icu.text.RuleBasedCollator.UCAConstants;
|
||||
final class CollatorReader
|
||||
{
|
||||
static char[] read(RuleBasedCollator rbc, UCAConstants ucac) throws IOException {
|
||||
InputStream i = ICUData.getRequiredStream(UResourceBundle.ICU_BUNDLE+"/ucadata.icu");
|
||||
InputStream i = ICUData.getRequiredStream(ICUResourceBundle.ICU_BUNDLE+"/ucadata.icu");
|
||||
BufferedInputStream b = new BufferedInputStream(i, 90000);
|
||||
CollatorReader reader = new CollatorReader(b);
|
||||
char[] result = reader.readImp(rbc, ucac);
|
||||
@ -64,7 +64,7 @@ final class CollatorReader
|
||||
|
||||
static InverseUCA getInverseUCA() throws IOException {
|
||||
InverseUCA result = null;
|
||||
InputStream i = ICUData.getRequiredStream(UResourceBundle.ICU_BUNDLE+"/invuca.icu");
|
||||
InputStream i = ICUData.getRequiredStream(ICUResourceBundle.ICU_BUNDLE+"/invuca.icu");
|
||||
// try {
|
||||
// String invdat = "/com/ibm/icu/impl/data/invuca.icu";
|
||||
// InputStream i = CollationParsedRuleBuilder.class.getResourceAsStream(invdat);
|
||||
|
@ -18,7 +18,7 @@ import com.ibm.icu.impl.ICUService.Factory;
|
||||
import com.ibm.icu.impl.LocaleUtility;
|
||||
import com.ibm.icu.text.Collator.CollatorFactory;
|
||||
import com.ibm.icu.util.ULocale;
|
||||
import com.ibm.icu.util.UResourceBundle;
|
||||
import com.ibm.icu.impl.ICUResourceBundle;
|
||||
|
||||
final class CollatorServiceShim extends Collator.ServiceShim {
|
||||
|
||||
@ -82,14 +82,14 @@ final class CollatorServiceShim extends Collator.ServiceShim {
|
||||
Locale[] getAvailableLocales() {
|
||||
// TODO rewrite this to just wrap getAvailableULocales later
|
||||
if (service.isDefault()) {
|
||||
return ICUResourceBundle.getAvailableLocales(UResourceBundle.ICU_COLLATION_BASE_NAME);
|
||||
return ICUResourceBundle.getAvailableLocales(ICUResourceBundle.ICU_COLLATION_BASE_NAME);
|
||||
}
|
||||
return service.getAvailableLocales();
|
||||
}
|
||||
|
||||
ULocale[] getAvailableULocales() {
|
||||
if (service.isDefault()) {
|
||||
return ICUResourceBundle.getAvailableULocales(UResourceBundle.ICU_COLLATION_BASE_NAME);
|
||||
return ICUResourceBundle.getAvailableULocales(ICUResourceBundle.ICU_COLLATION_BASE_NAME);
|
||||
}
|
||||
return service.getAvailableULocales();
|
||||
}
|
||||
|
@ -696,7 +696,7 @@ public abstract class DateFormat extends UFormat {
|
||||
*/
|
||||
public static Locale[] getAvailableLocales()
|
||||
{
|
||||
return ICUResourceBundle.getAvailableLocales(UResourceBundle.ICU_BASE_NAME);
|
||||
return ICUResourceBundle.getAvailableLocales(ICUResourceBundle.ICU_BASE_NAME);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -418,6 +418,7 @@ public class DateFormatSymbols implements Serializable, Cloneable {
|
||||
|
||||
protected void initializeData(ULocale desiredLocale, CalendarData calData)
|
||||
{
|
||||
|
||||
// FIXME: cache only ResourceBundle. Hence every time, will do
|
||||
// getObject(). This won't be necessary if the Resource itself
|
||||
// is cached.
|
||||
@ -438,7 +439,7 @@ public class DateFormatSymbols implements Serializable, Cloneable {
|
||||
ampms = calData.getStringArray("AmPmMarkers");
|
||||
|
||||
// These really do use rb and not calData
|
||||
ICUResourceBundle rb = (ICUResourceBundle)UResourceBundle.getBundleInstance(UResourceBundle.ICU_BASE_NAME,desiredLocale);
|
||||
ICUResourceBundle rb = (ICUResourceBundle)UResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BASE_NAME,desiredLocale);
|
||||
// hack around class cast problem
|
||||
// zoneStrings = (String[][])rb.getObject("zoneStrings");
|
||||
ICUResourceBundle zoneObject = rb.get("zoneStrings");
|
||||
|
@ -491,14 +491,14 @@ final public class DecimalFormatSymbols implements Cloneable, Serializable {
|
||||
String[] numberElements;
|
||||
if (data == null) { /* cache miss */
|
||||
data = new String[1][];
|
||||
ICUResourceBundle rb = (ICUResourceBundle)UResourceBundle.getBundleInstance(UResourceBundle.ICU_BASE_NAME,locale);
|
||||
ICUResourceBundle rb = (ICUResourceBundle)UResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BASE_NAME,locale);
|
||||
data[0] = rb.getStringArray("NumberElements");
|
||||
/* update cache */
|
||||
cachedLocaleData.put(locale, data);
|
||||
}
|
||||
numberElements = data[0];
|
||||
|
||||
ICUResourceBundle r = (ICUResourceBundle)UResourceBundle.getBundleInstance(UResourceBundle.ICU_BASE_NAME,locale);
|
||||
ICUResourceBundle r = (ICUResourceBundle)UResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BASE_NAME,locale);
|
||||
|
||||
// TODO: Determine actual and valid locale correctly.
|
||||
ULocale uloc = r.getULocale();
|
||||
|
@ -10,7 +10,7 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import com.ibm.icu.impl.ICUData;
|
||||
import com.ibm.icu.util.UResourceBundle;
|
||||
import com.ibm.icu.impl.ICUResourceBundle;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -44,7 +44,6 @@ public final class IDNA {
|
||||
|
||||
private static final int MAX_LABEL_LENGTH = 63;
|
||||
private static final int HYPHEN = 0x002D;
|
||||
private static final String NAME_PREP_PROFILE = "uidna";
|
||||
private static final int CAPITAL_A = 0x0041;
|
||||
private static final int CAPITAL_Z = 0x005A;
|
||||
private static final int LOWER_CASE_DELTA = 0x0020;
|
||||
@ -84,7 +83,7 @@ public final class IDNA {
|
||||
/* private constructor to prevent construction of the object */
|
||||
private IDNA(){
|
||||
try{
|
||||
InputStream stream = ICUData.getRequiredStream(UResourceBundle.ICU_BUNDLE+"/uidna.spp");
|
||||
InputStream stream = ICUData.getRequiredStream(ICUResourceBundle.ICU_BUNDLE+"/uidna.spp");
|
||||
namePrep = new StringPrep(stream);
|
||||
stream.close();
|
||||
}catch (IOException e){
|
||||
@ -135,7 +134,7 @@ public final class IDNA {
|
||||
|
||||
/* Case-insensitive comparison */
|
||||
if(c1!=c2) {
|
||||
rc=(int)toASCIILower(c1)-(int)toASCIILower(c2);
|
||||
rc=toASCIILower(c1)-toASCIILower(c2);
|
||||
if(rc!=0) {
|
||||
return rc;
|
||||
}
|
||||
@ -307,7 +306,7 @@ public final class IDNA {
|
||||
boolean srcIsLDH = true;
|
||||
|
||||
//get the options
|
||||
boolean useSTD3ASCIIRules = (boolean)((options & USE_STD3_RULES) != 0);
|
||||
boolean useSTD3ASCIIRules = ((options & USE_STD3_RULES) != 0);
|
||||
|
||||
int failPos = -1;
|
||||
// step 2
|
||||
@ -605,7 +604,7 @@ public final class IDNA {
|
||||
boolean srcIsLDH = true;
|
||||
|
||||
//get the options
|
||||
boolean useSTD3ASCIIRules = (boolean)((options & USE_STD3_RULES) != 0);
|
||||
boolean useSTD3ASCIIRules = ((options & USE_STD3_RULES) != 0);
|
||||
|
||||
int failPos = -1;
|
||||
int ch;
|
||||
|
@ -708,7 +708,7 @@ public abstract class NumberFormat extends UFormat {
|
||||
*/
|
||||
public static Locale[] getAvailableLocales() {
|
||||
if (shim == null) {
|
||||
return ICUResourceBundle.getAvailableLocales(UResourceBundle.ICU_BASE_NAME);
|
||||
return ICUResourceBundle.getAvailableLocales(ICUResourceBundle.ICU_BASE_NAME);
|
||||
}
|
||||
return getShim().getAvailableLocales();
|
||||
}
|
||||
@ -1070,7 +1070,7 @@ public abstract class NumberFormat extends UFormat {
|
||||
//}
|
||||
|
||||
// {dlf}
|
||||
ICUResourceBundle rb = (ICUResourceBundle)UResourceBundle.getBundleInstance(UResourceBundle.ICU_BASE_NAME,forLocale);
|
||||
ICUResourceBundle rb = (ICUResourceBundle)UResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BASE_NAME,forLocale);
|
||||
String[] numberPatterns = rb.getStringArray("NumberPatterns");
|
||||
|
||||
/* {dlf}
|
||||
|
@ -27,7 +27,7 @@ class NumberFormatServiceShim extends NumberFormat.NumberFormatShim {
|
||||
|
||||
Locale[] getAvailableLocales() {
|
||||
if (service.isDefault()) {
|
||||
return ICUResourceBundle.getAvailableLocales(UResourceBundle.ICU_BASE_NAME);
|
||||
return ICUResourceBundle.getAvailableLocales(ICUResourceBundle.ICU_BASE_NAME);
|
||||
}
|
||||
return service.getAvailableLocales();
|
||||
}
|
||||
|
@ -1578,7 +1578,7 @@ public final class RuleBasedCollator extends Collator
|
||||
// IMPLICIT_BASE_4BYTE_ = ((IMPLICIT_BASE_BYTE_
|
||||
// + IMPLICIT_3BYTE_COUNT_) << 24) + 0x030303;
|
||||
UCA_.init();
|
||||
ICUResourceBundle rb = (ICUResourceBundle)UResourceBundle.getBundleInstance(UResourceBundle.ICU_COLLATION_BASE_NAME, ULocale.ENGLISH);
|
||||
ICUResourceBundle rb = (ICUResourceBundle)UResourceBundle.getBundleInstance(ICUResourceBundle.ICU_COLLATION_BASE_NAME, ULocale.ENGLISH);
|
||||
UCA_.m_rules_ = (String)rb.getObject("%%UCARULES");
|
||||
}
|
||||
catch (Exception e)
|
||||
@ -1612,7 +1612,7 @@ public final class RuleBasedCollator extends Collator
|
||||
*/
|
||||
RuleBasedCollator(ULocale locale)
|
||||
{
|
||||
ICUResourceBundle rb = (ICUResourceBundle)UResourceBundle.getBundleInstance(UResourceBundle.ICU_COLLATION_BASE_NAME, locale);
|
||||
ICUResourceBundle rb = (ICUResourceBundle)UResourceBundle.getBundleInstance(ICUResourceBundle.ICU_COLLATION_BASE_NAME, locale);
|
||||
initUtility();
|
||||
if (rb != null) {
|
||||
try {
|
||||
|
@ -323,7 +323,6 @@ public class SimpleDateFormat extends DateFormat {
|
||||
String[] dateTimePatterns = (String[]) cachedLocaleData.get(loc);
|
||||
if (dateTimePatterns == null) { /* cache miss */
|
||||
CalendarData calData = new CalendarData(new ULocale(loc), null); // TODO: type?
|
||||
|
||||
// TODO: get correct actual/valid locale here
|
||||
ULocale uloc = calData.getULocale();
|
||||
setLocale(uloc, uloc);
|
||||
|
@ -1216,7 +1216,7 @@ public abstract class Transliterator {
|
||||
//If we ever integrate this with the Sun JDK, the resource bundle
|
||||
// root will change to sun.text.resources.LocaleElements
|
||||
|
||||
ICUResourceBundle bundle = (ICUResourceBundle)UResourceBundle.getBundleInstance(UResourceBundle.ICU_BASE_NAME,inLocale);
|
||||
ICUResourceBundle bundle = (ICUResourceBundle)UResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BASE_NAME,inLocale);
|
||||
|
||||
// Normalize the ID
|
||||
String stv[] = TransliteratorIDParser.IDtoSTV(id);
|
||||
|
@ -119,7 +119,7 @@ class TransliteratorRegistry {
|
||||
// If 'top' is not a script name, try a locale lookup
|
||||
if (script == UScript.INVALID_CODE) {
|
||||
Locale toploc = LocaleUtility.getLocaleFromName(top);
|
||||
res = (ICUResourceBundle)UResourceBundle.getBundleInstance(UResourceBundle.ICU_BASE_NAME,toploc);
|
||||
res = (ICUResourceBundle)UResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BASE_NAME,toploc);
|
||||
// Make sure we got the bundle we wanted; otherwise, don't use it
|
||||
if (res!=null && LocaleUtility.isFallbackOf(res.getULocale().toString(), top)) {
|
||||
isSpecLocale = true;
|
||||
|
@ -1628,7 +1628,7 @@ public abstract class Calendar implements Serializable, Cloneable {
|
||||
public static Locale[] getAvailableLocales()
|
||||
{
|
||||
return service == null
|
||||
? ICUResourceBundle.getAvailableLocales(UResourceBundle.ICU_BASE_NAME)
|
||||
? ICUResourceBundle.getAvailableLocales(ICUResourceBundle.ICU_BASE_NAME)
|
||||
: service.getAvailableLocales();
|
||||
}
|
||||
///CLOVER:OFF
|
||||
@ -3686,6 +3686,7 @@ public abstract class Calendar implements Serializable, Cloneable {
|
||||
WeekData data = (WeekData) cachedLocaleData.get(locale);
|
||||
|
||||
if (data == null) { /* cache miss */
|
||||
|
||||
CalendarData calData = new CalendarData(new ULocale(locale), getType());
|
||||
int[] dateTimeElements = calData.get("DateTimeElements").getIntVector();
|
||||
int[] weekend = calData.get("weekend").getIntVector();
|
||||
|
@ -106,7 +106,7 @@ public class Currency extends MeasureUnit implements Serializable {
|
||||
if (variant.equals("PREEURO") || variant.equals("EURO")) {
|
||||
country = country + '_' + variant;
|
||||
}
|
||||
ICUResourceBundle bundle = (ICUResourceBundle)UResourceBundle.getBundleInstance(UResourceBundle.ICU_BASE_NAME,"root");
|
||||
ICUResourceBundle bundle = (ICUResourceBundle)UResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BASE_NAME,"root");
|
||||
ICUResourceBundle cm = bundle.get("CurrencyMap");
|
||||
|
||||
// Do a linear search
|
||||
@ -174,7 +174,7 @@ public class Currency extends MeasureUnit implements Serializable {
|
||||
*/
|
||||
public static Locale[] getAvailableLocales() {
|
||||
if (shim == null) {
|
||||
return ICUResourceBundle.getAvailableLocales(UResourceBundle.ICU_BASE_NAME);
|
||||
return ICUResourceBundle.getAvailableLocales(ICUResourceBundle.ICU_BASE_NAME);
|
||||
} else {
|
||||
return shim.getAvailableLocales();
|
||||
}
|
||||
@ -262,7 +262,7 @@ public class Currency extends MeasureUnit implements Serializable {
|
||||
|
||||
// Multi-level resource inheritance fallback loop
|
||||
while (locale != null) {
|
||||
ICUResourceBundle rb = (ICUResourceBundle)UResourceBundle.getBundleInstance(UResourceBundle.ICU_BASE_NAME,locale);
|
||||
ICUResourceBundle rb = (ICUResourceBundle)UResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BASE_NAME,locale);
|
||||
// We can't cast this to String[][]; the cast has to happen later
|
||||
try {
|
||||
ICUResourceBundle currencies = rb.get("Currencies");
|
||||
@ -369,7 +369,7 @@ public class Currency extends MeasureUnit implements Serializable {
|
||||
// Multi-level resource inheritance fallback loop
|
||||
|
||||
while (locale != null) {
|
||||
ICUResourceBundle rb = (ICUResourceBundle)UResourceBundle.getBundleInstance(UResourceBundle.ICU_BASE_NAME,locale);
|
||||
ICUResourceBundle rb = (ICUResourceBundle)UResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BASE_NAME,locale);
|
||||
// We can't cast this to String[][]; the cast has to happen later
|
||||
|
||||
try {
|
||||
@ -513,7 +513,7 @@ public class Currency extends MeasureUnit implements Serializable {
|
||||
// Get CurrencyMeta resource out of root locale file. [This may
|
||||
// move out of the root locale file later; if it does, update this
|
||||
// code.]
|
||||
ICUResourceBundle root = (ICUResourceBundle)UResourceBundle.getBundleInstance(UResourceBundle.ICU_BASE_NAME,"root");
|
||||
ICUResourceBundle root = (ICUResourceBundle)UResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BASE_NAME,"root");
|
||||
ICUResourceBundle currencyMeta = root.get("CurrencyMeta");
|
||||
|
||||
//Integer[] i = null;
|
||||
|
@ -24,7 +24,7 @@ final class CurrencyServiceShim extends Currency.ServiceShim {
|
||||
|
||||
Locale[] getAvailableLocales() {
|
||||
if (service.isDefault()) {
|
||||
return ICUResourceBundle.getAvailableLocales(UResourceBundle.ICU_BASE_NAME);
|
||||
return ICUResourceBundle.getAvailableLocales(ICUResourceBundle.ICU_BASE_NAME);
|
||||
}
|
||||
return service.getAvailableLocales();
|
||||
}
|
||||
|
@ -41,7 +41,7 @@ public final class LocaleData {
|
||||
* @draft ICU 3.0
|
||||
*/
|
||||
public static UnicodeSet getExemplarSet(ULocale locale, int options) {
|
||||
ICUResourceBundle bundle = (ICUResourceBundle)UResourceBundle.getBundleInstance(UResourceBundle.ICU_BASE_NAME, locale);
|
||||
ICUResourceBundle bundle = (ICUResourceBundle)UResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BASE_NAME, locale);
|
||||
String pattern = bundle.getString(EXEMPLAR_CHARS);
|
||||
return new UnicodeSet(pattern, UnicodeSet.IGNORE_SPACE | options);
|
||||
}
|
||||
@ -81,7 +81,7 @@ public final class LocaleData {
|
||||
* @draft ICU 3.0
|
||||
*/
|
||||
public static final MeasurementSystem getMeasurementSystem(ULocale locale){
|
||||
ICUResourceBundle bundle = (ICUResourceBundle)UResourceBundle.getBundleInstance(UResourceBundle.ICU_BASE_NAME, locale);
|
||||
ICUResourceBundle bundle = (ICUResourceBundle)UResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BASE_NAME, locale);
|
||||
ICUResourceBundle sysBundle = bundle.get(MEASUREMENT_SYSTEM);
|
||||
|
||||
int system = sysBundle.getInt();
|
||||
@ -135,7 +135,7 @@ public final class LocaleData {
|
||||
* @draft ICU 3.0
|
||||
*/
|
||||
public static final PaperSize getPaperSize(ULocale locale){
|
||||
ICUResourceBundle bundle = (ICUResourceBundle)UResourceBundle.getBundleInstance(UResourceBundle.ICU_BASE_NAME, locale);
|
||||
ICUResourceBundle bundle = (ICUResourceBundle)UResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BASE_NAME, locale);
|
||||
ICUResourceBundle obj = bundle.get(PAPER_SIZE);
|
||||
int[] size = obj.getIntVector();
|
||||
return new PaperSize(size[0], size[1]);
|
||||
|
@ -14,7 +14,6 @@ import java.util.Map;
|
||||
import java.util.MissingResourceException;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
import com.ibm.icu.impl.ICUData;
|
||||
import com.ibm.icu.impl.ICUResourceBundle;
|
||||
import com.ibm.icu.impl.ICUResourceBundleReader;
|
||||
import com.ibm.icu.impl.ResourceBundleWrapper;
|
||||
@ -43,58 +42,7 @@ import com.ibm.icu.util.ULocale;
|
||||
* @author ram
|
||||
*/
|
||||
public abstract class UResourceBundle extends ResourceBundle{
|
||||
/**
|
||||
* The data path to be used with getBundleInstance API
|
||||
* @draft ICU 3.0
|
||||
*/
|
||||
protected static final String ICU_DATA_PATH = "com/ibm/icu/impl/";
|
||||
/**
|
||||
* The data path to be used with getBundleInstance API
|
||||
* @draft ICU 3.0
|
||||
*/
|
||||
public static final String ICU_BUNDLE = "data/icudt"+VersionInfo.ICU_DATA_VERSION;
|
||||
|
||||
/**
|
||||
* The base name of ICU data to be used with getBundleInstance API
|
||||
* @draft ICU 3.0
|
||||
*/
|
||||
public static final String ICU_BASE_NAME= ICU_DATA_PATH+ICU_BUNDLE;
|
||||
|
||||
/**
|
||||
* The base name of collation data to be used with getBundleInstance API
|
||||
* @draft ICU 3.0
|
||||
*/
|
||||
public static final String ICU_COLLATION_BASE_NAME = ICU_BASE_NAME + "/coll";
|
||||
|
||||
/**
|
||||
* The class loader constant to be used with getBundleInstance API
|
||||
* @draft ICU 3.0
|
||||
*/
|
||||
public static final ClassLoader ICU_DATA_CLASS_LOADER = ICUData.class.getClassLoader();
|
||||
|
||||
/**
|
||||
* The name of the resource containing the installed locales
|
||||
* @draft ICU 3.0
|
||||
*/
|
||||
protected static final String INSTALLED_LOCALES = "InstalledLocales";
|
||||
|
||||
/**
|
||||
* The locale ID of this bundle
|
||||
* @draft ICU 3.0
|
||||
*/
|
||||
protected String localeID;
|
||||
|
||||
/**
|
||||
* The base name with which this bundle was opened
|
||||
* @draft ICU 3.0
|
||||
*/
|
||||
protected String baseName;
|
||||
|
||||
/**
|
||||
* Denotes if this bundle has fallback or not
|
||||
* @draft ICU 3.0
|
||||
*/
|
||||
protected boolean hasFallback;
|
||||
|
||||
|
||||
/**
|
||||
* Creates a resource bundle using the specified base name and locale.
|
||||
@ -107,7 +55,7 @@ public abstract class UResourceBundle extends ResourceBundle{
|
||||
* @draft ICU 3.0
|
||||
*/
|
||||
public static final UResourceBundle getBundleInstance(String baseName, String localeName){
|
||||
return getBundleInstance(baseName, localeName, ICU_DATA_CLASS_LOADER, false);
|
||||
return getBundleInstance(baseName, localeName, ICUResourceBundle.ICU_DATA_CLASS_LOADER, false);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -164,7 +112,7 @@ public abstract class UResourceBundle extends ResourceBundle{
|
||||
if(locale==null){
|
||||
locale = ULocale.getDefault();
|
||||
}
|
||||
return getBundleInstance( ICU_BASE_NAME, locale.toString(), ICU_DATA_CLASS_LOADER );
|
||||
return getBundleInstance( ICUResourceBundle.ICU_BASE_NAME, locale.toString(), ICUResourceBundle.ICU_DATA_CLASS_LOADER );
|
||||
}
|
||||
/**
|
||||
* Creates a UResourceBundle for the default locale and specified base name,
|
||||
@ -175,7 +123,7 @@ public abstract class UResourceBundle extends ResourceBundle{
|
||||
* @draft ICU 3.0
|
||||
*/
|
||||
public static final UResourceBundle getBundleInstance(String baseName){
|
||||
return getBundleInstance( baseName, ULocale.getDefault().toString(), ICU_DATA_CLASS_LOADER );
|
||||
return getBundleInstance( baseName, ULocale.getDefault().toString(), ICUResourceBundle.ICU_DATA_CLASS_LOADER );
|
||||
}
|
||||
/**
|
||||
* Creates a UResourceBundle for the specified locale and specified base name,
|
||||
@ -203,7 +151,7 @@ public abstract class UResourceBundle extends ResourceBundle{
|
||||
* @draft ICU 3.0
|
||||
*/
|
||||
public static final UResourceBundle getBundleInstance(String baseName, ULocale locale){
|
||||
return getBundleInstance(baseName, locale.toString(),ICU_DATA_CLASS_LOADER);
|
||||
return getBundleInstance(baseName, locale.toString(),ICUResourceBundle.ICU_DATA_CLASS_LOADER);
|
||||
}
|
||||
|
||||
|
||||
@ -216,9 +164,12 @@ public abstract class UResourceBundle extends ResourceBundle{
|
||||
* @return the locale of this resource bundle
|
||||
* @draft ICU 3.0
|
||||
*/
|
||||
public ULocale getULocale() {
|
||||
return new ULocale(localeID);
|
||||
}
|
||||
public abstract ULocale getULocale();
|
||||
|
||||
protected abstract String getLocaleID();
|
||||
protected abstract String getBaseName();
|
||||
protected abstract UResourceBundle getParent();
|
||||
|
||||
|
||||
/**
|
||||
* Get the locale of this bundle
|
||||
@ -228,14 +179,7 @@ public abstract class UResourceBundle extends ResourceBundle{
|
||||
public Locale getLocale(){
|
||||
return getULocale().toLocale();
|
||||
}
|
||||
/**
|
||||
* Set the parent bundle of this bundle
|
||||
* @param parent
|
||||
* @draft ICU 3.0
|
||||
*/
|
||||
protected void setParent(UResourceBundle parent){
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
// Cache for ResourceBundle instantiation
|
||||
private static SoftReference BUNDLE_CACHE;
|
||||
|
||||
@ -362,27 +306,30 @@ public abstract class UResourceBundle extends ResourceBundle{
|
||||
// first try to create an ICUResourceBundle
|
||||
// the expectation is that most client using
|
||||
// this interface will open an *.res file
|
||||
try{
|
||||
if(disableFallback){
|
||||
ULocale defaultLocale = ULocale.getDefault();
|
||||
String fullName = ICUResourceBundleReader.getFullName(baseName, localeName);
|
||||
UResourceBundle b = null;
|
||||
if(disableFallback){
|
||||
ULocale defaultLocale = ULocale.getDefault();
|
||||
localeName = ULocale.getBaseName(localeName);
|
||||
String fullName = ICUResourceBundleReader.getFullName(baseName, localeName);
|
||||
cacheKey.setKeyValues(root, fullName, defaultLocale);
|
||||
b = loadFromCache(cacheKey);
|
||||
if(b==null){
|
||||
b = ICUResourceBundle.createBundle(baseName, localeName, root);
|
||||
cacheKey.setKeyValues(root, fullName, defaultLocale);
|
||||
UResourceBundle b = loadFromCache(cacheKey);
|
||||
if(b==null){
|
||||
b = ICUResourceBundle.createBundle(baseName, localeName, root);
|
||||
cacheKey.setKeyValues(root, fullName, defaultLocale);
|
||||
addToCache(cacheKey, b);
|
||||
}
|
||||
b.hasFallback = disableFallback;
|
||||
return b;
|
||||
}else{
|
||||
return instantiateICUResource(baseName,localeName,root);
|
||||
addToCache(cacheKey, b);
|
||||
}
|
||||
}catch(MissingResourceException e){
|
||||
}else{
|
||||
b = instantiateICUResource(baseName,localeName,root);
|
||||
}
|
||||
if(b==null){
|
||||
// we can't find an *.res file .. so fallback to
|
||||
// Java ResourceBundle loadeing
|
||||
return new ResourceBundleWrapper(baseName, localeName, root);
|
||||
b = new ResourceBundleWrapper(baseName, localeName, root);
|
||||
}
|
||||
if(b==null){
|
||||
throw new MissingResourceException("Could not find the bundle ", baseName,localeName );
|
||||
}
|
||||
return b;
|
||||
}
|
||||
/**
|
||||
* Creates a new ICUResourceBundle for the given locale, baseName and class loader
|
||||
@ -401,44 +348,47 @@ public abstract class UResourceBundle extends ResourceBundle{
|
||||
String fullName = ICUResourceBundleReader.getFullName(baseName, localeName);
|
||||
cacheKey.setKeyValues(root, fullName, defaultLocale);
|
||||
UResourceBundle b = loadFromCache(cacheKey);
|
||||
final String rootLocale = "root";
|
||||
final String defaultID = ULocale.getDefault().toString();
|
||||
if(localeName.equals("")){
|
||||
localeName = rootLocale;
|
||||
}
|
||||
if (b == null) {
|
||||
UResourceBundle parent = null;
|
||||
int i = localeName.lastIndexOf('_');
|
||||
final String rootLocale = "root";
|
||||
|
||||
if (i != -1) {
|
||||
parent = instantiateICUResource(baseName, localeName.substring(0, i), root);
|
||||
}else{
|
||||
parent = ICUResourceBundle.createBundle(baseName, rootLocale, root);
|
||||
}
|
||||
try {
|
||||
UResourceBundle b1 = ICUResourceBundle.createBundle(baseName, localeName, root);
|
||||
|
||||
if (parent != null) {
|
||||
b1.setParent(parent);
|
||||
b = ICUResourceBundle.createBundle(baseName, localeName, root);
|
||||
if(b==null){
|
||||
int i = localeName.lastIndexOf('_');
|
||||
if (i != -1) {
|
||||
b = instantiateICUResource(baseName, localeName.substring(0, i), root);
|
||||
}else{
|
||||
if(defaultID.indexOf(localeName)==-1){
|
||||
b = instantiateICUResource(baseName, defaultID, root);
|
||||
}
|
||||
}
|
||||
|
||||
b = b1;
|
||||
|
||||
}else{
|
||||
localeName = b.getLocaleID();
|
||||
int i = localeName.lastIndexOf('_');
|
||||
cacheKey.setKeyValues(root, fullName, defaultLocale);
|
||||
addToCache(cacheKey, b);
|
||||
}catch (MissingResourceException e) {
|
||||
|
||||
// if a bogus locale is passed then the parent should be
|
||||
// the default locale not the root locale!
|
||||
if(localeName.indexOf('_')==-1){
|
||||
String defaultName = defaultLocale.toString();
|
||||
|
||||
if(!localeName.equals(rootLocale.toString()) &&
|
||||
defaultName.indexOf(localeName)==-1){
|
||||
parent = instantiateICUResource(baseName, defaultName, root);
|
||||
}
|
||||
UResourceBundle parent = null;
|
||||
if (i != -1) {
|
||||
parent = instantiateICUResource(baseName, localeName.substring(0, i), root);
|
||||
}else{
|
||||
parent = ICUResourceBundle.createBundle(baseName, rootLocale, root);
|
||||
}
|
||||
b = parent;
|
||||
}
|
||||
b.setParent(parent);
|
||||
}
|
||||
}
|
||||
return b;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
protected static UResourceBundle instantiateResource(String baseName,String localeID, ClassLoader root, boolean required){
|
||||
// first try
|
||||
try{
|
||||
}catch(MissingResourceException e){
|
||||
if(required){
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user