2 *******************************************************************************
3 * Copyright (C) 2009-2010, International Business Machines
4 * Corporation and others. All Rights Reserved.
5 *******************************************************************************
8 package com.ibm.icu.impl;
10 import java.util.MissingResourceException;
12 import com.ibm.icu.util.UResourceBundle;
13 import com.ibm.icu.util.VersionInfo;
15 public final class ICUDataVersion {
16 private static final String U_ICU_VERSION_BUNDLE = "icuver";
17 private static final String U_ICU_STD_BUNDLE = "icustd";
19 private static final String U_ICU_DATA_KEY = "DataVersion";
22 * This function loads up icuver and compares the data version to the wired-in ICU_DATA_VERSION.
23 * If icuver shows something less than ICU_DATA_VERSION it returns TRUE, else FALSE. The version
24 * found will be returned in the first fillin parameter (if non-null), and *isModified will be set
25 * to TRUE if "icustd" is NOT found. Thus, if the data has been repackaged or modified, "icustd"
26 * (standard ICU) will be missing, and the function will alert the caller that the data is not standard.
28 * @param dataVersionFillin icuver data version information to be filled in if not-null
29 * @return TRUE if ICU_DATA_VERSION is newer than icuver, else FALSE
31 public static boolean isDataOlder(VersionInfo dataVersionFillin) {
32 boolean result = true;
34 VersionInfo dataVersion = getDataVersion();
36 if (dataVersion!= null) {
37 if (dataVersion.compareTo(VersionInfo.ICU_DATA_VERSION) != -1) {
41 if (dataVersionFillin != null) {
42 dataVersionFillin = VersionInfo.getInstance(dataVersion.toString());
50 * This function tests whether "icustd" is available in the data. If the data has been repackaged or modified, "icustd"
51 * (standard ICU) will be missing, and the function will alert the caller that the data is not standard.
53 * @return TRUE if data has been modified, else FALSE
55 public static boolean isDataModified() {
56 if (hasICUSTDBundle()) {
63 * This function retrieves the data version from icuver and returns a VersionInfo object with that version information.
65 * @return Current icu data version
67 public static VersionInfo getDataVersion() {
68 UResourceBundle icudatares = null;
70 icudatares = UResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BASE_NAME, ICUDataVersion.U_ICU_VERSION_BUNDLE, ICUResourceBundle.ICU_DATA_CLASS_LOADER);
71 icudatares = icudatares.get(ICUDataVersion.U_ICU_DATA_KEY);
72 } catch (MissingResourceException ex) {
76 return VersionInfo.getInstance(icudatares.getString());
79 private static boolean hasICUSTDBundle() {
81 UResourceBundle.getBundleInstance(ICUDataVersion.U_ICU_STD_BUNDLE);
82 } catch (MissingResourceException ex) {