@Override
public NameValuePair[] getSubmitKeyValuePairs() {
String value = getValueAttribute();
if (StringUtils.isEmpty(value)) {
return new NameValuePair[] {new KeyDataPair(getNameAttribute(), new File(""), null, null)};
}
File file = null;
// to tolerate file://
if (value.startsWith("file:/")) {
if (value.startsWith("file://") && !value.startsWith("file:///")) {
value = "file:///" + value.substring(7);
}
try {
file = new File(new URI(value));
}
catch (final URISyntaxException e) {
// nothing here
}
}
if (file == null) {
file = new File(value);
}
// contentType and charset are determined from browser and page
// perhaps it could be interesting to have setters for it in this class
// to give finer control to user
final String contentType;
if (contentType_ == null) {
contentType = getPage().getWebClient().guessContentType(file);
}
else {
contentType = contentType_;
}
final String charset = getPage().getPageEncoding();
final KeyDataPair keyDataPair = new KeyDataPair(getNameAttribute(), file, contentType, charset);
keyDataPair.setData(data_);
return new NameValuePair[] {keyDataPair};
}