use of org.jabref.logic.importer.FetcherException in project jabref by JabRef.
the class GoogleScholar method performSearch.
@Override
public List<BibEntry> performSearch(String query) throws FetcherException {
try {
obtainAndModifyCookie();
List<BibEntry> foundEntries = new ArrayList<>(10);
URIBuilder uriBuilder = new URIBuilder(BASIC_SEARCH_URL);
uriBuilder.addParameter("hl", "en");
uriBuilder.addParameter("btnG", "Search");
uriBuilder.addParameter("q", query);
addHitsFromQuery(foundEntries, uriBuilder.toString());
if (foundEntries.size() == 10) {
uriBuilder.addParameter("start", "10");
addHitsFromQuery(foundEntries, uriBuilder.toString());
}
return foundEntries;
} catch (URISyntaxException e) {
throw new FetcherException("Error while fetching from " + getName(), e);
} catch (IOException e) {
// java.io.IOException: Server returned HTTP response code: 503 for URL: https://ipv4.google.com/sorry/index?continue=https://scholar.google.com/scholar%3Fhl%3Den%26btnG%3DSearch%26q%3Dbpmn&hl=en&q=CGMSBI0NBDkYuqy9wAUiGQDxp4NLQCWbIEY1HjpH5zFJhv4ANPGdWj0
if (e.getMessage().contains("Server returned HTTP response code: 503 for URL")) {
throw new FetcherException("Fetching from Google Scholar failed.", Localization.lang("This might be caused by reaching the traffic limitation of Google Scholar (see 'Help' for details)."), e);
} else {
throw new FetcherException("Error while fetching from " + getName(), e);
}
}
}
use of org.jabref.logic.importer.FetcherException in project jabref by JabRef.
the class MedlineFetcher method getPubMedIdsFromQuery.
/**
* When using 'esearch.fcgi?db=<database>&term=<query>' we will get a list of IDs matching the query.
* Input: Any text query (&term)
* Output: List of UIDs matching the query
*
* @see <a href="https://www.ncbi.nlm.nih.gov/books/NBK25500/">www.ncbi.nlm.nih.gov/books/NBK25500/</a>
*/
private List<String> getPubMedIdsFromQuery(String query) throws FetcherException {
boolean fetchIDs = false;
boolean firstOccurrenceOfCount = false;
List<String> idList = new ArrayList<>();
try {
URL ncbi = createSearchUrl(query);
XMLInputFactory inputFactory = XMLInputFactory.newFactory();
XMLStreamReader streamReader = inputFactory.createXMLStreamReader(ncbi.openStream());
fetchLoop: while (streamReader.hasNext()) {
int event = streamReader.getEventType();
switch(event) {
case XMLStreamConstants.START_ELEMENT:
if (streamReader.getName().toString().equals("Count")) {
firstOccurrenceOfCount = true;
}
if (streamReader.getName().toString().equals("IdList")) {
fetchIDs = true;
}
break;
case XMLStreamConstants.CHARACTERS:
if (firstOccurrenceOfCount) {
numberOfResultsFound = Integer.parseInt(streamReader.getText());
firstOccurrenceOfCount = false;
}
if (fetchIDs) {
idList.add(streamReader.getText());
}
break;
case XMLStreamConstants.END_ELEMENT:
//Everything relevant is listed before the IdList. So we break the loop right after the IdList tag closes.
if (streamReader.getName().toString().equals("IdList")) {
break fetchLoop;
}
}
streamReader.next();
}
streamReader.close();
return idList;
} catch (IOException | URISyntaxException e) {
throw new FetcherException("Unable to get PubMed IDs", Localization.lang("Unable to get PubMed IDs"), e);
} catch (XMLStreamException e) {
throw new FetcherException("Error while parsing ID list", Localization.lang("Error while parsing ID list"), e);
}
}
use of org.jabref.logic.importer.FetcherException in project jabref by JabRef.
the class MrDLibFetcher method makeServerRequest.
/**
* Contact the server with the title of the selected item
*
* @param query: The query holds the title of the selected entry. Used to make a query to the MDL Server
* @return Returns the server response. This is an XML document as a String.
*/
private String makeServerRequest(String queryByTitle) throws FetcherException {
try {
URLDownload urlDownload = new URLDownload(constructQuery(queryByTitle));
urlDownload.bypassSSLVerification();
String response = urlDownload.asString();
//Conversion of < and >
response = response.replaceAll(">", ">");
response = response.replaceAll("<", "<");
return response;
} catch (IOException e) {
throw new FetcherException("Problem downloading", e);
}
}
Aggregations