@@ -0,0 +1,2392 @@
+package org.craft.atom.protocol.http;%0A%0Aimport java.text.DateFormat;%0Aimport java.text.SimpleDateFormat;%0Aimport java.util.Date;%0Aimport java.util.Locale;%0Aimport java.util.TimeZone;%0A%0Aimport org.craft.atom.protocol.http.model.HttpHeader;%0Aimport org.craft.atom.protocol.http.model.HttpHeaderType;%0A%0A/**%0A * Factory and utility methods for %7B@link HttpHeader%7D.%0A * %0A * @author mindwind%0A * @version 1.0, Mar 14, 2013%0A */%0Apublic class HttpHeaders %7B%0A%09%0A%09/**%0A%09 * Creates a HTTP %22Server%22 header with specified server name.%0A%09 * %0A%09 * @param serverName%0A%09 * @return the newly created header%0A%09 */%0A%09public static HttpHeader newServerHeader(String serverName) %7B%0A%09%09return new HttpHeader(HttpHeaderType.SERVER.getName(), serverName);%0A%09%7D%0A%09%0A%09/**%0A%09 * Creates a HTTP %22Date%22 header with current datetime.%0A%09 * %0A%09 * @param keepAlive is keep alive.%0A%09 * @return%0A%09 */%0A%09public static HttpHeader newConnectionHeader(boolean keepAlive) %7B%0A%09%09if (keepAlive) %7B%0A%09%09%09return new HttpHeader(HttpHeaderType.CONNECTION.getName(), %22keep-alive%22);%0A%09%09%7D else %7B%0A%09%09%09return new HttpHeader(HttpHeaderType.CONNECTION.getName(), %22close%22);%0A%09%09%7D%0A%09%7D%0A%09%0A%09/**%0A%09 * Creates a HTTP %22Date%22 header with current date time.%0A%09 * %0A%09 * @return the newly created header%0A%09 */%0A%09public static HttpHeader newDateHeader() %7B%0A%09%09return new HttpHeader(HttpHeaderType.DATE.getName(), HttpDates.currentDate());%0A%09%7D%0A%09%0A%09// ~ -----------------------------------------------------------------------------------------------------------%0A%09%0A%09private static class HttpDates %7B%0A%09%09/** The date format pattern used to generate the header in RFC 1123 format. */%0A%09    private static final String DATE_FORMAT_RFC1123 = %22EEE, dd MMM yyyy HH:mm:ss zzz%22;%0A%09    %0A%09    /** The time zone to use in the date header. */%0A%09    private static final TimeZone GMT = TimeZone.getTimeZone(%22GMT%22);%0A%09    %0A%09    /** The date format object */%0A%09    private static final DateFormat DATE_FORMAT;%0A%09    %0A%09    static %7B%0A%09    %09 DATE_FORMAT = new SimpleDateFormat(DATE_FORMAT_RFC1123, Locale.US);%0A%09    %09 DATE_FORMAT.setTimeZone(GMT);%0A%09    %7D%0A%09    %0A%09    private static long dateAsLong = 0L;%0A%09    private static String dateAsText = null;%0A%09    %0A%09    synchronized public static String currentDate() %7B%0A%09        long now = System.currentTimeMillis();%0A%09        if (now - dateAsLong %3E 1000) %7B%0A%09            dateAsText = DATE_FORMAT.format(new Date(now));%0A%09            dateAsLong = now;%0A%09        %7D%0A%09        return dateAsText;%0A%09    %7D%0A%09%7D%0A%09%0A%7D%0A

add - http header factory class HttpHeaders