1 28 29 package HTTPClient; 30 31 32 42 43 public class HttpHeaderElement 44 { 45 46 private String name; 47 48 49 private String value; 50 51 52 private NVPair[] parameters; 53 54 55 57 64 public HttpHeaderElement(String name) 65 { 66 this.name = name; 67 this.value = null; 68 parameters = new NVPair[0]; 69 } 70 71 72 77 public HttpHeaderElement(String name, String value, NVPair[] params) 78 { 79 this.name = name; 80 this.value = value; 81 if (params != null) 82 { 83 parameters = new NVPair[params.length]; 84 System.arraycopy(params, 0, parameters, 0, params.length); 85 } 86 else 87 parameters = new NVPair[0]; 88 } 89 90 91 93 96 public String getName() 97 { 98 return name; 99 } 100 101 102 105 public String getValue() 106 { 107 return value; 108 } 109 110 111 114 public NVPair[] getParams() 115 { 116 return parameters; 117 } 118 119 120 128 public boolean equals(Object obj) 129 { 130 if ((obj != null) && (obj instanceof HttpHeaderElement)) 131 { 132 String other = ((HttpHeaderElement) obj).name; 133 return name.equalsIgnoreCase(other); 134 } 135 136 return false; 137 } 138 139 140 144 public String toString() 145 { 146 StringBuffer buf = new StringBuffer (); 147 appendTo(buf); 148 return buf.toString(); 149 } 150 151 152 160 public void appendTo(StringBuffer buf) 161 { 162 buf.append(name); 163 164 if (value != null) 165 { 166 if (Util.needsQuoting(value)) 167 { 168 buf.append("=\""); 169 buf.append(Util.quoteString(value, "\\\"")); 170 buf.append('"'); 171 } 172 else 173 { 174 buf.append('='); 175 buf.append(value); 176 } 177 } 178 179 for (int idx=0; idx<parameters.length; idx++) 180 { 181 buf.append(";"); 182 buf.append(parameters[idx].getName()); 183 String pval = parameters[idx].getValue(); 184 if (pval != null) 185 { 186 if (Util.needsQuoting(pval)) 187 { 188 buf.append("=\""); 189 buf.append(Util.quoteString(pval, "\\\"")); 190 buf.append('"'); 191 } 192 else 193 { 194 buf.append('='); 195 buf.append(pval); 196 } 197 } 198 } 199 } 200 } 201 202 | Popular Tags |