001
014
015 package com.liferay.portal.kernel.servlet;
016
017 import com.liferay.portal.kernel.util.StringBundler;
018
019 import java.io.Serializable;
020
021 import javax.servlet.http.Cookie;
022
023
026 public class Header implements Serializable {
027
028 public static final int COOKIE_TYPE = 4;
029
030 public static final int DATE_TYPE = 2;
031
032 public static final int INTEGER_TYPE = 1;
033
034 public static final int STRING_TYPE = 3;
035
036 @Override
037 public boolean equals(Object obj) {
038 if (this == obj) {
039 return true;
040 }
041
042 if (!(obj instanceof Header)) {
043 return false;
044 }
045
046 Header header = (Header)obj;
047
048 if (_type != header.getType()) {
049 return false;
050 }
051
052 String string = toString();
053
054 return string.equals(header.toString());
055 }
056
057 public Cookie getCookieValue() {
058 return _cookieValue;
059 }
060
061 public long getDateValue() {
062 return _dateValue;
063 }
064
065 public int getIntValue() {
066 return _intValue;
067 }
068
069 public String getStringValue() {
070 return _stringValue;
071 }
072
073 public int getType() {
074 return _type;
075 }
076
077 public void setCookieValue(Cookie cookieValue) {
078 _cookieValue = cookieValue;
079 }
080
081 public void setDateValue(long dateValue) {
082 _dateValue = dateValue;
083 }
084
085 public void setIntValue(int intValue) {
086 _intValue = intValue;
087 }
088
089 public void setStringValue(String stringValue) {
090 _stringValue = stringValue;
091 }
092
093 public void setType(int type) {
094 _type = type;
095 }
096
097 @Override
098 public String toString() {
099 if (_type == COOKIE_TYPE) {
100 StringBundler sb = new StringBundler(17);
101
102 sb.append("{comment=");
103 sb.append(_cookieValue.getComment());
104 sb.append(", domain=");
105 sb.append(_cookieValue.getDomain());
106 sb.append(", maxAge=");
107 sb.append(_cookieValue.getMaxAge());
108 sb.append(", name=");
109 sb.append(_cookieValue.getName());
110 sb.append(", path=");
111 sb.append(_cookieValue.getPath());
112 sb.append(", secure=");
113 sb.append(_cookieValue.getSecure());
114 sb.append(", value=");
115 sb.append(_cookieValue.getValue());
116 sb.append(", version=");
117 sb.append(_cookieValue.getVersion());
118 sb.append("}");
119
120 return sb.toString();
121 }
122 else if (_type == DATE_TYPE) {
123 return String.valueOf(_dateValue);
124 }
125 else if (_type == INTEGER_TYPE) {
126 return String.valueOf(_intValue);
127 }
128 else {
129 return _stringValue;
130 }
131 }
132
133 private Cookie _cookieValue;
134 private long _dateValue;
135 private int _intValue;
136 private String _stringValue;
137 private int _type;
138
139 }