diff --git a/icu4j/main/classes/core/src/com/ibm/icu/impl/ICUDataVersion.java b/icu4j/main/classes/core/src/com/ibm/icu/impl/ICUDataVersion.java new file mode 100644 index 00000000000..e36cca52faf --- /dev/null +++ b/icu4j/main/classes/core/src/com/ibm/icu/impl/ICUDataVersion.java @@ -0,0 +1,97 @@ +/* +******************************************************************************* +* Copyright (C) 2009, International Business Machines +* Corporation and others. All Rights Reserved. +******************************************************************************* +*/ + +package com.ibm.icu.impl; + +import com.ibm.icu.util.VersionInfo; +import com.ibm.icu.util.UResourceBundle; + +import java.util.MissingResourceException; + +public final class ICUDataVersion { + private static final String U_ICU_VERSION_BUNDLE = "icuver"; + private static final String U_ICU_STD_BUNDLE = "icustd"; + + private static final String U_ICU_DATA_KEY = "DataVersion"; + + /** + * This function loads up icuver and compares the data version to the wired-in ICU_DATA_VERSION. + * If icuver shows something less than ICU_DATA_VERSION it returns TRUE, else FALSE. The version + * found will be returned in the first fillin parameter (if non-null), and *isModified will be set + * to TRUE if "icustd" is NOT found. Thus, if the data has been repackaged or modified, "icustd" + * (standard ICU) will be missing, and the function will alert the caller that the data is not standard. + * + * @param dataVersionFillin icuver data version information to be filled in if not-null + * @param status stores the error code from the calls to resource bundle + * + * @return TRUE if ICU_DATA_VERSION is newer than icuver, else FALSE + * + * @draft ICU 4.4 + */ + public static boolean isDataOlder(VersionInfo dataVersionFillin) { + boolean result = true; + + VersionInfo dataVersion = getDataVersion(); + + if (dataVersion!= null) { + if (dataVersion.compareTo(VersionInfo.ICU_DATA_VERSION) != -1) { + result = false; + } + + if (dataVersionFillin != null) { + dataVersionFillin = VersionInfo.getInstance(dataVersion.toString()); + } + } + + return result; + } + + /** + * This function tests whether "icustd" is available in the data. If the data has been repackaged or modified, "icustd" + * (standard ICU) will be missing, and the function will alert the caller that the data is not standard. + * + * @return TRUE if data has been modified, else FALSE + * + * @draft ICU 4.4 + */ + public static boolean isDataModified() { + if (hasICUSTDBundle()) { + return false; + } + return true; + } + + /** + * This function retrieves the data version from icuver and returns a VersionInfo object with that version information. + * + * @return Current icu data version + * + * @draft ICU 4.4 + */ + public static VersionInfo getDataVersion() { + UResourceBundle icudatares = null; + try { + icudatares = UResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BASE_NAME, ICUDataVersion.U_ICU_VERSION_BUNDLE, ICUResourceBundle.ICU_DATA_CLASS_LOADER); + icudatares = icudatares.get(ICUDataVersion.U_ICU_DATA_KEY); + } catch (MissingResourceException ex) { + return null; + } + + return VersionInfo.getInstance(icudatares.getString()); + } + + private static boolean hasICUSTDBundle() { + try { + UResourceBundle.getBundleInstance(ICUDataVersion.U_ICU_STD_BUNDLE); + } catch (MissingResourceException ex) { + return false; + } + + return true; + } + +} diff --git a/icu4j/main/classes/core/src/com/ibm/icu/impl/ICUResourceBundle.java b/icu4j/main/classes/core/src/com/ibm/icu/impl/ICUResourceBundle.java index 5824661ea08..a12c07d6ed5 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/impl/ICUResourceBundle.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/impl/ICUResourceBundle.java @@ -42,7 +42,7 @@ public class ICUResourceBundle extends UResourceBundle { /** * The data path to be used with getBundleInstance API */ - public static final String ICU_BUNDLE = "data/icudt" + VersionInfo.ICU_DATA_VERSION; + public static final String ICU_BUNDLE = "data/icudt" + VersionInfo.ICU_DATA_VERSION_PATH; /** * The base name of ICU data to be used with getBundleInstance API diff --git a/icu4j/main/classes/core/src/com/ibm/icu/util/TimeZone.java b/icu4j/main/classes/core/src/com/ibm/icu/util/TimeZone.java index 17dde5c471f..a9d47c210fe 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/util/TimeZone.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/util/TimeZone.java @@ -861,7 +861,7 @@ abstract public class TimeZone implements Serializable, Cloneable { public static synchronized String getTZDataVersion() { if (TZDATA_VERSION == null) { UResourceBundle tzbundle = UResourceBundle.getBundleInstance( - "com/ibm/icu/impl/data/icudt" + VersionInfo.ICU_DATA_VERSION, "zoneinfo"); + "com/ibm/icu/impl/data/icudt" + VersionInfo.ICU_DATA_VERSION_PATH, "zoneinfo"); TZDATA_VERSION = tzbundle.getString("TZVersion"); } return TZDATA_VERSION; diff --git a/icu4j/main/classes/core/src/com/ibm/icu/util/VTimeZone.java b/icu4j/main/classes/core/src/com/ibm/icu/util/VTimeZone.java index 680d3ae9905..657ad08d270 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/util/VTimeZone.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/util/VTimeZone.java @@ -406,7 +406,7 @@ public class VTimeZone extends BasicTimeZone { // Initialize ICU_TZVERSION try { UResourceBundle tzbundle = UResourceBundle.getBundleInstance( - "com/ibm/icu/impl/data/icudt" + VersionInfo.ICU_DATA_VERSION, "zoneinfo"); + "com/ibm/icu/impl/data/icudt" + VersionInfo.ICU_DATA_VERSION_PATH, "zoneinfo"); ICU_TZVERSION = tzbundle.getString("TZVersion"); } catch (MissingResourceException e) { ///CLOVER:OFF diff --git a/icu4j/main/classes/core/src/com/ibm/icu/util/VersionInfo.java b/icu4j/main/classes/core/src/com/ibm/icu/util/VersionInfo.java index 5dd5c2b165f..e11ea55fb0c 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/util/VersionInfo.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/util/VersionInfo.java @@ -126,11 +126,18 @@ public final class VersionInfo implements Comparable public static final VersionInfo ICU_VERSION; /** - * Data version string for ICU's internal data + * Data version string for ICU's internal data. + * Used for appending to data path (e.g. icudt43b) * @internal * @deprecated This API is ICU internal only. */ - public static final String ICU_DATA_VERSION = "43b"; + public static final String ICU_DATA_VERSION_PATH = "43b"; + + /** + * Data version in ICU4J. + * @draft ICU 4.4 + */ + public static final VersionInfo ICU_DATA_VERSION; /** * ICU4J collator runtime version @@ -453,6 +460,7 @@ public final class VersionInfo implements Comparable UNICODE_5_0 = getInstance(5, 0, 0, 0); UNICODE_5_1 = getInstance(5, 1, 0, 0); ICU_VERSION = getInstance(4, 3, 2, 0); + ICU_DATA_VERSION = getInstance(4, 3, 2, 0); UCOL_RUNTIME_VERSION = getInstance(6); UCOL_BUILDER_VERSION = getInstance(7); UCOL_TAILORINGS_VERSION = getInstance(1); diff --git a/icu4j/main/shared/data/icudata.jar b/icu4j/main/shared/data/icudata.jar index 5e2f6a10911..cfba8c806a5 100755 --- a/icu4j/main/shared/data/icudata.jar +++ b/icu4j/main/shared/data/icudata.jar @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:c2cc70dea00dfd051df385d5c42102b57e144410814901a64026f2b71db44940 -size 6407935 +oid sha256:2e0e9765959db0043f13753f536fdd17f5c3575134c62e2fc3605f0468ec9e0d +size 6408404 diff --git a/icu4j/main/shared/data/testdata.jar b/icu4j/main/shared/data/testdata.jar index 1d0b9700eda..d47550218ad 100755 --- a/icu4j/main/shared/data/testdata.jar +++ b/icu4j/main/shared/data/testdata.jar @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:c4530426df37d8a0f3d5d66ba23fcbe059faeae9abd211d4205659ab21a34eb0 -size 720074 +oid sha256:02091ec2784bdaf2c4f03191092760c4729c3724ed78dab3efe23733227b4fe9 +size 717064