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:gov.nih.nci.firebird.common.ValidationFailure.java

/**
 * Creates a new failure instance (non-field level).
 *
 * @param resources contains the failure messages
 * @param messageKey the key to the specific failure
 * @param arguments parameter values to be inserted into the failure message
 * @return the failure// w w  w .ja  va  2 s .c  o m
 */
public static ValidationFailure create(ResourceBundle resources, String messageKey, Object... arguments) {
    MessageFormat format = new MessageFormat(resources.getString(messageKey));
    String message = format.format(arguments, new StringBuffer(), new FieldPosition(0)).toString();
    return new ValidationFailure(message);
}

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

private StringBuffer convertLocalTimeToUTC(String value) {
    StringBuffer localTimeColumnValue = null;
    try {/*from  ww  w.j  a  v a2s. c  om*/
        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 a short value, returning a 16 bit hexadecimal number. (4 digits
 * with leading zeros)//  w w w  . j a v  a 2 s  . co  m
 * 
 * @param number
 *            the short to format
 * @return the formatted binary number
 * 
 * @since 1.0
 */
public String format(short number) {
    return (format(number, new StringBuffer(), new FieldPosition(0)).toString());
}

From source file:com.anjz.util.CookieUtils.java

private static void getCookieHeaderValue(final Cookie cookie, final StringBuffer buf, final boolean httpOnly) {
    final int version = cookie.getVersion();

    // this part is the same for all cookies

    String name = cookie.getName(); // Avoid NPE on malformed cookies
    if (name == null) {
        name = "";
    }/*from  w w  w. j  a  va 2 s. c  o m*/
    String value = cookie.getValue();
    if (value == null) {
        value = "";
    }

    buf.append(name);
    buf.append("=");

    maybeQuote(version, buf, value);

    // add version 1 specific information
    if (version == 1) {
        // Version=1 ... required
        buf.append("; Version=1");

        // Comment=comment
        if (cookie.getComment() != null) {
            buf.append("; Comment=");
            maybeQuote(version, buf, cookie.getComment());
        }
    }

    // add domain information, if present

    if (cookie.getDomain() != null) {
        buf.append("; Domain=");
        maybeQuote(version, buf, cookie.getDomain());
    }

    // Max-Age=secs/Discard ... or use old "Expires" format
    if (cookie.getMaxAge() >= 0) {
        if (version == 0) {
            buf.append("; Expires=");
            SimpleDateFormat dateFormat = new SimpleDateFormat(OLD_COOKIE_PATTERN, LOCALE_US);
            dateFormat.setTimeZone(TimeZone.getTimeZone("GMT")); //GMT?
            if (cookie.getMaxAge() == 0) {
                dateFormat.format(new Date(10000), buf, new FieldPosition(0));
            } else {
                dateFormat.format(new Date(System.currentTimeMillis() + cookie.getMaxAge() * 1000L), buf,
                        new FieldPosition(0));
            }
        } else {
            buf.append("; Max-Age=");
            buf.append(cookie.getMaxAge());
        }
    } else if (version == 1) {
        buf.append("; Discard");
    }

    // Path=path
    if (cookie.getPath() != null) {
        buf.append("; Path=");
        maybeQuote(version, buf, cookie.getPath());
    }

    // Secure
    if (cookie.getSecure()) {
        buf.append("; Secure");
    }

    // HttpOnly
    if (httpOnly) {
        buf.append("; HttpOnly");
    }
}

From source file:HexFormat.java

/**
 * Format an int value, returning a 32 bit hexadecimal number. (8 digits
 * with leading zeros)/*from   ww w.  j  a  v  a 2 s .  co m*/
 * 
 * @param number
 *            the int to format
 * @return the formatted binary number
 * 
 * @since 1.0
 */
public String format(int number) {
    return (format(number, new StringBuffer(), new FieldPosition(0)).toString());
}

From source file:HexFormat.java

/**
 * Format a long value, returning a 64 bit hexadecimal number. (16 digits
 * with leading zeros)//from  w w w  .  java  2  s.com
 * 
 * @param number
 *            the long to format
 * @return the formatted binary number
 * 
 * @since 1.0
 */
public String format(long number) {
    return (format(number, new StringBuffer(), new FieldPosition(0)).toString());
}

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

/**
 * Helper to generate the link from the link format and values of the site and tag.
 *
 * @param fmt  link format.  This should have positional parameters {0} representing site with terminal /,  {1} for
 *             url-encoded-tag, and {2} for visible tag text.
 * @param site base portion of the URL// w  w w  .j  av  a  2 s  .  co m
 * @param tag  tag value
 * @return the generated link as a string
 */
protected String generateLink(MessageFormat fmt, String site, String tag) {
    // Allocate initial capacity of buffer of approximately the right length.
    StringBuffer sb = new StringBuffer(site.length() + tag.length() + getLinkFormatString().length());
    fmt.format(new Object[] { site, urlEncode(tag), tag }, sb, new FieldPosition(0));
    return sb.toString();
}

From source file:net.mumie.coursecreator.graph.MetaInfos.java

public String getFormattedDate(Calendar cal) {

    StringBuffer datesb = new StringBuffer();
    FieldPosition field = new FieldPosition(DateFormat.Field.ofCalendarField(Calendar.DATE));

    datesb = DATE_FORMAT.format(cal.getTime(), datesb, field);
    return datesb.toString();
}

From source file:net.sf.farrago.namespace.sfdc.SfdcUdx.java

public static void getDeleted(String objectName, String start, String end, PreparedStatement resultInserter)
        throws SQLException {
    SoapBindingStub binding = (SoapBindingStub) FarragoUdrRuntime.getDataServerRuntimeSupport(null);

    if (((start == null) || start.equals("")) || ((end == null) || end.equals(""))) {
        throw SfdcResource.instance().InvalidRangeException.ex();
    }/* w ww  . j  a  v  a  2 s.c o m*/

    Calendar startTime;
    Calendar endTime;
    Calendar thirtyDaysAgo;

    try {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
        java.util.Date sd = sdf.parse(start, new ParsePosition(0));
        startTime = Calendar.getInstance();
        startTime.setTime(sd);

        java.util.Date now = new java.util.Date();

        // 30 days == 30*24*60*60*1000 ms
        Long thirty = new Long("2592000000");
        java.util.Date thirtyDate = new java.util.Date(now.getTime() - thirty.longValue());
        thirtyDaysAgo = Calendar.getInstance();
        thirtyDaysAgo.setTime(thirtyDate);

        java.util.Date ed = sdf.parse(end, new ParsePosition(0));
        endTime = Calendar.getInstance();
        endTime.setTime(ed);
    } catch (Exception ex) {
        ex.printStackTrace();
        throw SfdcResource.instance().InvalidTimeException.ex(ex.getMessage());
    }
    if (thirtyDaysAgo.compareTo(startTime) > 0) {
        throw SfdcResource.instance().InvalidStartTimeException.ex(startTime.getTime().toString());
    }

    if (startTime.compareTo(endTime) > 0) {
        throw SfdcResource.instance().InvalidEndTimeException.ex(endTime.getTime().toString(),
                startTime.getTime().toString());
    }

    SfdcDataServer server = (SfdcDataServer) FarragoUdrRuntime.getDataServerRuntimeSupport(new Object());
    try {
        DescribeSObjectResult describeSObjectResult = (DescribeSObjectResult) server
                .getEntityDescribe(objectName);

        // check the name
        if ((describeSObjectResult != null) && describeSObjectResult.getName().equals(objectName)) {
            // check if data replication is allowed on object
            if (!describeSObjectResult.isReplicateable()) {
                throw SfdcResource.instance().ReplicationException.ex(objectName);
            }
        } else {
            throw SfdcResource.instance().InvalidObjectException.ex(objectName);
        }
        GetDeletedResult gdr = binding.getDeleted(objectName, startTime, endTime);
        if ((gdr.getDeletedRecords() != null) && (gdr.getDeletedRecords().length > 0)) {
            for (int i = 0; i < gdr.getDeletedRecords().length; i++) {
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                StringBuffer sbuf = new StringBuffer();
                String idString = gdr.getDeletedRecords(i).getId();
                int prec = 25 + server.getVarcharPrecision();
                if (idString.length() > prec) {
                    idString = idString.substring(0, prec);
                }
                resultInserter.setString(1, idString);
                String timeStr = sdf
                        .format(gdr.getDeletedRecords(i).getDeletedDate().getTime(), sbuf, new FieldPosition(0))
                        .toString();
                resultInserter.setTimestamp(2, java.sql.Timestamp.valueOf(timeStr));
                resultInserter.executeUpdate();
            }
        }
    } catch (AxisFault ae) {
        SQLException retryExcn = new SQLException(ae.getFaultString(), null, 460150);
        Exception chainedEx = FarragoResource.instance().RetryableFailure.ex(retryExcn);
        throw SfdcResource.instance().BindingCallException.ex(ae.getFaultString(), chainedEx);
    } catch (RemoteException re) {
        SQLException retryExcn = new SQLException(re.getMessage(), null, 460150);
        Exception chainedEx = FarragoResource.instance().RetryableFailure.ex(retryExcn);
        throw SfdcResource.instance().BindingCallException.ex(re.getMessage(), chainedEx);
    }
}

From source file:DateTimeEditor.java

private void getFieldPositions() {
    m_fieldPositions.clear();/*from  www . ja  va 2  s .co  m*/
    for (int ctr = 0; ctr < m_fieldTypes.length; ++ctr) {
        int fieldId = m_fieldTypes[ctr];
        FieldPosition fieldPosition = new FieldPosition(fieldId);
        StringBuffer formattedField = new StringBuffer();
        m_format.format(m_lastDate, formattedField, fieldPosition);
        if (fieldPosition.getEndIndex() > 0)
            m_fieldPositions.add(fieldPosition);
    }
    m_fieldPositions.trimToSize();
    Collections.sort(m_fieldPositions, new Comparator() {
        public int compare(Object o1, Object o2) {
            return (((FieldPosition) o1).getBeginIndex() - ((FieldPosition) o2).getBeginIndex());
        }
    });
}