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:it.jnrpe.plugin.CCheckOracle.java

/**
 * Checks database usage/*from  w w  w.j av a 2  s . c  om*/
 * @param c
 * @param cl
 * @return
 */
private CReturnValue checkTablespace(Connection c, CCommandLine cl) {
    //        Integer iWarning = new Integer(cl.getOptionValue("warning", "70"));
    //        Integer iCritical = new Integer(cl.getOptionValue("critical", "80"));

    String sWarning = cl.getOptionValue("warning", "70");
    String sCritical = cl.getOptionValue("critical", "80");

    String sTablespace = cl.getOptionValue("tablespace").toUpperCase();

    String sQry = "select NVL(b.free,0.0),a.total,100 - trunc(NVL(b.free,0.0)/a.total * 1000) / 10 prc"
            + " from (" + " select tablespace_name,sum(bytes)/1024/1024 total"
            + " from dba_data_files group by tablespace_name) A" + " LEFT OUTER JOIN"
            + " ( select tablespace_name,sum(bytes)/1024/1024 free"
            + " from dba_free_space group by tablespace_name) B"
            + " ON a.tablespace_name=b.tablespace_name WHERE a.tablespace_name='" + sTablespace + "'";

    Statement stmt = null;
    ResultSet rs = null;

    try {
        stmt = c.createStatement();
        rs = stmt.executeQuery(sQry);

        boolean bFound = rs.next();

        if (!bFound)
            return new CReturnValue(IJNRPEConstants.STATE_UNKNOWN, "CHECK_ORACLE : UNKNOWN - Tablespace "
                    + cl.getOptionValue("tablespace") + " do not exist?");

        BigDecimal ts_free = rs.getBigDecimal(1);
        BigDecimal ts_total = rs.getBigDecimal(2);
        BigDecimal ts_pct = rs.getBigDecimal(3);

        String sMsg = "{0} : {1} {2} - {3,number,0.#}% used [ {4,number,0.#} / {5,number,0.#} MB available ]|{1}={3,number,0.#}%;{6};{7};0;100";

        Object[] vObjs = new Object[8];
        vObjs[0] = cl.getOptionValue("db");
        vObjs[1] = cl.getOptionValue("tablespace");
        vObjs[2] = "OK";
        vObjs[3] = ts_pct;
        vObjs[4] = ts_free;
        vObjs[5] = ts_total;
        vObjs[6] = sWarning;
        vObjs[7] = sCritical;

        MessageFormat mf = new MessageFormat(sMsg);

        //if (ts_pct.compareTo(new BigDecimal(iCritical.intValue())) == 1)
        if (ThresholdUtil.isValueInRange(sCritical, ts_pct)) {
            vObjs[2] = "CRITICAL";
            CReturnValue rv = new CReturnValue(IJNRPEConstants.STATE_CRITICAL, mf.format(vObjs));
            return rv;
        }

        if (ThresholdUtil.isValueInRange(sWarning, ts_pct)) {
            vObjs[2] = "WARNING";
            CReturnValue rv = new CReturnValue(IJNRPEConstants.STATE_WARNING, mf.format(vObjs));

            return rv;
        }

        CReturnValue rv = new CReturnValue(IJNRPEConstants.STATE_OK, mf.format(vObjs));

        return rv;

    } catch (Exception e) {
        return new CReturnValue(IJNRPEConstants.STATE_CRITICAL, "CHECK_ORACLE : CRITICAL - " + e.getMessage());
    } finally {
        try {
            stmt.close();
            rs.close();
        } catch (Exception e) {
        }
    }

}

From source file:com.dbschools.quickquiz.client.giver.MainWindow.java

private void setFrameTitle() {
    final Object[] messageArguments = { getQuizName() };
    final MessageFormat formatter = new MessageFormat(Resources.getString("serverTitle"));
    setTitle(formatter.format(messageArguments));
}

From source file:it.govpay.web.utils.Utils.java

public static String fileSizeConverter(Number bytes) {
    MessageFormat mf = new MessageFormat("{0,number,#.##}");
    Double len = null;//w  ww  .j a v  a 2 s  .  c om
    String res = "";

    // il valore e' in byte
    len = bytes.doubleValue();
    long d = Math.round(len / 1024);
    //Originale e funzionante :)
    //      if (d <= 1) {
    //         // byte
    //         Object[] objs = { len };
    //         res = mf.format(objs);
    //         res += " B";
    //      } else if (d > 1 && d < 1000) {
    //         // kilo byte
    //         Object[] objs = { len / 1024 };
    //         res = mf.format(objs);
    //         res += " KB";
    //      } else {
    //         // mega byte
    //         Object[] objs = { len / 1048576 };
    //         res = mf.format(objs);
    //         res += " MB";
    //      }

    if (d <= 1) {
        // byte
        Object[] objs = { len };
        res = mf.format(objs);
        res += " B";
    } else if (d > 1 && d < 1000) {
        // kilo byte
        Object[] objs = { len / 1024 };
        res = mf.format(objs);
        res += " KB";
    } else if (d >= 1000 && d < 1000000) {
        // mega byte
        Object[] objs = { len / 1048576 };
        res = mf.format(objs);
        res += " MB";
    } else {
        // giga byte
        Object[] objs = { len / 1073741824 };
        res = mf.format(objs);
        res += " GB";
    }

    return res;
}

From source file:cc.redpen.validator.Validator.java

/**
 * returns localized error message for the given key formatted with argument
 *
 * @param key  message key//from ww  w.  ja v a  2  s . c  o m
 * @param args objects to format
 * @return localized error message
 */
protected String getLocalizedErrorMessage(String key, Object... args) {
    if (errorMessages != null) {
        String suffix = key != null ? "." + key : "";
        MessageFormat fmt = new MessageFormat(errorMessages.getString(this.getClass().getSimpleName() + suffix),
                locale);
        return fmt.format(args);
    } else {
        throw new AssertionError("message resource not found.");
    }
}

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

@Transactional
@Override/*from  w  w  w.j a  v  a 2s  .  co m*/
public String[] issueAsString(String numberName, int count) {

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

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

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

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

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

/**
 * continuity_control() MPEG-2 TS???????<br>
 * 015???MPEG-2 TS?1??????? <br>//from   w w  w  .ja v  a  2  s  .  c  o  m
 * ?????????? MPEG-2 TS???????0??<br>
 * ???TS????????????????????<br>
 * ??2??????<br>
 *
 * @return ?
 * @throws IllegalStateException ????(015?)????
 */
public synchronized int getContinuity_counter() throws IllegalStateException {
    int temp;
    temp = ByteConverter.byteToInt(this.data.getData()[3]);
    temp = temp & 0x0F;
    if ((temp >= 0) && (temp <= 15)) {
        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

/**
 * PID(ID)/*from w w w.j  a va 2  s .  co m*/
 *
 * @return
 * @throws IllegalStateException ????(0x00000x1FFF?)????
 */
public synchronized int getPid() throws IllegalStateException {
    byte[] t = new byte[2];
    System.arraycopy(this.data.getData(), 1, t, 0, t.length);
    int temp = ByteConverter.bytesToInt(t);
    temp = temp & 0x1FFF;
    if ((temp >= 0x0000) && (temp <= 0x1FFF)) {
        return temp;
    } else {
        MessageFormat msg = new MessageFormat("PID(ID)?????={0}");
        Object[] parameters = { temp };
        throw new IllegalStateException(msg.format(parameters));
    }
}

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

/**
 * Checks if the Azure Key Vault key path is Empty or Null (and raises exception if they are).
 * /*  www.j a  v  a2s .c o  m*/
 * @param masterKeyPath
 * @throws SQLServerException
 */
private void ValidateNonEmptyAKVPath(String masterKeyPath) throws SQLServerException {
    // throw appropriate error if masterKeyPath is null or empty
    if (null == masterKeyPath || masterKeyPath.trim().isEmpty()) {
        MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_AKVPathNull"));
        Object[] msgArgs = { masterKeyPath };
        throw new SQLServerException(null, form.format(msgArgs), null, 0, false);
    } else {
        URI parsedUri = null;
        try {
            parsedUri = new URI(masterKeyPath);
        } catch (URISyntaxException e) {
            MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_AKVURLInvalid"));
            Object[] msgArgs = { masterKeyPath };
            throw new SQLServerException(null, form.format(msgArgs), null, 0, false);
        }

        // A valid URI.
        // Check if it is pointing to AKV.
        if (!parsedUri.getHost().toLowerCase().endsWith(azureKeyVaultDomainName)) {
            // Return an error indicating that the AKV url is invalid.
            MessageFormat form = new MessageFormat(
                    SQLServerException.getErrString("R_AKVMasterKeyPathInvalid"));
            Object[] msgArgs = { masterKeyPath };
            throw new SQLServerException(null, form.format(msgArgs), null, 0, false);
        }
    }
}

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

/**
 * sync_byte(?)// w  w  w. ja  va2  s  .  c om
 *
 * @return
 * @throws IllegalStateException ????(0x47)????
 */
public synchronized int getSync_byte() throws IllegalStateException {
    int temp = ByteConverter.byteToInt(this.data.getData()[0]);
    if (temp == TsPacket.TS_SYNC_BYTE) {
        return temp;
    } else {
        MessageFormat msg = new MessageFormat("?????={0}");
        Object[] parameters = { Integer.toHexString(temp) };
        throw new IllegalStateException(msg.format(parameters));
    }
}