[Htmlparser-cvs] htmlparser/src/org/htmlparser/http ConnectionManager.java,1.3,1.4 Cookie.java,1.2,1
Brought to you by:
derrickoswald
From: Derrick O. <der...@us...> - 2005-05-15 11:49:15
|
Update of /cvsroot/htmlparser/htmlparser/src/org/htmlparser/http In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31674/src/org/htmlparser/http Modified Files: ConnectionManager.java Cookie.java Log Message: Documentation revamp part four. Remove some checkstyle warnings. Index: Cookie.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/http/Cookie.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Cookie.java 10 Apr 2005 23:20:43 -0000 1.2 --- Cookie.java 15 May 2005 11:49:04 -0000 1.3 *************** *** 58,72 **** * Cookies are being standardized by the IETF. This class supports the original * Cookie specification (from Netscape Communications Corp.) as well as the ! * updated <a href="http://www.ietf.org/rfc/rfc2109.txt">RFC 2109</a> specification. */ public class Cookie ! implements ! Cloneable, ! Serializable { ! // ! // from RFC 2068, token special case characters ! // ! private static final String mSpecials = "()<>@,;:\\\"/[]?={} \t"; /** --- 58,74 ---- * Cookies are being standardized by the IETF. This class supports the original * Cookie specification (from Netscape Communications Corp.) as well as the ! * updated <a href="http://www.ietf.org/rfc/rfc2109.txt">RFC 2109</a> ! * specification. */ public class Cookie ! implements ! Cloneable, ! Serializable { ! /** ! * Special characters to watch out for. ! * From RFC 2068, token special case characters. ! */ ! private static final String SPECIALS = "()<>@,;:\\\"/[]?={} \t"; /** *************** *** 330,334 **** } ! /* * Return true iff the string counts as an HTTP/1.1 "token". * Valid tokens cannot have characters outside the ASCII range 0x20-0x7e, --- 332,336 ---- } ! /** * Return true iff the string counts as an HTTP/1.1 "token". * Valid tokens cannot have characters outside the ASCII range 0x20-0x7e, *************** *** 342,346 **** char c; boolean ret; ! ret = true; --- 344,348 ---- char c; boolean ret; ! ret = true; *************** *** 349,353 **** { c = value.charAt (i); ! if (c < 0x20 || c >= 0x7f || mSpecials.indexOf (c) != -1) ret = false; } --- 351,355 ---- { c = value.charAt (i); ! if (c < ' ' || c > '~' || SPECIALS.indexOf (c) != -1) ret = false; } *************** *** 379,383 **** { StringBuffer ret; ! ret = new StringBuffer (50); if (getSecure ()) --- 381,385 ---- { StringBuffer ret; ! ret = new StringBuffer (50); if (getSecure ()) *************** *** 394,398 **** ret.append (" for "); ret.append (getDomain ()); ! if (null != getPath ()) ret.append (getPath ()); --- 396,400 ---- ret.append (" for "); ret.append (getDomain ()); ! if (null != getPath ()) ret.append (getPath ()); *************** *** 422,427 **** ret.append (getComment ()); } ! return (ret.toString ()); } ! } \ No newline at end of file --- 424,429 ---- ret.append (getComment ()); } ! return (ret.toString ()); } ! } Index: ConnectionManager.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/http/ConnectionManager.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** ConnectionManager.java 10 Apr 2005 23:20:43 -0000 1.3 --- ConnectionManager.java 15 May 2005 11:49:04 -0000 1.4 *************** *** 39,42 **** --- 39,43 ---- import java.util.Enumeration; import java.util.Hashtable; + import java.util.Iterator; import java.util.List; import java.util.Map; *************** *** 48,52 **** /** ! * Handles proxies, password protected URLs and request properties including cookies. */ public class ConnectionManager --- 49,54 ---- /** ! * Handles proxies, password protected URLs and request properties ! * including cookies. */ public class ConnectionManager *************** *** 59,81 **** static { ! mDefaultRequestProperties.put ("User-Agent", "HTMLParser/" + org.htmlparser.Parser.VERSION_NUMBER); mDefaultRequestProperties.put ("Accept-Encoding", "gzip, deflate"); } ! /** * Messages for page not there (404). */ ! static private final String[] mFourOhFour = { ! "The web site you seek cannot be located, but countless more exist", ! "You step in the stream, but the water has moved on. This page is not here.", ! "Yesterday the page existed. Today it does not. The internet is like that.", ! "That page was so big. It might have been very useful. But now it is gone.", ! "Three things are certain: death, taxes and broken links. Guess which has occured.", ! "Chaos reigns within. Reflect, repent and enter the correct URL. Order shall return.", ! "Stay the patient course. Of little worth is your ire. The page is not found.", "A non-existant URL reduces your expensive computer to a simple stone.", ! "Many people have visited that page. Today, you are not one of the lucky ones.", ! "Cutting the wind with a knife. Bookmarking a URL. Both are ephemeral.", }; --- 61,93 ---- static { ! mDefaultRequestProperties.put ("User-Agent", "HTMLParser/" ! + org.htmlparser.Parser.VERSION_NUMBER); mDefaultRequestProperties.put ("Accept-Encoding", "gzip, deflate"); } ! /** * Messages for page not there (404). */ ! private static final String[] FOUR_OH_FOUR = { ! "The web site you seek cannot be located," ! + " but countless more exist", ! "You step in the stream, but the water has moved on." ! + " This page is not here.", ! "Yesterday the page existed. Today it does not." ! + " The internet is like that.", ! "That page was so big. It might have been very useful." ! + " But now it is gone.", ! "Three things are certain: death, taxes and broken links." ! + " Guess which has occured.", ! "Chaos reigns within. Reflect, repent and enter the correct URL." ! + " Order shall return.", ! "Stay the patient course. Of little worth is your ire." ! + " The page is not found.", "A non-existant URL reduces your expensive computer to a simple stone.", ! "Many people have visited that page." ! + " Today, you are not one of the lucky ones.", ! "Cutting the wind with a knife. Bookmarking a URL." ! + " Both are ephemeral.", }; *************** *** 83,94 **** * Base 64 character translation table. */ ! static private final char[] mCharacterTable = ! "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".toCharArray(); ! /** * Request header fields. */ protected Hashtable mRequestProperties; ! /** * The proxy server name. --- 95,107 ---- * Base 64 character translation table. */ ! private static final char[] BASE64_CHAR_TABLE = ! ("ABCDEFGHIJKLMNOPQRSTUVWXYZ" ! + "abcdefghijklmnopqrstuvwxyz0123456789+/").toCharArray (); ! /** * Request header fields. */ protected Hashtable mRequestProperties; ! /** * The proxy server name. *************** *** 142,146 **** /** * Create a connection manager with the given connection properties. ! * @param properties Name value pairs that are to be added to the HTTP request. */ public ConnectionManager (Hashtable properties) --- 155,159 ---- /** * Create a connection manager with the given connection properties. ! * @param properties Name/value pairs to be added to the HTTP request. */ public ConnectionManager (Hashtable properties) *************** *** 155,159 **** mCookieJar = null; mMonitor = null; - } --- 168,171 ---- *************** *** 186,195 **** * connection is fetched. Setting these request header fields affects all * subsequent connections opened by the parser. For more direct control ! * create a <code>URLConnection</code> massage it the way you want and * then set it on the parser.<p> ! * From <a href="http://www.ietf.org/rfc/rfc2616.txt">RFC 2616 Hypertext Transfer Protocol -- HTTP/1.1</a>: * <pre> * 5.3 Request Header Fields ! * * The request-header fields allow the client to pass additional * information about the request, and about the client itself, to the --- 198,208 ---- * connection is fetched. Setting these request header fields affects all * subsequent connections opened by the parser. For more direct control ! * create a <code>URLConnection</code> massage it the way you want and * then set it on the parser.<p> ! * From <a href="http://www.ietf.org/rfc/rfc2616.txt"> ! * RFC 2616 Hypertext Transfer Protocol -- HTTP/1.1</a>: * <pre> * 5.3 Request Header Fields ! * * The request-header fields allow the client to pass additional * information about the request, and about the client itself, to the *************** *** 197,201 **** * equivalent to the parameters on a programming language method * invocation. ! * * request-header = Accept ; Section 14.1 * | Accept-Charset ; Section 14.2 --- 210,214 ---- * equivalent to the parameters on a programming language method * invocation. ! * * request-header = Accept ; Section 14.1 * | Accept-Charset ; Section 14.2 *************** *** 217,221 **** * | TE ; Section 14.39 * | User-Agent ; Section 14.43 ! * * Request-header field names can be extended reliably only in * combination with a change in the protocol version. However, new or --- 230,234 ---- * | TE ; Section 14.39 * | User-Agent ; Section 14.43 ! * * Request-header field names can be extended reliably only in * combination with a change in the protocol version. However, new or *************** *** 249,253 **** String key; List items; ! buffer = new StringBuffer (1024); buffer.append (connection.getRequestMethod ()); --- 262,266 ---- String key; List items; ! buffer = new StringBuffer (1024); buffer.append (connection.getRequestMethod ()); *************** *** 256,262 **** buffer.append (" HTTP/1.1\n"); map = connection.getRequestProperties (); ! for (java.util.Iterator iterator = map.keySet ().iterator (); iterator.hasNext ();) { ! key = (String)iterator.next (); items = (List)map.get (key); buffer.append (key); --- 269,275 ---- buffer.append (" HTTP/1.1\n"); map = connection.getRequestProperties (); ! for (Iterator iter = map.keySet ().iterator (); iter.hasNext (); ) { ! key = (String)iter.next (); items = (List)map.get (key); buffer.append (key); *************** *** 270,274 **** buffer.append ("\n"); } ! return (buffer.toString ()); } --- 283,287 ---- buffer.append ("\n"); } ! return (buffer.toString ()); } *************** *** 281,288 **** * <em>This header is generated from the contents of the connection * and may not be exactly the same as the response that was received.</em> ! * @param connection The connection to convert into an HTTP response header. * @return The string that was sent as the HTTP response. */ ! public static String getResponseHeader (HttpURLConnection connection) { // dump it --- 294,301 ---- * <em>This header is generated from the contents of the connection * and may not be exactly the same as the response that was received.</em> ! * @param conn The connection to convert into an HTTP response header. * @return The string that was sent as the HTTP response. */ ! public static String getResponseHeader (HttpURLConnection conn) { // dump it *************** *** 296,320 **** try { ! code = connection.getResponseCode (); ! if (-1 != code) ! { ! message = connection.getResponseMessage (); ! buffer.append ("HTTP/1.1 "); ! buffer.append (code); ! buffer.append (" "); ! buffer.append (message); ! buffer.append ("\n"); ! for (int i = 0; null != (value = connection.getHeaderField (i)); i++) ! { ! key = connection.getHeaderFieldKey (i); ! if (null != key) ! { ! buffer.append (key); ! buffer.append (": "); ! buffer.append (value); ! buffer.append ("\n"); ! } ! } ! } } catch (IOException ioe) --- 309,333 ---- try { ! code = conn.getResponseCode (); ! if (-1 != code) ! { ! message = conn.getResponseMessage (); ! buffer.append ("HTTP/1.1 "); ! buffer.append (code); ! buffer.append (" "); ! buffer.append (message); ! buffer.append ("\n"); ! for (int i = 0; null != (value = conn.getHeaderField (i)); i++) ! { ! key = conn.getHeaderFieldKey (i); ! if (null != key) ! { ! buffer.append (key); ! buffer.append (": "); ! buffer.append (value); ! buffer.append ("\n"); ! } ! } ! } } catch (IOException ioe) *************** *** 380,384 **** return (mProxyPort); } ! /** * Set the proxy port number. --- 393,397 ---- return (mProxyPort); } ! /** * Set the proxy port number. *************** *** 520,524 **** break; } ! else if (path.startsWith (probe.getPath ())) { cookies.insertElementAt (cookie, j); --- 533,537 ---- break; } ! else if (path.startsWith (probe.getPath ())) { cookies.insertElementAt (cookie, j); *************** *** 534,538 **** mCookieJar.put (domain, cookies); } ! } --- 547,551 ---- mCookieJar.put (domain, cookies); } ! } *************** *** 576,579 **** --- 589,594 ---- String port2 = null; // old http.proxyPort value HttpURLConnection http; + String auth; + String encoded; URLConnection ret; *************** *** 583,661 **** { // set up for proxy ! if ((null != getProxyHost ()) && (0 != getProxyPort ())) ! { ! sysprops = System.getProperties (); ! set = (String)sysprops.put ("proxySet", "true"); ! host = (String)sysprops.put ("proxyHost", getProxyHost ()); ! port = (String)sysprops.put ("proxyPort", Integer.toString (getProxyPort ())); ! // see http://java.sun.com/j2se/1.4.2/docs/guide/net/properties.html ! host2 = (String)sysprops.put ("http.proxyHost", getProxyHost ()); ! port2 = (String)sysprops.put ("http.proxyPort", Integer.toString (getProxyPort ())); ! System.setProperties (sysprops); ! ! } ! ! // open the connection... but don't connect yet ! ret = url.openConnection (); ! if (ret instanceof HttpURLConnection) ! { ! http = (HttpURLConnection)ret; ! ! // set the fixed request properties ! properties = getRequestProperties (); ! if (null != properties) ! for (enumeration = properties.keys (); enumeration.hasMoreElements ();) ! { ! key = (String)enumeration.nextElement (); ! value = (String)properties.get (key); ! ret.setRequestProperty (key, value); ! } ! ! // set the proxy name and password ! if ((null != getProxyUser ()) && (null != getProxyPassword ())) ! { ! String authorization = getProxyUser () + ":" + getProxyPassword (); ! String encodedauthorization = encode (authorization.getBytes("ISO-8859-1")); ! ret.setRequestProperty ("Proxy-Authorization", encodedauthorization); ! } ! ! // set the URL name and password ! if ((null != getUser ()) && (null != getPassword ())) ! { ! String authorization = getUser () + ":" + getPassword (); ! String encodedauthorization = encode (authorization.getBytes("ISO-8859-1")); ! ret.setRequestProperty ("Authorization", "Basic " + encodedauthorization); ! } ! ! // set the cookies based on the url ! addCookies (ret); ! if (null != getMonitor ()) ! getMonitor ().preConnect (http); ! } ! else ! http = null; ! try ! { ! ret.connect (); ! ! if (null != http) ! { ! if (null != getMonitor ()) ! getMonitor ().postConnect (http); ! ! parseCookies (ret); ! } ! } ! catch (UnknownHostException uhe) ! { ! int message = (int)(Math.random () * mFourOhFour.length); ! throw new ParserException (mFourOhFour[message], uhe); ! } ! catch (IOException ioe) ! { ! throw new ParserException (ioe.getMessage (), ioe); ! } } finally --- 598,682 ---- { // set up for proxy ! if ((null != getProxyHost ()) && (0 != getProxyPort ())) ! { ! sysprops = System.getProperties (); ! set = (String)sysprops.put ("proxySet", "true"); ! host = (String)sysprops.put ("proxyHost", getProxyHost ()); ! port = (String)sysprops.put ("proxyPort", ! Integer.toString (getProxyPort ())); ! // see http://java.sun.com/j2se/1.4.2/docs/guide/net/properties.html ! host2 = (String)sysprops.put ("http.proxyHost", ! getProxyHost ()); ! port2 = (String)sysprops.put ("http.proxyPort", ! Integer.toString (getProxyPort ())); ! System.setProperties (sysprops); ! ! } ! ! // open the connection... but don't connect yet ! ret = url.openConnection (); ! if (ret instanceof HttpURLConnection) ! { ! http = (HttpURLConnection)ret; ! ! // set the fixed request properties ! properties = getRequestProperties (); ! if (null != properties) ! for (enumeration = properties.keys (); ! enumeration.hasMoreElements ();) ! { ! key = (String)enumeration.nextElement (); ! value = (String)properties.get (key); ! ret.setRequestProperty (key, value); ! } ! ! // set the proxy name and password ! if ((null != getProxyUser ()) ! && (null != getProxyPassword ())) ! { ! auth = getProxyUser () + ":" + getProxyPassword (); ! encoded = encode (auth.getBytes("ISO-8859-1")); ! ret.setRequestProperty ("Proxy-Authorization", encoded); ! } ! ! // set the URL name and password ! if ((null != getUser ()) && (null != getPassword ())) ! { ! auth = getUser () + ":" + getPassword (); ! encoded = encode (auth.getBytes("ISO-8859-1")); ! ret.setRequestProperty ("Authorization", ! "Basic " + encoded); ! } ! ! // set the cookies based on the url ! addCookies (ret); ! if (null != getMonitor ()) ! getMonitor ().preConnect (http); ! } ! else ! http = null; ! try ! { ! ret.connect (); ! ! if (null != http) ! { ! if (null != getMonitor ()) ! getMonitor ().postConnect (http); ! ! parseCookies (ret); ! } ! } ! catch (UnknownHostException uhe) ! { ! int message = (int)(Math.random () * FOUR_OH_FOUR.length); ! throw new ParserException (FOUR_OH_FOUR[message], uhe); ! } ! catch (IOException ioe) ! { ! throw new ParserException (ioe.getMessage (), ioe); ! } } finally *************** *** 664,669 **** { sysprops = System.getProperties (); ! if (null != set) ! sysprops.put ("proxySet", set); else sysprops.remove ("proxySet"); --- 685,690 ---- { sysprops = System.getProperties (); ! if (null != set) ! sysprops.put ("proxySet", set); else sysprops.remove ("proxySet"); *************** *** 684,688 **** else sysprops.remove ("http.proxyPort"); ! System.setProperties (sysprops); } } --- 705,709 ---- else sysprops.remove ("http.proxyPort"); ! System.setProperties (sysprops); } } *************** *** 690,694 **** catch (IOException ioe) { ! String msg = "HTMLParser.openConnection() : Error in opening a connection to " + url.toExternalForm (); ParserException ex = new ParserException (msg, ioe); throw ex; --- 711,716 ---- catch (IOException ioe) { ! String msg = "Error in opening a connection to " ! + url.toExternalForm (); ParserException ex = new ParserException (msg, ioe); throw ex; *************** *** 698,707 **** } ! /** ! * Encodes a byte array into BASE64 in accordance with <a href="http://www.faqs.org/rfcs/rfc2045.html">RFC 2045</a>. ! * @param array The bytes to convert. ! * @return A BASE64 encoded string. ! */ ! public final static String encode (byte[] array) { int last; // last byte --- 720,730 ---- } ! /** ! * Encodes a byte array into BASE64 in accordance with ! * <a href="http://www.faqs.org/rfcs/rfc2045.html">RFC 2045</a>. ! * @param array The bytes to convert. ! * @return A BASE64 encoded string. ! */ ! public final static String encode (byte[] array) { int last; // last byte *************** *** 716,751 **** int n; // byte to encode int index; // index into output array ! String ret; if ((null != array) && (0 != array.length)) { ! last = array.length - 1; ! count = (last / 3 + 1) << 2; ! separators = (count - 1) / 76; ! length = count + separators; ! encoded = new char[length]; ! index = 0; ! separators = 0; ! for (int i = 0; i <= last; i += 3) ! { ! left = last - i; ! end = (left > 1 ? 2 : left); ! ! // collect 1 to 3 bytes to encode ! block = 0; ! r = 16; ! for (int j = 0; j <= end; j++) ! { ! n = array[i + j]; ! block += (n < 0 ? n + 256 : n) << r; ! r -= 8; ! } ! ! // encode into 2-4 chars padding with '=' if no data left ! encoded[index++] = mCharacterTable[(block >>> 18) & 0x3f]; ! encoded[index++] = mCharacterTable[(block >>> 12) & 0x3f]; ! encoded[index++] = left > 0 ? mCharacterTable[(block >>> 6) & 0x3f] : '='; ! encoded[index++] = left > 1 ? mCharacterTable[block & 0x3f] : '='; ! if ((0 == (index - separators) % 76) && (index < length)) { --- 739,778 ---- int n; // byte to encode int index; // index into output array ! String ret; if ((null != array) && (0 != array.length)) { ! last = array.length - 1; ! count = (last / 3 + 1) << 2; ! separators = (count - 1) / 76; ! length = count + separators; ! encoded = new char[length]; ! index = 0; ! separators = 0; ! for (int i = 0; i <= last; i += 3) ! { ! left = last - i; ! end = (left > 1 ? 2 : left); ! ! // collect 1 to 3 bytes to encode ! block = 0; ! r = 16; ! for (int j = 0; j <= end; j++) ! { ! n = array[i + j]; ! block += (n < 0 ? n + 256 : n) << r; ! r -= 8; ! } ! ! // encode into 2-4 chars padding with '=' if no data left ! encoded[index++] = BASE64_CHAR_TABLE[(block >>> 18) & 0x3f]; ! encoded[index++] = BASE64_CHAR_TABLE[(block >>> 12) & 0x3f]; ! encoded[index++] = left > 0 ? ! BASE64_CHAR_TABLE[(block >>> 6) & 0x3f] : ! '='; ! encoded[index++] = left > 1 ? ! BASE64_CHAR_TABLE[block & 0x3f] : ! '='; ! if ((0 == (index - separators) % 76) && (index < length)) { *************** *** 753,758 **** separators += 1; } ! } ! ret = new String (encoded); } else --- 780,785 ---- separators += 1; } ! } ! ret = new String (encoded); } else *************** *** 764,768 **** /** * Turn spaces into %20. ! * ToDo: make this more generic (see RFE #1010593 provide URL encoding/decoding utilities). * @param url The url containing spaces. * @return The URL with spaces as %20 sequences. --- 791,796 ---- /** * Turn spaces into %20. ! * ToDo: make this more generic ! * (see RFE #1010593 provide URL encoding/decoding utilities). * @param url The url containing spaces. * @return The URL with spaces as %20 sequences. *************** *** 826,830 **** File file = new File (string); resource = file.getCanonicalPath (); ! buffer = new StringBuffer (prefix.length () + resource.length ()); buffer.append (prefix); if (!resource.startsWith ("/")) --- 854,859 ---- File file = new File (string); resource = file.getCanonicalPath (); ! buffer = new StringBuffer (prefix.length () ! + resource.length ()); buffer.append (prefix); if (!resource.startsWith ("/")) *************** *** 836,840 **** catch (MalformedURLException murle2) { ! String msg = "HTMLParser.openConnection() : Error in opening a connection to " + string; ParserException ex = new ParserException (msg, murle2); throw ex; --- 865,869 ---- catch (MalformedURLException murle2) { ! String msg = "Error in opening a connection to " + string; ParserException ex = new ParserException (msg, murle2); throw ex; *************** *** 842,846 **** catch (IOException ioe) { ! String msg = "HTMLParser.openConnection() : Error in opening a connection to " + string; ParserException ex = new ParserException (msg, ioe); throw ex; --- 871,875 ---- catch (IOException ioe) { ! String msg = "Error in opening a connection to " + string; ParserException ex = new ParserException (msg, ioe); throw ex; *************** *** 880,902 **** if (null != mCookieJar) { ! list = null; ! // get the site from the URL ! url = connection.getURL (); ! host = url.getHost (); ! path = url.getPath (); ! if (0 == path.length ()) ! path = "/"; ! if (null != host) ! { // http://www.objectsdevelopment.com/portal/modules/freecontent/content/javawebserver.html ! list = addCookies ((Vector)mCookieJar.get (host), path, list); ! domain = getDomain (host); ! if (null != domain) ! list = addCookies ((Vector)mCookieJar.get (domain), path, list); ! else ! // maybe it is the domain we're accessing ! list = addCookies ((Vector)mCookieJar.get ("." + host), path, list); ! } ! if (null != list) ! connection.setRequestProperty ("Cookie", generateCookieProperty (list)); } } --- 909,934 ---- if (null != mCookieJar) { ! list = null; ! // get the site from the URL ! url = connection.getURL (); ! host = url.getHost (); ! path = url.getPath (); ! if (0 == path.length ()) ! path = "/"; ! if (null != host) ! { // http://www.objectsdevelopment.com/portal/modules/freecontent/content/javawebserver.html ! list = addCookies ((Vector)mCookieJar.get (host), path, list); ! domain = getDomain (host); ! if (null != domain) ! list = addCookies ((Vector)mCookieJar.get (domain), ! path, list); ! else ! // maybe it is the domain we're accessing ! list = addCookies ((Vector)mCookieJar.get ("." + host), ! path, list); ! } ! if (null != list) ! connection.setRequestProperty ("Cookie", ! generateCookieProperty (list)); } } *************** *** 974,980 **** if (ok) { ! // so take everything after the first token ! server = tokenizer.nextToken (); ! length = server.length (); ret = host.substring (length); } --- 1006,1012 ---- if (ok) { ! // so take everything after the first token ! server = tokenizer.nextToken (); ! length = server.length (); ret = host.substring (length); } *************** *** 985,991 **** /** ! * Creates the cookie request property value from the list of valid cookies for the domain. * @param cookies The list of valid cookies to be encoded in the request. ! * @return A string suitable for inclusion as the value of the "Cookie:" request property. */ protected String generateCookieProperty (Vector cookies) --- 1017,1025 ---- /** ! * Creates the cookie request property value from the list of ! * valid cookies for the domain. * @param cookies The list of valid cookies to be encoded in the request. ! * @return A string suitable for inclusion as the value of ! * the "Cookie:" request property. */ protected String generateCookieProperty (Vector cookies) *************** *** 1001,1005 **** version = 0; for (int i = 0; i < cookies.size (); i++) ! version = Math.max (version, ((Cookie)cookies.elementAt (i)).getVersion ()); if (0 != version) { --- 1035,1040 ---- version = 0; for (int i = 0; i < cookies.size (); i++) ! version = Math.max (version, ! ((Cookie)cookies.elementAt (i)).getVersion ()); if (0 != version) { *************** *** 1085,1089 **** { cookie = null; ! continue; } --- 1120,1124 ---- { cookie = null; ! continue; } *************** *** 1111,1159 **** else { ! if (key.equals ("expires")) // Wdy, DD-Mon-YY HH:MM:SS GMT ! { ! String comma = tokenizer.nextToken (); ! String rest = tokenizer.nextToken (); ! SimpleDateFormat format = new SimpleDateFormat ("EEE, dd-MMM-yy kk:mm:ss z"); ! try ! { ! Date date = format.parse (value + comma + rest); ! cookie.setExpiryDate (date); ! } ! catch (ParseException pe) ! { ! // ok now what ! cookie.setExpiryDate (null); ! } ! } ! else ! if (key.equals ("domain")) ! cookie.setDomain (value); ! else ! if (key.equals ("path")) ! cookie.setPath (value); ! else ! if (key.equals ("secure")) ! cookie.setSecure (true); ! else ! if (key.equals ("comment")) ! cookie.setComment (value); ! else ! if (key.equals ("version")) ! cookie.setVersion (Integer.parseInt (value)); ! else ! if (key.equals ("max-age")) ! { ! Date date = new Date (); ! long then = date.getTime () + Integer.parseInt (value) * 1000; ! date.setTime (then); ! cookie.setExpiryDate (date); ! } ! else ! { // error,? unknown attribute, ! // maybe just another cookie not separated by a comma ! cookie = new Cookie (name, value); ! cookies.addElement (cookie); ! } } } --- 1146,1200 ---- else { ! if (key.equals ("expires")) // Wdy, DD-Mon-YY HH:MM:SS GMT ! { ! String comma = tokenizer.nextToken (); ! String rest = tokenizer.nextToken (); ! SimpleDateFormat format = new SimpleDateFormat ( ! "EEE, dd-MMM-yy kk:mm:ss z"); ! try ! { ! Date date = format.parse (value + comma + rest); ! cookie.setExpiryDate (date); ! } ! catch (ParseException pe) ! { ! // ok now what ! cookie.setExpiryDate (null); ! } ! } ! else ! if (key.equals ("domain")) ! cookie.setDomain (value); ! else ! if (key.equals ("path")) ! cookie.setPath (value); ! else ! if (key.equals ("secure")) ! cookie.setSecure (true); ! else ! if (key.equals ("comment")) ! cookie.setComment (value); ! else ! if (key.equals ("version")) ! cookie.setVersion ( ! Integer.parseInt (value)); ! else ! if (key.equals ("max-age")) ! { ! Date date = new Date (); ! long then = date.getTime () ! + Integer.parseInt (value) ! * 1000; ! date.setTime (then); ! cookie.setExpiryDate (date); ! } ! else ! { // error,? unknown attribute, ! // maybe just another cookie ! // not separated by a comma ! cookie = new Cookie (name, ! value); ! cookies.addElement (cookie); ! } } } |