List of usage examples for java.text MessageFormat MessageFormat
public MessageFormat(String pattern)
From source file:libepg.ts.packet.TsPacket.java
/** * transport_error_indicator(?)/*from w w w . ja va 2s .c om*/ * 1???????1?????TS????? * * @return ? * @throws IllegalStateException ????(0,1)???? */ public synchronized int getTransport_error_indicator() throws IllegalStateException { int temp; temp = ByteConverter.byteToInt(this.data.getData()[1]); temp = temp >>> 7; if ((temp == 0) || (temp == 1)) { return temp; } else { MessageFormat msg = new MessageFormat( "?????={0}"); Object[] parameters = { temp }; throw new IllegalStateException(msg.format(parameters)); } }
From source file:libepg.ts.packet.PROGRAM_ID.java
@Override public synchronized String toString() { StringBuilder s = new StringBuilder(); for (int i : this.pids) { s.append("["); s.append(Integer.toHexString(i)); s.append("]"); }/*w w w. j a v a 2 s .c o m*/ String set = s.toString(); MessageFormat msg = new MessageFormat("{0}(pidName={1},PIDs={2})"); Object[] parameters = { super.toString(), this.getPidName(), set }; return msg.format(parameters); }
From source file:de.kaiserpfalzEdv.commons.HandleI18NImpl.java
@Override public String get(final String key, final Object[] parameters) { MessageFormat message = new MessageFormat(get(key)); message.setLocale(locale);//from ww w. j av a 2s . c om LOG.debug("Translating {}='{}' with parameters: {} ...", key, get(key), parameters); return message.format(parameters); }
From source file:com.taobao.tddl.common.ConfigServerHelper.java
/** * TDDL//w w w.j a va 2s . co m */ public static Object subscribeTDDLConfig(String appName, DataListener listener) { if (appName == null || appName.length() == 0) { throw new IllegalStateException("appName"); } String dataId = new MessageFormat(DATA_ID_TDDL_CLIENT_CONFIG).format(new Object[] { appName }); return ConfigServerHelper.subscribePersistentData(getCallerClassName(), dataId, listener); }
From source file:org.openqa.selenium.server.htmlrunner.DatabaseTestResults.java
public synchronized String createSqlTestCaseDescription(String setName, String caseId, String description) { MessageFormat mf = new MessageFormat( "insert into tsi_tests_tc_desc(PRODUCT_NAME, CATEGORY, CASE_ID, SET_NAME, VARIANT_SEQ, CASE_DESC) values(''{0}'', ''{1}'', ''{2}'', ''{3}'', 1, ''{4}'')"); String desc;//from ww w . j av a 2 s. c o m desc = description.replace('\u0000', ' '); desc = desc.replace('"', '^'); desc = desc.replace('\'', '^'); if (setName.length() > 29) setName = setName.substring(0, 27); // column size = 30 if (caseId.length() > 39) caseId = caseId.substring(0, 37); // column size = 40 if (desc.length() > 500) { int start = desc.length() - 495; desc = desc.substring(start, desc.length()) + "..."; } Object[] caseRecord = { productName, dbCategory, caseId, setName, desc }; return mf.format(caseRecord); }
From source file:com.hypersocket.i18n.I18N.java
public static String getResource(Locale locale, String resourceBundle, String key, Object... arguments) { if (key == null) { throw new IllegalArgumentException("You must specify a key!"); }//from w w w . j av a2s . c o m if (resourceBundle == null) { throw new IllegalArgumentException("You must specify a resource bundle for key " + key); } File overideFile = getOverrideFile(locale, resourceBundle); if (overideFile.exists()) { if (!overideProperties.containsKey(overideFile)) { Properties properties = new Properties(); try { InputStream in = new FileInputStream(overideFile); try { properties.load(in); } catch (IOException ex) { } finally { FileUtils.closeQuietly(in); } overideProperties.put(overideFile, properties); } catch (FileNotFoundException e) { } } if (overideProperties.containsKey(overideFile)) { Properties properties = overideProperties.get(overideFile); if (properties.containsKey(key)) { String localizedString = properties.getProperty(key); if (arguments == null || arguments.length == 0) { return localizedString; } MessageFormat messageFormat = new MessageFormat(localizedString); messageFormat.setLocale(locale); return messageFormat.format(formatParameters(arguments)); } } } String bundlePath = resourceBundle; if (!bundlePath.startsWith("i18n/")) { bundlePath = "i18n/" + resourceBundle; } try { ResourceBundle resource = ResourceBundle.getBundle(bundlePath, locale, I18N.class.getClassLoader()); String localizedString = resource.getString(key); if (arguments == null || arguments.length == 0) { return localizedString; } MessageFormat messageFormat = new MessageFormat(localizedString); messageFormat.setLocale(locale); return messageFormat.format(formatParameters(arguments)); } catch (MissingResourceException mre) { return "Missing resource key [i18n/" + resourceBundle + "/" + key + "]"; } }
From source file:com.haulmont.cuba.security.entity.User.java
public String getCaption() { String pattern = AppContext.getProperty("cuba.user.namePattern"); if (StringUtils.isBlank(pattern)) { pattern = "{1} [{0}]"; }//w ww . j a va 2 s. co m MessageFormat fmt = new MessageFormat(pattern); return StringUtils.trimToEmpty( fmt.format(new Object[] { StringUtils.trimToEmpty(login), StringUtils.trimToEmpty(name) })); }
From source file:it.jnrpe.plugin.CCheckOracle.java
/** * Checks database usage//from w w w.ja v a 2 s. c o m * @param c * @param cl * @return */ private CReturnValue checkTablespace(Connection c, CCommandLine cl) { // Integer iWarning = new Integer(cl.getOptionValue("warning", "70")); // Integer iCritical = new Integer(cl.getOptionValue("critical", "80")); String sWarning = cl.getOptionValue("warning", "70"); String sCritical = cl.getOptionValue("critical", "80"); String sTablespace = cl.getOptionValue("tablespace").toUpperCase(); String sQry = "select NVL(b.free,0.0),a.total,100 - trunc(NVL(b.free,0.0)/a.total * 1000) / 10 prc" + " from (" + " select tablespace_name,sum(bytes)/1024/1024 total" + " from dba_data_files group by tablespace_name) A" + " LEFT OUTER JOIN" + " ( select tablespace_name,sum(bytes)/1024/1024 free" + " from dba_free_space group by tablespace_name) B" + " ON a.tablespace_name=b.tablespace_name WHERE a.tablespace_name='" + sTablespace + "'"; Statement stmt = null; ResultSet rs = null; try { stmt = c.createStatement(); rs = stmt.executeQuery(sQry); boolean bFound = rs.next(); if (!bFound) return new CReturnValue(IJNRPEConstants.STATE_UNKNOWN, "CHECK_ORACLE : UNKNOWN - Tablespace " + cl.getOptionValue("tablespace") + " do not exist?"); BigDecimal ts_free = rs.getBigDecimal(1); BigDecimal ts_total = rs.getBigDecimal(2); BigDecimal ts_pct = rs.getBigDecimal(3); String sMsg = "{0} : {1} {2} - {3,number,0.#}% used [ {4,number,0.#} / {5,number,0.#} MB available ]|{1}={3,number,0.#}%;{6};{7};0;100"; Object[] vObjs = new Object[8]; vObjs[0] = cl.getOptionValue("db"); vObjs[1] = cl.getOptionValue("tablespace"); vObjs[2] = "OK"; vObjs[3] = ts_pct; vObjs[4] = ts_free; vObjs[5] = ts_total; vObjs[6] = sWarning; vObjs[7] = sCritical; MessageFormat mf = new MessageFormat(sMsg); //if (ts_pct.compareTo(new BigDecimal(iCritical.intValue())) == 1) if (ThresholdUtil.isValueInRange(sCritical, ts_pct)) { vObjs[2] = "CRITICAL"; CReturnValue rv = new CReturnValue(IJNRPEConstants.STATE_CRITICAL, mf.format(vObjs)); return rv; } if (ThresholdUtil.isValueInRange(sWarning, ts_pct)) { vObjs[2] = "WARNING"; CReturnValue rv = new CReturnValue(IJNRPEConstants.STATE_WARNING, mf.format(vObjs)); return rv; } CReturnValue rv = new CReturnValue(IJNRPEConstants.STATE_OK, mf.format(vObjs)); return rv; } catch (Exception e) { return new CReturnValue(IJNRPEConstants.STATE_CRITICAL, "CHECK_ORACLE : CRITICAL - " + e.getMessage()); } finally { try { stmt.close(); rs.close(); } catch (Exception e) { } } }
From source file:it.cnr.icar.eric.client.ui.swing.metal.MetalThemeMenu.java
/** * Updates the UI strings based on the current locale. *//*from w w w . j a v a 2 s .c o m*/ protected void updateText() { for (int i = 0; i < getItemCount(); i++) { JMenuItem item = getItem(i); // item is null if there is a JSeparator at that position. if (item != null) { String itemName = item.getName(); String themeName; try { themeName = themeNames.getString(itemName); } catch (MissingResourceException mre) { themeName = itemName; Object[] noResourceArgs = { itemName, getLocale() }; MessageFormat form = new MessageFormat(themeNames.getString("message.error.noResource")); log.error(form.format(noResourceArgs)); } item.setText(themeName); } } }
From source file:com.microsoft.sqlserver.jdbc.SQLServerColumnEncryptionAzureKeyVaultProvider.java
/** * This function uses the asymmetric key specified by the key path and decrypts an encrypted CEK with RSA encryption algorithm. * //from w ww. j a v a2 s .co m * @param masterKeyPath * - Complete path of an asymmetric key in AKV * @param encryptionAlgorithm * - Asymmetric Key Encryption Algorithm * @param encryptedColumnEncryptionKey * - Encrypted Column Encryption Key * @return Plain text column encryption key */ @Override public byte[] decryptColumnEncryptionKey(String masterKeyPath, String encryptionAlgorithm, byte[] encryptedColumnEncryptionKey) throws SQLServerException { // Validate the input parameters this.ValidateNonEmptyAKVPath(masterKeyPath); if (null == encryptedColumnEncryptionKey) { throw new SQLServerException(SQLServerException.getErrString("R_NullEncryptedColumnEncryptionKey"), null); } if (0 == encryptedColumnEncryptionKey.length) { throw new SQLServerException(SQLServerException.getErrString("R_EmptyEncryptedColumnEncryptionKey"), null); } // Validate encryptionAlgorithm encryptionAlgorithm = this.validateEncryptionAlgorithm(encryptionAlgorithm); // Validate whether the key is RSA one or not and then get the key size int keySizeInBytes = getAKVKeySize(masterKeyPath); // Validate and decrypt the EncryptedColumnEncryptionKey // Format is // version + keyPathLength + ciphertextLength + keyPath + ciphertext + signature // // keyPath is present in the encrypted column encryption key for identifying the original source of the asymmetric key pair and // we will not validate it against the data contained in the CMK metadata (masterKeyPath). // Validate the version byte if (encryptedColumnEncryptionKey[0] != firstVersion[0]) { MessageFormat form = new MessageFormat( SQLServerException.getErrString("R_InvalidEcryptionAlgorithmVersion")); Object[] msgArgs = { String.format("%02X ", encryptedColumnEncryptionKey[0]), String.format("%02X ", firstVersion[0]) }; throw new SQLServerException(this, form.format(msgArgs), null, 0, false); } // Get key path length int currentIndex = firstVersion.length; short keyPathLength = convertTwoBytesToShort(encryptedColumnEncryptionKey, currentIndex); // We just read 2 bytes currentIndex += 2; // Get ciphertext length short cipherTextLength = convertTwoBytesToShort(encryptedColumnEncryptionKey, currentIndex); currentIndex += 2; // Skip KeyPath // KeyPath exists only for troubleshooting purposes and doesnt need validation. currentIndex += keyPathLength; // validate the ciphertext length if (cipherTextLength != keySizeInBytes) { MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_AKVKeyLengthError")); Object[] msgArgs = { cipherTextLength, keySizeInBytes, masterKeyPath }; throw new SQLServerException(this, form.format(msgArgs), null, 0, false); } // Validate the signature length int signatureLength = encryptedColumnEncryptionKey.length - currentIndex - cipherTextLength; if (signatureLength != keySizeInBytes) { MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_AKVSignatureLengthError")); Object[] msgArgs = { signatureLength, keySizeInBytes, masterKeyPath }; throw new SQLServerException(this, form.format(msgArgs), null, 0, false); } // Get ciphertext byte[] cipherText = new byte[cipherTextLength]; System.arraycopy(encryptedColumnEncryptionKey, currentIndex, cipherText, 0, cipherTextLength); currentIndex += cipherTextLength; // Get signature byte[] signature = new byte[signatureLength]; System.arraycopy(encryptedColumnEncryptionKey, currentIndex, signature, 0, signatureLength); // Compute the hash to validate the signature byte[] hash = new byte[encryptedColumnEncryptionKey.length - signature.length]; System.arraycopy(encryptedColumnEncryptionKey, 0, hash, 0, encryptedColumnEncryptionKey.length - signature.length); MessageDigest md = null; try { md = MessageDigest.getInstance("SHA-256"); } catch (NoSuchAlgorithmException e) { throw new SQLServerException(SQLServerException.getErrString("R_NoSHA256Algorithm"), null); } md.update(hash); byte dataToVerify[] = md.digest(); if (null == dataToVerify) { throw new SQLServerException(SQLServerException.getErrString("R_HashNull"), null); } // Validate the signature if (!AzureKeyVaultVerifySignature(dataToVerify, signature, masterKeyPath)) { MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_CEKSignatureNotMatchCMK")); Object[] msgArgs = { masterKeyPath }; throw new SQLServerException(this, form.format(msgArgs), null, 0, false); } // Decrypt the CEK byte[] decryptedCEK = this.AzureKeyVaultUnWrap(masterKeyPath, encryptionAlgorithm, cipherText); return decryptedCEK; }