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) 

Source Link

Document

Constructs a MessageFormat for the default java.util.Locale.Category#FORMAT FORMAT locale and the specified pattern.

Usage

From source file:org.talend.core.ui.proposal.ContextParameterProposal.java

@Override
public String getDescription() {
    String desc = new String();
    if (!StringUtils.isEmpty(contextParameter.getComment())) {
        desc = contextParameter.getComment();
    } else {//from www. j a  va 2s . c o m
        desc = Messages.getString("ContextParameterProposal.NoCommentAvaiable"); //$NON-NLS-1$
    }
    // TDI-30683:fix the NPE pb and another description match pb(need move "\n" from message.propreties to code).
    MessageFormat format = new MessageFormat(getDescriptionMessagePattern());
    if (contextParameter.getContext() != null) {
        Object[] replaceArgs = new Object[] { desc, contextParameter.getContext().getName(),
                contextParameter.getType(), contextParameter.getName() };
        return format.format(replaceArgs);
    }
    return desc;

}

From source file:com.xpn.xwiki.render.filter.XWikiHeadingFilter.java

public void setInitialContext(InitialRenderContext context) {
    super.setInitialContext(context);
    String outputTemplate = outputMessages.getString(getLocaleKey() + ".print");
    formatter = new MessageFormat("");
    formatter.applyPattern(outputTemplate);
}

From source file:libepg.epg.section.sectionreconstructor.PayLoadSplitter.java

/**
 * @param packet //from  w  ww  .  j  a v a2s. c o m
 * @throws IllegalArgumentException
 * ?????????????
 */
public synchronized void setPacket(TsPacket packet) throws IllegalArgumentException {

    this.packet = packet;

    if ((this.packet.getAdaptation_field_control() == TsPacket.ADAPTATION_FIELD_CONTROL.ONLY_ADAPTATION_FIELD)
            || (this.packet.getAdaptation_field_control() == TsPacket.ADAPTATION_FIELD_CONTROL.RESERVED)) {
        MessageFormat msg2 = new MessageFormat(
                "?????????????={0}");
        Object[] parameters2 = { this.packet.toString() };
        throw new IllegalArgumentException(msg2.format(parameters2));
    }
}

From source file:br.com.sicoob.cro.cop.util.BatchPropertiesUtil.java

/**
 * Passa os argumentos para a string da mensagem.
 *
 * @param key Chave./*ww  w .  j a va  2  s  .co  m*/
 * @param replace Argumentos.
 * @return String formatada.
 */
private String applyArguments(String key, String... replace) {
    MessageFormat format = new MessageFormat("");
    format.applyPattern((String) properties.get(key));
    return format.format(replace);
}

From source file:cherry.foundation.numbering.NumberingManagerImpl.java

@Transactional
@Override//  ww  w  . j  ava 2  s . c  om
public String issueAsString(String numberName) {

    checkArgument(numberName != null, "numberName must not be null");

    NumberingDefinition def = getNumberingDefinition(numberName);
    MessageFormat fmt = new MessageFormat(def.getTemplate());
    long current = numberingStore.loadAndLock(numberName);
    int offset = 0;
    try {

        long v = current + 1;
        checkState(v >= def.getMinValue(), "%s must be >= %s", numberName, def.getMinValue());
        checkState(v <= def.getMaxValue(), "%s must be <= %s", numberName, def.getMaxValue());
        String result = fmt.format(new Object[] { Long.valueOf(v) });

        offset = 1;
        return result;
    } finally {
        numberingStore.saveAndUnlock(numberName, current + offset);
    }
}

From source file:org.jmesa.core.message.ResourceBundleMessages.java

@Override
public String getMessage(String code, Object[] args) {

    String result = findResource(customResourceBundle, code);

    if (result == null) {
        result = findResource(defaultResourceBundle, code);
    }/*from w ww. j  a  v a  2s .  co  m*/

    if (result != null && args != null) {
        MessageFormat formatter = new MessageFormat("");
        formatter.setLocale(locale);
        formatter.applyPattern(result);
        result = formatter.format(args);
    }

    return result;
}

From source file:cloud.google.oauth2.MyWayAuthentication.java

public String getAssertion(long exp, long iat) throws Exception {
    String header = "{\"alg\":\"RS256\",\"typ\":\"JWT\"}";
    String claimTemplate = "'{'\"iss\": \"{0}\", \"scope\": \"{1}\", \"aud\": \"{2}\", \"exp\": {3}, \"iat\": {4}'}'";
    StringBuffer token = new StringBuffer();

    /**//  www  . j av a2 s. c o m
     * Encode the JWT Header and add it to our string to sign
     * */
    token.append(Base64.encodeBase64URLSafeString(header.getBytes("UTF-8")));

    /**
     * Separate with a period
     * */
    token.append(".");

    /**
     * Create the JWT Claims Object
     * */
    String[] claimArray = new String[6];
    claimArray[0] = this.iss;
    claimArray[1] = GCDStatic.getScope();
    claimArray[2] = GCDStatic.getAud();
    claimArray[3] = "" + exp;
    claimArray[4] = "" + iat;

    MessageFormat claims = new MessageFormat(claimTemplate);
    String payload = claims.format(claimArray);

    /**
     * Add the encoded claims object
     * */
    token.append(Base64.encodeBase64URLSafeString(payload.getBytes("UTF-8")));

    /**
     * Load the private key
     * */
    PrivateKey privateKey = getPrivateKey(this.keystoreLoc, GCDStatic.getPassword());
    byte[] sig = signData(token.toString().getBytes("UTF-8"), privateKey);

    String signedPayload = Base64.encodeBase64URLSafeString(sig);

    /**
     * Separate with a period
     * */
    token.append(".");

    /**
     * Add the encoded signature
     * */
    token.append(signedPayload);

    return token.toString();
}

From source file:libepg.epg.section.descriptor.Descriptor.java

/**
 * ????DescriptorsLoop?????/*ww  w.j  a v  a 2  s . com*/
 *
 * @param data ??
 * @throws IllegalArgumentException
 * ?????preferedDescriptorTag???????????
 */
Descriptor(byte[] data) {

    this.data = new ByteDataBlock(data);

    int lengthFromData = ByteConverter.byteToInt(this.data.getData()[1]) + 2;
    int lengthFromArray = this.getData().length;
    if (lengthFromData != lengthFromArray) {
        MessageFormat msg1 = new MessageFormat(
                "?????????????={0} ?={1} ={2}");
        Object[] parameters1 = { lengthFromData, lengthFromArray, Hex.encodeHexString(this.data.getData()) };
        throw new IllegalArgumentException(msg1.format(parameters1));
    }

    int tag = ByteConverter.byteToInt(this.data.getData()[0]);
    this.descriptorTag = DESCRIPTOR_TAG.reverseLookUp(tag);
    if (this.descriptorTag == null) {
        MessageFormat msg = new MessageFormat(
                "???????={0} ={1}");
        Object[] parameters = { Integer.toHexString(tag), Hex.encodeHexString(this.data.getData()) };
        throw new IllegalArgumentException(msg.format(parameters));
    }
}

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

/**
 * TS???//from   w  w  w  . j av  a2 s  .  c o  m
 *
 * @param data TS?
 * @throws IllegalArgumentException ?188??????
 */
public TsPacket(final byte[] data) throws IllegalArgumentException {
    byte[] temp = Arrays.copyOf(data, data.length);
    if (temp.length != TsPacket.TS_PACKET_BYTE_LENGTH.PACKET_LENGTH.getByteLength()) {
        MessageFormat msg = new MessageFormat(
                "????????={0} ?={1}");
        Object[] parameters = { temp.length, Hex.encodeHexString(temp) };
        throw new IllegalArgumentException(msg.format(parameters));
    }
    this.data = new ByteDataBlock(temp);
}

From source file:com.logicoy.pdmp.pmpi.http.PMPIHttpClient.java

public boolean doLogin(boolean force) {

    if (force || !this.sessionObj.inSessionTimeoutWindow() || loggedIn) {
        if (this.userNameAndPassword == null) {
            throw new RuntimeException(
                    "Attempting to post to authenticate but the userNameAndPassword have not been set! ");
        }//from www. ja  va  2s .c  o  m

        Charset utf8 = Charset.forName("UTF-8");
        String strMessageBody = "";
        char checkmark = '\u2713'; //check mark in utf8. Not sure if it is needed. But it was present in the web form.
        strMessageBody += "utf-8=" + checkmark;
        strMessageBody += "&user_session[login]=" + userNameAndPassword.getUsername();
        strMessageBody += "&user_session[password]=" + userNameAndPassword.getPassword();
        //strMessageBody += "&commit=Login"; //this causes failure for the system user now..

        String URI = base_url + "/user_sessions";

        SimpleWebClient swc = new SimpleWebClient();
        PMPIHttpClientResponse resp = swc.sendRequest(this.sessionObj,
                new SimpleWebClientSettings(URI, SimpleWebClientSettings.ActionType.POST,
                        "application/x-www-form-urlencoded", strMessageBody, "application/xml", false, false,
                        false));

        log.info(new MessageFormat("Attempting login for Interconnect ID : {0} user {1} ")
                .format(this.userNameAndPassword.getInterocnnectid(), this.userNameAndPassword.getUsername()));
        if (resp != null) {
            if (resp.getHttpStatusCode() == HttpStatus.SC_OK) {
                //Request ok, attempt to parse xml.
                //this.ErrorMessage(currentMethod, "302 Found", swc, resp);
                log.warning("Server returned OK " + resp.getHttpStatusDesc());
                loggedIn = false;
                return loggedIn;
            } else if (resp.getHttpStatusCode() == HttpStatus.SC_MOVED_TEMPORARILY) {
                log.info(" Login expect (302 Found) received " + String.valueOf(resp.getHttpStatusCode()) + " "
                        + resp.getHttpStatusCode()
                        + " indicating that we have successfully logged in and the web server is trying to redirect us to the landing page. ");
                loggedIn = true;
                return loggedIn;
            } else {
                //this.ErrorMessage(currentMethod, "302 Found", swc, resp);
                log.warning("Server returned " + resp.getHttpStatusCode() + " " + resp.getHttpStatusDesc());
                loggedIn = false;
                return loggedIn;
            }
        } else {
            log.warning("No Response from Web Server");
            loggedIn = false;
            return loggedIn;
        }
    } else // Because we are not forcing a login and our session object has been created we are going to assume
    { // that we don't need to log in and just return success.
      // If we needed to really log in then our operation would fail and our method would try to login later.
        return true;
    }

}