Search in sources :

Example 51 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 52 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 53 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 54 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 55 with MessageFormat

use of java.text.MessageFormat in project translationstudio8 by heartsome.

the class AbstractShieldCommandStartup method readUnusedCommandFromFile.

@SuppressWarnings("unchecked")
protected Set<String> readUnusedCommandFromFile(String relativePath) {
    Set<String> set = Collections.EMPTY_SET;
    File file = ShieldActivator.getFile(relativePath);
    if (file != null) {
        BufferedReader br = null;
        try {
            br = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
            String line = null;
            set = new HashSet<String>();
            while ((line = br.readLine()) != null) {
                // 忽略以 # 开头注释行
                if (line.startsWith("#"))
                    continue;
                line = line.trim();
                // 忽略空行
                if (line.length() == 0)
                    continue;
                set.add(line);
            }
        } catch (FileNotFoundException e) {
            if (LOGGER.isErrorEnabled()) {
                String msg = Messages.getString("shield.AbstractShieldCommandStartup.logger1");
                Object[] args = { file.getAbsolutePath() };
                LOGGER.error(new MessageFormat(msg).format(args), e);
            }
        } catch (IOException e) {
            if (LOGGER.isErrorEnabled()) {
                String msg = Messages.getString("shield.AbstractShieldCommandStartup.logger2");
                Object[] args = { file.getAbsolutePath() };
                LOGGER.error(new MessageFormat(msg).format(args), e);
            }
        } finally {
            if (br != null) {
                try {
                    br.close();
                } catch (IOException e) {
                    if (LOGGER.isErrorEnabled()) {
                        String msg = Messages.getString("shield.AbstractShieldCommandStartup.logger3");
                        Object[] args = { file.getAbsolutePath() };
                        LOGGER.error(new MessageFormat(msg).format(args), e);
                    }
                }
            }
        }
    }
    return set;
}
Also used : InputStreamReader(java.io.InputStreamReader) MessageFormat(java.text.MessageFormat) BufferedReader(java.io.BufferedReader) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) File(java.io.File) FileInputStream(java.io.FileInputStream)

Aggregations

MessageFormat (java.text.MessageFormat)690 LogMessage (org.apache.qpid.server.logging.LogMessage)105 CertificateException (java.security.cert.CertificateException)52 KeyStoreException (java.security.KeyStoreException)48 IOException (java.io.IOException)47 UnrecoverableKeyException (java.security.UnrecoverableKeyException)46 UnrecoverableEntryException (java.security.UnrecoverableEntryException)43 CertStoreException (java.security.cert.CertStoreException)43 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)33 X509Certificate (java.security.cert.X509Certificate)30 ArrayList (java.util.ArrayList)27 ResourceBundle (java.util.ResourceBundle)27 Date (java.util.Date)23 Locale (java.util.Locale)22 File (java.io.File)21 Certificate (java.security.cert.Certificate)19 PrivateKey (java.security.PrivateKey)16 Format (java.text.Format)16 MissingResourceException (java.util.MissingResourceException)16 HashMap (java.util.HashMap)15