]> gitweb.fperrin.net Git - Dictionary.git/blob - jars/icu4j-4_4_2-src/main/classes/core/src/com/ibm/icu/impl/ICUDataVersion.java
go
[Dictionary.git] / jars / icu4j-4_4_2-src / main / classes / core / src / com / ibm / icu / impl / ICUDataVersion.java
1 /*\r
2 *******************************************************************************\r
3 *   Copyright (C) 2009-2010, International Business Machines\r
4 *   Corporation and others.  All Rights Reserved.\r
5 *******************************************************************************\r
6 */\r
7 \r
8 package com.ibm.icu.impl;\r
9 \r
10 import java.util.MissingResourceException;\r
11 \r
12 import com.ibm.icu.util.UResourceBundle;\r
13 import com.ibm.icu.util.VersionInfo;\r
14 \r
15 public final class ICUDataVersion {\r
16     private static final String U_ICU_VERSION_BUNDLE = "icuver";\r
17     private static final String U_ICU_STD_BUNDLE = "icustd";\r
18     \r
19     private static final String U_ICU_DATA_KEY = "DataVersion";\r
20     \r
21     /**\r
22      * This function loads up icuver and compares the data version to the wired-in ICU_DATA_VERSION.\r
23      * If icuver shows something less than ICU_DATA_VERSION it returns TRUE, else FALSE. The version\r
24      * found will be returned in the first fillin parameter (if non-null), and *isModified will be set\r
25      * to TRUE if "icustd" is NOT found. Thus, if the data has been repackaged or modified, "icustd"\r
26      * (standard ICU) will be missing, and the function will alert the caller that the data is not standard.\r
27      * \r
28      * @param dataVersionFillin icuver data version information to be filled in if not-null\r
29      * @return TRUE if ICU_DATA_VERSION is newer than icuver, else FALSE\r
30      */\r
31     public static boolean isDataOlder(VersionInfo dataVersionFillin) {\r
32         boolean result = true;\r
33         \r
34         VersionInfo dataVersion = getDataVersion();\r
35         \r
36         if (dataVersion!= null) {\r
37             if (dataVersion.compareTo(VersionInfo.ICU_DATA_VERSION) != -1) {\r
38                 result = false;\r
39             }\r
40             \r
41             if (dataVersionFillin != null) {\r
42                 dataVersionFillin = VersionInfo.getInstance(dataVersion.toString());\r
43             }\r
44         }\r
45         \r
46         return result;\r
47     }\r
48     \r
49     /**\r
50      * This function tests whether "icustd" is available in the data. If the data has been repackaged or modified, "icustd"\r
51      * (standard ICU) will be missing, and the function will alert the caller that the data is not standard.\r
52      *\r
53      * @return TRUE if data has been modified, else FALSE\r
54      */\r
55     public static boolean isDataModified() {\r
56         if (hasICUSTDBundle()) {\r
57             return false;\r
58         }\r
59         return true;\r
60     }\r
61     \r
62     /**\r
63      * This function retrieves the data version from icuver and returns a VersionInfo object with that version information.\r
64      *\r
65      * @return Current icu data version\r
66      */\r
67     public static VersionInfo getDataVersion() {\r
68         UResourceBundle icudatares = null;\r
69         try {\r
70             icudatares = UResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BASE_NAME, ICUDataVersion.U_ICU_VERSION_BUNDLE, ICUResourceBundle.ICU_DATA_CLASS_LOADER);\r
71             icudatares = icudatares.get(ICUDataVersion.U_ICU_DATA_KEY);\r
72         } catch (MissingResourceException ex) {\r
73             return null;\r
74         }\r
75         \r
76         return  VersionInfo.getInstance(icudatares.getString());\r
77     }\r
78     \r
79     private static boolean hasICUSTDBundle() {\r
80         try {\r
81             UResourceBundle.getBundleInstance(ICUDataVersion.U_ICU_STD_BUNDLE);\r
82         } catch (MissingResourceException ex) {\r
83             return false;\r
84         }\r
85         \r
86         return true;\r
87     }\r
88     \r
89 }\r