Search in sources :

Example 16 with MessageFormat

use of java.text.MessageFormat in project j2objc by google.

the class Support_MessageFormat method t_format_with_FieldPosition.

public void t_format_with_FieldPosition() {
    // This test assumes a default DateFormat.is24Hour setting.
    /* J2ObjC: DateFormat.is24Hour is Android-specific.
		DateFormat.is24Hour = null;*/
    String pattern = "On {4,date} at {3,time}, he ate {2,number, integer} hamburger{2,choice,1#|1<s} and drank {1, number} liters of coke. That was {0,choice,1#just enough|1<more than enough} food!";
    MessageFormat format = new MessageFormat(pattern, Locale.US);
    Date date = new GregorianCalendar(2005, 1, 28, 14, 20, 16).getTime();
    Integer hamburgers = new Integer(8);
    Object[] objects = new Object[] { hamburgers, new Double(3.5), hamburgers, date, date };
    super.text = "On Feb 28, 2005 at 2:20:16 PM, he ate 8 hamburgers and drank 3.5 liters of coke. That was more than enough food!";
    // test with MessageFormat.Field.ARGUMENT
    t_FormatWithField(1, format, objects, null, Field.ARGUMENT, 3, 15);
    // test other format fields that are included in the formatted text
    t_FormatWithField(2, format, objects, null, DateFormat.Field.AM_PM, 0, 0);
    t_FormatWithField(3, format, objects, null, NumberFormat.Field.FRACTION, 0, 0);
    // test fields that are not included in the formatted text
    t_FormatWithField(4, format, objects, null, DateFormat.Field.ERA, 0, 0);
    t_FormatWithField(5, format, objects, null, NumberFormat.Field.EXPONENT_SIGN, 0, 0);
}
Also used : MessageFormat(java.text.MessageFormat) GregorianCalendar(java.util.GregorianCalendar) Date(java.util.Date)

Example 17 with MessageFormat

use of java.text.MessageFormat in project j2objc by google.

the class Support_MessageFormat method t_formatToCharacterIterator.

public void t_formatToCharacterIterator() {
    // This test assumes a default DateFormat.is24Hour setting.
    /* J2ObjC: DateFormat.is24Hour is Android-specific.
		DateFormat.is24Hour = null;*/
    String pattern = "On {4,date} at {3,time}, he ate {2,number, integer} hamburger{2,choice,1#|1<s} and drank {1, number} liters of coke. That was {0,choice,1#just enough|1<more than enough} food!";
    MessageFormat format = new MessageFormat(pattern, Locale.US);
    Date date = new GregorianCalendar(2005, 1, 28, 14, 20, 16).getTime();
    Integer hamburgers = new Integer(8);
    Object[] objects = new Object[] { hamburgers, new Double(3.5), hamburgers, date, date };
    t_Format(1, objects, format, getMessageVector1());
}
Also used : MessageFormat(java.text.MessageFormat) GregorianCalendar(java.util.GregorianCalendar) Date(java.util.Date)

Example 18 with MessageFormat

use of java.text.MessageFormat in project j2objc by google.

the class Locale method formatList.

/**
     * Format a list using given pattern strings.
     * If either of the patterns is null, then a the list is
     * formatted by concatenation with the delimiter ','.
     * @param stringList the list of strings to be formatted.
     * @param listPattern should create a MessageFormat taking 0-3 arguments
     * and formatting them into a list.
     * @param listCompositionPattern should take 2 arguments
     * and is used by composeList.
     * @return a string representing the list.
     */
private static String formatList(String[] stringList, String listPattern, String listCompositionPattern) {
    // non-localized way.
    if (listPattern == null || listCompositionPattern == null) {
        StringBuffer result = new StringBuffer();
        for (int i = 0; i < stringList.length; ++i) {
            if (i > 0)
                result.append(',');
            result.append(stringList[i]);
        }
        return result.toString();
    }
    // Compose the list down to three elements if necessary
    if (stringList.length > 3) {
        MessageFormat format = new MessageFormat(listCompositionPattern);
        stringList = composeList(format, stringList);
    }
    // Rebuild the argument list with the list length as the first element
    Object[] args = new Object[stringList.length + 1];
    System.arraycopy(stringList, 0, args, 1, stringList.length);
    args[0] = new Integer(stringList.length);
    // Format it using the pattern in the resource
    MessageFormat format = new MessageFormat(listPattern);
    return format.format(args);
}
Also used : MessageFormat(java.text.MessageFormat)

Example 19 with MessageFormat

use of java.text.MessageFormat in project languagetool by languagetool-org.

the class FalseFriendRuleLoader method getRules.

public final List<AbstractPatternRule> getRules(InputStream stream, Language textLanguage, Language motherTongue) throws ParserConfigurationException, SAXException, IOException {
    FalseFriendRuleHandler handler = new FalseFriendRuleHandler(textLanguage, motherTongue);
    SAXParserFactory factory = SAXParserFactory.newInstance();
    SAXParser saxParser = factory.newSAXParser();
    saxParser.getXMLReader().setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
    saxParser.parse(stream, handler);
    List<AbstractPatternRule> rules = handler.getRules();
    // Add suggestions to each rule:
    ResourceBundle messages = ResourceBundle.getBundle(JLanguageTool.MESSAGE_BUNDLE, motherTongue.getLocale());
    MessageFormat msgFormat = new MessageFormat(messages.getString("false_friend_suggestion"));
    for (AbstractPatternRule rule : rules) {
        List<String> suggestions = handler.getSuggestionMap().get(rule.getId());
        if (suggestions != null) {
            String[] msg = { formatSuggestions(suggestions) };
            rule.setMessage(rule.getMessage() + " " + msgFormat.format(msg));
        }
    }
    return rules;
}
Also used : MessageFormat(java.text.MessageFormat) SAXParser(javax.xml.parsers.SAXParser) ResourceBundle(java.util.ResourceBundle) SAXParserFactory(javax.xml.parsers.SAXParserFactory)

Example 20 with MessageFormat

use of java.text.MessageFormat in project hazelcast by hazelcast.

the class XMLConfigBuilderTest method testMapNativeMaxSizePolicy.

@Test
public void testMapNativeMaxSizePolicy() {
    String xmlFormat = HAZELCAST_START_TAG + "<map name=\"mymap\">" + "<in-memory-format>NATIVE</in-memory-format>" + "<max-size policy=\"{0}\">9991</max-size>" + "</map>" + HAZELCAST_END_TAG;
    MessageFormat messageFormat = new MessageFormat(xmlFormat);
    MaxSizeConfig.MaxSizePolicy[] maxSizePolicies = MaxSizeConfig.MaxSizePolicy.values();
    for (MaxSizeConfig.MaxSizePolicy maxSizePolicy : maxSizePolicies) {
        Object[] objects = { maxSizePolicy.toString() };
        String xml = messageFormat.format(objects);
        Config config = buildConfig(xml);
        MapConfig mapConfig = config.getMapConfig("mymap");
        MaxSizeConfig maxSizeConfig = mapConfig.getMaxSizeConfig();
        assertEquals(9991, maxSizeConfig.getSize());
        assertEquals(maxSizePolicy, maxSizeConfig.getMaxSizePolicy());
    }
}
Also used : MessageFormat(java.text.MessageFormat) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

MessageFormat (java.text.MessageFormat)260 CertificateException (java.security.cert.CertificateException)27 KeyStoreException (java.security.KeyStoreException)23 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)22 UnrecoverableKeyException (java.security.UnrecoverableKeyException)22 Date (java.util.Date)22 UnrecoverableEntryException (java.security.UnrecoverableEntryException)21 CertStoreException (java.security.cert.CertStoreException)21 X509Certificate (java.security.cert.X509Certificate)17 IOException (java.io.IOException)15 ArrayList (java.util.ArrayList)15 File (java.io.File)14 Format (java.text.Format)12 Support_MessageFormat (tests.support.Support_MessageFormat)12 Certificate (java.security.cert.Certificate)10 ChoiceFormat (java.text.ChoiceFormat)10 DateFormat (java.text.DateFormat)10 MissingResourceException (java.util.MissingResourceException)10 SimpleDateFormat (java.text.SimpleDateFormat)9 ResourceBundle (java.util.ResourceBundle)9