1 18 19 package cowsultants.itracker.ejb.client.util; 20 21 import java.util.*; 22 23 import cowsultants.itracker.ejb.client.interfaces.SystemConfiguration; 24 import cowsultants.itracker.ejb.client.models.*; 25 import cowsultants.itracker.ejb.client.resources.*; 26 27 public class SystemConfigurationUtilities { 28 public static final String DEFAULT_DATASOURCE = "java:/ITrackerDS"; 29 public static final String DEFAULT_COMPONENTBEAN_TABLE_NAME = "componentbean"; 30 public static final String DEFAULT_COMPONENTBEAN_REL_TABLE_NAME = "issue_component_rel"; 31 public static final String DEFAULT_ISSUEBEAN_TABLE_NAME = "issuebean"; 32 public static final String DEFAULT_ISSUEHISTORYBEAN_TABLE_NAME = "issuehistorybean"; 33 public static final String DEFAULT_PROJECTBEAN_TABLE_NAME = "projectbean"; 34 public static final String DEFAULT_VERSIONBEAN_TABLE_NAME = "versionbean"; 35 public static final String DEFAULT_VERSIONBEAN_REL_TABLE_NAME = "issue_version_rel"; 36 37 public static final int TYPE_INITIALIZED = -1; 38 public static final int TYPE_LOCALE = 1; 39 public static final int TYPE_STATUS = 2; 40 public static final int TYPE_SEVERITY = 3; 41 public static final int TYPE_RESOLUTION = 4; 42 public static final int TYPE_CUSTOMFIELD = 5; 43 44 public static final int ACTION_CREATE = 1; 45 public static final int ACTION_UPDATE = 2; 46 public static final int ACTION_REMOVE = 3; 47 48 public static final int LOCALE_TYPE_INVALID = -1; 49 public static final int LOCALE_TYPE_BASE = 1; 50 public static final int LOCALE_TYPE_LANGUAGE = 2; 51 public static final int LOCALE_TYPE_LOCALE = 3; 52 53 54 61 public static String getLanguageKey(ConfigurationModel model) { 62 if(model != null) { 63 int type = model.getType(); 64 if(type == SystemConfigurationUtilities.TYPE_STATUS) { 65 return ITrackerResources.KEY_BASE_STATUS + model.getValue(); 66 } else if(type == SystemConfigurationUtilities.TYPE_SEVERITY) { 67 return ITrackerResources.KEY_BASE_SEVERITY + model.getValue(); 68 } else if(type == SystemConfigurationUtilities.TYPE_RESOLUTION) { 69 return ITrackerResources.KEY_BASE_RESOLUTION + model.getValue(); 70 } 71 } 72 return ""; 73 } 74 75 82 public static void initializeAllLanguages(SystemConfiguration sc, boolean forceReload) { 83 HashSet definedLocales = new HashSet(); 84 85 sc.initializeLocale(ITrackerResources.BASE_LOCALE, forceReload); 86 87 LanguageModel definedLocalesString = sc.getLanguageItemByKey(ITrackerResources.DEFINED_LOCALES_KEY, null); 88 89 if(definedLocalesString != null && definedLocalesString.getResourceValue() != null) { 90 String locales = definedLocalesString.getResourceValue(); 91 StringTokenizer token = new StringTokenizer(locales, ","); 92 while(token.hasMoreTokens()) { 93 String locale = token.nextToken(); 94 if(locale.length() == 5 && locale.indexOf('_') == 2) { 95 definedLocales.add(locale.substring(0, 2)); 96 } 97 definedLocales.add(locale); 98 } 99 } 100 101 for(Iterator iter = definedLocales.iterator(); iter.hasNext(); ) { 102 String locale = (String ) iter.next(); 103 Logger.logDebug("Starting language initialization for " + locale); 104 sc.initializeLocale(locale, forceReload); 105 } 106 } 107 108 public static long getVersionAsLong(String version) { 109 long versionNumber = 0; 110 111 if(version != null) { 112 try { 113 StringTokenizer token = new StringTokenizer(version, "."); 114 if(token.countTokens() == 3) { 115 versionNumber += 1000000 * Integer.parseInt(token.nextToken()); 116 versionNumber += 1000 * Integer.parseInt(token.nextToken()); 117 versionNumber += Integer.parseInt(token.nextToken()); 118 } 119 } catch(Exception e) { 120 } 121 } 122 123 return versionNumber; 124 } 125 126 public static int getLocaleType(String locale) { 127 if(locale == null || locale.equals("")) { 128 return LOCALE_TYPE_INVALID; 129 } 130 131 if(ITrackerResources.BASE_LOCALE.equalsIgnoreCase(locale)) { 132 return LOCALE_TYPE_BASE; 133 } else if(locale.length() == 5 && locale.indexOf('_') == 2) { 134 return LOCALE_TYPE_LOCALE; 135 } else if(locale.length() == 2) { 136 return LOCALE_TYPE_LANGUAGE; 137 } else { 138 return LOCALE_TYPE_INVALID; 139 } 140 } 141 142 public static String getLocalePart(String locale, int partType) { 143 if(locale == null || partType == LOCALE_TYPE_INVALID) { 144 return null; 145 } 146 147 if(partType == LOCALE_TYPE_LOCALE && locale.length() == 5 && locale.indexOf('_') == 2) { 148 return locale; 149 } else if(partType == LOCALE_TYPE_LANGUAGE && locale.length() == 5 && locale.indexOf('_') == 2) { 150 return locale.substring(0, 2); 151 } else if(partType == LOCALE_TYPE_LANGUAGE && locale.length() == 2) { 152 return locale; 153 } else if(partType == LOCALE_TYPE_BASE) { 154 return ITrackerResources.BASE_LOCALE; 155 } 156 157 return null; 158 } 159 160 public static ConfigurationModel[] nvpArrayToConfigurationArray(int configType, NameValuePairModel[] names) { 161 if(names == null) { 162 return new ConfigurationModel[0]; 163 } 164 165 ConfigurationModel[] configModels = new ConfigurationModel[names.length]; 166 for(int i = 0; i < names.length; i++) { 167 configModels[i] = new ConfigurationModel(configType, names[i]); 168 } 169 170 return configModels; 171 } 172 } 173 | Popular Tags |