private static String convertV0SetCookie(HttpCookie cookie, boolean isRFC1123DateEnabled) {

        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
            Tr.debug(tc, "Cookie Name: " + cookie.getName());
            Tr.debug(tc, "Cookie MaxAge: " + cookie.getMaxAge());
            Tr.debug(tc, "RFC1123 Date Enabled (4 digit year): " + isRFC1123DateEnabled);
        }

        StringBuilder buffer = new StringBuilder(40);

        // Append name=value
        buffer.append(cookie.getName());
        String value = cookie.getValue();
        if (null != value && 0 != value.length()) {
            buffer.append('=');
            buffer.append(value);
        } else {
            // PK48196 - send an empty value string
            buffer.append("=\"\"");
        }

        // check for optional comment
        String comment = cookie.getComment();
        if (null != comment && 0 != comment.length()) {
            buffer.append("; Comment=");
            maybeQuote(buffer, comment);
        }

        // check for optional max-age/expires
        int expires = cookie.getMaxAge();
        if (-1 < expires) {
            if (0 == expires) {
                if (!isRFC1123DateEnabled) {
                    buffer.append(longAgo);
                } else {
                    buffer.append(longAgoRFC1123);
                }
            } else {
                buffer.append("; Expires=");
                if (!isRFC1123DateEnabled) {
                    buffer.append(HttpDispatcher.getDateFormatter().getRFC2109Time(new Date(HttpDispatcher.getApproxTime() + (expires * 1000L))));
                } else {
                    buffer.append(HttpDispatcher.getDateFormatter().getRFC1123Time(new Date(HttpDispatcher.getApproxTime() + (expires * 1000L))));
                }
            }
        } else if (cookie.isDiscard()) {
            // convert discard to immediate expiration
            if (!isRFC1123DateEnabled) {
                buffer.append(longAgo);
            } else {
                buffer.append(longAgoRFC1123);
            }
        }

        // check for optional path
        value = cookie.getPath();
        if (null != value && 0 != value.length()) {
            buffer.append("; Path=");
            buffer.append(value);
        }

        // check for optional domain
        value = cookie.getDomain();
        if (null != value && 0 != value.length()) {
            buffer.append("; Domain=");
            buffer.append(value);
        }

        if (cookie.isSecure()) {
            buffer.append("; Secure");
        }

        if (cookie.isHttpOnly()) {
            buffer.append("; HttpOnly");
        }

        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
            Tr.debug(tc, "Created v0 Set-Cookie: [" + GenericUtils.nullOutPasswords(buffer.toString(), (byte) '&') + "]");
        }
        return buffer.toString();
    }
private static String convertV0SetCookie ( HttpCookie cookie , boolean isRFC1123DateEnabled ) { if ( TraceComponent . isAnyTracingEnabled ( ) && tc . isDebugEnabled ( ) ) { Tr . debug ( tc , "Cookie Name: " + cookie . getName ( ) ) ; Tr . debug ( tc , "Cookie MaxAge: " + cookie . getMaxAge ( ) ) ; Tr . debug ( tc , "RFC1123 Date Enabled (4 digit year): " + isRFC1123DateEnabled ) ; } StringBuilder buffer = new StringBuilder ( 40 ) ; buffer . append ( cookie . getName ( ) ) ; String value = cookie . getValue ( ) ; if ( null != value && 0 != value . length ( ) ) { buffer . append ( '=' ) ; buffer . append ( value ) ; } else { buffer . append ( "=\"\"" ) ; } String comment = cookie . getComment ( ) ; if ( null != comment && 0 != comment . length ( ) ) { buffer . append ( "; Comment=" ) ; maybeQuote ( buffer , comment ) ; } int expires = cookie . getMaxAge ( ) ; if ( - 1 < expires ) { if ( 0 == expires ) { if ( ! isRFC1123DateEnabled ) { buffer . append ( longAgo ) ; } else { buffer . append ( longAgoRFC1123 ) ; } } else { buffer . append ( "; Expires=" ) ; if ( ! isRFC1123DateEnabled ) { buffer . append ( HttpDispatcher . getDateFormatter ( ) . getRFC2109Time ( new Date ( HttpDispatcher . getApproxTime ( ) + ( expires * 1000L ) ) ) ) ; } else { buffer . append ( HttpDispatcher . getDateFormatter ( ) . getRFC1123Time ( new Date ( HttpDispatcher . getApproxTime ( ) + ( expires * 1000L ) ) ) ) ; } } } else if ( cookie . isDiscard ( ) ) { if ( ! isRFC1123DateEnabled ) { buffer . append ( longAgo ) ; } else { buffer . append ( longAgoRFC1123 ) ; } } value = cookie . getPath ( ) ; if ( null != value && 0 != value . length ( ) ) { buffer . append ( "; Path=" ) ; buffer . append ( value ) ; } value = cookie . getDomain ( ) ; if ( null != value && 0 != value . length ( ) ) { buffer . append ( "; Domain=" ) ; buffer . append ( value ) ; } if ( cookie . isSecure ( ) ) { buffer . append ( "; Secure" ) ; } if ( cookie . isHttpOnly ( ) ) { buffer . append ( "; HttpOnly" ) ; } if ( TraceComponent . isAnyTracingEnabled ( ) && tc . isDebugEnabled ( ) ) { Tr . debug ( tc , "Created v0 Set-Cookie: [" + GenericUtils . nullOutPasswords ( buffer . toString ( ) , ( byte ) '&' ) + "]" ) ; } return buffer . toString ( ) ; }
Convert the V0 Cookie into a Set-Cookie header string.

@param cookie
@return the value of the header.