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();
}
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;
}
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();
}
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();
}
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()));
}
Aggregations