You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by su...@apache.org on 2002/09/05 06:45:36 UTC
cvs commit: jakarta-commons/httpclient/src/java/org/apache/commons/httpclient HttpState.java
sullis 2002/09/04 21:45:36
Modified: httpclient/src/java/org/apache/commons/httpclient
HttpState.java
Log:
implemented a "toString()" method.
improved javadocs
the "log" variable is now private. (Previously, it was public)
instance variables are now final
updated javadocs
Revision Changes Path
1.11 +103 -6 jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpState.java
Index: HttpState.java
===================================================================
RCS file: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpState.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- HttpState.java 2 Aug 2002 02:15:44 -0000 1.10
+++ HttpState.java 5 Sep 2002 04:45:36 -0000 1.11
@@ -65,6 +65,8 @@
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
+import java.util.Map;
+import java.util.List;
import java.util.Iterator;
import org.apache.commons.logging.Log;
@@ -79,7 +81,10 @@
* @author <a href="mailto:remm@apache.org">Remy Maucherat</a>
* @author Rodney Waldhoff
* @author <a href="mailto:jsdever@apache.org">Jeff Dever</a>
+ * @author Sean C. Sullivan
+ *
* @version $Revision$ $Date$
+ *
*/
public class HttpState {
@@ -103,7 +108,7 @@
// -------------------------------------------------------- Class Variables
/** Log object for this class. */
- public static final Log log = LogFactory.getLog(HttpState.class);
+ private static final Log log = LogFactory.getLog(HttpState.class);
// ------------------------------------------------------------- Properties
@@ -111,7 +116,11 @@
* Add a cookie.
* If the given <i>cookie</i> has already expired,
* deletes the corresponding existing cookie (if any).
+ *
* @param cookie the {@link Cookie} to add
+ *
+ * @see #addCookies(Cookie[])
+ *
*/
public void addCookie(Cookie cookie) {
log.trace("enter HttpState.addCookie(Cookie)");
@@ -135,7 +144,12 @@
* Add zero or more cookies
* If any given <i>cookie</i> has already expired,
* deletes the corresponding existing cookie (if any).
+ *
* @param newcookies the {@link Cookie}s to add
+ *
+ * @see #addCookies(Cookie)
+ *
+ *
*/
public void addCookies(Cookie[] newcookies) {
log.trace("enter HttpState.addCookies(Cookie[])");
@@ -185,7 +199,9 @@
* Remove all of my {@link Cookie}s that
* have expired according to the current
* system time.
+ *
* @see #purgeExpiredCookies(java.util.Date)
+ *
*/
public boolean purgeExpiredCookies() {
log.trace("enter HttpState.purgeExpiredCookies()");
@@ -195,7 +211,10 @@
/**
* Remove all of my {@link Cookie}s that
* have expired by the specified <i>date</i>.
+ *
* @see Cookie#isExpired(java.util.Date)
+ * @see #purgeExpiredCookies()
+ *
*/
public boolean purgeExpiredCookies(Date date) {
log.trace("enter HttpState.purgeExpiredCookies(Date)");
@@ -224,6 +243,9 @@
*
* @param realm the authentication realm
* @param credentials the authentication credentials for the given realm
+ *
+ * @see #getCredentials()
+ *
*/
public void setCredentials(String realm, Credentials credentials) {
log.trace("enter HttpState.setCredentials(String, Credentials)");
@@ -240,7 +262,9 @@
*
* @param realm the authentication realm
* @return the credentials
- * @see #setCredentials
+ *
+ * @see #setCredentials(String, Credentials)
+ *
*/
public Credentials getCredentials(String realm) {
log.trace("enter HttpState.getCredentials(String)");
@@ -267,6 +291,9 @@
*
* @param realm the authentication realm
* @param credentials the authentication credentials for the given realm
+ *
+ * @see #getProxyCredentials(String)
+ *
*/
public void setProxyCredentials(String realm, Credentials credentials) {
log.trace("enter HttpState.setProxyCredentials(String, credentials)");
@@ -293,5 +320,75 @@
}
return creds;
}
+
+ public String toString()
+ {
+ StringBuffer sbResult = new StringBuffer();
+
+ sbResult.append("[");
+ sbResult.append(getProxyCredentialsStringRepresentation(proxyCred));
+ sbResult.append(" | ");
+ sbResult.append(getCredentialsStringRepresentation(proxyCred));
+ sbResult.append(" | ");
+ sbResult.append(getCookiesStringRepresentation(cookies));
+ sbResult.append("]");
+
+ String strResult = sbResult.toString();
+ return strResult;
+ }
+
+ private static StringBuffer getProxyCredentialsStringRepresentation(final Map proxyCredMap)
+ {
+ StringBuffer sbResult = new StringBuffer();
+ Iterator iter = proxyCredMap.keySet().iterator();
+ while (iter.hasNext())
+ {
+ String key = (String) iter.next();
+ Credentials cred = (Credentials) proxyCredMap.get(key);
+ if (sbResult.length() > 0)
+ {
+ sbResult.append(", ");
+ }
+ sbResult.append(key);
+ sbResult.append("#");
+ sbResult.append(cred.toString());
+ }
+ return sbResult;
+ }
+
+ private static StringBuffer getCredentialsStringRepresentation(final Map credMap)
+ {
+ StringBuffer sbResult = new StringBuffer();
+ Iterator iter = credMap.keySet().iterator();
+ while (iter.hasNext())
+ {
+ String key = (String) iter.next();
+ Credentials cred = (Credentials) credMap.get(key);
+ if (sbResult.length() > 0)
+ {
+ sbResult.append(", ");
+ }
+ sbResult.append(key);
+ sbResult.append("#");
+ sbResult.append(cred.toString());
+ }
+ return sbResult;
+ }
+
+ private static StringBuffer getCookiesStringRepresentation(final List cookies)
+ {
+ StringBuffer sbResult = new StringBuffer();
+ Iterator iter = cookies.iterator();
+ while (iter.hasNext())
+ {
+ Cookie ck = (Cookie) iter.next();
+ if (sbResult.length() > 0)
+ {
+ sbResult.append("#");
+ }
+ sbResult.append(ck.toExternalForm());
+ }
+ return sbResult;
+ }
}
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>