Skip to content

Commit

Permalink
Help files and some improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
oscargus committed Nov 4, 2015
1 parent 53d04c3 commit dcb603d
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 38 deletions.
81 changes: 46 additions & 35 deletions src/main/java/net/sf/jabref/importer/fetcher/DOAJFetcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,42 +61,55 @@ public boolean processQuery(String query, ImportInspector inspector, OutputPrint
JSONObject jo = jsonResponse.getBody().getObject();
int hits = jo.getInt("total");
int numberToFetch = 0;
while (true) {
String strCount = JOptionPane.showInputDialog(Localization.lang("References found") + ": " + hits + " "
+ Localization.lang("Number of references to fetch?"), Integer.toString(hits));

if (strCount == null) {
status.setStatus(Localization.lang("DOAJ search canceled"));
return false;
}

try {
numberToFetch = Integer.parseInt(strCount.trim());
break;
} catch (RuntimeException ex) {
status.showMessage(Localization.lang("Please enter a valid number"));
if (hits > 0) {
if (hits > maxPerPage) {
while (true) {
String strCount = JOptionPane
.showInputDialog(
Localization.lang("References found") + ": " + hits + " "
+ Localization.lang("Number of references to fetch?"),
Integer.toString(hits));

if (strCount == null) {
status.setStatus(Localization.lang("DOAJ search canceled"));
return false;
}

try {
numberToFetch = Integer.parseInt(strCount.trim());
break;
} catch (RuntimeException ex) {
status.showMessage(Localization.lang("Please enter a valid number"));
}
}
} else {
numberToFetch = hits;
}
}

for (int page = 1; ((page - 1) * maxPerPage) <= numberToFetch; page++) {
if (!shouldContinue) {
break;
}
for (int page = 1; ((page - 1) * maxPerPage) <= numberToFetch; page++) {
if (!shouldContinue) {
break;
}

int noToFetch = Math.min(maxPerPage, numberToFetch - ((page - 1) * maxPerPage));
jsonResponse = Unirest.get(searchURL + query + "?page=" + page + "&pageSize=" + noToFetch)
.header("accept", "application/json").asJson();
jo = jsonResponse.getBody().getObject();
if (jo.has("results")) {
JSONArray results = jo.getJSONArray("results");
for (int i = 0; i < results.length(); i++) {
JSONObject bibJsonEntry = results.getJSONObject(i).getJSONObject("bibjson");
BibtexEntry entry = BibJSONConverter.BibJSONtoBibtex(bibJsonEntry);
inspector.addEntry(entry);
int noToFetch = Math.min(maxPerPage, numberToFetch - ((page - 1) * maxPerPage));
jsonResponse = Unirest.get(searchURL + query + "?page=" + page + "&pageSize=" + noToFetch)
.header("accept", "application/json").asJson();
jo = jsonResponse.getBody().getObject();
if (jo.has("results")) {
JSONArray results = jo.getJSONArray("results");
for (int i = 0; i < results.length(); i++) {
JSONObject bibJsonEntry = results.getJSONObject(i).getJSONObject("bibjson");
BibtexEntry entry = BibJSONConverter.BibJSONtoBibtex(bibJsonEntry);
inspector.addEntry(entry);
}
}
}
return true;
} else {
status.showMessage(Localization.lang("No entries found for the search string '%0'", query),
Localization.lang("Search DOAJ"), JOptionPane.INFORMATION_MESSAGE);
return false;
}
return true;
} catch (UnirestException e) {
LOGGER.warn("Problem searching DOAJ", e);
return false;
Expand All @@ -106,19 +119,17 @@ public boolean processQuery(String query, ImportInspector inspector, OutputPrint

@Override
public String getTitle() {
return "DOAJ (Directory of Open Access Journals";
return "DOAJ (Directory of Open Access Journals)";
}

@Override
public String getKeyName() {
// TODO Auto-generated method stub
return null;
return "DOAJ";
}

@Override
public String getHelpPage() {
// TODO Auto-generated method stub
return null;
return "DOAJHelp.html";
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,13 @@ public static BibtexEntry BibJSONtoBibtex(JSONObject bibJsonEntry) {
JSONArray authors = bibJsonEntry.getJSONArray("author");
StringBuffer sb = new StringBuffer();
for (int i = 0; i < authors.length(); i++) {
sb.append(authors.getJSONObject(i).getString("name"));
if (i < (authors.length() - 1)) {
sb.append(" and ");
if (authors.getJSONObject(i).has("name")) {
sb.append(authors.getJSONObject(i).getString("name"));
if (i < (authors.length() - 1)) {
sb.append(" and ");
}
} else {
LOGGER.info("Empty author name.");
}
}
entry.setField("author", sb.toString());
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/help/en/Contents.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ <h2>Import/Export</h2>
<li><a href="ACMPortalHelp.html">Fetching entries from <em>ACM</em> Portal</a></li>
<li><a href="CiteSeerHelp.html">Fetching entries from <em>CiteSeerX</em></a></li>
<li><a href="DiVAtoBibTeXHelp.html">Fetching entries from <em>DiVA</em></a></li>
<li><a href="DOAJHelp.html">Fetching entries from <em>DOAJ</em></a></li>
<li><a href="DOItoBibTeXHelp.html">Fetching entries using the <em>DOI to BibTeX Converter</em></a></li>
<li><a href="GoogleScholarHelp.html">Fetching entries from <em>Google Scholar</em></a></li>
<li><a href="IEEEXploreHelp.html">Fetching entries from <em>IEEExplore</em></a></li>
Expand Down
27 changes: 27 additions & 0 deletions src/main/resources/help/en/DOAJHelp.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link rel="stylesheet" type="text/css" href="jabref_help.css"/>
</head>

<body>
<h1>Fetching entries from DOAJ</h1>

<p><a href="http://www.diva-portal.org/">DOAJ (Directory of Open Access Journals)</a> is a database
covering open access journals.

<p>To use this feature, choose <b>Search -&gt; Web search</b>, and the
search interface will appear in the side pane. Select <b>DOAJ (Directory of Open Access Journals)</b> in the dropdown menu.</p>

<p>Enter the text you want to search for in the search field
and press <b>Enter</b> or the <b>Fetch</b> button.

<p>It is possible to limit the search by adding a field name to the search, as field:text. The supported fields area
<ul>
<li> title: The title of the article
<li> doi: The DOI of the article
<li> issn: The ISSN of the journal
<li> publisher: The publisher of the journal
<li> abstract: The abstract of the article
</ul>
</body>
</html>

0 comments on commit dcb603d

Please sign in to comment.