List of usage examples for java.text MessageFormat MessageFormat
public MessageFormat(String pattern)
From source file:org.taverna.server.master.localworker.SimpleFormattedCompletionNotifier.java
/** * @param messageFormat/* w w w . ja v a 2 s .c o m*/ * The template for the body of the message to send. Parameter #0 * will be substituted with the ID of the job, and parameter #1 * will be substituted with the exit code. */ public void setMessageFormat(String messageFormat) { this.format = new MessageFormat(messageFormat); }
From source file:I18N.java
/** * Given a message and parameters, resolve all message's parameter * placeholders with the parameter value. The firstParam can change which * parameter relates to {0} placeholder in the message, and all increment * from this index. If any of the parameters also have placeholders, this * recursively calls itself to fill their placeholders, setting the * firstParam to the index following all parameters that are used by the * current message so params must be in the order p0..pN, p00..p0N..pMN, * p000..p00N..p0MN..pLMN... where each additional index is for nested * placeholders (ones in params) and assumes every message/param contains * N M L placeholders; any that don't contain placeholders can have their * pXXX.. taken out, so long as the order of remaining params don't change * @param message Message to format//from w w w . jav a 2 s.co m * @param firstParam Index of parameter that relates to {0} placeholder, * all parameters following this one relate to incrementing placeholders * @param params The parameters used to fill the placeholders * @return Message with all placeholders filled with relative parameters */ private static String formatMessage(String message, int firstParam, Object[] params) { // Only need to do any formatting if there are parameters to do the // formatting with. If there are none, the message input is returned // unmodified if (params != null && firstParam < params.length) { MessageFormat parser; Locale locale = Locale.getDefault(); Format[] formats; // Set up parser = new MessageFormat(""); parser.setLocale(locale); parser.applyPattern(message); // Used only to count how many parameters are needed by this message formats = parser.getFormatsByArgumentIndex(); // Recursively format the parameters used by this message for (int paramIndex = 0; paramIndex < formats.length; paramIndex++) if (params[firstParam + paramIndex] instanceof String) params[firstParam + paramIndex] = formatMessage(params[firstParam + paramIndex].toString(), firstParam + formats.length, params); // Format the message using the formatted parameters message = parser.format(getParams(params, firstParam, firstParam + formats.length)); } return message; }
From source file:libepg.epg.section.SectionBody.java
/** * ??????????//from w ww. ja v a 2 s. c o m * * @param sectionBody */ public SectionBody(SectionBody sectionBody) { this.tableID = sectionBody.tableID; this.data = sectionBody.data; if (this.getClass() != this.tableID.getDataType()) { MessageFormat msg1 = new MessageFormat( "??????????????={0} ?={1} ={2}"); Object[] parameters1 = { this.getClass(), this.tableID.getDataType(), Hex.encodeHexString(this.data.getData()) }; throw new IllegalArgumentException(msg1.format(parameters1)); } }
From source file:br.com.semanticwot.cd.infra.MailManager.java
public void sendNewPurchaseMail(SystemUser user, String emailTemplate) throws MessagingException { Object[] args = { user.getName(), user.getUsername() }; MessageFormat fmt = new MessageFormat(emailTemplate); MimeMessage message = mailer.createMimeMessage(); // use the true flag to indicate you need a multipart message MimeMessageHelper helper = new MimeMessageHelper(message, true); // use the true flag to indicate the text included is HTML helper.setText(fmt.format(args), true); System.out.println("Passei por aqui " + user.getUsername()); //SimpleMailMessage email = new SimpleMailMessage(); helper.setFrom(user.getUsername());//from ww w.jav a 2 s . c om // Somente por enquanto, que esta em teste. // Em producao mudar para helper.setTo(user.getLogin()); helper.setTo("notlian.junior@gmail.com"); helper.setSubject("PSWoT Register"); mailer.send(message); }
From source file:org.sipfoundry.sipxconfig.alarm.AlarmConfigurationTest.java
@Test public void testGenerateAlarmServer() throws Exception { AlarmConfiguration c = new AlarmConfiguration(); c.setMessageSource(new AbstractMessageSource() { protected MessageFormat resolveCode(String arg0, Locale arg1) { return new MessageFormat(arg0); }//ww w .ja v a 2 s .co m }); AlarmServer server = new AlarmServer(); server.setAlarmNotificationEnabled(true); String host = "post.example.org"; StringWriter actual = new StringWriter(); AlarmGroup g1 = new AlarmGroup(); g1.setName("g1"); g1.setEmailAddresses(Arrays.asList("e1@example.org", "e2@example.org")); AlarmGroup g2 = new AlarmGroup(); g2.setName("g2"); List<AlarmGroup> groups = Arrays.asList(g1, g2); Alarm a1 = new Alarm(new AlarmDefinition("a1")); Alarm a2 = new Alarm(new AlarmDefinition("a2")); a1.setGroupName(g1.getName()); a2.setGroupName(g2.getName()); List<Alarm> alarms = Arrays.asList(a1, a2); Address smtp = new Address(MailManager.SMTP, "mail.example.org"); c.writeEmailHandlerConfig(actual, alarms, groups, server, host, smtp, Locale.ENGLISH); InputStream expected = getClass().getResourceAsStream("expected-sipxtrap-handler.yaml"); assertEquals(IOUtils.toString(expected), actual.toString()); }
From source file:org.dasein.cloud.google.GenerateToken.java
public static String getToken(String iss, String p12File) { String header = "{\"alg\":\"RS256\",\"typ\":\"JWT\"}"; String claimTemplate = "'{'\"iss\": \"{0}\", \"scope\": \"{1}\", \"aud\": \"{2}\", \"exp\": \"{3}\", \"iat\": \"{4}\"'}'"; try {//from ww w .ja v a 2 s . co m StringBuffer token = new StringBuffer(); //Encode the JWT Header and add it to our string to sign token.append(Base64.encodeBase64URLSafeString(header.getBytes("UTF-8"))); //Separate with a period token.append("."); //Create the JWT Claims Object String[] claimArray = new String[5]; claimArray[0] = iss; claimArray[1] = "https://www.googleapis.com/auth/compute"; claimArray[2] = "https://accounts.google.com/o/oauth2/token"; claimArray[3] = Long.toString((System.currentTimeMillis() / 1000) + 300); claimArray[4] = Long.toString((System.currentTimeMillis() / 1000)); MessageFormat claims; claims = new MessageFormat(claimTemplate); String payload = claims.format(claimArray); // System.out.println(claimArray[3]); // System.out.println(claimArray[4]); //Add the encoded claims object token.append(Base64.encodeBase64URLSafeString(payload.getBytes("UTF-8"))); char[] password = "notasecret".toCharArray(); FileInputStream fin = new FileInputStream(new File(p12File)); KeyStore store = KeyStore.getInstance("PKCS12"); try { store.load(fin, password); } finally { try { fin.close(); } catch (IOException e) { } } String alias = ""; // KeyStore keystore = getKeyStore(password); Enumeration<String> enum1 = store.aliases(); // List the aliases while (enum1.hasMoreElements()) { String keyStoreAlias = enum1.nextElement().toString(); if (store.isKeyEntry(keyStoreAlias)) { //Does alias refer to a private key? alias = keyStoreAlias; break; } } PrivateKey privateKey = (PrivateKey) store.getKey(alias, password); //Sign the JWT Header + "." + JWT Claims Object Signature signature = Signature.getInstance("SHA256withRSA"); signature.initSign(privateKey); signature.update(token.toString().getBytes("UTF-8")); String signedPayload = Base64.encodeBase64URLSafeString(signature.sign()); //Separate with a period token.append("."); //Add the encoded signature token.append(signedPayload); // System.out.println(token.toString()); return token.toString(); } catch (Exception e) { e.printStackTrace(); } return null; }
From source file:libepg.epg.section.descriptor.contentdescriptor.Nibble.java
Nibble(byte[] data) { this.data = new ByteDataBlock(data); int lengthFromData = this.data.getData().length; if (lengthFromData != 2) { MessageFormat msg1 = new MessageFormat( "?????????????={0} ??={1}"); Object[] parameters1 = { lengthFromData, 2 }; throw new IllegalArgumentException(msg1.format(parameters1)); }// ww w . j a v a 2 s . c om }
From source file:libepg.epg.section.descriptor.Descriptor.java
/** * ??????????//from ww w .j a v a 2 s. co m * * @param descriptor ? */ public Descriptor(Descriptor descriptor) { this.descriptorTag = descriptor.descriptorTag; if (this.getClass() != this.descriptorTag.getDataType()) { MessageFormat msg1 = new MessageFormat( "??????????????={0} ?={1} ={2}"); Object[] parameters1 = { this.getClass(), this.descriptorTag.getDataType(), Hex.encodeHexString(descriptor.getData()) }; throw new IllegalArgumentException(msg1.format(parameters1)); } this.data = descriptor.data; }
From source file:libepg.epg.util.datetime.BCD.java
public BCD(byte bcd) { high = bcd >>> 4;/* w w w . j a va 2 s.c o m*/ low = bcd & 0x0f; Object[] parameters = null; CHECK: { if (!BCD_RANGE.contains(high)) { parameters = new Object[] { Integer.toHexString(bcd), "", Integer.toHexString(bcd) }; break CHECK; } if (!BCD_RANGE.contains(low)) { parameters = new Object[] { Integer.toHexString(bcd), "", Integer.toHexString(bcd) }; break CHECK; } } if (parameters != null) { MessageFormat msg = new MessageFormat( "??????????={0} ?={1} ?????={2}"); throw new IllegalArgumentException(msg.format(parameters)); } }
From source file:com.edgenius.wiki.render.filter.UrlFilter.java
public void init() { regexProvider.compile(getRegex(), Pattern.MULTILINE); formatter = new MessageFormat(getReplacement()); }