private Vector getFormQuery(Form form, URI baseURI) {
Vector qryStrList = new Vector();
Vector qryList = new Vector();
String queryString = "";
HttpRequestHeader reqHeader = null;
HttpBody reqBody = null;
if (form.getAction()==null) {
return qryList;
}
int combinationCount = 1;
for (int i=0; i<form.getSelect().length; i++) {
// restrict max # of options to 2
combinationCount *= (form.getSelect()[i].getOption().length > 2) ? 2: form.getSelect()[i].getOption().length;
}
if (combinationCount > 512) {
return qryList;
}
try {
// build all queryString using input tags
for (int i=0; i<form.getInput().length; i++) {
Input input = form.getInput()[i];
if (input.getName()== null || input.getName().length() == 0) {
continue;
}
if (input.getType() != null) {
if (//input.getType().equalsIgnoreCase(Input.SUBMIT) ||
// submit field should also be sent for better crawling.
input.getType().equalsIgnoreCase(Input.PASSWORD) ||
input.getType().equalsIgnoreCase(Input.CHECKBOX) ||
input.getType().equalsIgnoreCase(Input.RESET)) {
continue;
}
}
String value = input.getValue();
if (input.getType().equalsIgnoreCase(Input.TEXT) && value.equals("")) {
// arbitrary fill a "1" for displayable fields.
value = "1";
}
queryString = buildPostQueryString(queryString, input.getName(), value);
}
// build all queryString using textarea tags
for (int i=0; i<form.getTextArea().length; i++) {
TextArea textarea = form.getTextArea()[i];
if (textarea.getName()== null || textarea.getName().length() == 0) {
continue;
}
String value = textarea.getValue();
queryString = buildPostQueryString(queryString, textarea.getName(), value);
}
// build all queryString using SELECT and OPTION tags
qryStrList.addElement(queryString);
for (int i=0; i<form.getSelect().length;i++) {
Select select = form.getSelect()[i];
if (select.getName()== null || select.getName().length() == 0) {
continue;
}
qryStrList = addSelectField(qryStrList, select);
}
for (int i=0; i<qryStrList.size(); i++) {
HttpMessage msg = null;
URI uri = null;
String qryStr = (String) qryStrList.elementAt(i);
if (form.getMethod().equalsIgnoreCase(Form.GET)) {
String action = (form.getAction().indexOf(QUESTION) <0) ? form.getAction()+QUESTION+qryStr : form.getAction()+AMPERSAND+qryStr;
uri = new URI(baseURI, action, true);
reqHeader = new HttpRequestHeader(form.getMethod().trim().toUpperCase(), uri, HttpHeader.HTTP11);
msg = new HttpMessage(reqHeader);
} else if (form.getMethod().equalsIgnoreCase(Form.POST)) {
if (!parent.getParent().getSpiderParam().isPostForm()) {
continue;
}
uri = new URI(baseURI, form.getAction(), true);
reqHeader = new HttpRequestHeader(form.getMethod().trim().toUpperCase(), uri, HttpHeader.HTTP11);
reqBody = new HttpBody(qryStr);
reqHeader.setContentLength(reqBody.length());
msg = new HttpMessage(reqHeader, reqBody);
} else {
continue;
}
msg.getRequestHeader().setContentLength(msg.getRequestBody().length());