ICU-4251 promote API to UResourceBundle class. Fix problems and modularize and streamline the resource bundle objects.

X-SVN-Rev: 20851
This commit is contained in:
Ram Viswanadha 2007-01-03 23:13:25 +00:00
parent 70bca54abe
commit 38d4426632
22 changed files with 1335 additions and 1381 deletions

1
.gitattributes vendored
View file

@ -111,6 +111,7 @@ icu4j/src/com/ibm/icu/dev/tool/docs/icu4j342.api.gz -text
icu4j/src/com/ibm/icu/dev/tool/docs/icu4j343.api.gz -text
icu4j/src/com/ibm/icu/impl/data/icudata.jar -text
icu4j/src/com/ibm/icu/impl/data/th.brk -text
icu4j/src/com/ibm/icu/util/UResourceBundleIterator.java -text
icu4j/src/com/ibm/richtext/textapps/resources/unicode.arabic.red -text
icu4j/src/com/ibm/richtext/textapps/resources/unicode.hebrew.red -text
tools/unicodetools/com/ibm/rbm/docs/images/TitleLogo_transparent.gif -text

View file

@ -1,7 +1,7 @@
//##header
/*
**********************************************************************
* Copyright (c) 2006, International Business Machines
* Copyright (c) 2006-2007, International Business Machines
* Corporation and others. All Rights Reserved.
**********************************************************************
* Created on 2006-4-21
@ -17,8 +17,8 @@ import java.util.MissingResourceException;
import java.util.NoSuchElementException;
import com.ibm.icu.impl.ICUResourceBundle;
import com.ibm.icu.impl.ICUResourceBundleIterator;
import com.ibm.icu.util.UResourceBundle;
import com.ibm.icu.util.UResourceBundleIterator;
import com.ibm.icu.util.UResourceTypeMismatchException;
/**
@ -71,20 +71,20 @@ class ResourceModule implements TestDataModule {
private static final String DATA = "Cases";
ICUResourceBundle res;
ICUResourceBundle info;
ICUResourceBundle defaultHeader;
ICUResourceBundle testData;
UResourceBundle res;
UResourceBundle info;
UResourceBundle defaultHeader;
UResourceBundle testData;
ResourceModule(String baseName, String localeName) throws DataModuleFormatError{
res = (ICUResourceBundle) UResourceBundle.getBundleInstance(baseName, localeName);
info = getFromTable(res, INFO, ICUResourceBundle.TABLE);
testData = getFromTable(res, TEST_DATA, ICUResourceBundle.TABLE);
res = (UResourceBundle) UResourceBundle.getBundleInstance(baseName, localeName);
info = getFromTable(res, INFO, UResourceBundle.TABLE);
testData = getFromTable(res, TEST_DATA, UResourceBundle.TABLE);
try {
// unfortunately, actually, data can be either ARRAY or STRING
defaultHeader = getFromTable(info, HEADER, new int[]{ICUResourceBundle.ARRAY, ICUResourceBundle.STRING});
defaultHeader = getFromTable(info, HEADER, new int[]{UResourceBundle.ARRAY, UResourceBundle.STRING});
} catch (MissingResourceException e){
defaultHeader = null;
}
@ -104,35 +104,35 @@ class ResourceModule implements TestDataModule {
public Iterator getTestDataIterator() {
return new IteratorAdapter(testData){
protected Object prepareNext(ICUResourceBundle nextRes) throws DataModuleFormatError {
protected Object prepareNext(UResourceBundle nextRes) throws DataModuleFormatError {
return new UResourceTestData(defaultHeader, nextRes);
}
};
}
/**
* To make ICUResourceBundleIterator works like Iterator
* To make UResourceBundleIterator works like Iterator
* and return various data-driven test object for next() call
*
* @author Raymond Yang
*/
private abstract static class IteratorAdapter implements Iterator{
private ICUResourceBundle res;
private ICUResourceBundleIterator itr;
private UResourceBundle res;
private UResourceBundleIterator itr;
private Object preparedNextElement = null;
// fix a strange behavior for ICUResourceBundleIterator for
// ICUResourceBundle.STRING. It support hasNext(), but does
// fix a strange behavior for UResourceBundleIterator for
// UResourceBundle.STRING. It support hasNext(), but does
// not support next() now.
//
// Use the iterated resource itself as the result from next() call
private boolean isStrRes = false;
private boolean isStrResPrepared = false; // for STRING resouce, we only prepare once
IteratorAdapter(ICUResourceBundle theRes) {
IteratorAdapter(UResourceBundle theRes) {
assert_not (theRes == null);
res = theRes;
itr = res.getIterator();
isStrRes = res.getType() == ICUResourceBundle.STRING;
itr = ((ICUResourceBundle)res).getIterator();
isStrRes = res.getType() == UResourceBundle.STRING;
}
public void remove() {
@ -163,7 +163,7 @@ class ResourceModule implements TestDataModule {
if (isStrRes) return hasNextForStrRes();
if (preparedNextElement != null) return true;
ICUResourceBundle t = null;
UResourceBundle t = null;
if (itr.hasNext()) {
// Notice, other RuntimeException may be throwed
t = itr.next();
@ -197,7 +197,7 @@ class ResourceModule implements TestDataModule {
/**
* To prepare data-driven test object for next() call, should not return null
*/
abstract protected Object prepareNext(ICUResourceBundle nextRes) throws DataModuleFormatError;
abstract protected Object prepareNext(UResourceBundle nextRes) throws DataModuleFormatError;
}
@ -234,13 +234,13 @@ class ResourceModule implements TestDataModule {
* silently also. The behavior is modified because some resource are
* optional and can be missed.
*/
static ICUResourceBundle getFromTable(ICUResourceBundle res, String key, int expResType) throws DataModuleFormatError{
static UResourceBundle getFromTable(UResourceBundle res, String key, int expResType) throws DataModuleFormatError{
return getFromTable(res, key, new int[]{expResType});
}
static ICUResourceBundle getFromTable(ICUResourceBundle res, String key, int[] expResTypes) throws DataModuleFormatError{
assert_is (res != null && key != null && res.getType() == ICUResourceBundle.TABLE);
ICUResourceBundle t = res.get(key);
static UResourceBundle getFromTable(UResourceBundle res, String key, int[] expResTypes) throws DataModuleFormatError{
assert_is (res != null && key != null && res.getType() == UResourceBundle.TABLE);
UResourceBundle t = res.get(key);
assert_not (t ==null);
int type = t.getType();
@ -257,21 +257,21 @@ class ResourceModule implements TestDataModule {
}
/**
* Unfortunately, ICUResourceBundle is unable to treat one string as string array.
* This function return a String[] from ICUResourceBundle, regardless it is an array or a string
* Unfortunately, UResourceBundle is unable to treat one string as string array.
* This function return a String[] from UResourceBundle, regardless it is an array or a string
*/
static String[] getStringArrayHelper(ICUResourceBundle res, String key) throws DataModuleFormatError{
ICUResourceBundle t = getFromTable(res, key, new int[]{ICUResourceBundle.ARRAY, ICUResourceBundle.STRING});
static String[] getStringArrayHelper(UResourceBundle res, String key) throws DataModuleFormatError{
UResourceBundle t = getFromTable(res, key, new int[]{UResourceBundle.ARRAY, UResourceBundle.STRING});
return getStringArrayHelper(t);
}
static String[] getStringArrayHelper(ICUResourceBundle res) throws DataModuleFormatError{
static String[] getStringArrayHelper(UResourceBundle res) throws DataModuleFormatError{
try{
int type = res.getType();
switch (type) {
case ICUResourceBundle.ARRAY:
case UResourceBundle.ARRAY:
return res.getStringArray();
case ICUResourceBundle.STRING:
case UResourceBundle.STRING:
return new String[]{res.getString()};
default:
throw new UResourceTypeMismatchException("Only accept ARRAY and STRING types.");
@ -299,24 +299,24 @@ class ResourceModule implements TestDataModule {
}
private static class UResourceTestData implements TestData{
private ICUResourceBundle res;
private ICUResourceBundle info;
private ICUResourceBundle settings;
private ICUResourceBundle header;
private ICUResourceBundle data;
private UResourceBundle res;
private UResourceBundle info;
private UResourceBundle settings;
private UResourceBundle header;
private UResourceBundle data;
UResourceTestData(ICUResourceBundle defaultHeader, ICUResourceBundle theRes) throws DataModuleFormatError{
UResourceTestData(UResourceBundle defaultHeader, UResourceBundle theRes) throws DataModuleFormatError{
assert_is (theRes != null && theRes.getType() == ICUResourceBundle.TABLE);
assert_is (theRes != null && theRes.getType() == UResourceBundle.TABLE);
res = theRes;
// unfortunately, actually, data can be either ARRAY or STRING
data = getFromTable(res, DATA, new int[]{ICUResourceBundle.ARRAY, ICUResourceBundle.STRING});
data = getFromTable(res, DATA, new int[]{UResourceBundle.ARRAY, UResourceBundle.STRING});
try {
// unfortunately, actually, data can be either ARRAY or STRING
header = getFromTable(res, HEADER, new int[]{ICUResourceBundle.ARRAY, ICUResourceBundle.STRING});
header = getFromTable(res, HEADER, new int[]{UResourceBundle.ARRAY, UResourceBundle.STRING});
} catch (MissingResourceException e){
if (defaultHeader == null) {
throw new DataModuleFormatError("Unable to find a header for test data '" + res.getKey() + "' and no default header exist.");
@ -325,8 +325,8 @@ class ResourceModule implements TestDataModule {
}
}
try{
settings = getFromTable(res, SETTINGS, ICUResourceBundle.ARRAY);
info = getFromTable(res, INFO, ICUResourceBundle.TABLE);
settings = getFromTable(res, SETTINGS, UResourceBundle.ARRAY);
info = getFromTable(res, INFO, UResourceBundle.TABLE);
} catch (MissingResourceException e){
// do nothing, left them null;
settings = data;
@ -342,9 +342,9 @@ class ResourceModule implements TestDataModule {
}
public Iterator getSettingsIterator() {
assert_is (settings.getType() == ICUResourceBundle.ARRAY);
assert_is (settings.getType() == UResourceBundle.ARRAY);
return new IteratorAdapter(settings){
protected Object prepareNext(ICUResourceBundle nextRes) throws DataModuleFormatError {
protected Object prepareNext(UResourceBundle nextRes) throws DataModuleFormatError {
return new UTableResource(nextRes);
}
};
@ -352,10 +352,10 @@ class ResourceModule implements TestDataModule {
public Iterator getDataIterator() {
// unfortunately,
assert_is (data.getType() == ICUResourceBundle.ARRAY
|| data.getType() == ICUResourceBundle.STRING);
assert_is (data.getType() == UResourceBundle.ARRAY
|| data.getType() == UResourceBundle.STRING);
return new IteratorAdapter(data){
protected Object prepareNext(ICUResourceBundle nextRes) throws DataModuleFormatError {
protected Object prepareNext(UResourceBundle nextRes) throws DataModuleFormatError {
return new UArrayResource(header, nextRes);
}
};
@ -363,9 +363,9 @@ class ResourceModule implements TestDataModule {
}
private static class UTableResource implements DataMap{
private ICUResourceBundle res;
private UResourceBundle res;
UTableResource(ICUResourceBundle theRes){
UTableResource(UResourceBundle theRes){
res = theRes;
}
public String getString(String key) {
@ -385,7 +385,7 @@ class ResourceModule implements TestDataModule {
private static class UArrayResource implements DataMap{
private Map theMap;
UArrayResource(ICUResourceBundle theHeader, ICUResourceBundle theData) throws DataModuleFormatError{
UArrayResource(UResourceBundle theHeader, UResourceBundle theData) throws DataModuleFormatError{
assert_is (theHeader != null && theData != null);
String[] header;
@ -394,9 +394,9 @@ class ResourceModule implements TestDataModule {
throw new DataModuleFormatError("The count of Header and Data is mismatch.");
theMap = new HashMap();
for (int i = 0; i < header.length; i++) {
if(theData.getType()==ICUResourceBundle.ARRAY){
if(theData.getType()==UResourceBundle.ARRAY){
theMap.put(header[i], theData.get(i));
}else if(theData.getType()==ICUResourceBundle.STRING){
}else if(theData.getType()==UResourceBundle.STRING){
theMap.put(header[i], theData.getString());
}else{
throw new DataModuleFormatError("Did not get the expected data!");

View file

@ -1,7 +1,7 @@
//##header
/*****************************************************************************************
*
* Copyright (C) 1996-2006, International Business Machines
* Copyright (C) 1996-2007, International Business Machines
* Corporation and others. All Rights Reserved.
**/
@ -953,14 +953,14 @@ 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(ICUResourceBundle.ICU_BASE_NAME,locales[i]);
UResourceBundle rb = UResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BASE_NAME,locales[i]);
//
// Get the currency pattern for this locale. We have to fish it
// out of the ResourceBundle directly, since DecimalFormat.toPattern
// will return the localized symbol, not \00a4
//
ICUResourceBundle numPatterns = rb.get("NumberPatterns");
UResourceBundle numPatterns = rb.get("NumberPatterns");
String pattern = numPatterns.getString(1);
if (pattern.indexOf('\u00A4') == -1 ) { // 'x' not "x" -- workaround bug in IBM JDK 1.4.1

View file

@ -1,6 +1,6 @@
/*
**********************************************************************
* Copyright (c) 2006, International Business Machines
* Copyright (c) 2006-2007, International Business Machines
* Corporation and others. All Rights Reserved.
**********************************************************************
*/
@ -16,7 +16,7 @@ import com.ibm.icu.util.UResourceBundle;
public class ResourceBundlePerf extends PerfTest {
private ICUResourceBundle icuRes = null;
private UResourceBundle icuRes = null;
private ResourceBundle javaRes = null;
public static void main(String[] org_args) throws Exception {
@ -24,7 +24,7 @@ public class ResourceBundlePerf extends PerfTest {
}
protected void setup(String[] args) {
icuRes = (ICUResourceBundle)UResourceBundle.getBundleInstance("com/ibm/icu/dev/data/testdata", "testtypes");
icuRes = UResourceBundle.getBundleInstance("com/ibm/icu/dev/data/testdata", "testtypes");
javaRes = ICULocaleData.getResourceBundle("com.ibm.icu.dev.data","TestDataElements","testtypes");
}
@ -132,7 +132,7 @@ public class ResourceBundlePerf extends PerfTest {
this.expected = expected;
}
public void call() {
ICUResourceBundle temp = icuRes.get(key);
UResourceBundle temp = icuRes.get(key);
int t = temp.getInt();
if (t != expected) throw new Error("not equal");
}
@ -190,7 +190,7 @@ public class ResourceBundlePerf extends PerfTest {
PerfTest.Function TestGetMinusOneUintICU(){
return new PerfTest.Function(){
public void call(){
ICUResourceBundle sub = icuRes.get("minusone");
UResourceBundle sub = icuRes.get("minusone");
int t = sub.getUInt();
if (t != 0xFFFFFFF) throw new Error("not equal");
}
@ -221,7 +221,7 @@ public class ResourceBundlePerf extends PerfTest {
this.expected = expected;
}
public void call() {
ICUResourceBundle temp = icuRes.get(key);
UResourceBundle temp = icuRes.get(key);
int[] iv = temp.getIntVector();
for (int i = 0; i < iv.length; i++){
if (expected[i] != iv[i]) throw new Error("not equal");
@ -254,7 +254,7 @@ public class ResourceBundlePerf extends PerfTest {
this.expected_len = expected_len;
}
public void call() {
ICUResourceBundle temp = icuRes.get(key);
UResourceBundle temp = icuRes.get(key);
ByteBuffer got = temp.getBinary();
if(got.remaining() != expected_len) throw new Error("not the expected len");
for(int i=0; i< got.remaining(); i++){
@ -327,16 +327,16 @@ public class ResourceBundlePerf extends PerfTest {
}
public void call() {
int p = 0;
ICUResourceBundle menus = icuRes.get(key);
UResourceBundle menus = icuRes.get(key);
int sizei = menus.getSize();
for (int i=0; i<sizei; i++){
ICUResourceBundle menu = menus.get(i);
UResourceBundle menu = menus.get(i);
String menu_name = menu.getKey();
if (!expected[p++].equals(menu_name)) throw new Error("not equal");
int sizej = menu.getSize();
for (int j=0; j< sizej; j++){
ICUResourceBundle menu_item = menu.get(j);
UResourceBundle menu_item = menu.get(j);
String key = menu_item.getKey();
String value = menu_item.getString();
if(!expected[p++].equals(key)) throw new Error("not equal");

View file

@ -1,6 +1,6 @@
/*
*******************************************************************************
* Copyright (C) 2003-2004, International Business Machines Corporation and *
* Copyright (C) 2003-2007, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*/
@ -35,8 +35,7 @@ public class NamePrepTransform {
private NamePrepTransform(){
// load the resource bundle
// ICUResourceBundle bundle = (ICUResourceBundle)ICUResourceBundle.getBundleInstance("com/ibm/icu/dev/data/testdata","idna_rules", true);
ICUResourceBundle bundle = (ICUResourceBundle)ICUResourceBundle.createBundle("com/ibm/icu/dev/data/testdata","idna_rules", NamePrepTransform.class.getClassLoader());
ICUResourceBundle bundle = (ICUResourceBundle)ICUResourceBundle.getBundleInstance("com/ibm/icu/dev/data/testdata","idna_rules", NamePrepTransform.class.getClassLoader(), true);
String mapRules = bundle.getString("MapNoNormalization");
mapRules += bundle.getString("MapNFKC");
mapTransform = Transliterator.createFromRules("CaseMap",mapRules,Transliterator.FORWARD);

View file

@ -1,6 +1,6 @@
/*
*******************************************************************************
* Copyright (C) 2003-2006, International Business Machines Corporation and *
* Copyright (C) 2003-2007, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*/
@ -811,4 +811,36 @@ public class TestIDNA extends TestFmwk {
logln("Got the expected exception: " + ex.getMessage());
}
}
public void TestJB5275(){
String domain = "xn--m\u00FCller.de";
try{
IDNA.convertIDNToUnicode(domain, IDNA.DEFAULT);
}catch(StringPrepParseException ex){
logln("Got the expected exception. "+ex.getMessage());
}catch (Exception ex){
errln("Did not get the expected exception "+ex.getMessage());
}
try{
IDNA.convertIDNToUnicode(domain, IDNA.USE_STD3_RULES);
}catch(StringPrepParseException ex){
logln("Got the expected exception. "+ex.getMessage());
}catch (Exception ex){
errln("Did not get the expected exception "+ex.getMessage());
}
try{
IDNA.convertToUnicode("xn--m\u00FCller", IDNA.DEFAULT);
}catch(Exception ex){
errln("ToUnicode operation failed! "+ex.getMessage());
}
try{
IDNA.convertToUnicode("xn--m\u00FCller", IDNA.USE_STD3_RULES);
}catch(Exception ex){
errln("ToUnicode operation failed! "+ex.getMessage());
}
try{
IDNA.convertIDNToUnicode("xn--m\u1234ller", IDNA.USE_STD3_RULES);
}catch(StringPrepParseException ex){
errln("ToUnicode operation failed! "+ex.getMessage());
}
}
}

View file

@ -1,6 +1,6 @@
/*
*******************************************************************************
* Copyright (C) 1996-2006, International Business Machines Corporation and *
* Copyright (C) 1996-2007, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*/
@ -128,7 +128,7 @@ public class DisplayNameTest extends TestFmwk {
ICUResourceBundle bundle = (ICUResourceBundle)UResourceBundle.getBundleInstance(locale);
ICUResourceBundle table = bundle.getWithFallback("zoneStrings");
for (int i = 0; i < table.getSize(); ++i) {
ICUResourceBundle stringSet = table.get(i);
UResourceBundle stringSet = table.get(i);
//ICUResourceBundle stringSet = table.getWithFallback(String.valueOf(i));
String key = stringSet.getString(0);
if (SHOW_ALL) System.out.println("key: " + key);

View file

@ -1,17 +1,15 @@
//##header
/**
*******************************************************************************
* Copyright (C) 2001-2006, International Business Machines Corporation and *
* Copyright (C) 2001-2007, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*/
package com.ibm.icu.dev.test.util;
import java.io.BufferedReader;
import java.io.File;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.IOException;
import java.net.URL;
import java.net.URLConnection;
import java.net.JarURLConnection;
@ -94,7 +92,7 @@ public final class ICUResourceBundleTest extends TestFmwk {
}
bundle = UResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BASE_NAME, "bogus");
if(bundle instanceof ICUResourceBundle && bundle.getULocale().equals("en_US")){
if(bundle instanceof UResourceBundle && bundle.getULocale().equals("en_US")){
logln("wrapper mechanism works for bogus locale");
}else{
errln("wrapper mechanism failed for bogus locale.");
@ -115,7 +113,7 @@ public final class ICUResourceBundleTest extends TestFmwk {
// this tests tests loading of root bundle when a resource bundle
// for the default locale is requested
try {
ICUResourceBundle bundle = (ICUResourceBundle) UResourceBundle.getBundleInstance("com/ibm/icu/dev/data/testdata", ULocale.getDefault().toString(), testLoader);
UResourceBundle bundle = (UResourceBundle) UResourceBundle.getBundleInstance("com/ibm/icu/dev/data/testdata", ULocale.getDefault().toString(), testLoader);
if(bundle==null){
errln("could not create the resource bundle");
}
@ -125,18 +123,18 @@ public final class ICUResourceBundleTest extends TestFmwk {
}
}
public void TestOpen(){
ICUResourceBundle bundle = (ICUResourceBundle) UResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BASE_NAME, "en_US_POSIX");
UResourceBundle bundle = (UResourceBundle) UResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BASE_NAME, "en_US_POSIX");
if(bundle==null){
errln("could not create the resource bundle");
}
ICUResourceBundle obj = bundle.get("NumberPatterns");
UResourceBundle obj = bundle.get("NumberPatterns");
int size = obj.getSize();
int type = obj.getType();
if(type == ICUResourceBundle.ARRAY){
ICUResourceBundle sub;
if(type == UResourceBundle.ARRAY){
UResourceBundle sub;
for(int i=0; i<size; i++){
sub = obj.get(i);
String temp =sub.getString();
@ -158,8 +156,8 @@ public final class ICUResourceBundleTest extends TestFmwk {
size = obj.getSize();
type = obj.getType();
if(type == ICUResourceBundle.ARRAY){
ICUResourceBundle sub;
if(type == UResourceBundle.ARRAY){
UResourceBundle sub;
for(int i=0; i<size; i++){
sub = obj.get(i);
String temp =sub.getString();
@ -175,11 +173,11 @@ public final class ICUResourceBundleTest extends TestFmwk {
if(bundle==null){
errln("could not create the resource bundle");
}
bundle = (ICUResourceBundle)UResourceBundle.getBundleInstance(ICUResourceBundle.ICU_COLLATION_BASE_NAME, "en_US_POSIX");
bundle = (UResourceBundle)UResourceBundle.getBundleInstance(ICUResourceBundle.ICU_COLLATION_BASE_NAME, "en_US_POSIX");
if(bundle==null){
errln("could not load the stream");
}
bundle = (ICUResourceBundle) UResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BASE_NAME, "my_very_very_very_long_bogus_bundle");
bundle = (UResourceBundle) 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");
}
@ -188,9 +186,9 @@ public final class ICUResourceBundleTest extends TestFmwk {
}
public void TestBasicTypes(){
ICUResourceBundle bundle = null;
UResourceBundle bundle = null;
try {
bundle = (ICUResourceBundle)UResourceBundle.getBundleInstance("com/ibm/icu/dev/data/testdata", "testtypes", testLoader);
bundle = (UResourceBundle)UResourceBundle.getBundleInstance("com/ibm/icu/dev/data/testdata", "testtypes", testLoader);
}
catch (MissingResourceException e) {
warnln("could not load test data: " + e.getMessage());
@ -198,7 +196,7 @@ public final class ICUResourceBundleTest extends TestFmwk {
}
{
String expected = "abc\u0000def";
ICUResourceBundle sub = bundle.get("zerotest");
UResourceBundle sub = bundle.get("zerotest");
if(!expected.equals(sub.getString())){
errln("Did not get the expected string for key zerotest in bundle testtypes");
}
@ -215,7 +213,7 @@ public final class ICUResourceBundleTest extends TestFmwk {
}
{
int expected = 123;
ICUResourceBundle sub = bundle.get("onehundredtwentythree");
UResourceBundle sub = bundle.get("onehundredtwentythree");
if(expected!=sub.getInt()){
errln("Did not get the expected int value for key onehundredtwentythree in bundle testtypes");
}
@ -227,14 +225,14 @@ public final class ICUResourceBundleTest extends TestFmwk {
}
{
int expected = 1;
ICUResourceBundle sub = bundle.get("one");
UResourceBundle sub = bundle.get("one");
if(expected!=sub.getInt()){
errln("Did not get the expected int value for key one in bundle testtypes");
}
}
{
int expected = -1;
ICUResourceBundle sub = bundle.get("minusone");
UResourceBundle sub = bundle.get("minusone");
int got = sub.getInt();
if(expected!=got){
errln("Did not get the expected int value for key minusone in bundle testtypes");
@ -247,7 +245,7 @@ public final class ICUResourceBundleTest extends TestFmwk {
}
{
int expected = 1;
ICUResourceBundle sub = bundle.get("plusone");
UResourceBundle sub = bundle.get("plusone");
if(expected!=sub.getInt()){
errln("Did not get the expected int value for key minusone in bundle testtypes");
}
@ -255,7 +253,7 @@ public final class ICUResourceBundleTest extends TestFmwk {
}
{
int[] expected = new int[]{ 1, 2, 3, -3, 4, 5, 6, 7 } ;
ICUResourceBundle sub = bundle.get("integerarray");
UResourceBundle sub = bundle.get("integerarray");
if(!Utility.arrayEquals(expected,sub.getIntVector())){
errln("Did not get the expected int vector value for key integerarray in bundle testtypes");
}
@ -267,7 +265,7 @@ public final class ICUResourceBundleTest extends TestFmwk {
}
{
ICUResourceBundle sub = bundle.get("binarytest");
UResourceBundle sub = bundle.get("binarytest");
ByteBuffer got = sub.getBinary();
if(got.remaining()!=15){
errln("Did not get the expected length for the binary ByteBuffer");
@ -286,7 +284,7 @@ public final class ICUResourceBundleTest extends TestFmwk {
}
{
ICUResourceBundle sub = bundle.get("emptyarray");
UResourceBundle sub = bundle.get("emptyarray");
String key = sub.getKey();
if(!key.equals("emptyarray")){
errln("Did not get the expected key for emptytable item");
@ -296,17 +294,17 @@ public final class ICUResourceBundleTest extends TestFmwk {
}
}
{
ICUResourceBundle sub = bundle.get("menu");
UResourceBundle sub = bundle.get("menu");
String key = sub.getKey();
if(!key.equals("menu")){
errln("Did not get the expected key for menu item");
}
ICUResourceBundle sub1 = sub.get("file");
UResourceBundle sub1 = sub.get("file");
key = sub1.getKey();
if(!key.equals("file")){
errln("Did not get the expected key for file item");
}
ICUResourceBundle sub2 = sub1.get("open");
UResourceBundle sub2 = sub1.get("open");
key = sub2.getKey();
if(!key.equals("open")){
errln("Did not get the expected key for file item");
@ -374,16 +372,16 @@ public final class ICUResourceBundleTest extends TestFmwk {
new TestCase ( "1ooooooo11o11oo1o", 65970 ),
new TestCase ( "1ooooooo111oo1111", 65999 )
};
ICUResourceBundle bundle = null;
UResourceBundle bundle = null;
try {
bundle = (ICUResourceBundle)UResourceBundle.getBundleInstance("com/ibm/icu/dev/data/testdata","testtable32", testLoader);
bundle = (UResourceBundle)UResourceBundle.getBundleInstance("com/ibm/icu/dev/data/testdata","testtable32", testLoader);
}
catch (MissingResourceException ex) {
warnln("could not load resource data: " + ex.getMessage());
return;
}
if(bundle.getType()!= ICUResourceBundle.TABLE){
if(bundle.getType()!= UResourceBundle.TABLE){
errln("Could not get the correct type for bundle testtable32");
}
int size =bundle.getSize();
@ -391,16 +389,16 @@ public final class ICUResourceBundleTest extends TestFmwk {
errln("Could not get the correct size for bundle testtable32");
}
for(int i =0; i<size; i++){
ICUResourceBundle item = bundle.get(i);
UResourceBundle item = bundle.get(i);
String key = item.getKey();
int parsedNumber = parseTable32Key(key);
int number=-1;
switch(item.getType()){
case ICUResourceBundle.STRING:
case UResourceBundle.STRING:
String value = item.getString();
number = UTF16.charAt(value,0);
break;
case ICUResourceBundle.INT:
case UResourceBundle.INT:
number = item.getInt();
break;
default:
@ -415,7 +413,7 @@ public final class ICUResourceBundleTest extends TestFmwk {
}
for(int i=0;i<arr.length; i++){
String expected = arr[i].key;
ICUResourceBundle item = bundle.get(expected);
UResourceBundle item = bundle.get(expected);
int number=0;
String key = item.getKey();
int parsedNumber = parseTable32Key(key);
@ -423,11 +421,11 @@ public final class ICUResourceBundleTest extends TestFmwk {
errln("Did not get the expected key. Expected: "+expected+" Got:"+key);
}
switch(item.getType()){
case ICUResourceBundle.STRING:
case UResourceBundle.STRING:
String value = item.getString();
number = UTF16.charAt(value,0);
break;
case ICUResourceBundle.INT:
case UResourceBundle.INT:
number = item.getInt();
break;
default:
@ -458,12 +456,12 @@ public final class ICUResourceBundleTest extends TestFmwk {
public void TestAliases(){
String simpleAlias = "Open";
ICUResourceBundle rb = (ICUResourceBundle)ICUResourceBundle.createBundle("com/ibm/icu/dev/data/testdata","testaliases", testLoader);
UResourceBundle rb = (UResourceBundle)UResourceBundle.getBundleInstance("com/ibm/icu/dev/data/testdata","testaliases", testLoader);
if (rb == null) {
warnln("could not load testaliases data");
return;
}
ICUResourceBundle sub = rb.get("simplealias");
UResourceBundle sub = rb.get("simplealias");
String s1 = sub.getString("simplealias");
if(s1.equals(simpleAlias)){
logln("Alias mechanism works for simplealias");
@ -472,7 +470,7 @@ public final class ICUResourceBundleTest extends TestFmwk {
}
{
try{
rb = (ICUResourceBundle)UResourceBundle.getBundleInstance("com/ibm/icu/dev/data/testdata","testaliases",testLoader);
rb = (UResourceBundle)UResourceBundle.getBundleInstance("com/ibm/icu/dev/data/testdata","testaliases",testLoader);
sub = rb.get("nonexisting");
errln("Did not get the expected exception for nonexisting");
}catch(MissingResourceException ex){
@ -480,7 +478,7 @@ public final class ICUResourceBundleTest extends TestFmwk {
}
}
{
rb = (ICUResourceBundle)UResourceBundle.getBundleInstance("com/ibm/icu/dev/data/testdata","testaliases",testLoader);
rb = (UResourceBundle)UResourceBundle.getBundleInstance("com/ibm/icu/dev/data/testdata","testaliases",testLoader);
sub = rb.get("referencingalias");
s1 = sub.getString();
if(s1.equals("Hani")){
@ -490,7 +488,7 @@ public final class ICUResourceBundleTest extends TestFmwk {
}
}
{
rb = (ICUResourceBundle)UResourceBundle.getBundleInstance("com/ibm/icu/dev/data/testdata","testaliases",testLoader);
rb = (UResourceBundle)UResourceBundle.getBundleInstance("com/ibm/icu/dev/data/testdata","testaliases",testLoader);
sub = rb.get("boundaries");
String word = sub.getString("word");
@ -502,7 +500,7 @@ public final class ICUResourceBundleTest extends TestFmwk {
}
{
ICUResourceBundle rb1 = (ICUResourceBundle)UResourceBundle.getBundleInstance("com/ibm/icu/dev/data/testdata","testaliases",testLoader);
UResourceBundle rb1 = (UResourceBundle)UResourceBundle.getBundleInstance("com/ibm/icu/dev/data/testdata","testaliases",testLoader);
if(rb1!=rb){
errln("Caching of the resource bundle failed");
}else{
@ -574,15 +572,15 @@ public final class ICUResourceBundleTest extends TestFmwk {
}
}
// should not get an exception
rb = (ICUResourceBundle) UResourceBundle.getBundleInstance(ICUResourceBundle.ICU_RBNF_BASE_NAME,"fr_BE");
rb = (UResourceBundle) UResourceBundle.getBundleInstance(ICUResourceBundle.ICU_RBNF_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(ICUResourceBundle.ICU_COLLATION_BASE_NAME,"zh_TW");
ICUResourceBundle b = (ICUResourceBundle) rb.getObject("collations");
rb = (UResourceBundle) UResourceBundle.getBundleInstance(ICUResourceBundle.ICU_COLLATION_BASE_NAME,"zh_TW");
UResourceBundle b = (UResourceBundle) rb.getObject("collations");
if(b != null){
if(b.get(0).getKey().equals( "default")){
logln("Alias mechanism works");
@ -596,8 +594,8 @@ public final class ICUResourceBundleTest extends TestFmwk {
}
public void TestAlias(){
logln("Testing %%ALIAS");
ICUResourceBundle rb = (ICUResourceBundle) UResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BASE_NAME,"iw_IL");
ICUResourceBundle b = rb.get("NumberPatterns");
UResourceBundle rb = (UResourceBundle) UResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BASE_NAME,"iw_IL");
UResourceBundle b = rb.get("NumberPatterns");
if(b != null){
if(b.getSize()>0){
logln("%%ALIAS mechanism works");
@ -609,8 +607,8 @@ public final class ICUResourceBundleTest extends TestFmwk {
}
}
public void TestXPathAlias(){
ICUResourceBundle rb = (ICUResourceBundle) UResourceBundle.getBundleInstance("com/ibm/icu/dev/data/testdata","te_IN",testLoader);
ICUResourceBundle b = rb.get("aliasClient");
UResourceBundle rb = (UResourceBundle) UResourceBundle.getBundleInstance("com/ibm/icu/dev/data/testdata","te_IN",testLoader);
UResourceBundle b = rb.get("aliasClient");
String result = b.getString();
String expResult= "correct";
@ -618,7 +616,7 @@ public final class ICUResourceBundleTest extends TestFmwk {
errln("Did not get the expected result for XPath style alias");
}
try{
ICUResourceBundle c = rb.get("rootAliasClient");
UResourceBundle c = rb.get("rootAliasClient");
result = c.getString();
expResult = "correct";
if(!result.equals(expResult)){
@ -630,8 +628,8 @@ public final class ICUResourceBundleTest extends TestFmwk {
}
public void TestCircularAliases(){
try{
ICUResourceBundle rb = (ICUResourceBundle)UResourceBundle.getBundleInstance("com/ibm/icu/dev/data/testdata","testaliases",testLoader);
ICUResourceBundle sub = rb.get("aaa");
UResourceBundle rb = (UResourceBundle)UResourceBundle.getBundleInstance("com/ibm/icu/dev/data/testdata","testaliases",testLoader);
UResourceBundle sub = rb.get("aaa");
String s1 = sub.getString();
if(s1!=null){
errln("Did not get the expected exception");
@ -646,7 +644,7 @@ public final class ICUResourceBundleTest extends TestFmwk {
public void TestGetWithFallback(){
/*
ICUResourceBundle bundle =(ICUResourceBundle) UResourceBundle.getBundleInstance("com/ibm/icu/dev/data/testdata","te_IN");
UResourceBundle bundle =(UResourceBundle) UResourceBundle.getBundleInstance("com/ibm/icu/dev/data/testdata","te_IN");
String key = bundle.getStringWithFallback("Keys/collation");
if(!key.equals("COLLATION")){
errln("Did not get the expected result from getStringWithFallback method.");
@ -837,8 +835,8 @@ public final class ICUResourceBundleTest extends TestFmwk {
public void TestNorwegian(){
try{
ICUResourceBundle rb = (ICUResourceBundle)UResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BASE_NAME, "no_NO_NY");
ICUResourceBundle sub = rb.get("Countries");
UResourceBundle rb = UResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BASE_NAME, "no_NO_NY");
UResourceBundle sub = rb.get("Countries");
String s1 = sub.getString("NO");
if(s1.equals("Noreg")){
logln("got expected output ");
@ -851,7 +849,7 @@ public final class ICUResourceBundleTest extends TestFmwk {
}
public void TestJB4102(){
try {
ICUResourceBundle root =(ICUResourceBundle) ICUResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BASE_NAME, "root");
ICUResourceBundle root =(ICUResourceBundle) UResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BASE_NAME, "root");
ICUResourceBundle t = null;
try{
t = root.getWithFallback("calendar/islamic-civil/AmPmMarkers");
@ -880,12 +878,12 @@ public final class ICUResourceBundleTest extends TestFmwk {
logln("Testing CLDR style aliases......\n");
ICUResourceBundle rb = (ICUResourceBundle)UResourceBundle.getBundleInstance("com/ibm/icu/dev/data/testdata", "te_IN_REVISED",testLoader);
ICUResourceBundle alias = rb.get("a");
UResourceBundle rb = UResourceBundle.getBundleInstance("com/ibm/icu/dev/data/testdata", "te_IN_REVISED",testLoader);
ICUResourceBundle alias = (ICUResourceBundle)rb.get("a");
for(int i = 1; i < 5 ; i++) {
String resource="a"+i;
ICUResourceBundle a = ((ICUResourceBundle)alias).getWithFallback(resource);
UResourceBundle a = (alias).getWithFallback(resource);
result = a.getString();
if(result.equals(expected)) {
errln("CLDR style aliases failed resource with name "+resource+"resource, exp "+expects[i] +" , got " + result);
@ -923,22 +921,22 @@ public final class ICUResourceBundleTest extends TestFmwk {
logln("Test to verify loading status of get(String)");
bundle = (ICUResourceBundle)UResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BASE_NAME, "te_IN");
ICUResourceBundle countries = bundle.get("Countries");
status =countries.getLoadingStatus();
UResourceBundle countries = bundle.get("Countries");
status = ((ICUResourceBundle)countries).getLoadingStatus();
if(status != ICUResourceBundle.FROM_FALLBACK){
errln("Did not get the expected value for loading status. Expected "+ getLSString(ICUResourceBundle.FROM_FALLBACK)
+ " Got: " + getLSString(status));
}
/*
ICUResourceBundle auxExemplar = bundle.get("AuxExemplarCharacters");
UResourceBundle auxExemplar = bundle.get("AuxExemplarCharacters");
status = auxExemplar.getLoadingStatus();
if(status != ICUResourceBundle.FROM_ROOT){
errln("Did not get the expected value for loading status. Expected "+ getLSString(ICUResourceBundle.FROM_ROOT)
if(status != UResourceBundle.FROM_ROOT){
errln("Did not get the expected value for loading status. Expected "+ getLSString(UResourceBundle.FROM_ROOT)
+ " Got: " + getLSString(status));
}
*/
logln("Test to verify loading status of get(int)");
ICUResourceBundle ms = bundle.get("MeasurementSystem");
ICUResourceBundle ms = (ICUResourceBundle)bundle.get("MeasurementSystem");
status = ms.getLoadingStatus();
if(status != ICUResourceBundle.FROM_ROOT){
errln("Did not get the expected value for loading status. Expected "+ getLSString(ICUResourceBundle.FROM_ROOT)
@ -947,7 +945,7 @@ public final class ICUResourceBundleTest extends TestFmwk {
logln("Test to verify loading status of getwithFallback");
bundle = (ICUResourceBundle)UResourceBundle.getBundleInstance("com/ibm/icu/dev/data/testdata", "sh_YU",testLoader);
ICUResourceBundle temp = bundle.getWithFallback("a/a2");
ICUResourceBundle temp = (ICUResourceBundle)bundle.getWithFallback("a/a2");
status = temp.getLoadingStatus();
if(status != ICUResourceBundle.FROM_LOCALE){
errln("Did not get the expected value for loading status. Expected "+ getLSString(ICUResourceBundle.FROM_LOCALE)

File diff suppressed because it is too large Load diff

View file

@ -1,224 +1,165 @@
//##header
/*
******************************************************************************
* Copyright (C) 2004-2006, International Business Machines Corporation and *
* others. All Rights Reserved. *
******************************************************************************
/**
*******************************************************************************
* Copyright (C) 2001-2007, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*/
package com.ibm.icu.impl;
import java.nio.ByteBuffer;
import java.util.HashMap;
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.UResourceBundleIterator;
import com.ibm.icu.util.UResourceTypeMismatchException;
//#ifndef FOUNDATION
import java.nio.ByteBuffer;
//#endif
/**
* @author ram
*/
public class ICUResourceBundleImpl extends ICUResourceBundle {
//protected byte[] version;
private byte[] rawData;
private long rootResource;
private boolean noFallback;
private String localeID;
private String baseName;
private ULocale ulocale;
private ClassLoader loader;
private static final boolean ASSERT = false;
class ICUResourceBundleImpl {
/**
*
* @param baseName
* @param localeID
* @param root
* @return the new bundle
*/
public static ICUResourceBundle createBundle(String baseName,
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;
}
ICUResourceBundleImpl bundle = new ICUResourceBundleImpl(reader,
baseName, localeID, root);
return bundle.getBundle();
}
protected String getLocaleID() {
return localeID;
}
protected String getBaseName() {
return baseName;
}
public ULocale getULocale() {
return ulocale;
}
public UResourceBundle getParent() {
return (UResourceBundle) parent;
}
protected void setParent(ResourceBundle parent) {
this.parent = parent;
}
/**
* Get the noFallback flag specified in the loaded bundle.
* @return The noFallback flag.
*/
protected boolean getNoFallback() {
return noFallback;
}
private ICUResourceBundle getBundle() {
int type = RES_GET_TYPE(rootResource);
if (type == TABLE) {
ResourceTable table = new ResourceTable(null, rootResource, "", true);
if(table.size==1){
ICUResourceBundle b = table.handleGet(0, table);
String itemKey = b.getKey();
// %%ALIAS is such a hack!
if (itemKey.equals("%%ALIAS")) {
String locale = b.getString();
ICUResourceBundle actual = (ICUResourceBundle) UResourceBundle.getBundleInstance(baseName, locale);
return (ResourceTable) actual;
}else{
return table;
}
}else {
return table;
static final class ResourceArray extends ICUResourceBundle {
protected String[] handleGetStringArray() {
String[] strings = new String[size];
UResourceBundleIterator iter = getIterator();
int i = 0;
while (iter.hasNext()) {
strings[i++] = iter.next().getString();
}
} else if (type == TABLE32) {
// genrb does not generate Table32 with %%ALIAS
return new ResourceTable32(null, rootResource, "", true);
} else {
throw new IllegalStateException("Invalid format error");
return strings;
}
/**
* @internal ICU 3.0
*/
public String[] getStringArray() {
return handleGetStringArray();
}
protected UResourceBundle handleGet(String index, UResourceBundle requested) {
return handleGet(index, null, requested);
}
protected UResourceBundle handleGet(String index, HashMap table, UResourceBundle requested) {
int val = getIndex(index);
if (val > -1) {
return handleGet(val, table, requested);
}
throw new UResourceTypeMismatchException("Could not get the correct value for index: "+ index);
}
protected UResourceBundle handleGet(int index, UResourceBundle requested) {
return handleGet(index, null, requested);
}
protected UResourceBundle handleGet(int index, HashMap table, UResourceBundle requested) {
if (index > size) {
throw new IndexOutOfBoundsException();
}
int offset = RES_GET_OFFSET(resource);
int itemOffset = offset + getIntOffset(index + 1);
long itemResource = (UNSIGNED_INT_MASK) & ICUResourceBundle.getInt(rawData,itemOffset);
String path = (isTopLevel == true) ? Integer.toString(index) : resPath + "/" + index;
return createBundleObject(null, itemResource, path, table, requested, this);
}
private int countItems() {
int offset = RES_GET_OFFSET(resource);
int value = getInt(rawData,offset);
return value;
}
ResourceArray(String key, String resPath, long resource, ICUResourceBundle bundle) {
assign(this, bundle);
this.resource = resource;
this.key = key;
this.size = countItems();
this.resPath = resPath;
}
}
private ICUResourceBundleImpl(ICUResourceBundleReader reader, String baseName,
String localeID, ClassLoader loader) {
this.rawData = reader.getData();
this.rootResource = (UNSIGNED_INT_MASK) & reader.getRootResource();
this.noFallback = reader.getNoFallback();
this.baseName = baseName;
this.localeID = localeID;
this.ulocale = new ULocale(localeID);
this.loader = loader;
}
static final int RES_GET_TYPE(long res) {
return (int) ((res) >> 28L);
}
private static final int RES_GET_OFFSET(long res) {
return (int) ((res & 0x0fffffff) * 4);
}
/* get signed and unsigned integer values directly from the Resource handle */
private static final int RES_GET_INT(long res) {
return (((int) ((res) << 4L)) >> 4L);
}
private static final long RES_GET_UINT(long res) {
long t = ((res) & 0x0fffffffL);
return t;
}
private static final StringBuffer RES_GET_KEY(byte[] rawData,
int keyOffset) {
char ch = 0xFFFF; //sentinel
StringBuffer key = new StringBuffer();
while ((ch = (char) rawData[keyOffset]) != 0) {
key.append(ch);
keyOffset++;
static final class ResourceBinary extends ICUResourceBundle {
private byte[] value;
public ByteBuffer getBinary() {
return ByteBuffer.wrap(value);
}
public byte [] getBinary(byte []ba) {
return value;
}
return key;
}
private static final int getIntOffset(int offset) {
return (offset * 4);
}
private static final int getCharOffset(int offset) {
return (offset * 2);
}
private final ICUResourceBundle createBundleObject(String key,
long resource, String resPath, HashMap table, ICUResourceBundle requested) {
//if (resource != RES_BOGUS) {
switch (RES_GET_TYPE(resource)) {
case STRING : {
return new ResourceString(key, resPath, resource);
}
case BINARY : {
return new ResourceBinary(key, resPath, resource);
}
case ALIAS : {
return findResource(key, resource, table, requested);
}
case INT : {
return new ResourceInt(key, resPath, resource);
}
case INT_VECTOR : {
return new ResourceIntVector(key, resPath, resource);
}
case ARRAY : {
return new ResourceArray(key, resPath, resource);
}
case TABLE32 : {
return new ResourceTable32(key, resPath, resource);
}
case TABLE : {
return new ResourceTable(key, resPath, resource);
}
default :
throw new IllegalStateException("The resource type is unknown");
private byte[] getValue() {
int offset = RES_GET_OFFSET(resource);
int length = ICUResourceBundle.getInt(rawData,offset);
int byteOffset = offset + getIntOffset(1);
byte[] dst = new byte[length];
if (ASSERT) Assert.assrt("byteOffset+length < rawData.length", byteOffset+length < rawData.length);
System.arraycopy(rawData, byteOffset, dst, 0, length);
return dst;
}
//}
//return null;
}
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;
for (;;) {
mid = ((start + limit) / 2);
if (lastMid == mid) { /* Have we moved? */
break; /* We haven't moved, and it wasn't found. */
}
lastMid = mid;
String comp = res.getKey(currentOffset, mid);
rc = target.compareTo(comp);
if (rc < 0) {
limit = mid;
} else if (rc > 0) {
start = mid;
} else {
return mid;
}
ResourceBinary(String key, String resPath, long resource, ICUResourceBundle bundle) {
assign(this, bundle);
this.resource = resource;
this.key = key;
this.resPath = resPath;
value = getValue();
}
return -1;
}
private interface Resource {
public String getKey(int currentOfset, int index);
static final class ResourceInt extends ICUResourceBundle {
public int getInt() {
return RES_GET_INT(resource);
}
public int getUInt() {
long ret = RES_GET_UINT(resource);
return (int) ret;
}
ResourceInt(String key, String resPath, long resource, ICUResourceBundle bundle) {
assign(this, bundle);
this.key = key;
this.resource = resource;
this.resPath = resPath;
}
}
private class ResourceTable extends ICUResourceBundle implements Resource {
static final class ResourceString extends ICUResourceBundle {
private String value;
public String getString() {
return value;
}
ResourceString(String key, String resPath, long resource, ICUResourceBundle bundle) {
assign(this, bundle);
value = getStringValue(resource);
this.key = key;
this.resource = resource;
this.resPath = resPath;
}
}
static final class ResourceIntVector extends ICUResourceBundle {
private int[] value;
public int[] getIntVector() {
return value;
}
private int[] getValue() {
int offset = RES_GET_OFFSET(resource);
int length = ICUResourceBundle.getInt(rawData,offset);
int intOffset = offset + getIntOffset(1);
int[] val = new int[length];
int byteLength = getIntOffset(length);
if (ASSERT) Assert.assrt("(intOffset+byteLength)<rawData.length", (intOffset+byteLength)<rawData.length);
for(int i=0; i<length;i++){
val[i]=ICUResourceBundle.getInt(rawData, intOffset+getIntOffset(i));
}
return val;
}
ResourceIntVector(String key, String resPath, long resource, ICUResourceBundle bundle) {
assign(this, bundle);
this.key = key;
this.resource = resource;
this.size = 1;
this.resPath = resPath;
value = getValue();
}
}
static final class ResourceTable extends ICUResourceBundle {
protected ICUResourceBundle handleGet(String key, ICUResourceBundle requested) {
protected UResourceBundle handleGet(String key, UResourceBundle requested) {
return handleGet(key, null, requested);
}
protected ICUResourceBundle handleGet(String key, HashMap table, ICUResourceBundle requested) {
protected UResourceBundle handleGet(String key, HashMap table, UResourceBundle requested) {
if(size<=0){
return null;
}
@ -237,11 +178,11 @@ public class ICUResourceBundleImpl extends ICUResourceBundle {
}
currentOffset += getCharOffset(size + (~size & 1))
+ getIntOffset(foundOffset);
long resource = (UNSIGNED_INT_MASK) & ICUResourceBundleImpl.getInt(rawData, currentOffset);
long resource = (UNSIGNED_INT_MASK) & ICUResourceBundle.getInt(rawData, currentOffset);
String path = (isTopLevel == true) ? key : resPath + "/" + key;
return createBundleObject(key, resource, path, table, requested);
return createBundleObject(key, resource, path, table, requested, this);
}
protected ICUResourceBundle handleGet(int index, ICUResourceBundle requested) {
protected UResourceBundle handleGet(int index, UResourceBundle requested) {
return handleGet(index, null, requested);
}
public String getKey(int currentOffset, int index) {
@ -249,7 +190,7 @@ public class ICUResourceBundleImpl extends ICUResourceBundle {
int keyOffset = getChar(rawData,charOffset);
return RES_GET_KEY(rawData, keyOffset).toString();
}
protected ICUResourceBundle handleGet(int index, HashMap table, ICUResourceBundle requested) {
protected UResourceBundle handleGet(int index, HashMap table, UResourceBundle requested) {
if (index > size) {
throw new IndexOutOfBoundsException();
}
@ -260,54 +201,56 @@ public class ICUResourceBundleImpl extends ICUResourceBundle {
String itemKey = getKey(currentOffset, index);
currentOffset += getCharOffset(size + (~size & 1))
+ getIntOffset(index);
long resource = (UNSIGNED_INT_MASK) & ICUResourceBundleImpl.getInt(rawData,currentOffset);
long resource = (UNSIGNED_INT_MASK) & ICUResourceBundle.getInt(rawData,currentOffset);
String path = (isTopLevel == true)
? Integer.toString(index)
: resPath + "/" + index;
return createBundleObject(itemKey, resource, path, table, requested);
return createBundleObject(itemKey, resource, path, table, requested, this);
}
private int countItems() {
int offset = RES_GET_OFFSET(resource);
int value = getChar(rawData,offset);
return value;
}
private ResourceTable(String key, String resPath, long resource) {
this(key, resource, resPath, false);
ResourceTable(String key, String resPath, long resource, ICUResourceBundle bundle) {
this(key, resPath, resource, bundle, false);
}
private ResourceTable(String key, long resource, String resPath,
boolean isTopLevel) {
ResourceTable(ICUResourceBundleReader reader, String baseName, String localeID, ClassLoader loader) {
this.rawData = reader.getData();
this.rootResource = (UNSIGNED_INT_MASK) & reader.getRootResource();
this.noFallback = reader.getNoFallback();
this.baseName = baseName;
this.localeID = localeID;
this.ulocale = new ULocale(localeID);
this.loader = loader;
initialize(null, "", rootResource, null, isTopLevel);
}
void initialize(String key, String resPath, long resource,
ICUResourceBundle bundle, boolean isTopLevel){
if(bundle!=null){
assign(this, bundle);
}
this.key = key;
this.resource = resource;
this.isTopLevel = isTopLevel;
this.size = countItems();
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.setParent(parent);
ResourceTable(String key, String resPath, long resource,
ICUResourceBundle bundle, boolean isTopLevel) {
initialize(key, resPath, resource, bundle, isTopLevel);
}
}
private class ResourceTable32 extends ICUResourceBundle implements Resource {
static final class ResourceTable32 extends ICUResourceBundle{
protected ICUResourceBundle handleGet(String key, ICUResourceBundle requested) {
protected UResourceBundle handleGet(String key, UResourceBundle requested) {
if(size<=0){
return null;
}
return handleGet(key, null, requested);
}
protected ICUResourceBundle handleGet(String key, HashMap table, ICUResourceBundle requested) {
protected UResourceBundle handleGet(String key, HashMap table, UResourceBundle requested) {
int offset = RES_GET_OFFSET(resource);
// offset+0 contains number of entries
// offset+1 contains the keyOffset
@ -322,19 +265,19 @@ public class ICUResourceBundleImpl extends ICUResourceBundle {
key);
}
currentOffset += getIntOffset(size) + getIntOffset(foundOffset);
long resource = (UNSIGNED_INT_MASK) & ICUResourceBundleImpl.getInt(rawData,currentOffset);
long resource = (UNSIGNED_INT_MASK) & ICUResourceBundle.getInt(rawData,currentOffset);
String path = (isTopLevel == true) ? key : resPath + "/" + key;
return createBundleObject(key, resource, path, table, requested);
return createBundleObject(key, resource, path, table, requested, this);
}
protected ICUResourceBundle handleGet(int index, ICUResourceBundle requested) {
protected UResourceBundle handleGet(int index, UResourceBundle requested) {
return handleGet(index, null, requested);
}
public String getKey(int currentOffset, int index) {
int charOffset = currentOffset + getIntOffset(index);
int keyOffset = ICUResourceBundleImpl.getInt(rawData,charOffset);
int keyOffset = ICUResourceBundle.getInt(rawData,charOffset);
return RES_GET_KEY(rawData, keyOffset).toString();
}
protected ICUResourceBundle handleGet(int index, HashMap table, ICUResourceBundle requested) {
protected UResourceBundle handleGet(int index, HashMap table, UResourceBundle requested) {
if (index > size) {
throw new IndexOutOfBoundsException();
}
@ -345,380 +288,46 @@ public class ICUResourceBundleImpl extends ICUResourceBundle {
+ getIntOffset(index);
String itemKey = getKey(currentOffset, 0);
currentOffset += getIntOffset(size);
long resource = (UNSIGNED_INT_MASK) & ICUResourceBundleImpl.getInt(rawData,currentOffset);
long resource = (UNSIGNED_INT_MASK) & ICUResourceBundle.getInt(rawData,currentOffset);
String path = (isTopLevel == true)
? Integer.toString(index)
: resPath + "/" + index;
return createBundleObject(itemKey, resource, path, table, requested);
return createBundleObject(itemKey, resource, path, table, requested, this);
}
private int countItems() {
int offset = RES_GET_OFFSET(resource);
int value = ICUResourceBundleImpl.getInt(rawData, offset);
int value = ICUResourceBundle.getInt(rawData, offset);
return value;
}
private ResourceTable32(String key, long resource, String resPath,
boolean isTopLevel) {
this.resource = resource;
ResourceTable32(String key, String resPath, long resource, ICUResourceBundle bundle) {
this(key, resPath, resource, bundle, false);
}
ResourceTable32(ICUResourceBundleReader reader, String baseName, String localeID, ClassLoader loader) {
this.rawData = reader.getData();
this.rootResource = (UNSIGNED_INT_MASK) & reader.getRootResource();
this.noFallback = reader.getNoFallback();
this.baseName = baseName;
this.localeID = localeID;
this.ulocale = new ULocale(localeID);
this.loader = loader;
initialize(null, "", rootResource, null, isTopLevel);
}
void initialize(String key, String resPath, long resource,
ICUResourceBundle bundle, boolean isTopLevel){
if(bundle!=null){
assign(this, bundle);
}
this.key = key;
this.resource = resource;
this.isTopLevel = isTopLevel;
this.size = countItems();
this.resPath = resPath;
}
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.setParent(parent);
}
}
private class ResourceString extends ICUResourceBundle {
private String value;
public String getString() {
return value;
}
private ResourceString(String key, String resPath, long resource) {
value = getStringValue(resource);
this.key = key;
this.resource = resource;
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() {
return RES_GET_INT(resource);
}
public int getUInt() {
long ret = RES_GET_UINT(resource);
return (int) ret;
}
private ResourceInt(String key, String resPath, long resource) {
this.key = key;
this.resource = resource;
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() {
String[] strings = new String[size];
ICUResourceBundleIterator iter = getIterator();
int i = 0;
while (iter.hasNext()) {
strings[i++] = iter.next().getString();
}
return strings;
}
/**
* @internal ICU 3.0
*/
public String[] getStringArray() {
return handleGetStringArray();
}
protected ICUResourceBundle handleGet(String index, ICUResourceBundle requested) {
return handleGet(index, null, requested);
}
protected ICUResourceBundle handleGet(String index, HashMap table, ICUResourceBundle requested) {
int val = getIndex(index);
if (val > -1) {
return handleGet(val, table, requested);
}
throw new UResourceTypeMismatchException("Could not get the correct value for index: "+ index);
}
protected ICUResourceBundle handleGet(int index, ICUResourceBundle requested) {
return handleGet(index, null, requested);
}
protected ICUResourceBundle handleGet(int index, HashMap table, ICUResourceBundle requested) {
if (index > size) {
throw new IndexOutOfBoundsException();
}
int offset = RES_GET_OFFSET(resource);
int itemOffset = offset + getIntOffset(index + 1);
long itemResource = (UNSIGNED_INT_MASK) & ICUResourceBundleImpl.getInt(rawData,itemOffset);
String path = (isTopLevel == true) ? Integer.toString(index) : resPath + "/" + index;
return createBundleObject(null, itemResource, path, table, requested);
}
private int countItems() {
int offset = RES_GET_OFFSET(resource);
int value = ICUResourceBundleImpl.getInt(rawData,offset);
return value;
}
private ResourceArray(String key, String resPath, long resource) {
this.resource = resource;
this.key = key;
this.size = countItems();
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 static char makeChar(byte b1, byte b0) {
return (char)((b1 << 8) | (b0 & 0xff));
}
private static char getChar(byte[]data, int offset){
return makeChar(data[offset], data[offset+1]);
}
private static int makeInt(byte b3, byte b2, byte b1, byte b0) {
return (int)((((b3 & 0xff) << 24) |
((b2 & 0xff) << 16) |
((b1 & 0xff) << 8) |
((b0 & 0xff) << 0)));
}
private static int getInt(byte[] data, int offset){
if (ASSERT) Assert.assrt("offset < data.length", offset < data.length);
return makeInt(data[offset], data[offset+1],
data[offset+2], data[offset+3]);
}
private class ResourceBinary extends ICUResourceBundle {
private byte[] value;
public ByteBuffer getBinary() {
return ByteBuffer.wrap(value);
}
public byte [] getBinary(byte []ba) {
return value;
}
private byte[] getValue() {
int offset = RES_GET_OFFSET(resource);
int length = ICUResourceBundleImpl.getInt(rawData,offset);
int byteOffset = offset + getIntOffset(1);
byte[] dst = new byte[length];
if (ASSERT) Assert.assrt("byteOffset+length < rawData.length", byteOffset+length < rawData.length);
System.arraycopy(rawData, byteOffset, dst, 0, length);
return dst;
}
public ResourceBinary(String key, String resPath, long resource) {
this.resource = resource;
this.key = key;
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;
public int[] getIntVector() {
return value;
}
private int[] getValue() {
int offset = RES_GET_OFFSET(resource);
int length = ICUResourceBundleImpl.getInt(rawData,offset);
int intOffset = offset + getIntOffset(1);
int[] val = new int[length];
int byteLength = getIntOffset(length);
if (ASSERT) Assert.assrt("(intOffset+byteLength)<rawData.length", (intOffset+byteLength)<rawData.length);
for(int i=0; i<length;i++){
val[i]=ICUResourceBundleImpl.getInt(rawData, intOffset+getIntOffset(i));
}
return val;
}
public ResourceIntVector(String key, String resPath, long resource) {
this.key = key;
this.resource = resource;
this.size = 1;
this.resPath = resPath;
value = getValue();
ResourceTable32(String key, String resPath, long resource,
ICUResourceBundle bundle, boolean isTopLevel) {
initialize(key, resPath, resource, bundle, isTopLevel);
}
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) {
if (resource == 0) {
/*
* The data structure is documented as supporting resource==0 for empty strings.
* Return a fixed pointer in such a case.
* This was dropped in uresdata.c 1.17 as part of Jitterbug 1005 work
* on code coverage for ICU 2.0.
* Re-added for consistency with the design and with other code.
*/
return "";
}
int offset = RES_GET_OFFSET(resource);
int length = getInt(rawData,offset);
int stringOffset = offset + getIntOffset(1);
char[] dst = new char[length];
if (ASSERT) Assert.assrt("(stringOffset+getCharOffset(length)) < rawData.length", (stringOffset+getCharOffset(length)) < rawData.length);
for(int i=0; i<length; i++){
dst[i]=getChar(rawData, stringOffset+getCharOffset(i));
}
return new String(dst);
}
private static final char RES_PATH_SEP_CHAR = '/';
private static final String RES_PATH_SEP_STR = "/";
private static final String ICUDATA = "ICUDATA";
private static final char HYPHEN = '-';
private static final String LOCALE = "LOCALE";
private static final int getIndex(String s) {
if (s.length() >= 1) {
return Integer.valueOf(s).intValue();
}
return -1;
}
private ICUResourceBundle findResource(String key, long resource,
HashMap table,
ICUResourceBundle requested) {
ClassLoader loaderToUse = loader;
String locale = null, keyPath = null;
String bundleName;
String resPath = getStringValue(resource);
if (table == null) {
table = new HashMap();
}
if (table.get(resPath) != null) {
throw new IllegalArgumentException(
"Circular references in the resource bundles");
}
table.put(resPath, "");
if (resPath.indexOf(RES_PATH_SEP_CHAR) == 0) {
int i = resPath.indexOf(RES_PATH_SEP_CHAR, 1);
int j = resPath.indexOf(RES_PATH_SEP_CHAR, i + 1);
bundleName = resPath.substring(1, i);
locale = resPath.substring(i + 1);
if (j != -1) {
locale = resPath.substring(i + 1, j);
keyPath = resPath.substring(j + 1, resPath.length());
}
//there is a path included
if (bundleName.equals(ICUDATA)) {
bundleName = ICU_BASE_NAME;
loaderToUse = ICU_DATA_CLASS_LOADER;
}else if(bundleName.indexOf(ICUDATA)>-1){
int idx = bundleName.indexOf(HYPHEN);
if(idx>-1){
bundleName = ICU_BASE_NAME+RES_PATH_SEP_STR+bundleName.substring(idx+1,bundleName.length());
loaderToUse = ICU_DATA_CLASS_LOADER;
}
}
} else {
//no path start with locale
int i = resPath.indexOf(RES_PATH_SEP_CHAR);
keyPath = resPath.substring(i + 1);
if (i != -1) {
locale = resPath.substring(0, i);
} else {
locale = keyPath;
keyPath = null;//keyPath.substring(i, keyPath.length());
}
bundleName = baseName;
}
ICUResourceBundle bundle = null;
ICUResourceBundle sub = null;
if(bundleName.equals(LOCALE)){
bundleName = baseName;
bundle = requested;
keyPath = resPath.substring(LOCALE.length() + 2/* prepending and appending / */, resPath.length());
locale = requested.getLocaleID();
sub = ICUResourceBundle.findResourceWithFallback(keyPath, requested, null);
sub.resPath = "/" + sub.getLocaleID() + "/" + keyPath;
}else{
if (locale == null) {
// {dlf} must use requestor's class loader to get resources from same jar
bundle = (ICUResourceBundle) getBundleInstance(bundleName, "",
loaderToUse, false);
} else {
bundle = (ICUResourceBundle) getBundleInstance(bundleName, locale,
loaderToUse, false);
}
if (keyPath != null) {
StringTokenizer st = new StringTokenizer(keyPath, "/");
ICUResourceBundle current = bundle;
while (st.hasMoreTokens()) {
String subKey = st.nextToken();
sub = current.getImpl(subKey, table, requested);
if (sub == null) {
break;
}
current = sub;
}
} else {
// if the sub resource is not found
// try fetching the sub resource with
// the key of this alias resource
sub = bundle.get(key);
}
sub.resPath = resPath;
}
if (sub == null) {
throw new MissingResourceException(localeID, baseName, key);
}
return sub;
}
}

View file

@ -14,6 +14,7 @@ import com.ibm.icu.util.Calendar;
import com.ibm.icu.util.GregorianCalendar;
import com.ibm.icu.util.SimpleTimeZone;
import com.ibm.icu.util.TimeZone;
import com.ibm.icu.util.UResourceBundle;
/**
* A time zone based on the Olson database. Olson time zones change
@ -340,10 +341,10 @@ public class OlsonTimeZone extends TimeZone {
* to lookup the rule that `res' may refer to, if there is one.
* @param res the resource bundle of the zone to be constructed
*/
public OlsonTimeZone(ICUResourceBundle top, ICUResourceBundle res){
public OlsonTimeZone(UResourceBundle top, UResourceBundle res){
construct(top, res);
}
private void construct(ICUResourceBundle top, ICUResourceBundle res){
private void construct(UResourceBundle top, UResourceBundle res){
if ((top == null || res == null)) {
throw new IllegalArgumentException();
@ -368,7 +369,7 @@ public class OlsonTimeZone extends TimeZone {
}
// Transitions list may be empty
ICUResourceBundle r = res.get(0);
UResourceBundle r = res.get(0);
transitionTimes = r.getIntVector();
if ((transitionTimes.length<0 || transitionTimes.length>0x7FFF) ) {
@ -446,8 +447,8 @@ public class OlsonTimeZone extends TimeZone {
public OlsonTimeZone(String id){
ICUResourceBundle top = (ICUResourceBundle)ICUResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BASE_NAME, "zoneinfo", ICUResourceBundle.ICU_DATA_CLASS_LOADER);
ICUResourceBundle res = ZoneMeta.openOlsonResource(id);
UResourceBundle top = (UResourceBundle) UResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BASE_NAME, "zoneinfo", ICUResourceBundle.ICU_DATA_CLASS_LOADER);
UResourceBundle res = ZoneMeta.openOlsonResource(id);
construct(top, res);
if(finalZone!=null){
finalZone.setID(id);
@ -641,8 +642,8 @@ public class OlsonTimeZone extends TimeZone {
return julian - JULIAN_1970_CE; // JD => epoch day
}
private static ICUResourceBundle loadRule(ICUResourceBundle top, String ruleid) {
ICUResourceBundle r = top.get("Rules");
private static UResourceBundle loadRule(UResourceBundle top, String ruleid) {
UResourceBundle r = top.get("Rules");
r = r.get(ruleid);
return r;
}

View file

@ -1,6 +1,6 @@
/*
**********************************************************************
* Copyright (c) 2003-2006, International Business Machines
* Copyright (c) 2003-20067 International Business Machines
* Corporation and others. All Rights Reserved.
**********************************************************************
* Author: Alan Liu
@ -56,10 +56,10 @@ public final class ZoneMeta {
return EMPTY;
}
try{
ICUResourceBundle top = (ICUResourceBundle)ICUResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BASE_NAME, "zoneinfo", ICUResourceBundle.ICU_DATA_CLASS_LOADER);
ICUResourceBundle regions = top.get(kREGIONS);
ICUResourceBundle names = top.get(kNAMES); // dereference Zones section
ICUResourceBundle temp = regions.get(country);
UResourceBundle top = (ICUResourceBundle)ICUResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BASE_NAME, "zoneinfo", ICUResourceBundle.ICU_DATA_CLASS_LOADER);
UResourceBundle regions = top.get(kREGIONS);
UResourceBundle names = top.get(kNAMES); // dereference Zones section
UResourceBundle temp = regions.get(country);
int[] vector = temp.getIntVector();
if (ASSERT) Assert.assrt("vector.length>0", vector.length>0);
String[] ret = new String[vector.length];
@ -79,8 +79,8 @@ public final class ZoneMeta {
return EMPTY;
}
try{
ICUResourceBundle top = (ICUResourceBundle)ICUResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BASE_NAME, "zoneinfo", ICUResourceBundle.ICU_DATA_CLASS_LOADER);
ICUResourceBundle names = top.get(kNAMES); // dereference Zones section
UResourceBundle top = (ICUResourceBundle)ICUResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BASE_NAME, "zoneinfo", ICUResourceBundle.ICU_DATA_CLASS_LOADER);
UResourceBundle names = top.get(kNAMES); // dereference Zones section
return names.getStringArray();
}catch(MissingResourceException ex){
//throw away the exception
@ -110,8 +110,8 @@ public final class ZoneMeta {
}
private static String getID(int i) {
try{
ICUResourceBundle top = (ICUResourceBundle)ICUResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BASE_NAME, "zoneinfo", ICUResourceBundle.ICU_DATA_CLASS_LOADER);
ICUResourceBundle names = top.get(kNAMES); // dereference Zones section
UResourceBundle top = (ICUResourceBundle)ICUResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BASE_NAME, "zoneinfo", ICUResourceBundle.ICU_DATA_CLASS_LOADER);
UResourceBundle names = top.get(kNAMES); // dereference Zones section
return names.getString(i);
}catch(MissingResourceException ex){
//throw away the exception
@ -133,10 +133,10 @@ public final class ZoneMeta {
*/
public static synchronized int countEquivalentIDs(String id) {
ICUResourceBundle res = openOlsonResource(id);
UResourceBundle res = openOlsonResource(id);
int size = res.getSize();
if (size == 4 || size == 6) {
ICUResourceBundle r=res.get(size-1);
UResourceBundle r=res.get(size-1);
//result = ures_getSize(&r); // doesn't work
int[] v = r.getIntVector();
return v.length;
@ -164,19 +164,19 @@ public final class ZoneMeta {
*/
public static synchronized String getEquivalentID(String id, int index) {
String result="";
ICUResourceBundle res = openOlsonResource(id);
UResourceBundle res = openOlsonResource(id);
int zone = -1;
int size = res.getSize();
if (size == 4 || size == 6) {
ICUResourceBundle r = res.get(size-1);
UResourceBundle r = res.get(size-1);
int[] v = r.getIntVector();
if (index >= 0 && index < v.length && getOlsonMeta()) {
zone = v[index];
}
}
if (zone >= 0) {
ICUResourceBundle top = (ICUResourceBundle)ICUResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BASE_NAME, "zoneinfo", ICUResourceBundle.ICU_DATA_CLASS_LOADER);
ICUResourceBundle ares = top.get(kNAMES); // dereference Zones section
UResourceBundle top = UResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BASE_NAME, "zoneinfo", ICUResourceBundle.ICU_DATA_CLASS_LOADER);
UResourceBundle ares = top.get(kNAMES); // dereference Zones section
result = ares.getString(zone);
}
@ -379,19 +379,19 @@ public final class ZoneMeta {
* @param id zone id
* @return top-level resource bundle
*/
public static ICUResourceBundle openOlsonResource(String id)
public static UResourceBundle openOlsonResource(String id)
{
if(!getOlsonMeta()){
return null;
}
ICUResourceBundle top = (ICUResourceBundle)ICUResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BASE_NAME, "zoneinfo", ICUResourceBundle.ICU_DATA_CLASS_LOADER);
ICUResourceBundle res = getZoneByName(top, id);
ICUResourceBundle top = (ICUResourceBundle)UResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BASE_NAME, "zoneinfo", ICUResourceBundle.ICU_DATA_CLASS_LOADER);
UResourceBundle res = getZoneByName(top, id);
// Dereference if this is an alias. Docs say result should be 1
// but it is 0 in 2.8 (?).
if (res.getSize() <= 1 && getOlsonMeta(top)) {
int deref = res.getInt() + 0;
ICUResourceBundle ares = top.get(kZONES); // dereference Zones section
res = ares.get(deref);
UResourceBundle ares = top.get(kZONES); // dereference Zones section
res = (ICUResourceBundle) ares.get(deref);
}
return res;
}
@ -401,16 +401,16 @@ public final class ZoneMeta {
* @param id Time zone ID
* @return the zone's bundle if found, or undefined if error. Reuses oldbundle.
*/
private static ICUResourceBundle getZoneByName(ICUResourceBundle top, String id) {
private static UResourceBundle getZoneByName(UResourceBundle top, String id) {
// load the Rules object
ICUResourceBundle tmp = top.get(kNAMES);
UResourceBundle tmp = top.get(kNAMES);
// search for the string
int idx = findInStringArray(tmp, id);
if((idx == -1)) {
// not found
throw new MissingResourceException(kNAMES, tmp.resPath, id);
throw new MissingResourceException(kNAMES, ((ICUResourceBundle)tmp).getResPath(), id);
//ures_close(oldbundle);
//oldbundle = NULL;
} else {
@ -419,7 +419,7 @@ public final class ZoneMeta {
}
return tmp;
}
private static int findInStringArray(ICUResourceBundle array, String id){
private static int findInStringArray(UResourceBundle array, String id){
int start = 0;
int limit = array.getSize();
int mid;
@ -476,7 +476,7 @@ public final class ZoneMeta {
*/
private static boolean getOlsonMeta(ICUResourceBundle top) {
if (OLSON_ZONE_START < 0) {
ICUResourceBundle res = top.get(kZONES);
UResourceBundle res = top.get(kZONES);
OLSON_ZONE_COUNT = res.getSize();
OLSON_ZONE_START = 0;
}
@ -502,8 +502,8 @@ public final class ZoneMeta {
TimeZone z = (TimeZone)zoneCache.get(id);
if (z == null) {
try{
ICUResourceBundle top = (ICUResourceBundle)ICUResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BASE_NAME, "zoneinfo", ICUResourceBundle.ICU_DATA_CLASS_LOADER);
ICUResourceBundle res = openOlsonResource(id);
UResourceBundle top = UResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BASE_NAME, "zoneinfo", ICUResourceBundle.ICU_DATA_CLASS_LOADER);
UResourceBundle res = openOlsonResource(id);
z = new OlsonTimeZone(top, res);
z.setID(id);
zoneCache.put(id, z);

View file

@ -1,6 +1,6 @@
/**
*******************************************************************************
* Copyright (C) 2001-2006, International Business Machines Corporation and *
* Copyright (C) 2001-20067 International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*/
@ -664,7 +664,7 @@ public final class UScript {
if(rb.getLoadingStatus()==ICUResourceBundle.FROM_DEFAULT && ! locale.equals(ULocale.getDefault())){
return null;
}
ICUResourceBundle sub = rb.get(kLocaleScript);
UResourceBundle sub = rb.get(kLocaleScript);
int[] result = new int[sub.getSize()];
int w = 0;

View file

@ -1,6 +1,6 @@
/*
*******************************************************************************
* Copyright (C) 1996-2006, International Business Machines Corporation and *
* Copyright (C) 1996-2007, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*/
@ -1299,7 +1299,7 @@ public class DateFormatSymbols implements Serializable, Cloneable {
ICUResourceBundle bundle = (ICUResourceBundle)UResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BASE_NAME, tempLocale);
ICUResourceBundle zoneStringsBundle = bundle.getWithFallback("zoneStrings");
for(int i = 0; i < zoneStringsBundle.getSize(); i++){
ICUResourceBundle zoneTable = zoneStringsBundle.get(i);
ICUResourceBundle zoneTable = (ICUResourceBundle)zoneStringsBundle.get(i);
String key = Utility.replaceAll(zoneTable.getKey(), ":", "/");
// hack for the root zone strings
if(key.length() == 0|| zoneTable.getType() != ICUResourceBundle.TABLE){

View file

@ -1,6 +1,6 @@
/*
*******************************************************************************
* Copyright (C) 1996-2006, International Business Machines Corporation and *
* Copyright (C) 1996-2007, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*/
@ -658,7 +658,7 @@ final public class DecimalFormatSymbols implements Cloneable, Serializable {
try{
currency = currency.getWithFallback(currencyCode);
if(currency.getSize()>2) {
currency = currency.get(2);
currency = (ICUResourceBundle)currency.get(2);
currencyPattern = currency.getString(0);
monetarySeparator = currency.getString(1).charAt(0);
monetaryGroupingSeparator = currency.getString(2).charAt(0);

View file

@ -1,7 +1,7 @@
//##header
/*
*******************************************************************************
* Copyright (C) 1996-2006, International Business Machines Corporation and *
* Copyright (C) 1996-2007, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*/
@ -747,7 +747,7 @@ public class RuleBasedNumberFormat extends NumberFormat {
try {
description = bundle.getString(rulenames[format-1]);
ICUResourceBundle locb = bundle.get(locnames[format-1]);
UResourceBundle locb = bundle.get(locnames[format-1]);
localizations = new String[locb.getSize()][];
for (int i = 0; i < localizations.length; ++i) {
localizations[i] = locb.get(i).getStringArray();

View file

@ -1826,8 +1826,8 @@ public abstract class Transliterator {
*
* The extra blank field on "alias" lines is to make the array square.
*/
ICUResourceBundle bundle, transIDs, colBund;
bundle = (ICUResourceBundle)UResourceBundle.getBundleInstance(ICUResourceBundle.ICU_TRANSLIT_BASE_NAME, INDEX);
UResourceBundle bundle, transIDs, colBund;
bundle = UResourceBundle.getBundleInstance(ICUResourceBundle.ICU_TRANSLIT_BASE_NAME, INDEX);
transIDs = bundle.get(RB_RULE_BASED_IDS);
int row, maxRows;
@ -1835,7 +1835,7 @@ public abstract class Transliterator {
for (row = 0; row < maxRows; row++) {
colBund = transIDs.get(row);
String ID = colBund.getKey();
ICUResourceBundle res = colBund.get(0);
UResourceBundle res = colBund.get(0);
String type = res.getKey();
if (type.equals("file") || type.equals("internal")) {
// Rest of line is <resource>:<encoding>:<direction>

View file

@ -1,12 +1,11 @@
/*
* Copyright (C) 1996-2006, International Business Machines
* Copyright (C) 1996-2007, International Business Machines
* Corporation and others. All Rights Reserved.
*/
package com.ibm.icu.util;
import com.ibm.icu.impl.ICULocaleService;
import com.ibm.icu.impl.ICULocaleService.LocaleKeyFactory;
import com.ibm.icu.impl.ICUResourceBundle;
import com.ibm.icu.impl.ICUService.Factory;
import com.ibm.icu.impl.CalendarData;

View file

@ -1,6 +1,6 @@
/**
*******************************************************************************
* Copyright (C) 2001-2006, International Business Machines Corporation and *
* Copyright (C) 2001-2007, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*/
@ -135,7 +135,7 @@ public class Currency extends MeasureUnit implements Serializable {
if(bundle==null){
//throw new MissingResourceException()
}
ICUResourceBundle cm = bundle.get("CurrencyMap");
UResourceBundle cm = bundle.get("CurrencyMap");
// Do a linear search
String curriso = null;
@ -383,8 +383,8 @@ public class Currency extends MeasureUnit implements Serializable {
String s = null;
try {
ICUResourceBundle rb = (ICUResourceBundle)UResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BASE_NAME,locale);
ICUResourceBundle currencies = rb.get("Currencies");
UResourceBundle rb = UResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BASE_NAME,locale);
ICUResourceBundle currencies = (ICUResourceBundle)rb.get("Currencies");
// Fetch resource with multi-level resource inheritance fallback
s = currencies.getWithFallback(isoCode).getString(nameStyle);
@ -474,15 +474,15 @@ public class Currency extends MeasureUnit implements Serializable {
// Multi-level resource inheritance fallback loop
while (locale != null) {
ICUResourceBundle rb = (ICUResourceBundle)UResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BASE_NAME,locale);
UResourceBundle rb = 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");
UResourceBundle currencies = rb.get("Currencies");
// Do a linear search
for (int i=0; i<currencies.getSize(); ++i) {
//String name = ((String[]) currencies[i][1])[0];
ICUResourceBundle item = currencies.get(i);
UResourceBundle item = currencies.get(i);
String name = item.getString(0);
if (name.length() < 1) {
// Ignore zero-length names -- later, change this
@ -622,8 +622,8 @@ 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)ICUResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BASE_NAME,"CurrencyData", ICUResourceBundle.ICU_DATA_CLASS_LOADER);
ICUResourceBundle currencyMeta = root.get("CurrencyMeta");
UResourceBundle root = ICUResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BASE_NAME,"CurrencyData", ICUResourceBundle.ICU_DATA_CLASS_LOADER);
UResourceBundle currencyMeta = root.get("CurrencyMeta");
//Integer[] i = null;
//int defaultPos = -1;

View file

@ -1,6 +1,6 @@
/*
*******************************************************************************
* Copyright (C) 2004-2006, International Business Machines Corporation and *
* Copyright (C) 2004-2007, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*/
@ -127,7 +127,7 @@ public final class LocaleData {
public UnicodeSet getExemplarSet(int options, int extype) {
String [] exemplarSetTypes = { "ExemplarCharacters", "AuxExemplarCharacters" };
try{
ICUResourceBundle stringBundle = bundle.get(exemplarSetTypes[extype]);
ICUResourceBundle stringBundle = (ICUResourceBundle) bundle.get(exemplarSetTypes[extype]);
if ( noSubstitute && (stringBundle.getLoadingStatus() == ICUResourceBundle.FROM_ROOT) )
return null;
@ -211,7 +211,7 @@ public final class LocaleData {
"alternateQuotationStart",
"alternateQuotationEnd" };
ICUResourceBundle stringBundle = bundle.get("delimiters").get(delimiterTypes[type]);
ICUResourceBundle stringBundle = (ICUResourceBundle) bundle.get("delimiters").get(delimiterTypes[type]);
if ( noSubstitute && (stringBundle.getLoadingStatus() == ICUResourceBundle.FROM_ROOT) )
return null;
@ -255,8 +255,8 @@ public final class LocaleData {
* @stable ICU 3.0
*/
public static final MeasurementSystem getMeasurementSystem(ULocale locale){
ICUResourceBundle bundle = (ICUResourceBundle)UResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BASE_NAME, locale);
ICUResourceBundle sysBundle = bundle.get(MEASUREMENT_SYSTEM);
UResourceBundle bundle = (ICUResourceBundle)UResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BASE_NAME, locale);
UResourceBundle sysBundle = bundle.get(MEASUREMENT_SYSTEM);
int system = sysBundle.getInt();
if(MeasurementSystem.US.equals(system)){
@ -309,8 +309,8 @@ public final class LocaleData {
* @stable ICU 3.0
*/
public static final PaperSize getPaperSize(ULocale locale){
ICUResourceBundle bundle = (ICUResourceBundle)UResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BASE_NAME, locale);
ICUResourceBundle obj = bundle.get(PAPER_SIZE);
UResourceBundle bundle = (ICUResourceBundle)UResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BASE_NAME, locale);
UResourceBundle obj = bundle.get(PAPER_SIZE);
int[] size = obj.getIntVector();
return new PaperSize(size[0], size[1]);
}

View file

@ -1,6 +1,6 @@
/*
*******************************************************************************
* Copyright (C) 2004-2006, International Business Machines Corporation and *
* Copyright (C) 2004-2007, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*/
@ -18,7 +18,6 @@ import java.util.ResourceBundle;
import java.util.Vector;
import com.ibm.icu.impl.ICUResourceBundle;
import com.ibm.icu.impl.ICUResourceBundleImpl;
import com.ibm.icu.impl.ICUResourceBundleReader;
import com.ibm.icu.impl.ResourceBundleWrapper;
import com.ibm.icu.util.ULocale;
@ -245,6 +244,7 @@ public abstract class UResourceBundle extends ResourceBundle{
* @stable ICU 3.0
*/
protected abstract String getBaseName();
/**
* Gets the parent bundle
* @return The parent bundle
@ -507,6 +507,410 @@ public abstract class UResourceBundle extends ResourceBundle{
}
}
/**
* Returns a binary data from a binary resource.
*
* @return a pointer to a chuck of unsigned bytes which live in a memory mapped/DLL file.
* @see #getIntVector
* @see #getInt
* @throws MissingResourceException
* @throws UResourceTypeMismatchException
* @draft ICU 3.8
*/
public ByteBuffer getBinary() {
throw new UResourceTypeMismatchException("");
}
/**
* Returns a string from a string resource type
*
* @return a string
* @see #getBinary()
* @see #getIntVector
* @see #getInt
* @throws MissingResourceException
* @throws UResourceTypeMismatchException
* @draft ICU 3.8
*/
public String getString() {
throw new UResourceTypeMismatchException("");
}
/**
* Returns a string array from a array resource type
*
* @return a string
* @see #getString()
* @see #getIntVector
* @see #
* @throws MissingResourceException
* @throws UResourceTypeMismatchException
* @draft ICU 3.8
*/
public String[] getStringArray() {
throw new UResourceTypeMismatchException("");
}
/**
* Returns a binary data from a binary resource.
*
* @param ba The byte array to write the bytes to. A null variable is OK.
* @return an array bytes containing the binary data from the resource.
* @see #getIntVector
* @see #getInt
* @throws MissingResourceException
* @throws UResourceTypeMismatchException
* @draft ICU 3.8
*/
public byte[] getBinary(byte[] ba) {
throw new UResourceTypeMismatchException("");
}
/**
* Returns a 32 bit integer array from a resource.
*
* @return a pointer to a chunk of unsigned bytes which live in a memory mapped/DLL file.
* @see #getBinary()
* @see #getInt
* @throws MissingResourceException
* @throws UResourceTypeMismatchException
* @draft ICU 3.8
*/
public int[] getIntVector() {
throw new UResourceTypeMismatchException("");
}
/**
* Returns a signed integer from a resource.
*
* @return an integer value
* @see #getIntVector
* @see #getBinary()
* @throws MissingResourceException
* @throws UResourceTypeMismatchException
* @draft ICU 3.8
*/
public int getInt() {
throw new UResourceTypeMismatchException("");
}
/**
* Returns a unsigned integer from a resource.
* This integer is originally 28 bit and the sign gets propagated.
*
* @return an integer value
* @see #getIntVector
* @see #getBinary()
* @throws MissingResourceException
* @throws UResourceTypeMismatchException
* @draft ICU 3.8
*/
public int getUInt() {
throw new UResourceTypeMismatchException("");
}
/**
* Returns a resource in a given resource that has a given key.
*
* @param key a key associated with the wanted resource
* @return a resource bundle object representing rhe resource
* @throws MissingResourceException
* @draft ICU 3.8
*/
public UResourceBundle get(String key) {
UResourceBundle obj = handleGet(key, null, this);
UResourceBundle res = this;
if (obj == null) {
while((res=res.getParent())!=null && obj==null){
//call the get method to recursively fetch the resource
obj = res.handleGet(key, null, this);
}
if (obj == null) {
String fullName = ICUResourceBundleReader.getFullName(
getBaseName(), getLocaleID());
throw new MissingResourceException(
"Can't find resource for bundle " + fullName + ", key "
+ key, this.getClass().getName(), key);
}
}
ICUResourceBundle.setLoadingStatus(obj, getLocaleID());
return obj;
}
/**
* Returns the string in a given resource at the specified index.
*
* @param index an index to the wanted string.
* @return a string which lives in the resource.
* @throws IndexOutOfBoundsException
* @throws UResourceTypeMismatchException
* @draft ICU 3.8
*/
public String getString(int index) {
ICUResourceBundle temp = (ICUResourceBundle)get(index);
if (temp.getType() == STRING) {
return temp.getString();
}
throw new UResourceTypeMismatchException("");
}
/**
* Returns the resource in a given resource at the specified index.
*
* @param index an index to the wanted resource.
* @return the sub resource UResourceBundle object
* @throws IndexOutOfBoundsException
* @draft ICU 3.8
*/
public UResourceBundle get(int index) {
UResourceBundle obj = handleGet(index, null, this);
if (obj == null) {
obj = (ICUResourceBundle) getParent();
if (obj != null) {
obj = obj.get(index);
}
if (obj == null)
throw new MissingResourceException(
"Can't find resource for bundle "
+ this.getClass().getName() + ", key "
+ getKey(), this.getClass().getName(), getKey());
}
ICUResourceBundle.setLoadingStatus(obj, getLocaleID());
return obj;
}
/**
* Returns the keys in this bundle as an enumeration
* @return an enumeration containing key strings
* @draft ICU 3.8
*/
public Enumeration getKeys() {
initKeysVector();
return keys.elements();
}
private Vector keys = null;
private synchronized void initKeysVector(){
if(keys!=null){
return;
}
//ICUResourceBundle current = this;
keys = new Vector();
Enumeration e = this.handleGetKeys();
while(e.hasMoreElements()){
String elem = (String)e.nextElement();
if(!keys.contains(elem)){
keys.add(elem);
}
}
}
/**
* Returns the size of a resource. Size for scalar types is always 1,
* and for vector/table types is the number of child resources.
* <br><b><font color='red'>Warning: </font></b> Integer array is treated as a scalar type. There are no
* APIs to access individual members of an integer array. It
* is always returned as a whole.
* @return number of resources in a given resource.
* @draft ICU 3.8
*/
public int getSize() {
return size;
}
/**
* Returns the type of a resource.
* Available types are {@link #INT INT}, {@link #ARRAY ARRAY},
* {@link #BINARY BINARY}, {@link #INT_VECTOR INT_VECTOR},
* {@link #STRING STRING}, {@link #TABLE TABLE}.
*
* @return type of the given resource.
* @draft ICU 3.8
*/
public int getType() {
int type = ICUResourceBundle.RES_GET_TYPE(resource);
if(type==TABLE32){
return TABLE; //Mask the table32's real type
}
return type;
}
/**
* Return the version number associated with this UResourceBundle as an
* VersionInfo object.
* @return VersionInfo object containing the version of the bundle
* @draft ICU 3.8
*/
public VersionInfo getVersion() {
return null;
}
/**
* Returns the iterator which iterates over this
* resource bundle
* @draft ICU 3.8
*/
public UResourceBundleIterator getIterator() {
return new UResourceBundleIterator(this);
}
/**
* Returns the key associated with a given resource. Not all the resources have a key - only
* those that are members of a table.
* @return a key associated to this resource, or NULL if it doesn't have a key
* @draft ICU 3.8
*/
public String getKey() {
return key;
}
/**
* Resource type constant for "no resource".
* @draft ICU 3.8
*/
public static final int NONE = -1;
/**
* Resource type constant for strings.
* @draft ICU 3.8
*/
public static final int STRING = 0;
/**
* Resource type constant for binary data.
* @draft ICU 3.8
*/
public static final int BINARY = 1;
/**
* Resource type constant for tables of key-value pairs.
* @draft ICU 3.8
*/
public static final int TABLE = 2;
/**
* Resource type constant for aliases;
* internally stores a string which identifies the actual resource
* storing the data (can be in a different resource bundle).
* Resolved internally before delivering the actual resource through the API.
* @draft ICU 3.8
* @internal
*/
protected static final int ALIAS = 3;
/**
* Internal use only.
* Alternative resource type constant for tables of key-value pairs.
* Never returned by getType().
* @internal
* @draft ICU 3.8
*/
protected static final int TABLE32 = 4;
/**
* Resource type constant for a single 28-bit integer, interpreted as
* signed or unsigned by the getInt() function.
* @see #getInt
* @draft ICU 3.8
*/
public static final int INT = 7;
/**
* Resource type constant for arrays of resources.
* @draft ICU 3.8
*/
public static final int ARRAY = 8;
/**
* Resource type constant for vectors of 32-bit integers.
* @see #getIntVector
* @draft ICU 3.8
*/
public static final int INT_VECTOR = 14;
//====== protected members ==============
protected String key;
protected int size = 1;
protected long resource = RES_BOGUS;
protected boolean isTopLevel = false;
protected static final long RES_BOGUS = 0xffffffff;
protected UResourceBundle handleGet(String key, HashMap table, UResourceBundle requested) {
return null;
}
protected UResourceBundle handleGet(int index, HashMap table, UResourceBundle requested) {
return null;
}
protected UResourceBundle handleGet(int index, UResourceBundle requested) {
return null;
}
protected UResourceBundle handleGet(String key, UResourceBundle requested) {
return null;
}
protected String[] handleGetStringArray() {
return null;
}
protected Enumeration handleGetKeys(){
Vector keys = new Vector();
UResourceBundle item = null;
for (int i = 0; i < size; i++) {
item = get(i);
keys.add(item.getKey());
}
return keys.elements();
}
// this method is declared in ResourceBundle class
// so cannot change the signature
protected Object handleGetObject(String key) {
return handleGetObjectImpl(key, this);
}
// To facilitate XPath style aliases we need a way to pass the reference
// to requested locale. The only way I could figure out is to implement
// the look up logic here. This has a disadvantage that if the client
// loads an ICUResourceBundle, calls ResourceBundle.getObject method
// with a key that does not exist in the bundle then the lookup is
// done twice before throwing a MissingResourceExpection.
private Object handleGetObjectImpl(String key, UResourceBundle requested) {
Object obj = resolveObject(key, requested);
if (obj == null) {
UResourceBundle parent = getParent();
if (parent != null) {
obj = parent.handleGetObjectImpl(key, requested);
}
if (obj == null)
throw new MissingResourceException(
"Can't find resource for bundle "
+ this.getClass().getName() + ", key " + key,
this.getClass().getName(), key);
}
return obj;
}
// Routine for figuring out the type of object to be returned
// string or string array
private Object resolveObject(String key, UResourceBundle requested) {
if (getType() == STRING) {
return getString();
}
UResourceBundle obj = handleGet(key, requested);
if (obj != null) {
if (obj.getType() == STRING) {
return obj.getString();
}
try {
if (obj.getType() == ARRAY) {
return obj.handleGetStringArray();
}
} catch (UResourceTypeMismatchException ex) {
return obj;
}
}
return obj;
}
/**
* @internal
* @deprecated This API is ICU internal only.

View file

@ -1,98 +1,97 @@
/*
******************************************************************************
* Copyright (C) 2004, International Business Machines Corporation and *
* others. All Rights Reserved. *
******************************************************************************
*/
package com.ibm.icu.impl;
import java.util.NoSuchElementException;
import com.ibm.icu.util.UResourceTypeMismatchException;
/**
* <p>Class for enabling iteration over UResourceBundle objects.
* Example of use:<br>
* <pre>
* ICUResourceBundleIterator iterator = resB.getIterator();
* ICUResourceBundle temp;
* while (iterator.hasNext()) {
* temp = iterartor.next();
* int type = temp.getType();
* switch(type){
* case UResourceBundle.STRING:
* str = temp.getString();
* break;
* case UResourceBundle.INT:
* integer = temp.getInt();
* break;
* .....
* }
* // do something interesting with data collected
* }
* </pre>
* @author ram
* @draft ICU 3.0
*/
public class ICUResourceBundleIterator{
private ICUResourceBundle bundle;
private int index = 0;
private int size = 0;
/**
* Construct a resource bundle iterator for the
* given resource bundle
*
* @param bndl The resource bundle to iterate over
* @draft ICU 3.0
*/
public ICUResourceBundleIterator(ICUResourceBundle bndl){
bundle = bndl;
size = bundle.getSize();
}
/**
* Returns the next element of this iterator if this iterator object has at least one more element to provide
* @return the UResourceBundle object
* @throws NoSuchElementException
* @draft ICU 3.0
*/
public ICUResourceBundle next()throws NoSuchElementException{
if(index<size){
return bundle.get(index++);
}
throw new NoSuchElementException();
}
/**
* Returns the next String of this iterator if this iterator object has at least one more element to provide
* @return the UResourceBundle object
* @throws NoSuchElementException
* @throws UResourceTypeMismatchException
* @draft ICU 3.0
*/
public String nextString()throws NoSuchElementException, UResourceTypeMismatchException{
if(index<size){
return bundle.getString(index++);
}
throw new NoSuchElementException();
}
/**
* Resets the internal context of a resource so that iteration starts from the first element.
* @draft ICU 3.0
*/
public void reset(){
//reset the internal context
index = 0;
}
/**
* Checks whether the given resource has another element to iterate over.
* @return TRUE if there are more elements, FALSE if there is no more elements
* @draft ICU 3.0
*/
public boolean hasNext(){
return index < size;
}
/*
******************************************************************************
* Copyright (C) 2004, International Business Machines Corporation and *
* others. All Rights Reserved. *
******************************************************************************
*/
package com.ibm.icu.util;
import java.util.NoSuchElementException;
import com.ibm.icu.impl.ICUResourceBundle;
/**
* <p>Class for enabling iteration over UResourceBundle objects.
* Example of use:<br>
* <pre>
* ICUResourceBundleIterator iterator = resB.getIterator();
* ICUResourceBundle temp;
* while (iterator.hasNext()) {
* temp = iterartor.next();
* int type = temp.getType();
* switch(type){
* case UResourceBundle.STRING:
* str = temp.getString();
* break;
* case UResourceBundle.INT:
* integer = temp.getInt();
* break;
* .....
* }
* // do something interesting with data collected
* }
* </pre>
* @author ram
* @draft ICU 3.0
*/
public class UResourceBundleIterator{
private UResourceBundle bundle;
private int index = 0;
private int size = 0;
/**
* Construct a resource bundle iterator for the
* given resource bundle
*
* @param bndl The resource bundle to iterate over
* @draft ICU 3.0
*/
public UResourceBundleIterator(UResourceBundle bndl){
bundle = bndl;
size = bundle.getSize();
}
/**
* Returns the next element of this iterator if this iterator object has at least one more element to provide
* @return the UResourceBundle object
* @throws NoSuchElementException
* @draft ICU 3.0
*/
public UResourceBundle next()throws NoSuchElementException{
if(index<size){
return bundle.get(index++);
}
throw new NoSuchElementException();
}
/**
* Returns the next String of this iterator if this iterator object has at least one more element to provide
* @return the UResourceBundle object
* @throws NoSuchElementException
* @throws UResourceTypeMismatchException
* @draft ICU 3.0
*/
public String nextString()throws NoSuchElementException, UResourceTypeMismatchException{
if(index<size){
return bundle.getString(index++);
}
throw new NoSuchElementException();
}
/**
* Resets the internal context of a resource so that iteration starts from the first element.
* @draft ICU 3.0
*/
public void reset(){
//reset the internal context
index = 0;
}
/**
* Checks whether the given resource has another element to iterate over.
* @return TRUE if there are more elements, FALSE if there is no more elements
* @draft ICU 3.0
*/
public boolean hasNext(){
return index < size;
}
}