Example usage for java.text MessageFormat getFormats

List of usage examples for java.text MessageFormat getFormats

Introduction

In this page you can find the example usage for java.text MessageFormat getFormats.

Prototype

public Format[] getFormats() 

Source Link

Document

Gets the formats used for the format elements in the previously set pattern string.

Usage

From source file:net.gtaun.wl.lang.BeanMessageFormat.java

/**
 * Do something TODO. /*from w  w  w . j a va2 s.  co  m*/
 * <p> 
 * Details of the function. 
 * </p> 
 */
private void applyFormats(MessageFormat subFormat) {

    for (Format format : subFormat.getFormats()) {
        if (!(format instanceof ChoiceFormat)) {
            continue;
        }

        ChoiceFormat choice = (ChoiceFormat) format;
        String[] choiceFormats = (String[]) choice.getFormats();
        for (int i = 0; i < choiceFormats.length; i++) {
            String innerFormat = choiceFormats[i];
            if (innerFormat.contains("{")) {
                BeanMessageFormat recursive = new BeanMessageFormat(innerFormat, root);
                choiceFormats[i] = recursive.inner.toPattern();
            }
        }

        choice.setChoices(choice.getLimits(), choiceFormats);
    }
}

From source file:org.archive.wayback.util.StringFormatter.java

public MessageFormat getFormat(String pattern) {
    MessageFormat format = formats.get(pattern);
    if (format == null) {
        format = new MessageFormat(pattern, locale);
        // lets try to make sure any internal DateFormats use UTC:
        Format[] subFormats = format.getFormats();
        if (subFormats != null) {
            for (Format subFormat : subFormats) {
                if (subFormat instanceof DateFormat) {
                    DateFormat subDateFormat = (DateFormat) subFormat;
                    subDateFormat.setTimeZone(TZ_UTC);
                }//from   www . j  ava2  s .  c  o  m
            }
        }
        formats.put(pattern, format);
    }
    return format;
}

From source file:org.mypsycho.text.BeanMessageFormat.java

/**
 * Do something TODO./*from  w w  w.j a va2  s  .c  om*/
 * <p>
 * Details of the function.
 * </p>
 */
private void applyFormats(java.text.MessageFormat subFormat) {

    for (Format format : subFormat.getFormats()) {
        if (!(format instanceof ChoiceFormat)) {
            continue;
        }

        ChoiceFormat choice = (ChoiceFormat) format;
        String[] choiceFormats = (String[]) choice.getFormats();
        for (int i = 0; i < choiceFormats.length; i++) {
            String innerFormat = choiceFormats[i];
            if (innerFormat.contains("{")) {
                BeanMessageFormat recursive = new BeanMessageFormat(innerFormat, root);
                choiceFormats[i] = recursive.inner.toPattern();
            }
        }

        choice.setChoices(choice.getLimits(), choiceFormats);
    }
}

From source file:org.pentaho.reporting.libraries.docbundle.BundleUtilities.java

public static String getUniqueName(final DocumentBundle bundle, final String pattern) {
    if (bundle == null) {
        throw new NullPointerException();
    }//w  w w.  j  a v  a2s .c  o m
    if (pattern == null) {
        throw new NullPointerException();
    }

    final MessageFormat message = new MessageFormat(pattern);
    final Object[] objects = { "" };
    final String plain = message.format(objects);
    if (bundle.isEntryExists(plain) == false) {
        return plain;
    }

    final Format[] formats = message.getFormats();
    if (formats.length == 0) {
        // there is no variation in this name.
        return null;
    }

    int count = 1;
    while (count < 2000000) {
        objects[0] = String.valueOf(count);
        final String testFile = message.format(objects);
        if (bundle.isEntryExists(testFile) == false) {
            return testFile;
        }
        count += 1;
    }

    // If you have more than 2 million entries, you would hate me to test for the two billion entries, wont you?
    throw new IllegalStateException();
}