Can I use JavaXPCOM to ask XULRunner to download a file for me?
Carfield Yim <[email protected]> Wed, 11 Jul 2007 19:58:14 -0700
| Newsgroups | gmane.comp.mozilla.devel.java |
|---|---|
| Organization | http://groups.google.com |
| Message-ID | <1184209094.472016.48330__16103.4853932962$1184209218$gmane$org@d55g2000hsg.googlegroups.com> |
Hi, I have an application to get the links of the document from DOM
tree:
final nsIDOMHTMLCollection list = nsIDOMHTMLDocument.getLinks();
final List<String> links = new ArrayList<String>();
for (int i = 0; i < list.getLength(); i++) {
final String nodeValue =
list.item(i).getAttributes().getNamedItem("href").getNodeValue();
if (!nodeValue.contains("://")) {
final String link = url.getProtocol() + "://" + url.getHost() +
"/" + nodeValue;
links.add(link);
}
}
Then, I download the link using following code:
for (Iterator<String> iterator = links.iterator();
iterator.hasNext();) {
final String link = iterator.next();
final File file = new File(USER_DIR,
link.substring(link.lastIndexOf('/')).replace("?", "_"));
try {
file.createNewFile();
IOUtils.copy(new URL(link).openStream(), new
FileOutputStream(file));
inList.add(file.getAbsolutePath());
} catch (Exception e) {
System.err.println(file.getAbsolutePath());
e.printStackTrace();
}
}
However, this probably don't work if the site require user login to
view the page, because every new URL(link).openStream() will start a
new session at web server. Can I call XULRunner to download the link
to suitable place??