Skip to content

Commit

Permalink
Fixed the problem pointed out and improved some minor things
Browse files Browse the repository at this point in the history
  • Loading branch information
oscargus committed Dec 27, 2015
1 parent e964e2c commit 396c96e
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions src/main/java/net/sf/jabref/importer/fetcher/ACMPortalFetcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,9 @@ public class ACMPortalFetcher implements PreviewEntryFetcher {

private int piv;

private static final Pattern HITS_PATTERN = Pattern.compile("<strong>(\\d+)</strong> results found");
private static final Pattern MAX_HITS_PATTERN = Pattern.compile("Result \\d+ &ndash; \\d+ of (\\d+)");
private static final Pattern HITS_PATTERN = Pattern.compile("<strong>(\\d+,*\\d*)</strong> results found");
private static final Pattern MAX_HITS_PATTERN = Pattern
.compile("Result \\d+,*\\d* &ndash; \\d+,*\\d* of (\\d+,*\\d*)");

private static final Pattern FULL_CITATION_PATTERN = Pattern.compile("<a href=\"(citation.cfm.*)\" target.*");

Expand Down Expand Up @@ -131,22 +132,24 @@ public boolean processQueryGetPreview(String query, FetcherPreviewDialog preview

String page = Util.getResults(url);

int hits = getNumberOfHits(page, "<div id=\"resfound\">", ACMPortalFetcher.HITS_PATTERN);
String resultsFound = "<div id=\"resfound\">";
int hits = getNumberOfHits(page, resultsFound, ACMPortalFetcher.HITS_PATTERN);

int index = page.indexOf("<div id=\"resfound\">");
int index = page.indexOf(resultsFound);
if (index >= 0) {
page = page.substring(index + 5);
index = page.indexOf("<div id=\"resfound\">");
if (index >= 0) {
page = page.substring(index);
}
page = page.substring(index + resultsFound.length());
}

if (hits == 0) {
status.showMessage(Localization.lang("No entries found for the search string '%0'",
terms),
Localization.lang("Search ACM Portal"), 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 ACM Portal"), JOptionPane.INFORMATION_MESSAGE);
}

hits = getNumberOfHits(page, "<div class=\"pagerange\">", ACMPortalFetcher.MAX_HITS_PATTERN);
Expand Down Expand Up @@ -389,7 +392,9 @@ private static int getNumberOfHits(String page, String marker, Pattern pattern)
Matcher m = pattern.matcher(substring);
if (m.find()) {
try {
return Integer.parseInt(m.group(1));
String number = m.group(1);
number = number.replaceAll(",", ""); // Remove , as in 1,234
return Integer.parseInt(number);
} catch (IllegalStateException | NumberFormatException ex) {
throw new IOException("Cannot parse number of hits");
}
Expand Down

0 comments on commit 396c96e

Please sign in to comment.