use of org.jabref.logic.net.URLDownload in project jabref by JabRef.
the class EntryTableTransferHandler method handleDropTransfer.
private boolean handleDropTransfer(URL dropLink) throws IOException {
File tmpfile = File.createTempFile("jabrefimport", "");
tmpfile.deleteOnExit();
new URLDownload(dropLink).toFile(tmpfile.toPath());
// Import into new if entryTable==null, otherwise into current library:
ImportMenuItem importer = new ImportMenuItem(frame, entryTable == null);
importer.automatedImport(Collections.singletonList(tmpfile.getAbsolutePath()));
return true;
}
use of org.jabref.logic.net.URLDownload in project jabref by JabRef.
the class CiteSeerXFetcher method getSingleCitation.
private static BibEntry getSingleCitation(String urlString) throws IOException {
String cont = new URLDownload(urlString).asString();
// Find title, and create entry if we do. Otherwise assume we did not get an entry:
Matcher m = CiteSeerXFetcher.TITLE_PATTERN.matcher(cont);
if (m.find()) {
BibEntry entry = new BibEntry();
entry.setField(FieldName.TITLE, m.group(1));
// Find authors:
m = CiteSeerXFetcher.AUTHOR_PATTERN.matcher(cont);
if (m.find()) {
String authors = m.group(1);
entry.setField(FieldName.AUTHOR, new NormalizeNamesFormatter().format(authors));
}
// Find year:
m = CiteSeerXFetcher.YEAR_PATTERN.matcher(cont);
if (m.find()) {
entry.setField(FieldName.YEAR, m.group(1));
}
// Find abstract:
m = CiteSeerXFetcher.ABSTRACT_PATTERN.matcher(cont);
if (m.find()) {
entry.setField(FieldName.ABSTRACT, m.group(1));
}
return entry;
} else {
return null;
}
}
use of org.jabref.logic.net.URLDownload in project jabref by JabRef.
the class CiteSeerXFetcher method getCitationsFromUrl.
private static String getCitationsFromUrl(String urlQuery, List<String> ids) throws IOException {
String cont = new URLDownload(urlQuery).asString(Globals.prefs.getDefaultEncoding());
Matcher m = CiteSeerXFetcher.CITE_LINK_PATTERN.matcher(cont);
while (m.find()) {
ids.add(CiteSeerXFetcher.URL_START + m.group(1));
}
return null;
}
use of org.jabref.logic.net.URLDownload in project jabref by JabRef.
the class ArgumentProcessor method importFile.
private static Optional<ParserResult> importFile(String argument) {
String[] data = argument.split(",");
String address = data[0];
Path file;
if (address.startsWith("http://") || address.startsWith("https://") || address.startsWith("ftp://")) {
// Download web resource to temporary file
try {
file = new URLDownload(address).toTemporaryFile();
} catch (IOException e) {
System.err.println(Localization.lang("Problem downloading from %1", address) + e.getLocalizedMessage());
return Optional.empty();
}
} else {
if (OS.WINDOWS) {
file = Paths.get(address);
} else {
file = Paths.get(address.replace("~", System.getProperty("user.home")));
}
}
String importFormat;
if (data.length > 1) {
importFormat = data[1];
} else {
importFormat = "*";
}
Optional<ParserResult> importResult = importFile(file, importFormat);
importResult.ifPresent(result -> {
OutputPrinter printer = new SystemOutputPrinter();
if (result.hasWarnings()) {
printer.showMessage(result.getErrorMessage());
}
});
return importResult;
}
use of org.jabref.logic.net.URLDownload in project jabref by JabRef.
the class ACMPortalFetcher method processQueryGetPreview.
@Override
public boolean processQueryGetPreview(String query, FetcherPreviewDialog preview, OutputPrinter status) {
this.terms = query;
piv = 0;
shouldContinue = true;
acmOrGuide = acmButton.isSelected();
fetchAbstract = absCheckBox.isSelected();
String address = makeUrl();
LinkedHashMap<String, JLabel> previews = new LinkedHashMap<>();
try {
URLDownload dl = new URLDownload(address);
String page = dl.asString(Globals.prefs.getDefaultEncoding());
int hits = getNumberOfHits(page, RESULTS_FOUND_PATTERN, ACMPortalFetcher.HITS_PATTERN);
int index = page.indexOf(RESULTS_FOUND_PATTERN);
if (index >= 0) {
page = page.substring(index + RESULTS_FOUND_PATTERN.length());
}
if (hits == 0) {
status.showMessage(Localization.lang("No entries found for the search string '%0'", terms), Localization.lang("Search %0", getTitle()), JOptionPane.INFORMATION_MESSAGE);
return false;
} else if (hits > 20) {
status.showMessage(Localization.lang("%0 entries found. To reduce server load, only %1 will be downloaded.", String.valueOf(hits), String.valueOf(PER_PAGE)), Localization.lang("Search %0", getTitle()), JOptionPane.INFORMATION_MESSAGE);
}
hits = getNumberOfHits(page, PAGE_RANGE_PATTERN, ACMPortalFetcher.MAX_HITS_PATTERN);
parse(page, Math.min(hits, PER_PAGE), previews);
for (Map.Entry<String, JLabel> entry : previews.entrySet()) {
preview.addEntry(entry.getKey(), entry.getValue());
}
return true;
} catch (IOException e) {
LOGGER.error("Error while fetching from " + getTitle(), e);
preview.showErrorMessage(this.getTitle(), e.getLocalizedMessage());
return false;
}
}
Aggregations