| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
package org.itracker.services.util; |
| 20 |
|
|
| 21 |
|
import java.util.HashSet; |
| 22 |
|
import java.util.Iterator; |
| 23 |
|
import java.util.NoSuchElementException; |
| 24 |
|
import java.util.StringTokenizer; |
| 25 |
|
|
| 26 |
|
import org.apache.log4j.Logger; |
| 27 |
|
import org.itracker.core.resources.ITrackerResources; |
| 28 |
|
import org.itracker.model.Configuration; |
| 29 |
|
import org.itracker.model.NameValuePair; |
| 30 |
|
import org.itracker.services.ConfigurationService; |
| 31 |
|
|
|
|
|
| 0% |
Uncovered Elements: 119 (119) |
Complexity: 42 |
Complexity Density: 0.63 |
|
| 32 |
|
public class SystemConfigurationUtilities { |
| 33 |
|
|
| 34 |
|
public static final String DEFAULT_DATASOURCE = "java:/ITrackerDS"; |
| 35 |
|
private static final Logger log = Logger.getLogger(SystemConfigurationUtilities.class); |
| 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 |
|
|
| 55 |
|
|
| 56 |
|
|
| 57 |
|
|
| 58 |
|
@param |
| 59 |
|
|
| 60 |
|
@return |
| 61 |
|
|
|
|
|
| 0% |
Uncovered Elements: 17 (17) |
Complexity: 5 |
Complexity Density: 0.56 |
|
| 62 |
0
|
public static String getLanguageKey(Configuration configuration) {... |
| 63 |
0
|
if (configuration != null) { |
| 64 |
0
|
int type = configuration.getType(); |
| 65 |
0
|
if (type == SystemConfigurationUtilities.TYPE_STATUS) { |
| 66 |
0
|
return ITrackerResources.KEY_BASE_STATUS |
| 67 |
|
+ configuration.getValue(); |
| 68 |
0
|
} else if (type == SystemConfigurationUtilities.TYPE_SEVERITY) { |
| 69 |
0
|
return ITrackerResources.KEY_BASE_SEVERITY |
| 70 |
|
+ configuration.getValue(); |
| 71 |
0
|
} else if (type == SystemConfigurationUtilities.TYPE_RESOLUTION) { |
| 72 |
0
|
return ITrackerResources.KEY_BASE_RESOLUTION |
| 73 |
|
+ configuration.getValue(); |
| 74 |
|
} |
| 75 |
|
} |
| 76 |
0
|
return ""; |
| 77 |
|
} |
| 78 |
|
|
| 79 |
|
|
| 80 |
|
|
| 81 |
|
|
| 82 |
|
|
| 83 |
|
|
| 84 |
|
@param |
| 85 |
|
|
| 86 |
|
|
| 87 |
|
@param |
| 88 |
|
|
| 89 |
|
|
| 90 |
|
|
|
|
|
| 0% |
Uncovered Elements: 24 (24) |
Complexity: 7 |
Complexity Density: 0.44 |
|
| 91 |
0
|
public static void initializeAllLanguages(... |
| 92 |
|
ConfigurationService configurationService, boolean forceReload) { |
| 93 |
0
|
HashSet<String> definedLocales = new HashSet<String>(); |
| 94 |
|
|
| 95 |
0
|
configurationService.initializeLocale(ITrackerResources.BASE_LOCALE, |
| 96 |
|
forceReload); |
| 97 |
|
|
| 98 |
0
|
String definedLocalesString; |
| 99 |
0
|
try { |
| 100 |
0
|
definedLocalesString = configurationService |
| 101 |
|
.getLanguageItemByKey(ITrackerResources.DEFINED_LOCALES_KEY, |
| 102 |
|
null).getResourceValue(); |
| 103 |
|
} catch (RuntimeException e) { |
| 104 |
0
|
definedLocalesString = ITrackerResources.getString(ITrackerResources.DEFINED_LOCALES_KEY); |
| 105 |
|
} |
| 106 |
0
|
if (definedLocalesString != null) { |
| 107 |
0
|
StringTokenizer token = new StringTokenizer(definedLocalesString, ","); |
| 108 |
0
|
while (token.hasMoreTokens()) { |
| 109 |
0
|
String locale = token.nextToken(); |
| 110 |
0
|
if (locale.length() == 5 && locale.indexOf('_') == 2) { |
| 111 |
0
|
definedLocales.add(locale.substring(0, 2)); |
| 112 |
|
} |
| 113 |
0
|
definedLocales.add(locale); |
| 114 |
|
} |
| 115 |
|
} |
| 116 |
|
|
| 117 |
0
|
for (Iterator<String> iter = definedLocales.iterator(); iter.hasNext();) { |
| 118 |
0
|
String locale = iter.next(); |
| 119 |
0
|
configurationService.initializeLocale(locale, forceReload); |
| 120 |
|
} |
| 121 |
|
} |
| 122 |
|
|
|
|
|
| 0% |
Uncovered Elements: 24 (24) |
Complexity: 8 |
Complexity Density: 0.5 |
|
| 123 |
0
|
public static long getVersionAsLong(String version) {... |
| 124 |
0
|
long versionNumber = 0; |
| 125 |
0
|
if (log.isDebugEnabled()) { |
| 126 |
0
|
log.debug("getVersionAsLong: transforming " + version); |
| 127 |
|
} |
| 128 |
0
|
if (version != null) { |
| 129 |
0
|
StringTokenizer token = new StringTokenizer(version, "."); |
| 130 |
0
|
try { |
| 131 |
0
|
if (token.countTokens() > 0 && token.countTokens() <= 3) { |
| 132 |
0
|
versionNumber += 1000000L * Integer.parseInt(token |
| 133 |
|
.nextToken()); |
| 134 |
0
|
versionNumber += 1000L * Integer |
| 135 |
|
.parseInt(token.nextToken()); |
| 136 |
0
|
versionNumber += Integer.parseInt(token.nextToken()); |
| 137 |
|
} else { |
| 138 |
0
|
throw new IllegalArgumentException("The version " + version + " is not parseable, excpected '(int)number[.(int)major[.(int)minor]]"); |
| 139 |
|
} |
| 140 |
|
} catch (NumberFormatException nfe) { |
| 141 |
0
|
log.warn("getVersionAsLong: failed to parse version " + version, nfe); |
| 142 |
|
} catch (NoSuchElementException nsee) { |
| 143 |
0
|
log.warn("getVersionAsLong: failed to parse version, elements are not complete for " + version, nsee); |
| 144 |
|
} |
| 145 |
|
|
| 146 |
|
} |
| 147 |
|
|
| 148 |
0
|
if (log.isDebugEnabled()) { |
| 149 |
0
|
log.debug("getVersionAsLong: returning " + versionNumber); |
| 150 |
|
} |
| 151 |
0
|
return versionNumber; |
| 152 |
|
} |
| 153 |
|
|
|
|
|
| 0% |
Uncovered Elements: 17 (17) |
Complexity: 7 |
Complexity Density: 0.78 |
|
| 154 |
0
|
public static int getLocaleType(String locale) {... |
| 155 |
0
|
if (locale == null || locale.equals("")) { |
| 156 |
0
|
return LOCALE_TYPE_INVALID; |
| 157 |
|
} |
| 158 |
|
|
| 159 |
0
|
if (ITrackerResources.BASE_LOCALE.equalsIgnoreCase(locale)) { |
| 160 |
0
|
return LOCALE_TYPE_BASE; |
| 161 |
0
|
} else if (locale.length() == 5 && locale.indexOf('_') == 2) { |
| 162 |
0
|
return LOCALE_TYPE_LOCALE; |
| 163 |
0
|
} else if (locale.length() == 2) { |
| 164 |
0
|
return LOCALE_TYPE_LANGUAGE; |
| 165 |
|
} else { |
| 166 |
0
|
return LOCALE_TYPE_INVALID; |
| 167 |
|
} |
| 168 |
|
} |
| 169 |
|
|
|
|
|
| 0% |
Uncovered Elements: 21 (21) |
Complexity: 12 |
Complexity Density: 1.09 |
|
| 170 |
0
|
public static String getLocalePart(String locale, int partType) {... |
| 171 |
0
|
if (locale == null || partType == LOCALE_TYPE_INVALID) { |
| 172 |
0
|
return null; |
| 173 |
|
} |
| 174 |
|
|
| 175 |
0
|
if (partType == LOCALE_TYPE_LOCALE && locale.length() == 5 |
| 176 |
|
&& locale.indexOf('_') == 2) { |
| 177 |
0
|
return locale; |
| 178 |
0
|
} else if (partType == LOCALE_TYPE_LANGUAGE && locale.length() == 5 |
| 179 |
|
&& locale.indexOf('_') == 2) { |
| 180 |
0
|
return locale.substring(0, 2); |
| 181 |
0
|
} else if (partType == LOCALE_TYPE_LANGUAGE && locale.length() == 2) { |
| 182 |
0
|
return locale; |
| 183 |
0
|
} else if (partType == LOCALE_TYPE_BASE) { |
| 184 |
0
|
return ITrackerResources.BASE_LOCALE; |
| 185 |
|
} |
| 186 |
|
|
| 187 |
0
|
return null; |
| 188 |
|
} |
| 189 |
|
|
|
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 3 |
Complexity Density: 0.5 |
|
| 190 |
0
|
public static Configuration[] nvpArrayToConfigurationArray(int configType,... |
| 191 |
|
NameValuePair[] names) { |
| 192 |
0
|
if (names == null) { |
| 193 |
0
|
return new Configuration[0]; |
| 194 |
|
} |
| 195 |
|
|
| 196 |
0
|
Configuration[] configModels = new Configuration[names.length]; |
| 197 |
0
|
for (int i = 0; i < names.length; i++) { |
| 198 |
0
|
configModels[i] = new Configuration(configType, names[i]); |
| 199 |
|
} |
| 200 |
|
|
| 201 |
0
|
return configModels; |
| 202 |
|
} |
| 203 |
|
} |