Example usage for java.text FieldPosition FieldPosition

List of usage examples for java.text FieldPosition FieldPosition

Introduction

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

Prototype

public FieldPosition(Format.Field attribute) 

Source Link

Document

Creates a FieldPosition object for the given field constant.

Usage

From source file:org.apache.roller.weblogger.business.plugins.entry.SearchPluginBase.java

/**
 * Apply plugin to content of specified String.
 *
 * @param str String to which plugin should be applied.
 * @return Results of applying plugin to string.
 * @see org.apache.roller.weblogger.model.PagePlugin#render(String)
 *///from w w  w.  ja  v a  2 s  .c  o  m
public String render(WeblogEntry entry, String str) {
    Pattern pattern = getPattern();
    Matcher m = pattern.matcher(str);
    StringBuffer result = new StringBuffer(str.length() + 128); // rough guess at a reasonable length
    Object[] args = new Object[] { "", "", null, null };
    while (m.find()) {
        // parse out the parts of the match
        String type = m.group(1);
        boolean feelinLucky = type.equals("!"); // are ya feelin lucky? are ya punk?
        String linkText = m.group(2);
        String searchText = m.group(3);
        if (searchText == null || searchText.length() == 0) {
            searchText = linkText;
        }

        // URL-encode the search text
        String encodedSearchText = encodeSearchText(searchText);

        // form the replacement string
        MessageFormat linkFormat = feelinLucky ? getLuckyLinkFormat() : getLinkFormat();
        StringBuffer replacement = new StringBuffer(128);
        args[2] = linkText;
        args[3] = encodedSearchText;
        linkFormat.format(args, replacement, new FieldPosition(0));

        // append replacement
        m.appendReplacement(result, replacement.toString());
    }
    m.appendTail(result);

    return result.toString();
}

From source file:HexFormat.java

/**
 * Format a byte, returning an 8 bit hex number. (2 digits, with leading
 * zeros)// ww w . j av  a 2s .  c  om
 * 
 * @param number
 *            the byte to format
 * @return the formatted hex number
 * 
 * @since 1.0
 */
public final String format(byte number) {
    return (format(number, new StringBuffer(), new FieldPosition(0)).toString());
}

From source file:org.talend.core.ui.context.PatternCalendarDialog.java

@Override
public String getTalendDateString() {
    StringBuffer result = new StringBuffer();

    String pattern = time.getPatternText();
    if (pattern == null || pattern == "") { //$NON-NLS-1$
        pattern = "yyyy-MM-dd HH:mm:ss"; //$NON-NLS-1$
    } else if (pattern.startsWith("\"")) { //$NON-NLS-1$
        // remove quotes
        pattern = pattern.substring(1, pattern.length() - 1);

    }/*  ww w  .j ava2 s .  c  o  m*/
    SimpleDateFormat sdf = new SimpleDateFormat(pattern);
    sdf.format(getDate(), result, new FieldPosition(0));
    return pattern + ";" + result.toString(); //$NON-NLS-1$
}

From source file:com.vladium.emma.report.html.ReportGenerator.java

public ReportGenerator() {
    m_format = (DecimalFormat) NumberFormat.getPercentInstance(); // TODO: locale
    m_fieldPosition = new FieldPosition(DecimalFormat.INTEGER_FIELD);

    m_format.setMaximumFractionDigits(0);
}

From source file:org.egov.infra.utils.NumberToWord.java

public static String amountInWords(Double amount) {
    StringBuffer formattedAmount = new StringBuffer();
    new DecimalFormat("###0.00").format(amount, formattedAmount, new FieldPosition(0));
    return stripExtraSpaces(NumberToWord.convertToWord(formattedAmount.toString()));
}

From source file:org.apache.kylin.storage.jdbc.ITJDBCResourceStoreTest.java

@Before
public void setup() throws Exception {
    this.createTestMetadata();
    kylinConfig = KylinConfig.getInstanceFromEnv();
    KylinConfig configBackup = KylinConfig.createKylinConfig(kylinConfig);
    Statement statement = null;//w  ww. j  a  v  a  2  s  . c  om
    Connection conn = null;
    metadataUrlBackup = kylinConfig.getMetadataUrl();
    kylinConfig.setMetadataUrl(mainIdentifier + jdbcMetadataUrlNoIdentifier);
    JDBCSqlQueryFormat sqlQueryFormat = JDBCSqlQueryFormatProvider
            .createJDBCSqlQueriesFormat(KylinConfig.getInstanceFromEnv().getMetadataDialect());
    try {
        connectionManager = JDBCConnectionManager.getConnectionManager();
        conn = connectionManager.getConn();
        statement = conn.createStatement();
        String sql = new MessageFormat(sqlQueryFormat.getTestDropSql(), Locale.ROOT)
                .format(mainIdentifier, new StringBuffer(), new FieldPosition(0)).toString();
        statement.executeUpdate(sql);
        sql = new MessageFormat(sqlQueryFormat.getTestDropSql(), Locale.ROOT)
                .format(copyIdentifier, new StringBuffer(), new FieldPosition(0)).toString();
        statement.executeUpdate(sql);
        jdbcConnectable = true;
        ResourceTool.copy(configBackup, kylinConfig);
    } catch (RuntimeException ex) {
        logger.info("Init connection manager failed, skip test cases");
    } finally {
        JDBCConnectionManager.closeQuietly(statement);
        JDBCConnectionManager.closeQuietly(conn);
    }
}

From source file:org.openbravo.client.kernel.reference.AbsoluteTimeUIDefinition.java

private StringBuffer convertFromStringToStringBuffer(String value) {
    StringBuffer localTimeColumnValue = null;
    try {//ww  w.  ja  va  2 s  . com
        Date UTCDate = getClassicFormat().parse(value);
        Calendar now = Calendar.getInstance();

        Calendar calendar = Calendar.getInstance();
        calendar.setTime(UTCDate);
        calendar.set(Calendar.DATE, now.get(Calendar.DATE));
        calendar.set(Calendar.MONTH, now.get(Calendar.MONTH));
        calendar.set(Calendar.YEAR, now.get(Calendar.YEAR));

        localTimeColumnValue = getClassicFormat().format(calendar.getTime(), new StringBuffer(),
                new FieldPosition(0));
    } catch (ParseException e) {
        throw new OBException("Exception when parsing date ", e);
    }
    return localTimeColumnValue;
}

From source file:com.anrisoftware.globalpom.format.byteformat.ByteFormat.java

/**
 * @param multiplier/*from  ww w .  j  av  a2 s.c  o m*/
 *            the unit {@link UnitMultiplier}.
 *
 * @see #format(Object)
 */
public String format(Object obj, UnitMultiplier multiplier) {
    return format(obj, new StringBuffer(), new FieldPosition(0), multiplier).toString();
}

From source file:org.openbravo.client.kernel.reference.TimeUIDefinition.java

private StringBuffer convertUtcToLocalTime(String value) {
    StringBuffer localTimeColumnValue = null;
    try {/*from  ww  w  .j a v a2 s.  c o  m*/
        Date UTCDate = getClassicFormat().parse(value);
        Calendar now = Calendar.getInstance();

        Calendar calendar = Calendar.getInstance();
        calendar.setTime(UTCDate);
        calendar.set(Calendar.DATE, now.get(Calendar.DATE));
        calendar.set(Calendar.MONTH, now.get(Calendar.MONTH));
        calendar.set(Calendar.YEAR, now.get(Calendar.YEAR));

        int gmtMillisecondOffset = (now.get(Calendar.ZONE_OFFSET) + now.get(Calendar.DST_OFFSET));
        calendar.add(Calendar.MILLISECOND, gmtMillisecondOffset);
        localTimeColumnValue = getClassicFormat().format(calendar.getTime(), new StringBuffer(),
                new FieldPosition(0));
    } catch (ParseException e) {
        throw new OBException("Exception when parsing date ", e);
    }
    return localTimeColumnValue;
}

From source file:HexFormat.java

/**
 * Format an array of bytes, returning 8 bits per byte. (2 digits with
 * leading zeros, per byte) The byte at index zero is the most significant
 * byte, making it possible to enter a stream of bytes received from a
 * serial connection very easily.//  www . j  ava  2s.  c  om
 * 
 * @param number
 *            the bytes to format
 * @return the formatted binary number
 * 
 * @since 1.0
 */
public final String format(byte[] number) {
    return (format(number, new StringBuffer(), new FieldPosition(0)).toString());
}