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:libepg.epg.section.Section.java

/**
 * ?CRC?/*from   w w  w  .  j  av  a2s  . co  m*/
 *
 * @return ?
 */
public final synchronized CRC_STATUS checkCRC() {
    SectionCrcChecker checker = new SectionCrcChecker();

    int res = checker.checkCrc(this.getData());
    if (res == 0) {
        return CRC_STATUS.NO_CRC_ERROR;
    } else {
        if (LOG.isWarnEnabled()) {
            MessageFormat msg = new MessageFormat("CRC???0?????={0}");
            Object[] parameters = { res };
            LOG.warn(msg.format(parameters));
        }
        return CRC_STATUS.CRC_ERROR;
    }
}

From source file:com.okta.tools.awscli.java

private static String setAWSCredentials(AssumeRoleWithSAMLResult assumeResult, String credentialsProfileName)
        throws FileNotFoundException, UnsupportedEncodingException, IOException {
    BasicSessionCredentials temporaryCredentials = new BasicSessionCredentials(
            assumeResult.getCredentials().getAccessKeyId(), assumeResult.getCredentials().getSecretAccessKey(),
            assumeResult.getCredentials().getSessionToken());

    String awsAccessKey = temporaryCredentials.getAWSAccessKeyId();
    String awsSecretKey = temporaryCredentials.getAWSSecretKey();
    String awsSessionToken = temporaryCredentials.getSessionToken();

    if (credentialsProfileName.startsWith("arn:aws:sts::")) {
        credentialsProfileName = credentialsProfileName.substring(13);
    }//from  w  w w .  jav a 2 s  .  c  om
    if (credentialsProfileName.contains(":assumed-role")) {
        credentialsProfileName = credentialsProfileName.replaceAll(":assumed-role", "");
    }

    Object[] args = { new String(credentialsProfileName), selectedPolicyRank };
    MessageFormat profileNameFormat = new MessageFormat("{0}/{1}");
    credentialsProfileName = profileNameFormat.format(args);

    //update the credentials file with the unique profile name
    UpdateCredentialsFile(credentialsProfileName, awsAccessKey, awsSecretKey, awsSessionToken);
    //also override the default profile
    UpdateCredentialsFile(DefaultProfileName, awsAccessKey, awsSecretKey, awsSessionToken);

    return credentialsProfileName;
}

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

/**
 * ????DescriptorsLoop?????/*w  w w  .  j av  a  2 s.co m*/
 *
 * @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:org.web4thejob.print.CsvPrinter.java

@Override
public File print(String title, List<RenderScheme> renderSchemes, Query query, List<Entity> entities) {
    Assert.notNull(renderSchemes);/*w  w w .  j  a v  a2s .co m*/

    int i = 0;
    File file;
    try {
        String crlf = System.getProperty("line.separator");
        file = createTempFile();
        BufferedWriter writer = createFileStream(file);
        writer.write(title + crlf);
        writer.newLine();

        CSVWriter csv = new CSVWriter(writer);

        for (Entity entity : entities) {

            if (entity == null) {
                Assert.notNull(query);
                entity = ContextUtil.getDRS().findUniqueByQuery(query);
            }

            if (query != null && query.hasMasterCriterion()) {
                writer.write(describeMasterCriteria(query));
                writer.newLine();
            }

            if (query != null) {
                writer.write(describeCriteria(query));
                writer.newLine();
            }

            writeLine(csv, ContextUtil.getBean(ConversionService.class), entity, renderSchemes.get(i));
            writer.newLine();
            writer.newLine();
            i++;
        }

        //timestamp
        List<String> line = new ArrayList<String>();
        line.add(L10nMessages.L10N_LABEL_TIMESTAMP.toString());
        MessageFormat df = new MessageFormat("");
        df.setLocale(CoreUtil.getUserLocale());
        df.applyPattern("{0,date,yyyy-MM-dd hh:mm:ss}");
        line.add(df.format(new Object[] { new Date() }));
        csv.writeNext(line.toArray(new String[line.size()]));

        writer.newLine();

        writer.write("powered by web4thejob.org");
        writer.close();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }

    return file;

}

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

private void processQuizOverMsg() {
    final MessageFormat formatter = new MessageFormat(Resources.getString("quizOver"));
    JOptionPane.showMessageDialog(MainWindow.this, formatter.format(new Object[] { getQuizName() }));
    deregister();/*  w  ww.j  ava 2 s  .  c om*/
    System.exit(0);
}

From source file:org.eclipse.swt.examples.accessibility.Shape.java

void addListeners() {
    addPaintListener(e -> {/*from w  w w. jav a2 s .co m*/
        GC gc = e.gc;
        Display display = getDisplay();
        Color c = display.getSystemColor(color);
        gc.setBackground(c);
        Rectangle rect = getClientArea();
        int length = Math.min(rect.width, rect.height);
        if (shape == CIRCLE) {
            gc.fillOval(0, 0, length, length);
        } else {
            gc.fillRectangle(0, 0, length, length);
        }
        if (isFocusControl())
            gc.drawFocus(rect.x, rect.y, rect.width, rect.height);
    });

    addFocusListener(new FocusAdapter() {
        @Override
        public void focusGained(FocusEvent e) {
            redraw();
        }

        @Override
        public void focusLost(FocusEvent e) {
            redraw();
        }
    });

    addMouseListener(MouseListener.mouseDownAdapter(e -> {
        if (getClientArea().contains(e.x, e.y)) {
            setFocus();
        }
    }));

    addKeyListener(new KeyAdapter() {
        @Override
        public void keyPressed(KeyEvent e) {
            // key listener enables traversal out
        }
    });

    addTraverseListener(e -> {
        switch (e.detail) {
        case SWT.TRAVERSE_TAB_NEXT:
        case SWT.TRAVERSE_TAB_PREVIOUS:
            e.doit = true;
            break;
        }
    });

    getAccessible().addAccessibleListener(new AccessibleAdapter() {
        @Override
        public void getName(AccessibleEvent e) {
            MessageFormat formatter = new MessageFormat("");
            formatter.applyPattern(bundle.getString("name")); //$NON_NLS$
            String colorName = bundle.getString("color" + color); //$NON_NLS$
            String shapeName = bundle.getString("shape" + shape); //$NON_NLS$
            e.result = formatter.format(new String[] { colorName, shapeName }); //$NON_NLS$
        }
    });

    getAccessible().addAccessibleControlListener(new AccessibleControlAdapter() {
        @Override
        public void getRole(AccessibleControlEvent e) {
            e.detail = ACC.ROLE_GRAPHIC;
        }

        @Override
        public void getState(AccessibleControlEvent e) {
            e.detail = ACC.STATE_FOCUSABLE;
            if (isFocusControl())
                e.detail |= ACC.STATE_FOCUSED;
        }
    });
}

From source file:org.web4thejob.print.CsvPrinter.java

@Override
public File print(String title, RenderScheme renderScheme, Query query, List<Entity> entities) {
    Assert.notNull(renderScheme);// w  w  w . j  a  v a2s. c o  m
    Assert.isTrue(renderScheme.getSchemeType() == SchemeType.LIST_SCHEME);

    if (entities == null) {
        Assert.notNull(query);
        entities = ContextUtil.getDRS().findByQuery(query);
    }

    File file;
    try {
        String crlf = System.getProperty("line.separator");
        file = createTempFile();
        BufferedWriter writer = createFileStream(file);
        writer.write(title + crlf);
        writer.newLine();

        if (query != null && query.hasMasterCriterion()) {
            writer.write(describeMasterCriteria(query));
            writer.newLine();
        }

        if (query != null) {
            writer.write(describeCriteria(query));
            writer.newLine();
        }

        CSVWriter csv = new CSVWriter(writer);
        List<String> header = new ArrayList<String>();
        for (RenderElement item : renderScheme.getElements()) {
            if (item.getPropertyPath().getLastStep().isBlobType())
                continue;
            header.add(item.getFriendlyName());
        }
        csv.writeNext(header.toArray(new String[header.size()]));

        ConversionService conversionService = ContextUtil.getBean(ConversionService.class);
        for (final Entity entity : entities) {
            writeLine(csv, conversionService, entity, renderScheme);
        }

        writer.newLine();

        //timestamp
        List<String> line = new ArrayList<String>();
        line.add(L10nMessages.L10N_LABEL_TIMESTAMP.toString());
        MessageFormat df = new MessageFormat("");
        df.setLocale(CoreUtil.getUserLocale());
        df.applyPattern("{0,date,yyyy-MM-dd hh:mm:ss}");
        line.add(df.format(new Object[] { new Date() }));
        csv.writeNext(line.toArray(new String[line.size()]));

        writer.newLine();

        writer.write("powered by web4thejob.org");
        writer.close();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }

    return file;
}

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

/**
 * Subclasses can override this method to resolve a message without
 * arguments in an optimized fashion, that is, to resolve a message
 * without involving a MessageFormat./*w ww. j a  va  2 s .  c  om*/
 * <p>The default implementation <i>does</i> use MessageFormat,
 * through delegating to the <code>resolveCode</code> method.
 * Subclasses are encouraged to replace this with optimized resolution.
 * <p>Unfortunately, <code>java.text.MessageFormat</code> is not
 * implemented in an efficient fashion. In particular, it does not
 * detect that a message pattern doesn't contain argument placeholders
 * in the first place. Therefore, it's advisable to circumvent
 * MessageFormat completely for messages without arguments.
 * @param code the code of the message to resolve
 * @param locale the Locale to resolve the code for
 * (subclasses are encouraged to support internationalization)
 * @return the message String, or <code>null</code> if not found
 * @see #resolveCode
 * @see java.text.MessageFormat
 */
protected String resolveCodeWithoutArguments(String code, Locale locale) {
    MessageFormat messageFormat = resolveCode(code, locale);
    if (messageFormat != null) {
        synchronized (messageFormat) {
            return messageFormat.format(new Object[0]);
        }
    }
    return null;
}

From source file:it.jnrpe.plugin.CCheckOracle.java

/**
 * Checks if the database is reacheble/*from w  w w .ja  v  a  2  s.  com*/
 * @param c
 * @param cl
 * @return
 */
private CReturnValue checkAlive(Connection c, CCommandLine cl) {
    Statement stmt = null;
    ResultSet rs = null;

    String sMsg = "{0} : {1} - {2} {3}";

    Object[] vObjs = new Object[4];
    vObjs[0] = "CHECK_ORACLE";
    vObjs[1] = cl.getOptionValue("db");
    vObjs[2] = "OK";
    vObjs[3] = "";

    MessageFormat mf = new MessageFormat(sMsg);

    try {
        stmt = c.createStatement();
        rs = stmt.executeQuery("SELECT SYSDATE FROM DUAL");

        return new CReturnValue(IJNRPEConstants.STATE_OK, mf.format(vObjs));
    } catch (SQLException sqle) {
        vObjs[2] = "UNKNOWN";
        vObjs[3] = sqle.getMessage();

        return new CReturnValue(IJNRPEConstants.STATE_UNKNOWN, mf.format(vObjs));
    } catch (Exception e) {
        vObjs[2] = "CRITICAL";
        vObjs[3] = e.getMessage();

        return new CReturnValue(IJNRPEConstants.STATE_CRITICAL, mf.format(vObjs));
    } finally {
        try {
            stmt.close();
            rs.close();
        } catch (Exception e) {
        }
    }
}

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

/**
 * @param packet /*from w w  w .  ja v  a 2  s  . com*/
 * @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));
    }
}