Example usage for java.text MessageFormat MessageFormat

List of usage examples for java.text MessageFormat MessageFormat

Introduction

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

Prototype

public MessageFormat(String pattern, Locale locale) 

Source Link

Document

Constructs a MessageFormat for the specified locale and pattern.

Usage

From source file:org.opencms.i18n.CmsMessages.java

/**
 * Returns the selected localized message for the initialized resource bundle and locale.<p>
 * //w ww  . j  a va2 s  .com
 * If the key was found in the bundle, it will be formatted using
 * a <code>{@link MessageFormat}</code> using the provided parameters.<p>
 * 
 * If the key was not found in the bundle, the return value is
 * <code>"??? " + keyName + " ???"</code>. This will also be returned 
 * if the bundle was not properly initialized first.
 * 
 * @param key the message key
 * @param args the message arguments
 * 
 * @return the selected localized message for the initialized resource bundle and locale 
 */
public String key(String key, Object[] args) {

    if ((args == null) || (args.length == 0)) {
        // no parameters available, use simple key method
        return key(key);
    }

    String result = key(key, true);
    if (result == null) {
        // key was not found
        result = formatUnknownKey(key);
    } else {
        // key was found in the bundle - create and apply the formatter
        MessageFormat formatter = new MessageFormat(result, m_locale);
        result = formatter.format(args);
    }
    // return the result
    return result;
}

From source file:de.acosix.alfresco.mtsupport.repo.auth.ldap.EnhancedLDAPUserRegistry.java

@Override
public Collection<NodeDescription> getPersons(final Date modifiedSince) {
    final String query;
    if (modifiedSince == null) {
        query = this.personQuery;
    } else {// w  w  w .  ja v  a 2  s.  co  m
        final MessageFormat mf = new MessageFormat(this.personDifferentialQuery, Locale.ENGLISH);
        query = mf.format(new Object[] { this.timestampFormat.format(modifiedSince) });
    }

    final Supplier<InitialDirContext> contextSupplier = this.buildContextSupplier();
    final Function<InitialDirContext, Boolean> nextPageChecker = this.buildNextPageChecker();
    final Function<InitialDirContext, NamingEnumeration<SearchResult>> userSearcher = this
            .buildUserSearcher(query);

    final AtomicInteger totalEstimatedSize = new AtomicInteger(-1);
    if (this.enableProgressEstimation) {
        this.processQuery((result) -> {
            totalEstimatedSize.getAndIncrement();
        }, this.userSearchBase, query, new String[0]);
    }

    final NodeMapper userMapper = this.buildUserMapper();
    return new PersonCollection(contextSupplier, nextPageChecker, userSearcher, userMapper, this.queryBatchSize,
            totalEstimatedSize.get());
}

From source file:de.acosix.alfresco.mtsupport.repo.auth.ldap.EnhancedLDAPUserRegistry.java

/**
 *
 * {@inheritDoc}/*w  ww  .j a v a 2  s .  c  om*/
 */
@Override
public Collection<NodeDescription> getGroups(final Date modifiedSince) {
    // Work out whether the user and group trees are disjoint. This may allow us to optimize reverse DN
    // resolution.
    final LdapName groupDistinguishedNamePrefix = this.resolveDistinguishedNamePrefix(this.groupSearchBase);
    final LdapName userDistinguishedNamePrefix = this.resolveDistinguishedNamePrefix(this.userSearchBase);

    final boolean disjoint = !groupDistinguishedNamePrefix.startsWith(userDistinguishedNamePrefix)
            && !userDistinguishedNamePrefix.startsWith(groupDistinguishedNamePrefix);

    final String query;
    if (modifiedSince == null) {
        query = this.groupQuery;
    } else {
        final MessageFormat mf = new MessageFormat(this.groupDifferentialQuery, Locale.ENGLISH);
        query = mf.format(new Object[] { this.timestampFormat.format(modifiedSince) });
    }

    // find duplicate gid in advance
    final Set<String> groupNames = new HashSet<>();
    final Map<String, AtomicInteger> groupNameCounts = new HashMap<>();
    this.processQuery((result) -> {
        final Attribute nameAttribute = result.getAttributes().get(this.groupIdAttributeName);
        if (nameAttribute == null) {
            if (this.errorOnMissingUID) {
                final Object[] params = { result.getNameInNamespace(), this.groupIdAttributeName };
                throw new AlfrescoRuntimeException("synchronization.err.ldap.get.group.id.missing", params);
            } else {
                LOGGER.warn("Missing GID on {}", result.getNameInNamespace());
            }
        } else {
            final Collection<String> attributeValues = this.mapAttribute(nameAttribute, String.class);
            final String groupName = attributeValues.iterator().next();
            LOGGER.debug("Group DN recognized: {}", groupName);

            if (groupNames.contains(groupName)) {
                if (this.errorOnDuplicateGID) {
                    throw new AlfrescoRuntimeException("Duplicate group id found: " + groupName);
                }
                LOGGER.warn("Duplicate gid found for {} -> merging definitions", groupName);
                groupNameCounts.computeIfAbsent(groupName, (x) -> {
                    return new AtomicInteger(1);
                }).getAndIncrement();
            } else {
                groupNames.add(groupName);
            }
        }
    }, this.groupSearchBase, this.groupQuery, new String[] { this.groupIdAttributeName });

    final Supplier<InitialDirContext> contextSupplier = this.buildContextSupplier();
    final Function<InitialDirContext, Boolean> nextPageChecker = this.buildNextPageChecker();
    final Function<InitialDirContext, NamingEnumeration<SearchResult>> groupSearcher = this
            .buildGroupSearcher(query);

    final NodeMapper groupMapper = this.buildGroupMapper(disjoint, groupDistinguishedNamePrefix,
            userDistinguishedNamePrefix);
    return new PersonCollection(contextSupplier, nextPageChecker, groupSearcher, groupMapper,
            this.queryBatchSize, groupNames.size());
}

From source file:org.apache.kylin.common.persistence.JDBCResourceDAO.java

private String getCheckTableExistsSql(final String tableName) {
    final String sql = new MessageFormat(jdbcSqlQueryFormat.getCheckTableExistsSql(), Locale.ROOT)
            .format(new Object[] { tableName }, new StringBuffer(), new FieldPosition(0)).toString();
    return sql;//from   w ww. jav a 2s . com
}

From source file:org.apache.kylin.common.persistence.JDBCResourceDAO.java

private String getCreateIfNeededSql(String tableName) {
    String sql = new MessageFormat(jdbcSqlQueryFormat.getCreateIfNeedSql(), Locale.ROOT)
            .format(new Object[] { tableName, META_TABLE_KEY, META_TABLE_TS, META_TABLE_CONTENT },
                    new StringBuffer(), new FieldPosition(0))
            .toString();/*  ww w  .jav  a  2 s  .c  om*/
    return sql;
}

From source file:org.apache.kylin.common.persistence.JDBCResourceDAO.java

private String getCreateIndexSql(String indexName, String tableName, String indexCol) {
    String sql = new MessageFormat(jdbcSqlQueryFormat.getCreateIndexSql(), Locale.ROOT)
            .format(new Object[] { indexName, tableName, indexCol }, new StringBuffer(), new FieldPosition(0))
            .toString();/*from ww  w.  j a v a  2 s  . c om*/
    return sql;
}

From source file:org.apache.kylin.common.persistence.JDBCResourceDAO.java

private String getKeyEqualSqlString(String tableName, boolean fetchContent, boolean fetchTimestamp) {
    String sql = new MessageFormat(jdbcSqlQueryFormat.getKeyEqualsSql(), Locale.ROOT)
            .format(new Object[] { getSelectList(fetchContent, fetchTimestamp), tableName, META_TABLE_KEY },
                    new StringBuffer(), new FieldPosition(0))
            .toString();// w  w w.  j  av a  2 s .co m
    return sql;
}

From source file:org.apache.kylin.common.persistence.JDBCResourceDAO.java

private String getDeletePstatSql(String tableName) {
    String sql = new MessageFormat(jdbcSqlQueryFormat.getDeletePstatSql(), Locale.ROOT)
            .format(new Object[] { tableName, META_TABLE_KEY }, new StringBuffer(), new FieldPosition(0))
            .toString();/*from   ww  w.  ja v  a  2  s .  com*/
    return sql;
}

From source file:org.apache.kylin.common.persistence.JDBCResourceDAO.java

private String getListResourceSqlString(String tableName) {
    String sql = new MessageFormat(jdbcSqlQueryFormat.getListResourceSql(), Locale.ROOT)
            .format(new Object[] { META_TABLE_KEY, tableName, META_TABLE_KEY }, new StringBuffer(),
                    new FieldPosition(0))
            .toString();// w w w . jav  a 2  s  .  c  o  m
    return sql;
}

From source file:org.apache.click.util.Format.java

/**
 * Return a formatted string using the given message pattern and arguments.
 * See {@link java.text.MessageFormat} for information on the message
 * pattern string./* w  w w .ja v  a 2  s.  c om*/
 *
 * @param pattern the message pattern
 * @param arguments the message arguments
 * @return the formatted string
 */
public String message(String pattern, Object[] arguments) {
    MessageFormat format = new MessageFormat(pattern, getLocale());
    return format.format(arguments, new StringBuffer(), null).toString();
}