All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.googlecode.openbox.http.requests.FormBodyRequest Maven / Gradle / Ivy

There is a newer version: 2.1.6
Show newest version
package com.googlecode.openbox.http.requests;

import java.io.UnsupportedEncodingException;
import java.util.LinkedList;
import java.util.List;

import org.apache.http.HttpEntity;
import org.apache.http.NameValuePair;
import org.apache.http.client.entity.UrlEncodedFormEntity;

import com.googlecode.openbox.http.HttpClientException;
import com.googlecode.openbox.http.Request;

public abstract class FormBodyRequest extends Request {

	private List forms = null;

	public FormBodyRequest(String url) {
		super(url);
	}

	public FormBodyRequest(String scheme, String host, int port, String path) {
		super(scheme, host, port, path);
	}

	public void addForm(String name, String value) {
		if (null == forms) {
			forms = new LinkedList();
		}
		add(forms, name, value);
	}

	public void setForm(String name, String value) {
		if (null == forms) {
			forms = new LinkedList();
		}
		set(forms, name, value);
	}

	public void removeForm(String name) {
		remove(forms, name);
	}

	@Override
	public HttpEntity getEntity() {
		if (null != forms && forms.size() > 0) {
			try {
				return new UrlEncodedFormEntity(forms, CHARSET_UTF_8);
			} catch (UnsupportedEncodingException e) {
				throw new HttpClientException(
						"UnsupportedEncodingException as charset ="
								+ CHARSET_UTF_8, e);
			}
		}
		return null;
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy