Search in sources :

Example 1 with FieldPosition

use of java.text.FieldPosition in project tomcat by apache.

the class LegacyCookieProcessor method generateHeader.

@Override
public String generateHeader(Cookie cookie) {
    /*
         * The spec allows some latitude on when to send the version attribute
         * with a Set-Cookie header. To be nice to clients, we'll make sure the
         * version attribute is first. That means checking the various things
         * that can cause us to switch to a v1 cookie first.
         *
         * Note that by checking for tokens we will also throw an exception if a
         * control character is encountered.
         */
    int version = cookie.getVersion();
    String value = cookie.getValue();
    String path = cookie.getPath();
    String domain = cookie.getDomain();
    String comment = cookie.getComment();
    if (version == 0) {
        // Check for the things that require a v1 cookie
        if (needsQuotes(value, 0) || comment != null || needsQuotes(path, 0) || needsQuotes(domain, 0)) {
            version = 1;
        }
    }
    // Now build the cookie header
    // can't use StringBuilder due to DateFormat
    StringBuffer buf = new StringBuffer();
    // Just use the name supplied in the Cookie
    buf.append(cookie.getName());
    buf.append("=");
    // Value
    maybeQuote(buf, value, version);
    // Add version 1 specific information
    if (version == 1) {
        // Version=1 ... required
        buf.append("; Version=1");
        // Comment=comment
        if (comment != null) {
            buf.append("; Comment=");
            maybeQuote(buf, comment, version);
        }
    }
    // Add domain information, if present
    if (domain != null) {
        buf.append("; Domain=");
        maybeQuote(buf, domain, version);
    }
    // Max-Age=secs ... or use old "Expires" format
    int maxAge = cookie.getMaxAge();
    if (maxAge >= 0) {
        if (version > 0) {
            buf.append("; Max-Age=");
            buf.append(maxAge);
        }
        // They do understand Expires, even with V1 cookies!
        if (version == 0 || getAlwaysAddExpires()) {
            // Wdy, DD-Mon-YY HH:MM:SS GMT ( Expires Netscape format )
            buf.append("; Expires=");
            // To expire immediately we need to set the time in past
            if (maxAge == 0) {
                buf.append(ANCIENT_DATE);
            } else {
                COOKIE_DATE_FORMAT.get().format(new Date(System.currentTimeMillis() + maxAge * 1000L), buf, new FieldPosition(0));
            }
        }
    }
    // Path=path
    if (path != null) {
        buf.append("; Path=");
        maybeQuote(buf, path, version);
    }
    // Secure
    if (cookie.getSecure()) {
        buf.append("; Secure");
    }
    // HttpOnly
    if (cookie.isHttpOnly()) {
        buf.append("; HttpOnly");
    }
    return buf.toString();
}
Also used : FieldPosition(java.text.FieldPosition) Date(java.util.Date)

Example 2 with FieldPosition

use of java.text.FieldPosition in project GCViewer by chewiebug.

the class MemoryFormat method formatToFormatted.

public FormattedValue formatToFormatted(double memInK) {
    StringBuffer toAppendTo = new StringBuffer();
    FieldPosition pos = new FieldPosition(0);
    FormattedValue formed = formatToFormatted(memInK, toAppendTo, pos, false);
    return formed;
}
Also used : FieldPosition(java.text.FieldPosition)

Example 3 with FieldPosition

use of java.text.FieldPosition in project tdi-studio-se by Talend.

the class BusinessStructuralFeatureParser method getStringByPattern.

/**
     * @generated
     */
protected String getStringByPattern(IAdaptable adapter, int flags, String pattern, MessageFormat processor) {
    EObject element = (EObject) adapter.getAdapter(EObject.class);
    Object value = element.eGet(feature);
    value = getValidValue(feature, value);
    return processor.format(new Object[] { value }, new StringBuffer(), new FieldPosition(0)).toString();
}
Also used : EObject(org.eclipse.emf.ecore.EObject) EObject(org.eclipse.emf.ecore.EObject) FieldPosition(java.text.FieldPosition)

Example 4 with FieldPosition

use of java.text.FieldPosition in project tdi-studio-se by Talend.

the class BusinessStructuralFeaturesParser method getStringByPattern.

/**
     * @generated
     */
protected String getStringByPattern(IAdaptable adapter, int flags, String pattern, MessageFormat processor) {
    EObject element = (EObject) adapter.getAdapter(EObject.class);
    List values = new ArrayList(features.size());
    for (Iterator it = features.iterator(); it.hasNext(); ) {
        EStructuralFeature feature = (EStructuralFeature) it.next();
        Object value = element.eGet(feature);
        value = getValidValue(feature, value);
        values.add(value);
    }
    return processor.format(values.toArray(new Object[values.size()]), new StringBuffer(), new FieldPosition(0)).toString();
}
Also used : EObject(org.eclipse.emf.ecore.EObject) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) EStructuralFeature(org.eclipse.emf.ecore.EStructuralFeature) ArrayList(java.util.ArrayList) List(java.util.List) EObject(org.eclipse.emf.ecore.EObject) FieldPosition(java.text.FieldPosition)

Example 5 with FieldPosition

use of java.text.FieldPosition in project otapij by FellowTraveler.

the class DatePicker method formatDateText.

/**
     * Returns a short string representation of the specified date (January, 2001).
     * @param dt
     * @return short string
     */
private static String formatDateText(final Date dt) {
    final DateFormat df = DateFormat.getDateInstance(DateFormat.LONG);
    final StringBuffer mm = new StringBuffer();
    final StringBuffer yy = new StringBuffer();
    final FieldPosition mmfp = new FieldPosition(DateFormat.MONTH_FIELD);
    final FieldPosition yyfp = new FieldPosition(DateFormat.YEAR_FIELD);
    df.format(dt, mm, mmfp);
    df.format(dt, yy, yyfp);
    return (mm.toString().substring(mmfp.getBeginIndex(), mmfp.getEndIndex()) + " " + yy.toString().substring(yyfp.getBeginIndex(), yyfp.getEndIndex()));
}
Also used : DateFormat(java.text.DateFormat) FieldPosition(java.text.FieldPosition)

Aggregations

FieldPosition (java.text.FieldPosition)100 Date (java.util.Date)31 SimpleDateFormat (java.text.SimpleDateFormat)28 DecimalFormat (java.text.DecimalFormat)12 NumberFormat (java.text.NumberFormat)12 ParsePosition (java.text.ParsePosition)12 IsoDateFormat (alma.acs.util.IsoDateFormat)9 Test (org.junit.Test)9 ILogEntry (com.cosylab.logging.engine.log.ILogEntry)8 Format (java.text.Format)8 MessageFormat (java.text.MessageFormat)8 DateFormat (java.text.DateFormat)6 ACSLogParser (alma.acs.logging.engine.parser.ACSLogParser)5 IOException (java.io.IOException)3 ParseException (java.text.ParseException)3 Calendar (java.util.Calendar)3 GregorianCalendar (java.util.GregorianCalendar)3 Vector (java.util.Vector)3 ExtendedDateFormat (org.jkiss.utils.time.ExtendedDateFormat)3 LogTypeHelper (com.cosylab.logging.engine.log.LogTypeHelper)2