List of usage examples for java.text MessageFormat MessageFormat
public MessageFormat(String pattern)
From source file:libepg.epg.section.TABLE_ID.java
private TABLE_ID(String tableName, MAX_SECTION_LENGTH maxSectionLength, Class<? extends SectionBody> dataType, Integer tableID, Integer... tableIDs) { this.tableName = tableName; if ((this.tableName == null) || ("".equals(this.tableName))) { throw new IllegalArgumentException("???????????"); }//from www .j a va 2 s . c om List<Integer> t = new ArrayList<>(); if (tableID != null) { t.add(tableID); } else { throw new NullPointerException("ID??????"); } if (tableIDs != null) { t.addAll(Arrays.asList(tableIDs)); } Range<Integer> r = Range.between(0x0, 0xFF); for (Integer i : t) { if (!r.contains(i)) { MessageFormat msg = new MessageFormat( "ID????ID={0}"); Object[] parameters = { Integer.toHexString(i) }; throw new IllegalArgumentException(msg.format(parameters)); } } Set<Integer> temp = Collections.synchronizedSet(new HashSet<Integer>()); temp.addAll(t); this.tableIDs = Collections.unmodifiableSet(temp); this.dataType = dataType; this.maxSectionLength = maxSectionLength; }
From source file:libepg.epg.section.sectionreconstructor.PayLoadSplitter.java
private synchronized void dumpMap(Map<PayLoadSplitter.PAYLOAD_PART_KEY, byte[]> t_map) { if (LOG.isTraceEnabled() && PayLoadSplitter.CLASS_LOG_OUTPUT_MODE == true) { StringBuilder s = new StringBuilder(); s.append("?["); MessageFormat msg1 = new MessageFormat("={0} ?={1}"); Set<PayLoadSplitter.PAYLOAD_PART_KEY> keys = t_map.keySet(); for (PayLoadSplitter.PAYLOAD_PART_KEY key : keys) { Object[] parameters1 = { key, Hex.encodeHexString(t_map.get(key)) }; s.append(msg1.format(parameters1)); }//from w w w.j ava 2s . c o m s.append("]"); LOG.trace(s.toString()); } }
From source file:libepg.ts.packet.TsPacket.java
/** * transport_priority(?) ??PID????????1?? * * @return//from w w w.ja va 2s .c om * @throws IllegalStateException ????(0,1)???? */ public synchronized int getTransport_priority() throws IllegalStateException { int temp; temp = ByteConverter.byteToInt(this.data.getData()[1]); temp = temp & 0x20; temp = temp >>> 5; 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:org.pentaho.platform.plugin.action.deprecated.UtilityComponent.java
/** * @deprecated//from w ww . j av a2 s . c o m */ @Deprecated private boolean executeFormatAction(final Element componentDefinition) { String formatString = componentDefinition.element("format-string").getText(); //$NON-NLS-1$ String outputName = null; Element element = componentDefinition.element("return"); //$NON-NLS-1$ if (element != null) { outputName = element.getText(); } ArrayList formatArgs = new ArrayList(); List paramList = componentDefinition.selectNodes("arg"); //$NON-NLS-1$ for (Iterator it = paramList.iterator(); it.hasNext();) { formatArgs.add(((Node) it.next()).getText()); } boolean result = true; try { MessageFormat mf = new MessageFormat(formatString); String theResult = mf.format(formatArgs.toArray()); tmpOutputs.put(outputName, theResult); } catch (Exception e) { error(Messages.getInstance().getString("UtilityComponent.ERROR_0001_FORMAT_ERROR")); //$NON-NLS-1$ result = false; } return result; }
From source file:org.apache.roller.weblogger.business.plugins.entry.TopicTagPlugin.java
/** * Initialize the plugin instance. This sets up the configurable properties and default topic site. * // ww w .j a va 2 s .c o m * @param rreq Plugins may need to access RollerRequest. * @param ctx Plugins may place objects into the Velocity Context. * @see PagWeblogEntryPluginit(org.apache.roller.weblogger.presentation.RollerRequest, org.apache.velocity.context.Context) */ public void init(Weblog website) throws WebloggerException { if (mLogger.isDebugEnabled()) { mLogger.debug("TopicTagPlugin v. " + version); } // Initialize property settings initializeProperties(); // Build map of the user's bookmarks userBookmarks = buildBookmarkMap(website); // Determine default topic site from bookmark if present WeblogBookmark defaultTopicBookmark = (WeblogBookmark) userBookmarks.get(defaultTopicBookmarkName); if (defaultTopicBookmark != null) defaultTopicSite = defaultTopicBookmark.getUrl(); // Append / to defaultTopicSite if it doesn't have it if (!defaultTopicSite.endsWith("/")) { defaultTopicSite += "/"; } // Compile patterns and make sure they have the correct number of matching groups in them. try { tagPatternWithBookmark = Pattern.compile(tagRegexWithBookmark); } catch (PatternSyntaxException e) { throw new WebloggerException("Invalid regular expression for topic tags with bookmark '" + tagRegexWithBookmark + "': " + e.getMessage()); } int groupCount = tagPatternWithBookmark.matcher("").groupCount(); if (groupCount != 2) { throw new WebloggerException("Regular expression for topic tags with bookmark '" + tagRegexWithBookmark + "' contains wrong number of capture groups. Must have exactly 2. Contains " + groupCount); } try { tagPatternWithoutBookmark = Pattern.compile(tagRegexWithoutBookmark); } catch (PatternSyntaxException e) { throw new WebloggerException("Invalid regular expression for topic tags without bookmark '" + tagRegexWithoutBookmark + "': " + e.getMessage()); } groupCount = tagPatternWithoutBookmark.matcher("").groupCount(); if (groupCount != 1) { throw new WebloggerException("Regular expression for topic tags without bookmark '" + tagRegexWithoutBookmark + "' contains wrong number of capture groups. Must have exactly 1. Contains " + groupCount); } // Create link format from format string setLinkFormat(new MessageFormat(linkFormatString)); }
From source file:org.apache.manifoldcf.core.i18n.Messages.java
/** Obtain a string given a class, bundle, locale, message key, and arguments. *//* w w w. j a va 2 s .c o m*/ public static String getString(Class clazz, String bundleName, Locale locale, String messageKey, Object[] args) { String message = getMessage(clazz, bundleName, locale, messageKey); if (message == null) return messageKey; // Format the message String formatMessage; if (args != null) { MessageFormat fm = new MessageFormat(message); fm.setLocale(locale); formatMessage = fm.format(args); } else { formatMessage = message; } return formatMessage; }
From source file:nl.toolforge.karma.core.vc.cvsimpl.CVSRepository.java
public StringBuffer asXML(int leftIndent) { StringBuffer buffer = new StringBuffer(); MessageFormat formatter = new MessageFormat("<loc:location type=\"{0}\" id=\"{1}\">\n" + " <loc:protocol>{2}</loc:protocol>\n" + " <loc:host>{3}</loc:host>\n" + " <loc:port>{4}</loc:port>\n" + " <loc:repository>{5}</loc:repository>\n" + " <loc:module-offset>{6}</loc:module-offset>\n" + "</loc:location>\n"); buffer.append(formatter.format(new String[] { getType().toString(), getId(), getProtocol(), (getHost() == null ? "" : getHost()), "" + (getPort() == -1 ? "" : "" + getPort()), getRepository(), (getModuleOffset() == null ? "" : getModuleOffset()) })); return buffer; }
From source file:com.jaspersoft.jasperserver.war.themes.ThemeCache.java
private HierarchicalTheme createTheme(String tenantQualifiedThemeName) { String sep = configurationBean.getUserNameSeparator(); int sepPos = tenantQualifiedThemeName.indexOf(sep); String themeName = (sepPos > 0) ? tenantQualifiedThemeName.substring(0, sepPos) : tenantQualifiedThemeName; String themeFolder = configurationBean.getThemeFolderName() + "/" + themeName; if (sepPos > 0) { // tenant theme String tenantId = tenantQualifiedThemeName.substring(sepPos + 1); Tenant tenant = tenantService.getTenant(null, tenantId); String tenantFolder = tenant.getTenantFolderUri(); themeFolder = tenantFolder + themeFolder; }/* w w w .j a v a 2 s . c o m*/ FilterCriteria filterCriteria = FilterCriteria.createFilter(FileResource.class); filterCriteria.addFilterElement(FilterCriteria.createAncestorFolderFilter(themeFolder)); ExecutionContext executionContext = JasperServerUtil.getExecutionContext(); ResourceLookup[] lookups = repositoryService.findResource(executionContext, filterCriteria); final String uid = getNewUID(); ThemeMessageSource themeMessageSource = new ThemeMessageSource(); if (lookups != null) { int k = themeFolder.length() + 1; for (int i = 0; i < lookups.length; i++) { ResourceLookup rlu = lookups[i]; String relPath = rlu.getURIString().substring(k); Date lastModified = rlu.getUpdateDate(); FileResourceData frd = repositoryService.getResourceData(executionContext, rlu.getURIString()); byte[] data = frd.getData(); ThemeResource themeResource = new ThemeResource(lastModified, data); String webLink = configurationBean.getThemeServletPrefix() + "/" + uid + "/" + relPath; resourceMap.put(webLink, themeResource); themeMessageSource.addMessage(relPath, webLink); } } HierarchicalTheme theme = new RepositoryFolderTheme(tenantQualifiedThemeName, null, new AbstractMessageSource() { @Override protected MessageFormat resolveCode(String code, Locale locale) { return new MessageFormat( configurationBean.getThemeServletPrefix() + "/" + uid + "/" + code); } }); themeMap.put(tenantQualifiedThemeName, theme); uid2name.put(uid, tenantQualifiedThemeName); name2uid.put(tenantQualifiedThemeName, uid); return theme; }
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;//from w ww. j a v a 2 s .c o m 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:com.github.arven.rest.schema.WebServiceTests.java
@Test public void regularMessageFormat() throws Exception { JsonNode node = mapper.readTree(// w w w . j av a2 s.com new URL("file:///C:/Users/brian.becker/Git/java-rest-schema/target/test-classes/errorpage.json")); String error = node.get("error").asText(); MessageFormat format = new MessageFormat( "{0} {1}: The server was unable to find the {3} that was requested from Article {2}"); Object[] parsed = format.parse(error); println(Arrays.asList(parsed)); Assert.assertEquals(parsed[0], "404"); Assert.assertEquals(parsed[1], "Not Found"); Assert.assertEquals(parsed[2], "123"); Assert.assertEquals(parsed[3], "Comment resource"); }