List of usage examples for java.util ResourceBundle getString
public final String getString(String key)
From source file:com.salesmanager.core.util.ShippingUtil.java
/** * Helper method for building a Map of services <id,name> from a list of * services. It uses the resource bundles. * /*from w w w . j a v a 2 s .c o m*/ * @param servicelist * @param moduleid * @param locale * @return * @throws Exception */ public static Map<String, String> buildServiceMapFromList(List servicelist, String moduleid, Locale locale) throws Exception { ResourceBundle bundle = ResourceBundle.getBundle(moduleid, locale); Map returnmap = new HashMap(); if (servicelist == null) { return returnmap; } Iterator it = servicelist.iterator(); while (it.hasNext()) { String pkgid = (String) it.next(); String pkg = bundle.getString("shipping.quote.services.label." + pkgid); returnmap.put(pkgid, pkg); } return returnmap; }
From source file:org.fcrepo.client.FedoraClient.java
public static List<String> getCompatibleServerVersions() { ResourceBundle bundle = ResourceBundle.getBundle("org.fcrepo.client.resources.Client"); List<String> list = new ArrayList<String>(); String versions = bundle.getString("compatibleServerVersions"); if (versions != null && versions.trim().length() > 0) { String[] va = versions.trim().split(" "); for (String element : va) { list.add(element);/*from w ww.j a va 2 s .co m*/ } } String clientVersion = getVersion(); if (!list.contains(clientVersion)) { list.add(getVersion()); } return list; }
From source file:com.salesmanager.core.util.ShippingUtil.java
/** * Builds a Map<String,String> of package options ID, CODE from the service * .properties file the package line must be built using * <ID>|<SHIPPING_CODE>;<ID>|<SHIPPING_CODE> * /*from w ww. java 2 s. c o m*/ * @param packageline * @param moduleid * @param locale * @return */ public static Map<String, String> buildPackageMap(String moduleid, Locale locale) throws Exception { ReferenceService rservice = (ReferenceService) ServiceFactory.getService(ServiceFactory.ReferenceService); ModuleConfiguration serviceconfig = rservice.getModuleConfiguration(moduleid, "packages", locale.getCountry()); if (serviceconfig == null) { serviceconfig = rservice.getModuleConfiguration(moduleid, "packages", "XX");// generic } if (serviceconfig == null) { throw new Exception( "ModuleConfiguration does not exist for " + moduleid + "-packages-XX-" + locale.getCountry()); } String packageline = serviceconfig.getConfigurationValue(); ResourceBundle bundle = ResourceBundle.getBundle(moduleid, locale); Map packsmap = getConfigurationMap(packageline, ";", "|"); Map returnmap = new HashMap(); Iterator it = packsmap.keySet().iterator(); while (it.hasNext()) { String pkgid = (String) it.next(); String label = bundle.getString("shipping.quote.packageoption.label." + pkgid); returnmap.put(pkgid, label); } return returnmap; }
From source file:adalid.commons.properties.PropertiesHandler.java
public static Properties loadProperties(ResourceBundle bundle, boolean sortedKeys) { Properties properties = newProperties(sortedKeys); if (bundle == null) { logger.error("null properties bundle"); } else {/*from ww w . j a va2 s . c om*/ logger.trace("loading bundle " + bundle); Set<String> keySet = bundle.keySet(); String value; for (String key : keySet) { try { value = bundle.getString(key); if (StringUtils.isBlank(value)) { continue; } properties.setProperty(key, value.trim()); } catch (MissingResourceException e) { } } printProperties(properties); } return properties; }
From source file:com.salesmanager.core.util.ShippingUtil.java
/** * Builds a Map<String,String> of services avilables ID, CODE from the * service .properties file// www . j a v a 2 s . c om * * @param serviceline * @param moduleid * @param locale * @return */ public static Map<String, String> buildServiceMap(String moduleid, Locale locale) throws Exception { ReferenceService rservice = (ReferenceService) ServiceFactory.getService(ServiceFactory.ReferenceService); String country = locale.getCountry(); if (locale.getVariant().equals("EUR")) { country = "X1"; } ModuleConfiguration serviceconfig = rservice.getModuleConfiguration(moduleid, "service", country); if (serviceconfig == null) { serviceconfig = rservice.getModuleConfiguration(moduleid, "service", "XX");// generic } if (serviceconfig == null) { throw new Exception("ModuleConfiguration does not exist for " + moduleid + "-service-XX-" + country); } String serviceline = serviceconfig.getConfigurationValue(); ResourceBundle bundle = ResourceBundle.getBundle(moduleid, locale); List pkgids = getConfigurationList(serviceline); // List returnlist = new ArrayList(); Map returnmap = new HashMap(); Iterator it = pkgids.iterator(); while (it.hasNext()) { String pkgid = (String) it.next(); String pkg = bundle.getString("shipping.quote.services.label." + pkgid); returnmap.put(pkgid, pkg); } // return returnlist; return returnmap; }
From source file:com.dien.upload.server.UploadServlet.java
/** * Returns the localized text of a key./*from w w w.j av a2 s .c o m*/ */ public static String getMessage(String key, Object... pars) { ResourceBundle res = ResourceBundle.getBundle(UploadServlet.class.getName(), getThreadLocalRequest().getLocale()); return new MessageFormat(res.getString(key), getThreadLocalRequest().getLocale()).format(pars); }
From source file:at.alladin.rmbt.qos.QoSUtil.java
/** * /*from w w w.j a v a 2s . c o m*/ * @param settings * @param conn * @param answer * @param lang * @param errorList * @throws SQLException * @throws JSONException * @throws HstoreParseException * @throws IllegalAccessException * @throws IllegalArgumentException */ public static void evaluate(final ResourceBundle settings, final Connection conn, final TestUuid uuid, final JSONObject answer, String lang, final ErrorList errorList) throws SQLException, HstoreParseException, JSONException, IllegalArgumentException, IllegalAccessException { // Load Language Files for Client final List<String> langs = Arrays.asList(settings.getString("RMBT_SUPPORTED_LANGUAGES").split(",\\s*")); if (langs.contains(lang)) { errorList.setLanguage(lang); } else { lang = settings.getString("RMBT_DEFAULT_LANGUAGE"); } if (conn != null) { final Client client = new Client(conn); final Test test = new Test(conn); boolean necessaryDataAvailable = false; if (uuid != null && uuid.getType() != null && uuid.getUuid() != null) { switch (uuid.getType()) { case OPEN_TEST_UUID: if (test.getTestByOpenTestUuid(UUID.fromString(uuid.getUuid())) > 0 && client.getClientByUid(test.getField("client_id").intValue())) { necessaryDataAvailable = true; } break; case TEST_UUID: if (test.getTestByUuid(UUID.fromString(uuid.getUuid())) > 0 && client.getClientByUid(test.getField("client_id").intValue())) { necessaryDataAvailable = true; } break; } } final long timeStampFullEval = System.currentTimeMillis(); if (necessaryDataAvailable) { final Locale locale = new Locale(lang); final ResultOptions resultOptions = new ResultOptions(locale); final JSONArray resultList = new JSONArray(); QoSTestResultDao resultDao = new QoSTestResultDao(conn); List<QoSTestResult> testResultList = resultDao.getByTestUid(test.getUid()); if (testResultList == null || testResultList.isEmpty()) { throw new UnsupportedOperationException("test " + test + " has no result list"); } //map that contains all test types and their result descriptions determined by the test result <-> test objectives comparison Map<TestType, TreeSet<ResultDesc>> resultKeys = new HashMap<>(); //test description set: Set<String> testDescSet = new TreeSet<>(); //test summary set: Set<String> testSummarySet = new TreeSet<>(); //Staring timestamp for evaluation time measurement final long timeStampEval = System.currentTimeMillis(); //iterate through all result entries for (final QoSTestResult testResult : testResultList) { //reset test counters testResult.setFailureCounter(0); testResult.setSuccessCounter(0); //get the correct class of the result; TestType testType = null; try { testType = TestType.valueOf(testResult.getTestType().toUpperCase(Locale.US)); } catch (IllegalArgumentException e) { final String errorMessage = "WARNING: QoS TestType '" + testResult.getTestType().toUpperCase(Locale.US) + "' not supported by ControlServer. Test with UID: " + testResult.getUid() + " skipped."; System.out.println(errorMessage); errorList.addErrorString(errorMessage); testType = null; } if (testType == null) { continue; } Class<? extends AbstractResult<?>> clazz = testType.getClazz(); //parse hstore data final JSONObject resultJson = new JSONObject(testResult.getResults()); AbstractResult<?> result = QoSUtil.HSTORE_PARSER.fromJSON(resultJson, clazz); result.setResultJson(resultJson); if (result != null) { //add each test description key to the testDescSet (to fetch it later from the db) if (testResult.getTestDescription() != null) { testDescSet.add(testResult.getTestDescription()); } if (testResult.getTestSummary() != null) { testSummarySet.add(testResult.getTestSummary()); } testResult.setResult(result); } //compare test results compareTestResults(testResult, result, resultKeys, testType, resultOptions); //resultList.put(testResult.toJson()); //save all test results after the success and failure counters have been set //resultDao.updateCounter(testResult); } //ending timestamp for evaluation time measurement final long timeStampEvalEnd = System.currentTimeMillis(); //------------------------------------------------------------- //fetch all result strings from the db QoSTestDescDao descDao = new QoSTestDescDao(conn, locale); //FIRST: get all test descriptions Set<String> testDescToFetchSet = testDescSet; testDescToFetchSet.addAll(testSummarySet); Map<String, String> testDescMap = descDao.getAllByKeyToMap(testDescToFetchSet); for (QoSTestResult testResult : testResultList) { //and set the test results + put each one to the result list json array String preParsedDesc = testDescMap.get(testResult.getTestDescription()); if (preParsedDesc != null) { String description = String.valueOf( TestScriptInterpreter.interprete(testDescMap.get(testResult.getTestDescription()), QoSUtil.HSTORE_PARSER, testResult.getResult(), true, resultOptions)); testResult.setTestDescription(description); } //do the same for the test summary: String preParsedSummary = testDescMap.get(testResult.getTestSummary()); if (preParsedSummary != null) { String description = String.valueOf( TestScriptInterpreter.interprete(testDescMap.get(testResult.getTestSummary()), QoSUtil.HSTORE_PARSER, testResult.getResult(), true, resultOptions)); testResult.setTestSummary(description); } resultList.put(testResult.toJson(uuid.getType())); } //finally put results to json answer.put("testresultdetail", resultList); JSONArray resultDescArray = new JSONArray(); //SECOND: fetch all test result descriptions for (TestType testType : resultKeys.keySet()) { TreeSet<ResultDesc> descSet = resultKeys.get(testType); //fetch results to same object descDao.loadToTestDesc(descSet); //another tree set for duplicate entries: //TODO: there must be a better solution //(the issue is: compareTo() method returns differnt values depending on the .value attribute (if it's set or not)) TreeSet<ResultDesc> descSetNew = new TreeSet<>(); //add fetched results to json for (ResultDesc desc : descSet) { if (!descSetNew.contains(desc)) { descSetNew.add(desc); } else { for (ResultDesc d : descSetNew) { if (d.compareTo(desc) == 0) { d.getTestResultUidList().addAll(desc.getTestResultUidList()); } } } } for (ResultDesc desc : descSetNew) { if (desc.getValue() != null) { resultDescArray.put(desc.toJson()); } } } //System.out.println(resultDescArray); //put result descriptions to json answer.put("testresultdetail_desc", resultDescArray); QoSTestTypeDescDao testTypeDao = new QoSTestTypeDescDao(conn, locale); JSONArray testTypeDescArray = new JSONArray(); for (QoSTestTypeDesc desc : testTypeDao.getAll()) { final JSONObject testTypeDesc = desc.toJson(); if (testTypeDesc != null) { testTypeDescArray.put(testTypeDesc); } } //put result descriptions to json answer.put("testresultdetail_testdesc", testTypeDescArray); JSONObject evalTimes = new JSONObject(); evalTimes.put("eval", (timeStampEvalEnd - timeStampEval)); evalTimes.put("full", (System.currentTimeMillis() - timeStampFullEval)); answer.put("eval_times", evalTimes); //System.out.println(answer); } else errorList.addError("ERROR_REQUEST_TEST_RESULT_DETAIL_NO_UUID"); } else errorList.addError("ERROR_DB_CONNECTION"); }
From source file:hudson.Util.java
/** * Gets a human readable message for the given Win32 error code. * * @return//from w w w. j a v a 2 s. co m * null if no such message is available. */ public static String getWin32ErrorMessage(int n) { ResourceBundle rb = ResourceBundle.getBundle("/hudson/win32errors"); return rb.getString("error" + n); }
From source file:hudson.Util.java
/** * Extracts the Win32 error message from {@link Throwable} if possible. * * @return/*w w w . j av a 2s. c o m*/ * null if there seems to be no error code or if the platform is not Win32. */ public static String getWin32ErrorMessage(Throwable e) { String msg = e.getMessage(); if (msg != null) { Matcher m = errorCodeParser.matcher(msg); if (m.matches()) { try { ResourceBundle rb = ResourceBundle.getBundle("/hudson/win32errors"); return rb.getString("error" + m.group(1)); } catch (Exception _) { // silently recover from resource related failures } } } if (e.getCause() != null) return getWin32ErrorMessage(e.getCause()); return null; // no message }
From source file:com.opensymphony.xwork2.util.LocalizedTextUtil.java
/** * Returns a localized message for the specified key, aTextName. Neither the key nor the * message is evaluated.//from w w w.j a v a 2 s .c o m * * @param aTextName the message key * @param locale the locale the message should be for * @return a localized message based on the specified key, or null if no localized message can be found for it */ public static String findDefaultText(String aTextName, Locale locale) { List<String> localList = DEFAULT_RESOURCE_BUNDLES; for (String bundleName : localList) { ResourceBundle bundle = findResourceBundle(bundleName, locale); if (bundle != null) { reloadBundles(); try { return bundle.getString(aTextName); } catch (MissingResourceException e) { // ignore and try others } } } return null; }