Search in sources :

Example 1 with INSPIREBibtexFilterReader

use of org.jabref.logic.importer.util.INSPIREBibtexFilterReader in project jabref by JabRef.

the class INSPIREFetcher method importInspireEntries.

/**
     * Constructs a INSPIRE query url from slaccitation field
     *
     * @param slaccitation
     * @return query string
     *
     *         public static String constructUrlFromSlaccitation(String slaccitation) { String cmd = "j"; String key =
     *         slaccitation.replaceAll("^%%CITATION = ", "").replaceAll( ";%%$", ""); if (key.matches("^\\w*-\\w*[ /].*"
     *         )) cmd = "eprint"; try { key = URLEncoder.encode(key, "UTF-8"); } catch (UnsupportedEncodingException e)
     *         { } StringBuffer sb = new StringBuffer("http://").append(INSPIRE_HOST) .append("/");
     *         sb.append("spires/find/hep/www").append("?"); sb.append("rawcmd=find+").append(cmd).append("+");
     *         sb.append(key); return sb.toString(); }
     *
     *         /** Construct an INSPIRE query url from eprint field
     *
     * @param eprint
     * @return query string
     *
     *         public static String constructUrlFromEprint(String eprint) { String key = eprint.replaceAll(" [.*]$",
     *         ""); try { key = URLEncoder.encode(key, "UTF-8"); } catch (UnsupportedEncodingException e) { return ""; }
     *         StringBuffer sb = new StringBuffer("http://").append(INSPIRE_HOST) .append("/");
     *         sb.append("spires/find/hep/www").append("?"); sb.append("rawcmd=find+eprint+"); sb.append(key); return
     *         sb.toString(); }
     */
/**
     * Import an entry from an OAI2 archive. The BibEntry provided has to have the field OAI2_IDENTIFIER_FIELD set to
     * the search string.
     *
     * @param key The OAI2 key to fetch from ArXiv.
     * @return The imported BibEntry or null if none.
     */
private BibDatabase importInspireEntries(String key) throws IOException {
    String url = constructUrl(key);
    HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection();
    conn.setRequestProperty("User-Agent", "JabRef");
    InputStream inputStream = conn.getInputStream();
    try (INSPIREBibtexFilterReader reader = new INSPIREBibtexFilterReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8))) {
        ParserResult pr = new BibtexParser(Globals.prefs.getImportFormatPreferences()).parse(reader);
        return pr.getDatabase();
    }
}
Also used : ParserResult(org.jabref.logic.importer.ParserResult) HttpURLConnection(java.net.HttpURLConnection) InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) BibtexParser(org.jabref.logic.importer.fileformat.BibtexParser) INSPIREBibtexFilterReader(org.jabref.logic.importer.util.INSPIREBibtexFilterReader) URL(java.net.URL)

Aggregations

InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 HttpURLConnection (java.net.HttpURLConnection)1 URL (java.net.URL)1 ParserResult (org.jabref.logic.importer.ParserResult)1 BibtexParser (org.jabref.logic.importer.fileformat.BibtexParser)1 INSPIREBibtexFilterReader (org.jabref.logic.importer.util.INSPIREBibtexFilterReader)1