]> gitweb.fperrin.net Git - Dictionary.git/blob - jars/icu4j-4_8_1_1/main/classes/core/src/com/ibm/icu/impl/ICUDataVersion.java
Added flags.
[Dictionary.git] / jars / icu4j-4_8_1_1 / main / classes / core / src / com / ibm / icu / impl / ICUDataVersion.java
1 /*
2 *******************************************************************************
3 *   Copyright (C) 2009-2010, International Business Machines
4 *   Corporation and others.  All Rights Reserved.
5 *******************************************************************************
6 */
7
8 package com.ibm.icu.impl;
9
10 import java.util.MissingResourceException;
11
12 import com.ibm.icu.util.UResourceBundle;
13 import com.ibm.icu.util.VersionInfo;
14
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";
18     
19     private static final String U_ICU_DATA_KEY = "DataVersion";
20     
21     /**
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.
27      * 
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
30      */
31     public static boolean isDataOlder(VersionInfo dataVersionFillin) {
32         boolean result = true;
33         
34         VersionInfo dataVersion = getDataVersion();
35         
36         if (dataVersion!= null) {
37             if (dataVersion.compareTo(VersionInfo.ICU_DATA_VERSION) != -1) {
38                 result = false;
39             }
40             
41             if (dataVersionFillin != null) {
42                 dataVersionFillin = VersionInfo.getInstance(dataVersion.toString());
43             }
44         }
45         
46         return result;
47     }
48     
49     /**
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.
52      *
53      * @return TRUE if data has been modified, else FALSE
54      */
55     public static boolean isDataModified() {
56         if (hasICUSTDBundle()) {
57             return false;
58         }
59         return true;
60     }
61     
62     /**
63      * This function retrieves the data version from icuver and returns a VersionInfo object with that version information.
64      *
65      * @return Current icu data version
66      */
67     public static VersionInfo getDataVersion() {
68         UResourceBundle icudatares = null;
69         try {
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) {
73             return null;
74         }
75         
76         return  VersionInfo.getInstance(icudatares.getString());
77     }
78     
79     private static boolean hasICUSTDBundle() {
80         try {
81             UResourceBundle.getBundleInstance(ICUDataVersion.U_ICU_STD_BUNDLE);
82         } catch (MissingResourceException ex) {
83             return false;
84         }
85         
86         return true;
87     }
88     
89 }