org.apache.commons.httpclient

Class NameValuePair

Implemented Interfaces:
Serializable
Known Direct Subclasses:
Cookie, Header, HeaderElement

public class NameValuePair
extends Object
implements Serializable

A simple class encapsulating a name/value pair.
See Also:
Serialized Form

Constructor Summary

NameValuePair()
Default constructor.
NameValuePair(String name, String value)
Constructor.

Method Summary

boolean
equals(Object object)
Indicates whether some other object is "equal to" this one.
String
getName()
Return the name.
String
getValue()
Return the current value.
int
hashCode()
Returns a hash code value for the object.
void
setName(String name)
Set the name.
void
setValue(String value)
Set the value.
String
toString()
Get a String representation of this pair.

Methods inherited from class java.lang.Object

clone, equals, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructor Details

NameValuePair

public NameValuePair()
Default constructor.

NameValuePair

public NameValuePair(String name,
                     String value)
Constructor.
Parameters:
name - The name.
value - The value.
Usages and Demos :

View More Examples of NameValuePair(String name,String value)
   1:         method.addParameter( "Blah", "Whoop" );
   2:         method.addParameter( new NameValuePair( "Blah", "Whoop2" ) );
   3: 
   4:         client.executeMethod( method );
   5:         String response = method.getResponseBodyAsString();

View Full Code Here
   1:         final List compiledHeaders = new ArrayList();
   2:         compiledHeaders.add(new NameValuePair("Content-Type", "text/html"));
   3:         return new WebResponseData(content, 200, "OK", compiledHeaders);
   4:     }

View Full Code Here
   1:         PostMethod authpost = new PostMethod("/servlet/SessionServlet");
   2:         NameValuePair action   = new NameValuePair("action", "login");
   3:         ...
   4:         NameValuePair url      = new NameValuePair("url", "/index.html");
   5:         ...
   6:         NameValuePair userid   = new NameValuePair("UserId", "userid");
   7:         NameValuePair password = new NameValuePair("Password", "password");

View Full Code Here
   1:         final List compiledHeaders = new ArrayList(responseHeaders);
   2:         compiledHeaders.add(new NameValuePair("Content-Type", contentType));
   3:         final WebResponseData responseEntry = new WebResponseData(
   4:         ...
   5:         final List compiledHeaders = new ArrayList();
   6:         compiledHeaders.add(new NameValuePair("Content-Type", contentType));
   7:         final WebResponseData responseEntry = new WebResponseData(
   8:                 content,
   9:                 statusCode,

View Full Code Here
   1:           buffer.append("; ");
   2:           formatParam(buffer, new NameValuePair("$Path", cookie.getPath()), version);
   3:         }
   4:         ...
   5:             buffer.append("; ");
   6:             formatParam(buffer, new NameValuePair("$Domain", cookie.getDomain()), version);
   7:         }
   8:         ...
   9:         formatParam(buffer, 
  10:                 new NameValuePair("$Version", Integer.toString(version)), 
  11:                 version);

View Full Code Here

Method Details

equals

public boolean equals(Object object)
Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

The equals method for class Object implements the most discriminating possible equivalence relation on objects; that is, for any non-null reference values x and y, this method returns true if and only if x and y refer to the same object (x == y has the value true).

Note that it is generally necessary to override the hashCode method whenever this method is overridden, so as to maintain the general contract for the hashCode method, which states that equal objects must have equal hash codes.

Overrides:
equals in interface Object
Parameters:
Returns:
true if this object is the same as the obj argument; false otherwise.

getName

public String getName()
Return the name.
Returns:
String name The name
Usages and Demos :

View More Examples of getName()
   1: import org.apache.commons.httpclient.HeaderElement;
   2: import org.apache.commons.httpclient.NameValuePair;
   3: import org.apache.commons.httpclient.Cookie;
   4:         ...
   5:         Cookie cookie = new Cookie(host,
   6:                        headerelement.getName(),
   7:                        headerelement.getValue(),
   8:         ...
   9:                        false);
  10:         NameValuePair[] parameters = headerelement.getParameters();
  11:         if (parameters != null) {
  12:         ...
  13:     public void parseAttribute(
  14:         final NameValuePair attribute, final Cookie cookie)

View Full Code Here
   1: 
   2: import org.apache.commons.httpclient.NameValuePair;
   3: import org.apache.commons.httpclient.Cookie;
   4:         ...
   5:     public void parseAttribute(
   6:         final NameValuePair attribute, final Cookie cookie)
   7:         throws MalformedCookieException {
   8:         ...
   9:         }
  10:         final String paramName = attribute.getName().toLowerCase();
  11:         final String paramValue = attribute.getValue();
  12:         ...
  13:         
  14:         if (cookie.getName().indexOf(' ') != -1) {

View Full Code Here
   1: import org.apache.commons.httpclient.HttpStatus;
   2: import org.apache.commons.httpclient.NameValuePair;
   3: import org.apache.commons.httpclient.URI;
   4:         ...
   5:             else {
   6:                 final NameValuePair[] pairs = new NameValuePair[webRequestSettings.getRequestParameters().size()];
   7:                 webRequestSettings.getRequestParameters().toArray( pairs );
   8:         ...
   9:                     final NameValuePair pair = ( NameValuePair )iterator.next();
  10:                     postMethod.removeParameter( pair.getName(), pair.getValue() );
  11:                 }
  12:         ...
  13:                     final NameValuePair pair = ( NameValuePair )iterator.next();
  14:                     postMethod.addParameter( pair.getName(), pair.getValue() );

View Full Code Here
   1: import org.apache.commons.httpclient.HeaderElement;
   2: import org.apache.commons.httpclient.NameValuePair;
   3: import org.apache.commons.httpclient.util.DateParseException;
   4:         ...
   5:                 cookie = new Cookie(host,
   6:                                     headerelement.getName(),
   7:                                     headerelement.getValue(),
   8:         ...
   9:             }
  10:             NameValuePair[] parameters = headerelement.getParameters();
  11:             if (parameters != null) {
  12:         ...
  13:     public void parseAttribute(
  14:         final NameValuePair attribute, final Cookie cookie)

View Full Code Here

getValue

public String getValue()
Return the current value.
Returns:
String value The current value.
Usages and Demos :

View More Examples of getValue()
   1: import org.apache.commons.httpclient.HeaderElement;
   2: import org.apache.commons.httpclient.NameValuePair;
   3: 
   4:         ...
   5:             HeaderElement[] values = HeaderElement.parseElements(contentType);
   6:             NameValuePair charsetPair = null;
   7:             for (int i = 0; i < values.length; i++) {
   8:         ...
   9:             if (charset == null && charsetPair != null) {
  10:                 this.charset = charsetPair.getValue();
  11:             } else if (charset != null && charsetPair == null) {

View Full Code Here
   1: 
   2: import org.apache.commons.httpclient.NameValuePair;
   3: import org.apache.commons.lang.ArrayUtils;
   4:         ...
   5:         while (iterator.hasNext()) {
   6:             final NameValuePair pair = (NameValuePair) iterator.next();
   7:             if (pair.getName().equalsIgnoreCase(headerName)) {
   8:         ...
   9:                 return pair.getValue();
  10:             }

View Full Code Here
   1: import org.apache.commons.httpclient.HeaderElement;
   2: import org.apache.commons.httpclient.NameValuePair;
   3: import org.apache.commons.httpclient.Cookie;
   4:         ...
   5:                        headerelement.getName(),
   6:                        headerelement.getValue(),
   7:                        defaultPath, 
   8:         ...
   9:                        false);
  10:         NameValuePair[] parameters = headerelement.getParameters();
  11:         if (parameters != null) {
  12:         ...
  13:     public void parseAttribute(
  14:         final NameValuePair attribute, final Cookie cookie)

View Full Code Here
   1: 
   2: import org.apache.commons.httpclient.NameValuePair;
   3: import org.apache.commons.httpclient.Cookie;
   4:         ...
   5:     public void parseAttribute(
   6:         final NameValuePair attribute, final Cookie cookie)
   7:         throws MalformedCookieException {
   8:         ...
   9:         final String paramName = attribute.getName().toLowerCase();
  10:         final String paramValue = attribute.getValue();
  11: 
  12:         ...
  13: 
  14:     private void formatParam(final StringBuffer buffer, final NameValuePair param, int version) {

View Full Code Here
   1: import org.apache.commons.httpclient.HttpStatus;
   2: import org.apache.commons.httpclient.NameValuePair;
   3: import org.apache.commons.httpclient.URI;
   4:         ...
   5:             else {
   6:                 final NameValuePair[] pairs = new NameValuePair[webRequestSettings.getRequestParameters().size()];
   7:                 webRequestSettings.getRequestParameters().toArray( pairs );
   8:         ...
   9:                     final NameValuePair pair = ( NameValuePair )iterator.next();
  10:                     postMethod.removeParameter( pair.getName(), pair.getValue() );
  11:                 }
  12:         ...
  13:                     final NameValuePair pair = ( NameValuePair )iterator.next();
  14:                     postMethod.addParameter( pair.getName(), pair.getValue() );

View Full Code Here

hashCode

public int hashCode()
Returns a hash code value for the object. This method is supported for the benefit of hashtables such as those provided by java.util.Hashtable.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals(Object) method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the Object.equals(Object) method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hashtables.

As much as is reasonably practical, the hashCode method defined by class Object does return distinct integers for distinct objects. (This is typically implemented by converting the internal address of the object into an integer, but this implementation technique is not required by the JavaTM programming language.)

Overrides:
hashCode in interface Object
Returns:
a hash code value for this object.

setName

public void setName(String name)
Set the name.
Parameters:
name - The new name
See Also:
getName()

setValue

public void setValue(String value)
Set the value.
Parameters:
value - The new value.

toString

public String toString()
Get a String representation of this pair.
Overrides:
toString in interface Object
Returns:
A string representation.