form = e;
break;
}
}
} catch (IOException e) {
throw new IOException2("Failed to access "+url,e);
}
url = new URL(form.attributeValue("action"));
try {
HttpURLConnection con = (HttpURLConnection) ProxyConfiguration.open(url);
con.setRequestMethod("POST");
con.setDoOutput(true);
con.setRequestProperty("Cookie",cookie);
con.setRequestProperty("Content-Type","application/x-www-form-urlencoded");
PrintStream os = new PrintStream(con.getOutputStream());
// select platform
String primary=null,secondary=null;
Element p = (Element)form.selectSingleNode(".//select[@id='dnld_platform']");
for (Element opt : (List<Element>)p.elements("option")) {
String value = opt.attributeValue("value");
String vcap = value.toUpperCase(Locale.ENGLISH);
if(!platform.is(vcap)) continue;
switch (cpu.accept(vcap)) {
case PRIMARY: primary = value;break;
case SECONDARY: secondary=value;break;
case UNACCEPTABLE: break;
}
}
if(primary==null) primary=secondary;
if(primary==null)
throw new AbortException("Couldn't find the right download for "+platform+" and "+ cpu +" combination");
os.print(p.attributeValue("name")+'='+primary);
LOGGER.fine("Platform choice:"+primary);
// select language
Element l = (Element)form.selectSingleNode(".//select[@id='dnld_language']");
if (l != null) {
os.print("&"+l.attributeValue("name")+"="+l.element("option").attributeValue("value"));
}
// the rest
for (Element e : (List<Element>)form.selectNodes(".//input")) {
os.print('&');
os.print(e.attributeValue("name"));
os.print('=');
String value = e.attributeValue("value");
if(value==null)
os.print("on"); // assume this is a checkbox
else
os.print(URLEncoder.encode(value,"UTF-8"));
}
os.close();
return con;
} catch (IOException e) {
throw new IOException2("Failed to access "+url,e);
}
}