List of usage examples for java.text MessageFormat MessageFormat
public MessageFormat(String pattern)
From source file:com.safetys.framework.jmesa.core.message.ResourceBundleMessages.java
public String getMessage(String code, Object[] args) { String result = findResource(customResourceBundle, code); if (result == null) { result = findResource(defaultResourceBundle, code); }/*from w w w .j a v a2 s . c om*/ if (result != null && args != null) { MessageFormat formatter = new MessageFormat(""); formatter.setLocale(locale); formatter.applyPattern(result); result = formatter.format(args); } return result; }
From source file:org.languagetool.rules.patterns.FalseFriendRuleHandler.java
FalseFriendRuleHandler(Language textLanguage, Language motherTongue, String falseFriendHint) { englishMessages = ResourceBundle.getBundle(JLanguageTool.MESSAGE_BUNDLE, Languages.getLanguageForShortCode("en").getLocale()); messages = ResourceBundle.getBundle(JLanguageTool.MESSAGE_BUNDLE, motherTongue.getLocale()); formatter = new MessageFormat(""); formatter.setLocale(motherTongue.getLocale()); this.textLanguage = textLanguage; this.motherTongue = motherTongue; this.falseFriendHint = falseFriendHint; }
From source file:it.cnr.icar.eric.common.security.KeyToolStripped.java
/** * Generate a public/private key pair.//from ww w. j av a2 s.com * * @throws Exception */ public static void generateKeyPair(KeyStore keyStore, char[] storePass, String alias, char[] keyPass, String dname, String keyAlg, int validity) throws Exception { int keySize = 1024; if (keyStore.containsAlias(alias)) { MessageFormat messageformat = new MessageFormat("Key pair not generated, alias <alias> already exists"); Object[] aobj = { alias }; throw new Exception(messageformat.format(((Object) (aobj)))); } String sigAlg = null; if (keyAlg.equalsIgnoreCase("DSA")) { sigAlg = "SHA1WithDSA"; } else if (keyAlg.equalsIgnoreCase("RSA")) { sigAlg = "MD5WithRSA"; } else { throw new Exception("Cannot derive signature algorithm"); } //Must specify provider "SunRsaSign" otherwise it gets some weird NSS specific provider //when running in AppServer EE. CertAndKeyGen certandkeygen = new CertAndKeyGen(keyAlg, sigAlg); X500Name x500name; if (dname == null) { throw new Exception("Key pair not generated, dname is null."); } else { x500name = new X500Name(dname); } certandkeygen.generate(keySize); PrivateKey privatekey = certandkeygen.getPrivateKey(); X509Certificate[] ax509certificate = new X509Certificate[1]; ax509certificate[0] = certandkeygen.getSelfCertificate(x500name, validity * 24 * 60 * 60); keyStore.setKeyEntry(alias, privatekey, keyPass, ax509certificate); }
From source file:com.qut.middleware.spep.authn.bindings.impl.AuthnPostBindingImpl.java
public AuthnPostBindingImpl() { try {// w w w. ja v a 2s. c o m InputStream inputStream = this.getClass().getResourceAsStream("samlPostRequestTemplate.html"); DataInputStream dataInputStream = new DataInputStream(inputStream); byte[] document = new byte[dataInputStream.available()]; dataInputStream.readFully(document); // Load the document as UTF-8 format and create a formatter for it. String samlResponseTemplate = new String(document, "UTF-8"); this.samlMessageFormat = new MessageFormat(samlResponseTemplate); this.logger.info("Created AuthnPostBindingImpl successfully"); } catch (IOException e) { throw new IllegalArgumentException("HTTP POST binding form could not be loaded due to an I/O error", e); } }
From source file:com.qut.middleware.esoe.sso.plugins.post.handler.impl.PostLogicImpl.java
public PostLogicImpl() { try {/*from w w w . j a v a2 s . co m*/ URL url = this.getClass().getResource(this.SAML_RESPONSE_TEMPLATE); if (url == null) { throw new IllegalArgumentException( "Unable to construct logic class for HTTP POST binding. URL for SAML response template was null."); } this.samlResponseTemplate = FileCopyUtils.copyToString(new InputStreamReader(url.openStream())); this.samlMessageFormat = new MessageFormat(this.samlResponseTemplate); } catch (FileNotFoundException e) { throw new IllegalArgumentException( "Unable to construct logic class for HTTP POST binding. File was not found while trying to load the SAML response template.", e); } catch (IOException e) { throw new UnsupportedOperationException( "Unable to construct logic class for HTTP POST binding. IO error occurred while trying to load the SAML response template.", e); } this.logger.info("HTTP POST binding logic initialized"); }
From source file:org.ligoj.app.plugin.vm.schedule.VmJob.java
/** * Parses text from the beginning of the given string to produce an object array. The method may not use the entire * text of the given string.//w ww. j av a2 s.c o m * <p> * See the {@link MessageFormat#parse(String, ParsePosition)} method for more information on message parsing. * * @param source * A <code>String</code> whose beginning should be parsed. * @return An <code>Object</code> array parsed from the string. {@link ParseException} is caught to return an 2 * sized array object. */ protected static Object[] parse(final String source) { try { return new MessageFormat(TRIGGER_ID_PARSER).parse(source); } catch (final ParseException e) { // Ignore the parse error log.debug("Unable to parse job source", e); return new Object[2]; } }
From source file:com.hs.mail.security.login.JndiLoginModule.java
@Override public void initialize(Subject subject, CallbackHandler callbackHandler, Map<String, ?> sharedState, Map<String, ?> options) { super.initialize(subject, callbackHandler, sharedState, options); contextFactory = getOption("context.factory", "com.sun.jndi.ldap.LdapCtxFactory"); url = getOption("url", null); if (url == null) { throw new Error("No JNDI URL specified"); }// w ww .j a v a 2 s .c o m username = getOption("username", null); password = getOption("password", null); authentication = getOption("authentication", "simple"); base = getOption("base", null); String filter = getOption("searchFilter", "(uid={0})"); searchFilterFormat = new MessageFormat(filter); returnAttribute = getOption("returnAttribute", null); subtree = new Boolean(getOption("subtree", "true")).booleanValue(); }
From source file:components.TablePrintDemo.java
public void actionPerformed(java.awt.event.ActionEvent ignore) { MessageFormat header = new MessageFormat("Page {0,number,integer}"); try {// w ww . ja v a 2 s . c om table.print(JTable.PrintMode.FIT_WIDTH, header, null); } catch (java.awt.print.PrinterException e) { System.err.format("Cannot print %s%n", e.getMessage()); } }
From source file:grails.plugin.searchable.internal.util.StringQueryUtils.java
/** * Highlights the different terms in the second query and returns a new query string. * This method is intended to be used with suggested queries to display the suggestion * to the user in highlighted format, as per Google, so the queries are expected to roughly match * @param first the original query//w w w . j ava 2 s . c o m * @param second the second query, in which to highlight differences * @param highlightPattern the pattern used to highlight; should be a {@link MessageFormat} pattern where argument * zero is the highlighted term text * @return a new copy of second with term differences highlighted * @throws ParseException if either first or second query is invalid * @see #highlightTermDiffs(String, String) */ public static String highlightTermDiffs(String first, String second, String highlightPattern) throws ParseException { final String defaultField = "$StringQueryUtils_highlightTermDiffs$"; Term[] firstTerms = LuceneUtils.realTermsForQueryString(defaultField, first, WhitespaceAnalyzer.class); Term[] secondTerms = LuceneUtils.realTermsForQueryString(defaultField, second, WhitespaceAnalyzer.class); if (firstTerms.length != secondTerms.length) { LOG.warn("Expected the same number of terms for first query [" + first + "] and second query [" + second + "], " + "but first query has [" + firstTerms.length + "] terms and second query has [" + secondTerms.length + "] terms " + "so unable to provide user friendly version. Returning second query as-is."); return second; } MessageFormat format = new MessageFormat(highlightPattern); StringBuilder diff = new StringBuilder(second); int offset = 0; for (int i = 0; i < secondTerms.length; i++) { Term firstTerm = firstTerms[i]; Term secondTerm = secondTerms[i]; boolean noField = defaultField.equals(secondTerm.field()); String snippet = noField ? secondTerm.text() : secondTerm.field() + ":" + secondTerm.text(); int pos = diff.indexOf(snippet, offset); if (!firstTerm.text().equals(secondTerm.text())) { if (!noField) { pos += secondTerm.field().length() + 1; } diff.replace(pos, pos + secondTerm.text().length(), format.format(new Object[] { secondTerm.text() })); } offset = pos; } return diff.toString(); }
From source file:org.kineticsystem.commons.util.Localizer.java
/** * Retrieve and return a localized message from a resource bundle using the * given searching key.//from w w w . j av a 2 s . c om * @param resourceName The resource name. * @param key The resource key. * @param messageArguments Input parameters to be localized inside the * string. * @return The localized message. */ public static String localizeMessage(String resourceName, String key, Object[] messageArguments) { if (messageMode == DEBUG_MESSAGE_MODE) { return key; } else { String message = (String) doLocalize(resourceName, key); MessageFormat formatter = new MessageFormat(""); formatter.setLocale(Locale.getDefault()); formatter.applyPattern(message); return formatter.format(messageArguments); } }