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.kylin.common.persistence.JDBCResourceDAO.java

private String getInsertSql(String tableName) {
    String sql = new MessageFormat(jdbcSqlQueryFormat.getInsertSql(), Locale.ROOT)
            .format(new Object[] { tableName, META_TABLE_KEY, META_TABLE_TS, META_TABLE_CONTENT },
                    new StringBuffer(), new FieldPosition(0))
            .toString();/* w w w .j  a  v  a2  s  . c o m*/
    return sql;
}

From source file:org.apache.kylin.common.persistence.JDBCResourceDAO.java

@SuppressWarnings("unused")
private String getReplaceSqlWithoutContent(String tableName) {
    String sql = new MessageFormat(jdbcSqlQueryFormat.getReplaceSqlWithoutContent(), Locale.ROOT)
            .format(new Object[] { tableName, META_TABLE_TS, META_TABLE_KEY }, new StringBuffer(),
                    new FieldPosition(0))
            .toString();/*from  w  w w.  j  av  a2 s .co  m*/
    return sql;
}

From source file:org.apache.kylin.common.persistence.JDBCResourceDAO.java

private String getInsertSqlWithoutContent(String tableName) {
    String sql = new MessageFormat(jdbcSqlQueryFormat.getInsertSqlWithoutContent(), Locale.ROOT)
            .format(new Object[] { tableName, META_TABLE_KEY, META_TABLE_TS }, new StringBuffer(),
                    new FieldPosition(0))
            .toString();/*w  w w  .  ja v a  2  s . c o  m*/
    return sql;
}

From source file:org.apache.kylin.common.persistence.JDBCResourceDAO.java

private String getUpdateSqlWithoutContent(String tableName) {
    String sql = new MessageFormat(jdbcSqlQueryFormat.getUpdateSqlWithoutContent(), Locale.ROOT)
            .format(new Object[] { tableName, META_TABLE_TS, META_TABLE_KEY, META_TABLE_TS },
                    new StringBuffer(), new FieldPosition(0))
            .toString();/* ww  w  .j a v  a 2s. co  m*/
    return sql;
}

From source file:org.apache.kylin.common.persistence.JDBCResourceDAO.java

private String getUpdateContentSql(String tableName) {
    String sql = new MessageFormat(jdbcSqlQueryFormat.getUpdateContentSql(), Locale.ROOT)
            .format(new Object[] { tableName, META_TABLE_CONTENT, META_TABLE_KEY }, new StringBuffer(),
                    new FieldPosition(0))
            .toString();//from   ww  w.j  av a 2s.  co m
    return sql;
}

From source file:org.kuali.rice.kew.mail.service.impl.ActionListEmailServiceImpl.java

public String buildImmediateReminderBody(Person person, org.kuali.rice.kew.api.action.ActionItem actionItem,
        DocumentType documentType) {
    String docHandlerUrl = documentType.getResolvedDocumentHandlerUrl();
    if (StringUtils.isNotBlank(docHandlerUrl)) {
        if (!docHandlerUrl.contains("?")) {
            docHandlerUrl += "?";
        } else {/* w ww .j a  v a  2s  . co  m*/
            docHandlerUrl += "&";
        }
        docHandlerUrl += KewApiConstants.DOCUMENT_ID_PARAMETER + "=" + actionItem.getDocumentId();
        docHandlerUrl += "&" + KewApiConstants.COMMAND_PARAMETER + "=" + KewApiConstants.ACTIONLIST_COMMAND;
    }
    StringBuffer sf = new StringBuffer();

    /*sf
      .append("Your Action List has an eDoc(electronic document) that needs your attention: \n\n");
    sf.append("Document ID:\t" + actionItem.getDocumentId() + "\n");
    sf.append("Initiator:\t\t");
    try {
       sf.append(actionItem.getRouteHeader().getInitiatorUser()
         .getDisplayName()
         + "\n");
    } catch (Exception e) {
       LOG.error("Error retrieving initiator for action item "
         + actionItem.getDocumentId());
       sf.append("\n");
    }
    sf.append("Type:\t\t" + "Add/Modify "
      + actionItem.getRouteHeader().getDocumentType().getName()
      + "\n");
    sf.append("Title:\t\t" + actionItem.getDocTitle() + "\n");
    sf.append("\n\n");
    sf.append("To respond to this eDoc: \n");
    sf.append("\tGo to " + docHandlerUrl + "\n\n");
    sf.append("\tOr you may access the eDoc from your Action List: \n");
    sf.append("\tGo to " + getActionListUrl()
      + ", and then click on the numeric Document ID: "
      + actionItem.getDocumentId()
      + " in the first column of the List. \n");
    sf.append("\n\n\n");
    sf
      .append("To change how these email notifications are sent(daily, weekly or none): \n");
    sf.append("\tGo to " + getPreferencesUrl() + "\n");
    sf.append("\n\n\n");
    sf.append(getHelpLink(documentType) + "\n\n\n");*/

    MessageFormat messageFormat = null;
    String stringMessageFormat = ConfigContext.getCurrentContextConfig()
            .getProperty(IMMEDIATE_REMINDER_EMAIL_MESSAGE_KEY);
    LOG.debug("Immediate reminder email message from configuration (" + IMMEDIATE_REMINDER_EMAIL_MESSAGE_KEY
            + "): " + stringMessageFormat);
    if (stringMessageFormat == null) {
        messageFormat = DEFAULT_IMMEDIATE_REMINDER;
    } else {
        messageFormat = new MessageFormat(stringMessageFormat);
    }
    String initiatorUser = (person == null ? "" : person.getName());

    if (StringUtils.isNotBlank(docHandlerUrl)) {
        Object[] args = { actionItem.getDocumentId(), initiatorUser, documentType.getName(),
                actionItem.getDocTitle(), docHandlerUrl, getActionListUrl(), getPreferencesUrl(),
                getHelpLink(documentType) };

        messageFormat.format(args, sf, new FieldPosition(0));

        LOG.debug("default immediate reminder: " + DEFAULT_IMMEDIATE_REMINDER.format(args));
    } else {
        Object[] args = { actionItem.getDocumentId(), initiatorUser, documentType.getName(),
                actionItem.getDocTitle(), getActionListUrl(), getPreferencesUrl(), getHelpLink(documentType) };

        messageFormat.format(args, sf, new FieldPosition(0));

        LOG.debug("default immediate reminder: " + DEFAULT_IMMEDIATE_REMINDER_NO_DOC_HANDLER.format(args));
    }
    LOG.debug("immediate reminder: " + sf);

    // for debugging purposes on the immediate reminder only
    if (!isProduction()) {
        try {
            sf.append("Action Item sent to " + actionItem.getPrincipalId());
            if (actionItem.getDelegationType() != null) {
                sf.append(" for delegation type " + actionItem.getDelegationType());
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    return sf.toString();
}

From source file:org.zkoss.poi.ss.format.CellNumberFormatter.java

private void writeScientific(double value, StringBuffer output, Set<StringMod> mods) {

    StringBuffer result = new StringBuffer();
    FieldPosition fractionPos = new FieldPosition(DecimalFormat.FRACTION_FIELD);
    decimalFmt.format(value, result, fractionPos);
    writeInteger(result, output, integerSpecials, mods, integerCommas, false);
    writeFractional(result, output);/*www .  j a  v  a 2s. c o  m*/

    /*
    * Exponent sign handling is complex.
    *
    * In DecimalFormat, you never put the sign in the format, and the sign only
    * comes out of the format if it is negative.
    *
    * In Excel, you always say whether to always show the sign ("e+") or only
    * show negative signs ("e-").
    *
    * Also in Excel, where you put the sign in the format is NOT where it comes
    * out in the result.  In the format, the sign goes with the "e"; in the
    * output it goes with the exponent value.  That is, if you say "#e-|#" you
    * get "1e|-5", not "1e-|5". This makes sense I suppose, but it complicates
    * things.
    *
    * Finally, everything else in this formatting code assumes that the base of
    * the result is the original format, and that starting from that situation,
    * the indexes of the original special characters can be used to place the new
    * characters.  As just described, this is not true for the exponent's sign.
    * <p/>
    * So here is how we handle it:
    *
    * (1) When parsing the format, remove the sign from after the 'e' and put it
    * before the first digit of the exponent (where it will be shown).
    *
    * (2) Determine the result's sign.
    *
    * (3) If it's missing, put the sign into the output to keep the result
    * lined up with the output. (In the result, "after the 'e'" and "before the
    * first digit" are the same because the result has no extra chars to be in
    * the way.)
    *
    * (4) In the output, remove the sign if it should not be shown ("e-" was used
    * and the sign is negative) or set it to the correct value.
    */

    // (2) Determine the result's sign.
    int ePos = fractionPos.getEndIndex();
    int signPos = ePos + 1;
    char expSignRes = result.charAt(signPos);
    if (expSignRes != '-') {
        // not a sign, so it's a digit, and therefore a positive exponent
        expSignRes = '+';
        // (3) If it's missing, put the sign into the output to keep the result
        // lined up with the output.
        result.insert(signPos, '+');
    }

    // Now the result lines up like it is supposed to with the specials' indexes
    ListIterator<Special> it = exponentSpecials.listIterator(1);
    Special expSign = it.next();
    char expSignFmt = expSign.ch;

    // (4) In the output, remove the sign if it should not be shown or set it to
    // the correct value.
    if (expSignRes == '-' || expSignFmt == '+')
        mods.add(replaceMod(expSign, true, expSign, true, expSignRes));
    else
        mods.add(deleteMod(expSign, true, expSign, true));

    StringBuffer exponentNum = new StringBuffer(result.substring(signPos + 1));
    writeInteger(exponentNum, output, exponentDigitSpecials, mods, false, false);
}

From source file:org.zuinnote.hadoop.office.format.common.converter.ExcelConverterSimpleSpreadSheetCellDAO.java

/***
 * Converts a row consisting of objects of simple data types (String, byte,
 * short, int, long, etc.) to a row of SpreadSheetCellDAO
 * /*w w  w .  j ava  2  s . com*/
 * @param row
 * @param sheetName
 * @param rowNum
 * @return
 */
public SpreadSheetCellDAO[] getSpreadSheetCellDAOfromSimpleDataType(Object[] row, String sheetName,
        int rowNum) {
    // for each value in the row

    SpreadSheetCellDAO[] result = new SpreadSheetCellDAO[row.length];
    for (int currentColumnNum = 0; currentColumnNum < row.length; currentColumnNum++) { // for each element of the
        // row
        Object x = row[currentColumnNum];
        String formattedValue = "";
        String comment = "";
        String formula = "";
        String address = "";
        StringBuffer sb = new StringBuffer();
        if (x != null) {
            if (x instanceof SpreadSheetCellDAO) {
                result[currentColumnNum] = (SpreadSheetCellDAO) x;
            } else {
                if (x instanceof Boolean) {
                    formattedValue = "";
                    comment = "";
                    formula = String.valueOf(x);
                    address = MSExcelUtil.getCellAddressA1Format(rowNum, currentColumnNum);
                } else if (x instanceof Byte) {
                    formattedValue = "";
                    comment = "";
                    formula = String.valueOf(x);
                    address = MSExcelUtil.getCellAddressA1Format(rowNum, currentColumnNum);
                } else if (x instanceof Short) {
                    formattedValue = "";
                    comment = "";
                    formula = "";
                    formula = String.valueOf(x);
                    address = MSExcelUtil.getCellAddressA1Format(rowNum, currentColumnNum);
                } else if (x instanceof Integer) {
                    formattedValue = "";
                    comment = "";
                    formula = String.valueOf(x);
                    address = MSExcelUtil.getCellAddressA1Format(rowNum, currentColumnNum);
                } else if (x instanceof Long) {
                    formattedValue = "";
                    comment = "";
                    formula = String.valueOf(x);
                    address = MSExcelUtil.getCellAddressA1Format(rowNum, currentColumnNum);
                } else if (x instanceof Double) {
                    formattedValue = "";
                    comment = "";
                    formula = String.valueOf(x);
                    address = MSExcelUtil.getCellAddressA1Format(rowNum, currentColumnNum);
                } else if (x instanceof Float) {
                    formattedValue = "";
                    comment = "";
                    formula = String.valueOf(x);
                    address = MSExcelUtil.getCellAddressA1Format(rowNum, currentColumnNum);
                } else if (x instanceof BigDecimal) {
                    formattedValue = "";
                    comment = "";
                    formula = ((BigDecimal) x).toString();
                    address = MSExcelUtil.getCellAddressA1Format(rowNum, currentColumnNum);
                } else if (x instanceof Timestamp) {
                    if (this.dateTimeFormat == null) {
                        formattedValue = String.valueOf(x);
                    } else {
                        formattedValue = this.dateTimeFormat.format(x, sb, new FieldPosition(0)).toString();
                        sb.setLength(0);
                    }
                    comment = "";
                    formula = "";
                    address = MSExcelUtil.getCellAddressA1Format(rowNum, currentColumnNum);
                } else if (x instanceof Date) {
                    formattedValue = this.dateFormat.format((Date) x);
                    comment = "";
                    formula = "";
                    address = MSExcelUtil.getCellAddressA1Format(rowNum, currentColumnNum);
                } else if (x instanceof String) {
                    formattedValue = x.toString();
                    comment = "";
                    formula = "";
                    address = MSExcelUtil.getCellAddressA1Format(rowNum, currentColumnNum);
                } else if ((x instanceof String[]) && ((String[]) x).length == 5) {
                    String[] spreadSheetCellDAOAsArray = (String[]) x;
                    formattedValue = spreadSheetCellDAOAsArray[0];
                    comment = spreadSheetCellDAOAsArray[1];
                    formula = spreadSheetCellDAOAsArray[2];
                    address = spreadSheetCellDAOAsArray[3];
                    sheetName = spreadSheetCellDAOAsArray[4];
                } else {
                    LOG.warn("Unknown datatype in column number: " + currentColumnNum + ". Reported data type"
                            + x.getClass().getName() + ". Trying to use .toString");
                    formattedValue = x.toString();
                    comment = "";
                    formula = "";
                    address = MSExcelUtil.getCellAddressA1Format(rowNum, currentColumnNum);
                }
                result[currentColumnNum] = new SpreadSheetCellDAO(formattedValue, comment, formula, address,
                        sheetName);
            }
        }
    }
    return result;
}

From source file:com.sworddance.util.perf.LapTimer.java

/**
 * This returns an excel CVS line. The first cell is the name of this LapTimer.
 *
 * @return a comma separated value line.
 *///from   www  .j  a  va2  s.  c o m
public String toCSV() {
    StringBuffer sb = new StringBuffer(50);
    if (this.timerName != null) {
        sb.append(this.timerName);
    }
    sb.append(',');
    new SimpleDateFormat("MM/dd/yyyy HH:mm:ss.SSS").format(this.getStartDate(), sb, new FieldPosition(0));
    sb.append(',').append(this.hopCount);
    sb.append(',').append(this.elapsed());
    long[] history = this.getLapHistory();
    for (long element : history) {
        sb.append(',').append(element);
        if (this.denominator != 1.0f) {
            sb.append(',').append(element / this.denominator);
        }
    }
    return sb.toString();
}

From source file:eu.planets_project.tb.gui.backing.exp.NewExpWizardController.java

/**
 * Formats a gregorian calendar according to a specified format input schema
 * @param format/*  w w  w  .ja  v  a2 s .c  om*/
 * @param gc
 * @return
 */
private String doFormat(String format, Calendar gc) {
    SimpleDateFormat sdf = new SimpleDateFormat(format);
    FieldPosition fpos = new FieldPosition(0);

    StringBuffer b = new StringBuffer();
    StringBuffer sb = sdf.format(gc.getTime(), b, fpos);

    return sb.toString();
}