List of usage examples for java.text MessageFormat format
public final String format(Object obj)
From source file:com.microsoft.sqlserver.jdbc.SQLServerColumnEncryptionAzureKeyVaultProvider.java
/** * This function validates that the encryption algorithm is RSA_OAEP and if it is not, then throws an exception * /*from w w w.j a v a 2 s . co m*/ * @param encryptionAlgorithm * - Asymmetric key encryptio algorithm * @return The encryption algorithm that is going to be used. * @throws SQLServerException */ private String validateEncryptionAlgorithm(String encryptionAlgorithm) throws SQLServerException { if (null == encryptionAlgorithm) { throw new SQLServerException(null, SQLServerException.getErrString("R_NullKeyEncryptionAlgorithm"), null, 0, false); } // Transform to standard format (dash instead of underscore) to support both "RSA_OAEP" and "RSA-OAEP" if (encryptionAlgorithm.equalsIgnoreCase("RSA_OAEP")) { encryptionAlgorithm = "RSA-OAEP"; } if (!rsaEncryptionAlgorithmWithOAEPForAKV.equalsIgnoreCase(encryptionAlgorithm.trim())) { MessageFormat form = new MessageFormat( SQLServerException.getErrString("R_InvalidKeyEncryptionAlgorithm")); Object[] msgArgs = { encryptionAlgorithm, rsaEncryptionAlgorithmWithOAEPForAKV }; throw new SQLServerException(this, form.format(msgArgs), null, 0, false); } return encryptionAlgorithm; }
From source file:libepg.ts.packet.TsPacket.java
/** * TS???//from w ww . j av a 2 s. c o m * * @param data TS? * @throws IllegalArgumentException ?188?????? */ public TsPacket(final byte[] data) throws IllegalArgumentException { byte[] temp = Arrays.copyOf(data, data.length); if (temp.length != TsPacket.TS_PACKET_BYTE_LENGTH.PACKET_LENGTH.getByteLength()) { MessageFormat msg = new MessageFormat( "????????={0} ?={1}"); Object[] parameters = { temp.length, Hex.encodeHexString(temp) }; throw new IllegalArgumentException(msg.format(parameters)); } this.data = new ByteDataBlock(temp); }
From source file:org.wrml.runtime.format.text.html.WrmldocFormatter.java
protected String renderPage(final MessageFormat template, Object... params) throws IOException { final String renderedPage = template.format(params); return renderedPage; }
From source file:json_to_xml_1.java
private String getI10nStringFormatted(String i10nStringName, Object... arguments) { MessageFormat formatter = new MessageFormat(""); formatter.setLocale(this.getLocale()); formatter.applyPattern(getI10nString(i10nStringName)); return formatter.format(arguments); }
From source file:com.evolveum.midpoint.model.impl.validator.ResourceValidatorImpl.java
@NotNull private String getString(ResourceBundle bundle, String key, Object... parameters) { final String resolvedKey; if (key != null) { if (bundle.containsKey(key)) { resolvedKey = bundle.getString(key); } else {/*from w w w . j a v a 2 s .c o m*/ resolvedKey = key; } } else { resolvedKey = ""; } final MessageFormat format = new MessageFormat(resolvedKey, bundle.getLocale()); return format.format(parameters); }
From source file:jmemorize.gui.swing.frames.MainFrame.java
/** * If lesson was modified this shows a dialog that asks if the user wants to * save the lesson before closing it./*w ww . ja va 2 s . com*/ * * @return <code>true</code> if user chose not to cancel the lesson close * operation. If this method return <code>false</code> the closing * of jMemorize was canceled. */ public boolean allowTheUserToSaveIfClosing() { // first check the editCardFrame for unsaved changes final EditCardFrame editFrame = EditCardFrame.getInstance(); if (editFrame.isVisible() && !editFrame.close()) { return false; // user canceled closing of edit card frame } if (!m_newCardManager.closeAllFrames()) // close all addCard frames { return false; } // then see if lesson should to be saved final Lesson lesson = m_main.getLesson(); if (lesson.canSave()) { final int n = JOptionPane.showConfirmDialog(MainFrame.this, Localization.get("MainFrame.SAVE_MODIFIED"), //$NON-NLS-1$ "Warning", //$NON-NLS-1$ JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE); if (n == JOptionPane.OK_OPTION) { try { jMemorizeIO.saveLesson(lesson); jMemorizeIO.reset(); } catch (final Exception exception) { final File file = jMemorizeIO.getFile(); final Object[] args = { file != null ? file.getName() : "?" }; final MessageFormat form = new MessageFormat(Localization.get(LC.ERROR_SAVE)); final String msg = form.format(args); Main.logThrowable(msg, exception); new ErrorDialog(this, msg, exception).setVisible(true); } // if lesson was saved return true, false otherwise return !lesson.canSave(); } // if NO chosen continue, otherwise CANCEL was chosen return n == JOptionPane.NO_OPTION; } return true; }
From source file:edu.amc.sakai.user.SimpleLdapAttributeMapper.java
/** * Builds a filter of the form <login-attr>=<<code>eid</code>> *///from w ww . ja v a 2s. c o m public String getFindUserByEidFilter(String eid) { String eidAttr = attributeMappings.get(AttributeMappingConstants.LOGIN_ATTR_MAPPING_KEY); MessageFormat valueFormat = valueMappings.get(AttributeMappingConstants.LOGIN_ATTR_MAPPING_KEY); if (valueFormat == null) { return eidAttr + "=" + escapeSearchFilterTerm(eid); } else { valueFormat = (MessageFormat) valueFormat.clone(); return eidAttr + "=" + escapeSearchFilterTerm(valueFormat.format(new Object[] { eid })); } }
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 ww w.j a v a2 s.c o 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; }
From source file:edu.amc.sakai.user.SimpleLdapAttributeMapper.java
/** * Builds a filter of the form <email-attr>=<<code>emailAddr</code>> *///from www . ja v a 2 s . c o m public String getFindUserByEmailFilter(String emailAddr) { String emailAttr = attributeMappings.get(AttributeMappingConstants.EMAIL_ATTR_MAPPING_KEY); MessageFormat valueFormat = valueMappings.get(AttributeMappingConstants.EMAIL_ATTR_MAPPING_KEY); if (valueFormat == null) { return emailAttr + "=" + escapeSearchFilterTerm(emailAddr); } else { valueFormat = (MessageFormat) valueFormat.clone(); return emailAttr + "=" + escapeSearchFilterTerm(valueFormat.format(new Object[] { emailAddr })); } }
From source file:it.jnrpe.plugin.CCheckOracle.java
/** * Checks cache hit rates/*w w w . j a va 2 s . c o m*/ * @param c * @param cl * @return */ private CReturnValue checkCache(Connection c, CCommandLine cl) { String sWarning = cl.getOptionValue("warning", "70"); String sCritical = cl.getOptionValue("critical", "80"); String sQry1 = "select (1-(pr.value/(dbg.value+cg.value)))*100" + " from v$sysstat pr, v$sysstat dbg, v$sysstat cg" + " where pr.name='physical reads'" + " and dbg.name='db block gets'" + " and cg.name='consistent gets'"; String sQry2 = "select sum(lc.pins)/(sum(lc.pins)+sum(lc.reloads))*100 from v$librarycache lc"; Statement stmt = null; ResultSet rs = null; try { stmt = c.createStatement(); rs = stmt.executeQuery(sQry1); rs.next(); BigDecimal buf_hr = rs.getBigDecimal(1); rs = stmt.executeQuery(sQry2); rs.next(); BigDecimal lib_hr = rs.getBigDecimal(1); String sMessage = "{0} {1} - Cache Hit Rates: {2,number,0.#}% Lib -- {3,number,0.#}% Buff|lib={4,number,0.#}%;{5};{6};0;100 buffer={3,number,0.#};{5};{6};0;100"; MessageFormat mf = new MessageFormat(sMessage); Object[] vValues = new Object[7]; vValues[0] = cl.getOptionValue("db"); vValues[1] = "OK"; vValues[2] = lib_hr; vValues[3] = buf_hr; vValues[4] = lib_hr; vValues[5] = sWarning; vValues[6] = sCritical; //if (buf_hr.compareTo(new BigDecimal(iCritical.intValue())) == -1) if (ThresholdUtil.isValueInRange(sCritical, buf_hr)) { vValues[1] = "CRITICAL"; CReturnValue rv = new CReturnValue(IJNRPEConstants.STATE_CRITICAL, mf.format(vValues)); return rv; } //if (buf_hr.compareTo(new BigDecimal(iWarning.intValue())) == -1) if (ThresholdUtil.isValueInRange(sWarning, buf_hr)) { vValues[1] = "WARNING"; CReturnValue rv = new CReturnValue(IJNRPEConstants.STATE_WARNING, mf.format(vValues)); return rv; } CReturnValue rv = new CReturnValue(IJNRPEConstants.STATE_WARNING, mf.format(vValues)); 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) { } } }