[Htmlparser-cvs] htmlparser/src/org/htmlparser/http ConnectionManager.java,1.2,1.3 ConnectionMonitor
Brought to you by:
derrickoswald
From: Derrick O. <der...@us...> - 2005-04-10 23:21:42
|
Update of /cvsroot/htmlparser/htmlparser/src/org/htmlparser/http In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30655/htmlparser/src/org/htmlparser/http Modified Files: ConnectionManager.java ConnectionMonitor.java Cookie.java package.html Log Message: Documentation revamp part one. Deprecated node decorators. Added doSemanticAction for Text and Comment nodes. Added missing sitecapturer scripts. Fixed DOS batch files to work when called from any location. Index: package.html =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/http/package.html,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** package.html 2 Sep 2004 02:28:15 -0000 1.1 --- package.html 10 Apr 2005 23:20:43 -0000 1.2 *************** *** 76,98 **** { public void preConnect (HttpURLConnection connection) ! { System.out.println (ConnectionManager.getRequestHeader (connection)); ! } ! public void postConnect (HttpURLConnection connection) ! { System.out.println (ConnectionManager.getResponseHeader (connection)); ! } ! } manager.setMonitor (monitor); // perform the connection Parser parser = new Parser ("http://frehmeat.net"); </pre> ! The ConnectionManager used by the Parser class is actually held by the Page class. ! It is accessible from either the Parser or the Page class via ! <code>getConnectionManager()</code>. It is a static (singleton) instance ! so that subsequent connections made by the parser will use the contents of the ! cookie jar from previous connections. By default, cookie processing is not ! enabled. It can be enabled by either setting a cookie or using ! <code>setCookieProcessingEnabled().</code>. </body> </html> --- 76,100 ---- { public void preConnect (HttpURLConnection connection) ! { System.out.println (ConnectionManager.getRequestHeader (connection)); ! } ! public void postConnect (HttpURLConnection connection) ! { System.out.println (ConnectionManager.getResponseHeader (connection)); ! } ! }; manager.setMonitor (monitor); // perform the connection Parser parser = new Parser ("http://frehmeat.net"); </pre> ! The ConnectionManager used by the Parser class is actually held by the ! {@link org.htmlparser.lexer.Page#mConnectionManager Page} class. ! It is accessible from the Parser (or the Page class) via ! {@link org.htmlparser.Parser#getConnectionManager getConnectionManager()}. ! It is a static (singleton) instance so that subsequent connections made by the ! parser will use the contents of the cookie jar from previous connections. ! By default, cookie processing is not enabled. It can be enabled by either ! setting a cookie or using ! {@link org.htmlparser.http.ConnectionManager#setCookieProcessingEnabled setCookieProcessingEnabled()}. </body> </html> Index: Cookie.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/http/Cookie.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Cookie.java 2 Sep 2004 02:28:15 -0000 1.1 --- Cookie.java 10 Apr 2005 23:20:43 -0000 1.2 *************** *** 47,51 **** * Cookies are assigned by servers, using fields added to HTTP response headers. * Cookies are passed back to those servers using fields added to HTTP request ! * headers.Several cookies with the same name can be returned; * they have different path attributes, but those attributes * will not be visible when using "old format" cookies. --- 47,51 ---- * Cookies are assigned by servers, using fields added to HTTP response headers. * Cookies are passed back to those servers using fields added to HTTP request ! * headers. Several cookies with the same name can be returned; * they have different path attributes, but those attributes * will not be visible when using "old format" cookies. *************** *** 116,128 **** * The path for the cookie is set to the root ("/") and there is no * expiry time set. ! * @param name ! * name of the cookie ! * @param value ! * value of the cookie ! * @throws IllegalArgumentException * if the cookie name is not an HTTP/1.1 "token", or if it is * one of the tokens reserved for use by the cookie protocol */ public Cookie (String name, String value) { if (!isToken (name) || name.equalsIgnoreCase ("Comment") // rfc2019 --- 116,128 ---- * The path for the cookie is set to the root ("/") and there is no * expiry time set. ! * @param name The name of the cookie. ! * @param value The value of the cookie. ! * @exception IllegalArgumentException * if the cookie name is not an HTTP/1.1 "token", or if it is * one of the tokens reserved for use by the cookie protocol */ public Cookie (String name, String value) + throws + IllegalArgumentException { if (!isToken (name) || name.equalsIgnoreCase ("Comment") // rfc2019 *************** *** 149,153 **** * cookie's purpose will be described using this comment. This is not * supported by version zero cookies. ! * * @see #getComment */ --- 149,153 ---- * cookie's purpose will be described using this comment. This is not * supported by version zero cookies. ! * @param purpose The cookie comment. * @see #getComment */ *************** *** 160,165 **** * Returns the comment describing the purpose of this cookie, or null if no * such comment has been defined. - * * @see #setComment */ public String getComment () --- 160,165 ---- * Returns the comment describing the purpose of this cookie, or null if no * such comment has been defined. * @see #setComment + * @return The cookie comment, or <code>null</code> if none. */ public String getComment () *************** *** 175,180 **** * cookie. By default, cookies are only returned to the host which saved * them. - * * @see #getDomain */ public void setDomain (String pattern) --- 175,181 ---- * cookie. By default, cookies are only returned to the host which saved * them. * @see #getDomain + * @param pattern The domain name pattern. The pattern is converted to + * lower case to accommodate less capable browsers. */ public void setDomain (String pattern) *************** *** 185,189 **** /** * Returns the domain of this cookie. ! * * @see #setDomain */ --- 186,190 ---- /** * Returns the domain of this cookie. ! * @return The cookie domain (the base URL name it applies to). * @see #setDomain */ *************** *** 198,202 **** * the cookie is not stored persistently, and will be deleted when the user * agent (web browser) exits. ! * * @see #getExpiryDate */ --- 199,204 ---- * the cookie is not stored persistently, and will be deleted when the user * agent (web browser) exits. ! * @param expiry The expiry date for this cookie, or <code>null</code> if ! * the cookie is persistent. * @see #getExpiryDate */ *************** *** 210,214 **** * null is returned, indicating the default behaviour described * with <em>setExpiryDate</em>. ! * * @see #setExpiryDate */ --- 212,216 ---- * null is returned, indicating the default behaviour described * with <em>setExpiryDate</em>. ! * @return The cookie expiry date, or <code>null</code> if it is persistent. * @see #setExpiryDate */ *************** *** 224,228 **** * and in subdirectories, can all see the cookie unless a different path is * set. ! * * @see #getPath */ --- 226,230 ---- * and in subdirectories, can all see the cookie unless a different path is * set. ! * @param uri The exclusion prefix for the cookie. * @see #getPath */ *************** *** 234,238 **** /** * Returns the prefix of all URLs for which this cookie is targetted. ! * * @see #setPath */ --- 236,240 ---- /** * Returns the prefix of all URLs for which this cookie is targetted. ! * @return The cookie path (or "/" if no specific path is specified). * @see #setPath */ *************** *** 246,251 **** * secure protocol (https). This should only be set when the cookie's * originating server used a secure protocol to set the cookie's value. - * * @see #getSecure */ public void setSecure (boolean flag) --- 248,254 ---- * secure protocol (https). This should only be set when the cookie's * originating server used a secure protocol to set the cookie's value. * @see #getSecure + * @param flag Use <code>true</code> if the cookie is to be sent using + * secure protocols, <code>false</code> otherwise. */ public void setSecure (boolean flag) *************** *** 256,260 **** /** * Returns the value of the 'secure' flag. ! * * @see #setSecure */ --- 259,264 ---- /** * Returns the value of the 'secure' flag. ! * @return The <code>true</code> if this cookie should only be sent using ! * a secure protocol, <code>false</code> otherwise. * @see #setSecure */ *************** *** 267,270 **** --- 271,275 ---- * Returns the name of the cookie. This name may not be changed after the * cookie is created. + * @return The name of the cookie. */ public String getName () *************** *** 276,287 **** * Sets the value of the cookie. BASE64 encoding is suggested for use with * binary values. ! * ! * <P> ! * With version zero cookies, you need to be careful about the kinds of * values you use. Values with various special characters (whitespace, * brackets and parentheses, the equals sign, comma, double quote, slashes, * question marks, the "at" sign, colon, and semicolon) should be avoided. ! * Empty values may not behave the same way on all browsers. ! * * @see #getValue */ --- 281,290 ---- * Sets the value of the cookie. BASE64 encoding is suggested for use with * binary values. ! * <p>With version zero cookies, you need to be careful about the kinds of * values you use. Values with various special characters (whitespace, * brackets and parentheses, the equals sign, comma, double quote, slashes, * question marks, the "at" sign, colon, and semicolon) should be avoided. ! * Empty values may not behave the same way on all browsers.</p> ! * @param newValue The new value for the cookie. * @see #getValue */ *************** *** 293,297 **** /** * Returns the value of the cookie. ! * * @see #setValue */ --- 296,300 ---- /** * Returns the value of the cookie. ! * @return The cookie value. * @see #setValue */ *************** *** 307,312 **** * interoperability. Cookies provided by a user agent will identify the * cookie version used by the browser. - * * @see #setVersion */ public int getVersion () --- 310,315 ---- * interoperability. Cookies provided by a user agent will identify the * cookie version used by the browser. * @see #setVersion + * @return The cookie version. */ public int getVersion () *************** *** 319,323 **** * itself. Since the IETF standards are still being finalized, consider * version 1 as experimental; do not use it (yet) on production sites. ! * * @see #getVersion */ --- 322,326 ---- * itself. Since the IETF standards are still being finalized, consider * version 1 as experimental; do not use it (yet) on production sites. ! * @param version The version of the cookie, either 0 or 1. * @see #getVersion */ *************** *** 329,332 **** --- 332,339 ---- /* * Return true iff the string counts as an HTTP/1.1 "token". + * Valid tokens cannot have characters outside the ASCII range 0x20-0x7e, + * and cannot contain any of these characters: "()<>@,;:\\\"/[]?={} \t". + * @return The <code>true</code> if the provided string is a valid + * token, <code>false</code> otherwise. */ private boolean isToken (String value) *************** *** 351,354 **** --- 358,362 ---- /** * Returns a copy of this object. + * @return The clone of this cookie. */ public Object clone () Index: ConnectionMonitor.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/http/ConnectionMonitor.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** ConnectionMonitor.java 2 Sep 2004 02:28:15 -0000 1.1 --- ConnectionMonitor.java 10 Apr 2005 23:20:43 -0000 1.2 *************** *** 42,60 **** * connection, to alter the request method for example. * @param connection The connection which is about to be connected. ! * @exception This exception is thrown if the connection monitor ! * wants the ConnectionManager to bail out. */ void preConnect (HttpURLConnection connection) throws ! ParserException; /** Called just after calling connect. * The response code and header fields can be examined. * @param connection The connection that was just connected. ! * @exception This exception is thrown if the connection monitor ! * wants the ConnectionManager to bail out. */ void postConnect (HttpURLConnection connection) throws ! ParserException; } --- 42,60 ---- * connection, to alter the request method for example. * @param connection The connection which is about to be connected. ! * @exception ParserException This exception is thrown if the connection ! * monitor wants the ConnectionManager to bail out. */ void preConnect (HttpURLConnection connection) throws ! ParserException; /** Called just after calling connect. * The response code and header fields can be examined. * @param connection The connection that was just connected. ! * @exception ParserException This exception is thrown if the connection ! * monitor wants the ConnectionManager to bail out. */ void postConnect (HttpURLConnection connection) throws ! ParserException; } Index: ConnectionManager.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/http/ConnectionManager.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** ConnectionManager.java 12 Mar 2005 11:52:21 -0000 1.2 --- ConnectionManager.java 10 Apr 2005 23:20:43 -0000 1.3 *************** *** 166,169 **** --- 166,173 ---- * A String-to-String map of header keys and values. * These fields are set by the parser when creating a connection. + * @return The default set of request header properties that will + * currently be used. + * @see #mDefaultRequestProperties + * @see #setRequestProperties */ public static Hashtable getDefaultRequestProperties () *************** *** 182,186 **** * 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> and 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> --- 186,191 ---- * 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> *************** *** 220,223 **** --- 225,232 ---- * entity-header fields. * </pre> + * @param properties The new set of default request header properties to + * use. This affects all subsequently created connections. + * @see #mDefaultRequestProperties + * @see #setRequestProperties */ public static void setDefaultRequestProperties (Hashtable properties) *************** *** 321,324 **** --- 330,334 ---- * A String-to-String map of header keys and values, * excluding proxy items, cookies and URL authorization. + * @return The request header properties for this connection manager. */ public Hashtable getRequestProperties () *************** *** 344,347 **** --- 354,358 ---- /** + * Get the proxy host name, if any. * @return Returns the proxy host. */ *************** *** 352,357 **** /** * @param host The host to use for proxy access. ! * <em>Note: You must also set the proxy port.</em> */ public void setProxyHost (String host) --- 363,369 ---- /** + * Set the proxy host to use. * @param host The host to use for proxy access. ! * <em>Note: You must also set the proxy {@link #setProxyPort port}.</em> */ public void setProxyHost (String host) *************** *** 361,364 **** --- 373,377 ---- /** + * Get the proxy port number. * @return Returns the proxy port. */ *************** *** 369,373 **** --- 382,388 ---- /** + * Set the proxy port number. * @param port The proxy port. + * <em>Note: You must also set the proxy {@link #setProxyHost host}.</em> */ public void setProxyPort (int port) *************** *** 377,380 **** --- 392,396 ---- /** + * Get the user name for proxy authorization, if any. * @return Returns the proxy user, * or <code>null</code> if no proxy authorization is required. *************** *** 386,389 **** --- 402,406 ---- /** + * Set the user name for proxy authorization. * @param user The proxy user name. * <em>Note: You must also set the proxy {@link #setProxyPassword password}.</em> *************** *** 395,398 **** --- 412,416 ---- /** + * Set the proxy user's password. * @return Returns the proxy password. */ *************** *** 403,407 **** --- 421,427 ---- /** + * Get the proxy user's password. * @param password The password for the proxy user. + * <em>Note: You must also set the proxy {@link #setProxyUser user}.</em> */ public void setProxyPassword (String password) *************** *** 411,414 **** --- 431,435 ---- /** + * Get the user name to access the URL. * @return Returns the username that will be used to access the URL, * or <code>null</code> if no authorization is required. *************** *** 420,423 **** --- 441,445 ---- /** + * Set the user name to access the URL. * @param user The user name for accessing the URL. * <em>Note: You must also set the {@link #setPassword password}.</em> *************** *** 429,432 **** --- 451,455 ---- /** + * Get the URL users's password. * @return Returns the URL password. */ *************** *** 437,440 **** --- 460,464 ---- /** + * Set the URL users's password. * @param password The password for the URL. */ *************** *** 514,525 **** /** * @return Returns the monitor, or null if none has been assigned. */ public ConnectionMonitor getMonitor () { ! return mMonitor; } /** * @param monitor The monitor to set. */ --- 538,551 ---- /** + * Get the monitoring object, if any. * @return Returns the monitor, or null if none has been assigned. */ public ConnectionMonitor getMonitor () { ! return (mMonitor); } /** + * Set the monitoring object. * @param monitor The monitor to set. */ *************** *** 532,535 **** --- 558,562 ---- * Opens a connection using the given url. * @param url The url to open. + * @return The connection. * @exception ParserException if an i/o exception occurs accessing the url. */ *************** *** 775,778 **** --- 802,806 ---- * Embedded spaces are silently converted to %20 sequences. * @param string The name of a file or a url. + * @return The connection. * @exception ParserException if the string is not a valid url or file. */ *************** *** 1018,1021 **** --- 1046,1050 ---- /** * Check for cookie and parse into cookie jar. + * @param connection The connection to extract cookie information from. */ public void parseCookies (URLConnection connection) *************** *** 1134,1137 **** --- 1163,1171 ---- } + /** + * Save the cookies received in the response header. + * @param list The list of cookies extracted from the response header. + * @param connection The connection (used when a cookie has no domain). + */ protected void saveCookies (Vector list, URLConnection connection) { |