List of usage examples for java.text MessageFormat MessageFormat
public MessageFormat(String pattern)
From source file:org.pentaho.platform.plugin.action.deprecated.UtilityComponent.java
private boolean executeFormatAction(final FormatMsgAction formatMsgAction) { boolean result = true; String formatString = formatMsgAction.getFormatString().getStringValue(); IActionOutput actionOutput = formatMsgAction.getOutputString(); IActionInput[] msgInputs = formatMsgAction.getMsgInputs(); ArrayList formatArgs = new ArrayList(); for (IActionInput element : msgInputs) { formatArgs.add(element.getStringValue()); }// w w w . j ava 2s . c om try { MessageFormat mf = new MessageFormat(formatString); String theResult = mf.format(formatArgs.toArray()); if (actionOutput != null) { actionOutput.setValue(theResult); } } catch (Exception ex) { result = false; } return result; }
From source file:com.xpn.xwiki.XWikiException.java
@Override public String getMessage() { StringBuilder buffer = new StringBuilder(); buffer.append("Error number "); buffer.append(getCode());//from w w w . ja va2s . c om buffer.append(" in "); buffer.append(getModuleName()); String message = super.getMessage(); if (message != null) { buffer.append(": "); if (this.args == null) { buffer.append(message); } else { MessageFormat msgFormat = new MessageFormat(message); try { buffer.append(msgFormat.format(this.args)); } catch (Exception e) { buffer.append("Cannot format message [" + message + "] with args "); for (int i = 0; i < this.args.length; i++) { if (i != 0) { buffer.append(","); } buffer.append(this.args[i]); } } } } return buffer.toString(); }
From source file:org.jahia.ajax.gwt.helper.StubHelper.java
private List<GWTJahiaValueDisplayBean> fillResources(String fileType, Locale uiLocale, Map<String, Set<String>> availableResources) { List<GWTJahiaValueDisplayBean> snippetsByType; snippetsByType = new ArrayList<GWTJahiaValueDisplayBean>(); for (Map.Entry<String, String> resourceSnippetEntry : getCodeSnippets(fileType, "resources", null) .entrySet()) {/*from www . j a v a 2 s . c om*/ MessageFormat labelTemplate = null; for (Map.Entry<String, Set<String>> resourcesEntry : availableResources.entrySet()) { for (String resource : resourcesEntry.getValue()) { String resourceSnippet = StringUtils.replace( StringUtils.replace(resourceSnippetEntry.getValue(), "__resource__", resource), "__resourceType__", resourcesEntry.getKey()); if (null == labelTemplate) { labelTemplate = new MessageFormat( getLabelTemplate(fileType, "resources", resourceSnippetEntry.getKey(), uiLocale)); } snippetsByType.add(new GWTJahiaValueDisplayBean(resourceSnippet, labelTemplate.format(new String[] { resource }))); } } } return snippetsByType; }
From source file:com.xorcode.andtweet.PreferencesActivity.java
protected void showListPreference(String keyPreference, int keysR, int displayR, int summaryR) { String displayParm = ""; ListPreference lP = (ListPreference) findPreference(keyPreference); if (lP != null) { String[] k = getResources().getStringArray(keysR); String[] d = getResources().getStringArray(displayR); displayParm = d[0];//from w w w .ja va 2 s . c o m String listValue = lP.getValue(); for (int i = 0; i < k.length; i++) { if (listValue.equals(k[i])) { displayParm = d[i]; break; } } } else { displayParm = keyPreference + " was not found"; } MessageFormat sf = new MessageFormat(getText(summaryR).toString()); lP.setSummary(sf.format(new Object[] { displayParm })); }
From source file:org.web4thejob.web.zbox.PropertyBox.java
public void initFormat() { try {/* ww w .j a v a2 s .c o m*/ if (renderElement != null && renderElement.getFormat() != null) { formatter = new MessageFormat(""); formatter.setLocale(CoreUtil.getUserLocale()); formatter.applyPattern("{0," + renderElement.getFormat() + "}"); } else { formatter = null; } } catch (Exception e) { e.printStackTrace(); formatter = null; } }
From source file:libepg.ts.packet.TsPacket.java
/** * adaptation_field_control()// w w w .j av a2 s.co m * * @return ????? * @throws IllegalStateException ????(0,1,2,3)???? */ public synchronized ADAPTATION_FIELD_CONTROL getAdaptation_field_control() throws IllegalStateException { int temp; temp = ByteConverter.byteToInt(this.data.getData()[3]); temp = temp & 0x30; temp = temp >>> 4; switch (temp) { case 0: return TsPacket.ADAPTATION_FIELD_CONTROL.RESERVED; case 1: return TsPacket.ADAPTATION_FIELD_CONTROL.ONLY_PAYLOAD; case 2: return TsPacket.ADAPTATION_FIELD_CONTROL.ONLY_ADAPTATION_FIELD; case 3: return TsPacket.ADAPTATION_FIELD_CONTROL.BOTH_EXIST; } MessageFormat msg = new MessageFormat( "?????={0}"); Object[] parameters = { temp }; throw new IllegalStateException(msg.format(parameters)); }
From source file:net.sourceforge.fenixedu.presentationTier.Action.vigilancy.ConvokeManagement.java
public ActionForward confirmConvokes(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { Boolean havingVigilantsThatAreTeachers = false; ConvokeBean beanWithTeachers = null; if (RenderUtils.getViewState("selectVigilantsThatAreTeachers") != null) { beanWithTeachers = (ConvokeBean) RenderUtils.getViewState("selectVigilantsThatAreTeachers") .getMetaObject().getObject(); }/* www. j ava2 s .com*/ ConvokeBean beanWithVigilants = (ConvokeBean) RenderUtils.getViewState("selectVigilants").getMetaObject() .getObject(); ConvokeBean beanWithUnavailables = (ConvokeBean) RenderUtils .getViewState("selectVigilantsThatAreUnavailable").getMetaObject().getObject(); List<VigilantWrapper> teachers = null; List<VigilantWrapper> vigilants, unavailables; if (RenderUtils.getViewState("selectVigilantsThatAreTeachers") != null) { teachers = beanWithTeachers.getSelectedTeachers(); } vigilants = beanWithVigilants.getVigilants(); unavailables = beanWithUnavailables.getSelectedUnavailableVigilants(); String convokedVigilants = beanWithVigilants.getTeachersAsString(); String teachersVigilancies = null; if (RenderUtils.getViewState("selectVigilantsThatAreTeachers") != null) { teachersVigilancies = beanWithTeachers.getVigilantsAsString(); vigilants.addAll(teachers); } else { teachersVigilancies = RenderUtils.getResourceString("VIGILANCY_RESOURCES", "label.vigilancy.noone"); } vigilants.addAll(unavailables); beanWithVigilants.setVigilants(vigilants); String email = RenderUtils.getResourceString("VIGILANCY_RESOURCES", "label.vigilancy.emailConvoke"); MessageFormat format = new MessageFormat(email); WrittenEvaluation evaluation = beanWithVigilants.getWrittenEvaluation(); DateTime beginDate = evaluation.getBeginningDateTime(); String date = beginDate.getDayOfMonth() + "/" + beginDate.getMonthOfYear() + "/" + beginDate.getYear(); String minutes = String.format("%02d", new Object[] { beginDate.getMinuteOfHour() }); Object[] args = { evaluation.getFullName(), date, beginDate.getHourOfDay(), minutes, beanWithVigilants.getRoomsAsString(), teachersVigilancies, convokedVigilants, beanWithVigilants.getSelectedVigilantGroup().getRulesLink() }; beanWithVigilants.setEmailMessage(format.format(args)); request.setAttribute("bean", beanWithVigilants); return mapping.findForward("confirmConvokes"); }
From source file:org.springframework.cloud.deployer.resource.maven.MavenArtifactResolver.java
/** * Resolve an artifact and return its location in the local repository. Aether performs the normal * Maven resolution process ensuring that the latest update is cached to the local repository. * In addition, if the {@link MavenProperties#resolvePom} flag is <code>true</code>, * the POM is also resolved and cached.//from ww w. j a v a 2 s . c o m * @param resource the {@link MavenResource} representing the artifact * @return a {@link FileSystemResource} representing the resolved artifact in the local repository * @throws IllegalStateException if the artifact does not exist or the resolution fails */ Resource resolve(MavenResource resource) { Assert.notNull(resource, "MavenResource must not be null"); validateCoordinates(resource); RepositorySystemSession session = newRepositorySystemSession(this.repositorySystem, this.properties.getLocalRepository()); ArtifactResult resolvedArtifact; try { List<ArtifactRequest> artifactRequests = new ArrayList<>(2); if (properties.isResolvePom()) { artifactRequests.add( new ArtifactRequest(toPomArtifact(resource), this.remoteRepositories, JavaScopes.RUNTIME)); } artifactRequests .add(new ArtifactRequest(toJarArtifact(resource), this.remoteRepositories, JavaScopes.RUNTIME)); List<ArtifactResult> results = this.repositorySystem.resolveArtifacts(session, artifactRequests); resolvedArtifact = results.get(results.size() - 1); } catch (ArtifactResolutionException e) { ChoiceFormat pluralizer = new ChoiceFormat(new double[] { 0d, 1d, ChoiceFormat.nextDouble(1d) }, new String[] { "repositories: ", "repository: ", "repositories: " }); MessageFormat messageFormat = new MessageFormat( "Failed to resolve MavenResource: {0}. Configured remote {1}: {2}"); messageFormat.setFormat(1, pluralizer); String repos = properties.getRemoteRepositories().isEmpty() ? "none" : StringUtils.collectionToDelimitedString(properties.getRemoteRepositories().keySet(), ",", "[", "]"); throw new IllegalStateException(messageFormat .format(new Object[] { resource, properties.getRemoteRepositories().size(), repos }), e); } return toResource(resolvedArtifact); }
From source file:net.jcreate.e3.table.message.AbstractMessageSource.java
/** * Create a MessageFormat for the given message and Locale. * <p>This implementation creates an empty MessageFormat first, * populating it with Locale and pattern afterwards, to stay * compatible with J2SE 1.3./* www .java 2 s. c o m*/ * @param msg the message to create a MessageFormat for * @param locale the Locale to create a MessageFormat for * @return the MessageFormat instance */ protected MessageFormat createMessageFormat(String msg, Locale locale) { if (logger.isDebugEnabled()) { logger.debug("Creating MessageFormat for pattern [" + msg + "] and locale '" + locale + "'"); } MessageFormat messageFormat = new MessageFormat(""); messageFormat.setLocale(locale); if (msg != null) { messageFormat.applyPattern(msg); } return messageFormat; }
From source file:ninja.text.TextImpl.java
@Override public Text format(Object... args) { return Text.of(new MessageFormat(data.toString()).format(args)); }