List of usage examples for java.text MessageFormat format
public final String format(Object obj)
From source file:libepg.epg.section.descriptor.DESCRIPTOR_TAG.java
private DESCRIPTOR_TAG(String tagName, Class<? extends Descriptor> dataType, Integer tag, Integer... tags) { this.tagName = tagName; if ((this.tagName == null) || ("".equals(this.tagName))) { throw new IllegalArgumentException("???????????"); }/*from w w w . j a v a 2s.c om*/ List<Integer> t = new ArrayList<>(); if (tag != null) { t.add(tag); } else { throw new NullPointerException("??????"); } if (tags != null) { t.addAll(Arrays.asList(tags)); } Range<Integer> r = Range.between(0x0, 0xFF); for (Integer i : t) { if (!r.contains(i)) { MessageFormat msg = new MessageFormat("????={0}"); Object[] parameters = { Integer.toHexString(i) }; throw new IllegalArgumentException(msg.format(parameters)); } } Set<Integer> temp = Collections.synchronizedSet(new HashSet<Integer>()); temp.addAll(t); this.tags = Collections.unmodifiableSet(temp); this.dataType = dataType; }
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());//w w w.j a v a 2s. com // 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:es.urjc.mctwp.service.Command.java
/** * This method get the appropriate message template and applies arguments to * generate a valid localized message./*from w w w . j a v a 2s . co m*/ * * @param arguments * @param template */ protected void createLogComment(String template, Object... arguments) { MessageFormat formatter = new MessageFormat(""); formatter.applyPattern(messages.getString(template)); logComment = formatter.format(arguments); }
From source file:es.urjc.mctwp.service.Command.java
/** * This method get the appropriate message template and applies arguments to * generate a valid localized message./*from ww w. j a v a 2 s.c o m*/ * * @param arguments * @param template */ protected void createUserComment(String template, Object... arguments) { MessageFormat formatter = new MessageFormat(""); formatter.applyPattern(messages.getString(template)); userComment = formatter.format(arguments); }
From source file:com.github.jknack.handlebars.helper.I18nHelper.java
@Override public String message(final String key, final Locale locale, final Object... args) { isTrue(bundle.containsKey(key), "no message found: '%s' for locale '%s'.", key, locale); String message = bundle.getString(key); if (args.length == 0) { return message; }//from w w w. j a v a 2 s . c om MessageFormat format = new MessageFormat(message, locale); return format.format(args); }
From source file:libepg.ts.aligner.Alligner2.java
/** * ?PID?????/*from w w w . j a va 2 s.c o m*/ * * @param pid ?PID * @param packets ? * @throws IllegalArgumentException ?pid?????? */ public Alligner2(int pid, List<TsPacket> packets) throws IllegalArgumentException { this.pid = pid; if (!TsPacket.PID_RANGE.contains(this.pid)) { MessageFormat msg = new MessageFormat( "PID(ID)?????={0} ?={1} ?={2}"); Object[] parameters = { this.pid, TsPacket.PID_RANGE.getMinimum(), TsPacket.PID_RANGE.getMaximum() }; throw new IllegalArgumentException(msg.format(parameters)); } this.packets = new ArrayList<>(); this.packets.addAll(packets); }
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)); }/*w ww . j av a 2 s .c o m*/ }
From source file:edu.emory.cci.aiw.cvrg.eureka.services.resource.DataElementResource.java
private void deleteFailed(List<String> dataElementsUsedIn, DataElementEntity proposition) throws HttpStatusException { String dataElementList;/* w w w .j av a2 s . com*/ int size = dataElementsUsedIn.size(); if (size > 1) { List<String> subList = dataElementsUsedIn.subList(0, dataElementsUsedIn.size() - 1); dataElementList = StringUtils.join(subList, ", ") + " and " + dataElementsUsedIn.get(size - 1); } else { dataElementList = dataElementsUsedIn.get(0); } MessageFormat usedByOtherDataElements = new MessageFormat( messages.getString("dataElementResource.delete.error.usedByOtherDataElements")); String msg = usedByOtherDataElements .format(new Object[] { proposition.getDisplayName(), dataElementsUsedIn.size(), dataElementList }); throw new HttpStatusException(Response.Status.PRECONDITION_FAILED, msg); }
From source file:org.pentaho.reporting.libraries.pensol.vfs.LocalFileModel.java
public void createFolder(final FileName file) throws FileSystemException { final String[] fileName = computeFileNames(file); if (fileName.length < 2) { throw new FileSystemException("Cannot create directory in the root."); }/* w ww .ja v a2 s .c om*/ final String[] parentPath = new String[fileName.length - 1]; System.arraycopy(fileName, 0, parentPath, 0, parentPath.length); final FileInfo fileInfo = lookupNode(parentPath); if (fileInfo == null) { throw new FileSystemException("Cannot locate parent directory."); } try { final String solution = fileName[0]; final String path = buildPath(fileName, 1, fileName.length - 1); final String name = fileName[fileName.length - 1]; String description = getDescriptionEntries().get(file); if (description == null) { description = ""; } final Configuration config = LibPensolBoot.getInstance().getGlobalConfig(); final String urlMessage = config .getConfigProperty("org.pentaho.reporting.libraries.pensol.web.CreateNewFolder"); final MessageFormat fmt = new MessageFormat(urlMessage); final String fullpath = fmt .format(new Object[] { URLEncoder.encode(solution, "UTF-8"), URLEncoder.encode(path, "UTF-8"), URLEncoder.encode(name, "UTF-8"), URLEncoder.encode(description, "UTF-8") }); URI uri; String baseUrl = url + fullpath; try { URIBuilder builder = new URIBuilder(baseUrl); logger.debug("Connecting to '" + baseUrl + '\''); if (username != null) { builder.setParameter("user", username); } if (password != null) { builder.setParameter("password", password); } uri = builder.build(); } catch (URISyntaxException e) { throw new FileSystemException("Provided URL is invalid: " + baseUrl); } final HttpPost filePost = new HttpPost(uri); filePost.setHeader("Content-Type", "application/x-www-form-urlencoded; charset=utf-8"); HttpResponse httpResponse = client.execute(filePost, context); final int lastStatus = httpResponse.getStatusLine().getStatusCode(); if (lastStatus != HttpStatus.SC_OK) { throw new FileSystemException("Server error: HTTP status code " + lastStatus); } if (name == null) { throw new FileSystemException("Error creating folder: Empty name"); } new FileInfo(fileInfo, name, description); } catch (FileSystemException fse) { throw fse; } catch (IOException ioe) { throw new FileSystemException("Failed", ioe); } }
From source file:com.krawler.common.locale.MessageSourceSupport.java
protected String formatMessage(String msg, Object[] args, Locale locale) { if (msg == null || (!this.alwaysUseMessageFormat && (args == null || args.length == 0))) { return msg; }/* ww w . ja v a 2s . c o m*/ MessageFormat messageFormat; synchronized (this.cachedMessageFormats) { messageFormat = this.cachedMessageFormats.get(msg); if (messageFormat == null) { messageFormat = createMessageFormat(msg, locale); this.cachedMessageFormats.put(msg, messageFormat); } } synchronized (messageFormat) { return messageFormat.format(resolveArguments(args, locale)); } }