Example usage for java.text MessageFormat format

List of usage examples for java.text MessageFormat format

Introduction

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

Prototype

public final String format(Object obj) 

Source Link

Document

Formats an object to produce a string.

Usage

From source file:com.microsoft.sqlserver.jdbc.SQLServerColumnEncryptionAzureKeyVaultProvider.java

/**
 * Constructor that takes a callback function to authenticate to AAD. This is used by KeyVaultClient at runtime to authenticate to Azure Key
 * Vault.//from  ww w  . j a  va  2 s  .c  o  m
 * 
 * @param authenticationCallback
 *            - Callback function used for authenticating to AAD.
 * @param executorService
 *            - The ExecutorService used to create the keyVaultClient
 * @throws SQLServerException
 *             when an error occurs
 */
public SQLServerColumnEncryptionAzureKeyVaultProvider(
        SQLServerKeyVaultAuthenticationCallback authenticationCallback, ExecutorService executorService)
        throws SQLServerException {
    if (null == authenticationCallback) {
        MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_NullValue"));
        Object[] msgArgs1 = { "SQLServerKeyVaultAuthenticationCallback" };
        throw new SQLServerException(form.format(msgArgs1), null);
    }
    credential = new KeyVaultCredential(authenticationCallback);
    HttpClientBuilder builder = HttpClientBuilder.create();
    keyVaultClient = new KeyVaultClientImpl(builder, executorService, credential);
}

From source file:com.microsoft.sqlserver.jdbc.SQLServerColumnEncryptionAzureKeyVaultProvider.java

/**
 * Gets the public Key size in bytes//  w  w  w  .  ja v a  2  s  .  c  o m
 * 
 * @param masterKeyPath
 *            - Azure Key Vault Key path
 * @return Key size in bytes
 * @throws SQLServerException
 *             when an error occurs
 */
private int getAKVKeySize(String masterKeyPath) throws SQLServerException {

    KeyBundle retrievedKey = null;
    try {
        retrievedKey = keyVaultClient.getKeyAsync(masterKeyPath).get();
    } catch (InterruptedException | ExecutionException e) {
        throw new SQLServerException(SQLServerException.getErrString("R_GetAKVKeySize"), null);
    }

    if (!retrievedKey.getKey().getKty().equalsIgnoreCase("RSA")
            && !retrievedKey.getKey().getKty().equalsIgnoreCase("RSA-HSM")) {
        MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_NonRSAKey"));
        Object[] msgArgs = { retrievedKey.getKey().getKty() };
        throw new SQLServerException(null, form.format(msgArgs), null, 0, false);
    }

    return retrievedKey.getKey().getN().length;
}

From source file:libepg.ts.packet.TsPacket.java

/**
 * transport_priority(?) ??PID????????1??
 *
 * @return/*from w ww.ja va2  s . c o  m*/
 * @throws IllegalStateException ????(0,1)????
 */
public synchronized int getTransport_priority() throws IllegalStateException {
    int temp;
    temp = ByteConverter.byteToInt(this.data.getData()[1]);
    temp = temp & 0x20;
    temp = temp >>> 5;
    if ((temp == 0) || (temp == 1)) {
        return temp;
    } else {
        MessageFormat msg = new MessageFormat("??????={0}");
        Object[] parameters = { temp };
        throw new IllegalStateException(msg.format(parameters));
    }
}

From source file:libepg.ts.packet.TsPacket.java

/**
 * transport_error_indicator(?)/*from ww w  .  j av a2 s  .c o  m*/
 * 1???????1?????TS?????
 *
 * @return ?
 * @throws IllegalStateException ????(0,1)????
 */
public synchronized int getTransport_error_indicator() throws IllegalStateException {
    int temp;
    temp = ByteConverter.byteToInt(this.data.getData()[1]);
    temp = temp >>> 7;
    if ((temp == 0) || (temp == 1)) {
        return temp;
    } else {
        MessageFormat msg = new MessageFormat(
                "?????={0}");
        Object[] parameters = { temp };
        throw new IllegalStateException(msg.format(parameters));
    }
}

From source file:libepg.ts.packet.TsPacket.java

/**
 * payload_unit_start_indicator()<br>
 * 1??????PES?????PIS???????????(?)<br>
 * ??0??????????1?????<br>// w ww . j a v  a  2 s. c  o m
 * ??(ID)?0xFF????<br>
 *
 * @return ?????
 * @throws IllegalStateException ????(0,1)????
 */
public synchronized PAYLOAD_UNIT_START_INDICATOR getPayload_unit_start_indicator()
        throws IllegalStateException {
    int temp;
    temp = ByteConverter.byteToInt(this.data.getData()[1]);
    temp = temp & 0x40;
    temp = temp >>> 6;
    switch (temp) {
    case 0:
        return TsPacket.PAYLOAD_UNIT_START_INDICATOR.NOT_START_POINT;
    case 1:
        return TsPacket.PAYLOAD_UNIT_START_INDICATOR.START_PES_OR_START_SECTION;
    }
    MessageFormat msg = new MessageFormat(
            "?????={0}");
    Object[] parameters = { temp };
    throw new IllegalStateException(msg.format(parameters));
}

From source file:libepg.ts.packet.TsPacket.java

/**
 * transport_scrambling_control(?)// w w  w. jav  a  2 s.  c  om
 *
 * @return
 * @throws IllegalStateException ????(03?)????
 */
public synchronized TRANSPORT_SCRAMBLING_CONTROL getTransport_scrambling_control()
        throws IllegalStateException {
    int temp;
    temp = ByteConverter.byteToInt(this.data.getData()[3]);
    temp = temp >>> 6;
    switch (temp) {
    case 0:
        return TsPacket.TRANSPORT_SCRAMBLING_CONTROL.NOT_SCRAMBLED;
    case 1:
        return TsPacket.TRANSPORT_SCRAMBLING_CONTROL.RESERVED;
    case 2:
        return TsPacket.TRANSPORT_SCRAMBLING_CONTROL.SCRAMBLED_BY_EVEN_KEY;
    case 3:
        return TsPacket.TRANSPORT_SCRAMBLING_CONTROL.SCRAMBLED_BY_ODD_KEY;
    }
    MessageFormat msg = new MessageFormat(
            "??????={0}");
    Object[] parameters = { temp };
    throw new IllegalStateException(msg.format(parameters));

}

From source file:libepg.ts.packet.TsPacket.java

/**
 * adaptation_field_control()//from  w  ww .  ja v  a  2s .  c  om
 *
 * @return ?????
 * @throws IllegalStateException ????(0,1,2,3)????
 */
public synchronized ADAPTATION_FIELD_CONTROL getAdaptation_field_control() throws IllegalStateException {
    int temp;
    temp = ByteConverter.byteToInt(this.data.getData()[3]);
    temp = temp & 0x30;
    temp = temp >>> 4;

    switch (temp) {
    case 0:
        return TsPacket.ADAPTATION_FIELD_CONTROL.RESERVED;
    case 1:
        return TsPacket.ADAPTATION_FIELD_CONTROL.ONLY_PAYLOAD;
    case 2:
        return TsPacket.ADAPTATION_FIELD_CONTROL.ONLY_ADAPTATION_FIELD;
    case 3:
        return TsPacket.ADAPTATION_FIELD_CONTROL.BOTH_EXIST;
    }
    MessageFormat msg = new MessageFormat(
            "?????={0}");
    Object[] parameters = { temp };
    throw new IllegalStateException(msg.format(parameters));
}

From source file:de.acosix.alfresco.site.hierarchy.repo.service.SiteHierarchyServiceImpl.java

/**
 *
 * {@inheritDoc}//from w ww .j a  v  a  2  s  .c om
 */
@Override
public List<SiteInfo> listTopLevelSites(final boolean respectShowInHierarchyMode) {
    LOGGER.debug("Listing top level sites");

    final SearchParameters sp = new SearchParameters();
    sp.addStore(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE);
    sp.setQueryConsistency(QueryConsistency.TRANSACTIONAL_IF_POSSIBLE);
    sp.setLanguage(SearchService.LANGUAGE_FTS_ALFRESCO);

    final MessageFormat queryFormat = new MessageFormat("TYPE:\"{0}\" AND ASPECT:\"{1}\"", Locale.ENGLISH);
    String query = queryFormat.format(new Object[] { SiteModel.TYPE_SITE.toPrefixString(this.namespaceService),
            SiteHierarchyModel.ASPECT_TOP_LEVEL_SITE.toPrefixString(this.namespaceService) });

    if (respectShowInHierarchyMode) {
        // this will cause db-fts not to be used
        final MessageFormat queryFilterFormat = new MessageFormat("={0}:{1} OR (={0}:{2} AND ASPECT:\"{3}\")",
                Locale.ENGLISH);
        final String queryFilter = queryFilterFormat.format(new Object[] {
                SiteHierarchyModel.PROP_SHOW_IN_HIERARCHY_MODE.toPrefixString(this.namespaceService),
                SiteHierarchyModel.CONSTRAINT_SHOW_IN_HIERARCHY_MODES_ALWAYS,
                SiteHierarchyModel.CONSTRAINT_SHOW_IN_HIERARCHY_MODES_IF_PARENT_OR_CHILD,
                SiteHierarchyModel.ASPECT_PARENT_SITE.toPrefixString(this.namespaceService) });
        // if we did not want to support 5.0.d we could use filter query support
        // TODO find a way to dynamically use filter query support WITHOUT reflection
        query = query + " AND (" + queryFilter + ")";
    }

    sp.setQuery(query);

    LOGGER.debug("Using FTS query \"{}\" to list top level sites", query);

    // we use short name sort since that is properly handled in either db-fts or fts
    // and might be specific enough so that in-memory post sort does not have to do that much
    final String shortNameSort = "@" + ContentModel.PROP_NAME.toPrefixString(this.namespaceService);
    sp.addSort(shortNameSort, true);

    List<SiteInfo> sites;
    final ResultSet resultSet = this.searchService.query(sp);
    try {
        sites = new ArrayList<>(resultSet.length());
        resultSet.forEach(resultRow -> {
            final NodeRef nodeRef = resultRow.getNodeRef();
            final SiteInfo site = this.siteService.getSite(nodeRef);
            if (site != null) {
                sites.add(site);
            }
        });
    } finally {
        resultSet.close();
    }

    final Collator collator = Collator.getInstance(I18NUtil.getLocale());
    Collections.sort(sites, (siteA, siteB) -> {
        final int titleCompareResult = collator.compare(siteA.getTitle(), siteB.getTitle());
        return titleCompareResult;
    });

    LOGGER.debug("Listed top level sites {}", sites);

    return sites;
}

From source file:libepg.epg.section.descriptor.contentdescriptor.NIBBLE_LEVEL_2.java

private NIBBLE_LEVEL_2(NIBBLE_LEVEL_1 parentNibble, int code, String nibble_jp, String nibble_en) {
    this.parentNibble = parentNibble;
    if (this.parentNibble == null) {
        throw new NullPointerException("? ()?null??");
    }//from  ww w .  ja  v a 2s  .  c om
    this.code = code;
    if ((this.code < 0) || (this.code > 0xf)) {
        MessageFormat msg = new MessageFormat(
                "?0x00xF??={0}");
        Object[] parameters = { Integer.toHexString(this.code) };
        throw new IllegalArgumentException(msg.format(parameters));
    }
    this.nibble_en = nibble_en;
    if ((this.nibble_en == null) || (this.nibble_en.equals(""))) {
        MessageFormat msg = new MessageFormat("()?null????");
        Object[] parameters = { Integer.toHexString(this.code) };
        throw new IllegalArgumentException(msg.format(parameters));
    }
    this.nibble_jp = nibble_jp;
    if ((this.nibble_jp == null) || (this.nibble_jp.equals(""))) {
        MessageFormat msg = new MessageFormat("()?null????");
        Object[] parameters = { Integer.toHexString(this.code) };
        throw new IllegalArgumentException(msg.format(parameters));
    }
}

From source file:net.jcreate.e3.table.message.AbstractMessageSource.java

/**
 * Format the given message String, using cached MessageFormats.
 * By default invoked for passed-in default messages, to resolve
 * any argument placeholders found in them.
 * @param msg the message to format/*from   w w  w  . j a va  2 s  .com*/
 * @param args array of arguments that will be filled in for params within
 * the message, or <code>null</code> if none.
 * @param locale the Locale used for formatting
 * @return the formatted message (with resolved arguments)
 */
protected String formatMessage(String msg, Object[] args, Locale locale) {
    if (msg == null || (!this.alwaysUseMessageFormat && (args == null || args.length == 0))) {
        return msg;
    }
    MessageFormat messageFormat = null;
    synchronized (this.cachedMessageFormats) {
        messageFormat = (MessageFormat) this.cachedMessageFormats.get(msg);
        if (messageFormat == null) {
            messageFormat = createMessageFormat(msg, locale);
            this.cachedMessageFormats.put(msg, messageFormat);
        }
    }
    synchronized (messageFormat) {
        return messageFormat.format(resolveArguments(args, locale));
    }
}