package org.jabref.logic.importer.fetcher;

import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.net.URL;

import org.jabref.logic.help.HelpFile;
import org.jabref.logic.importer.FetcherException;
import org.jabref.logic.importer.IdBasedParserFetcher;
import org.jabref.logic.importer.ImportFormatPreferences;
import org.jabref.logic.importer.Parser;
import org.jabref.logic.importer.fileformat.BibtexParser;
import org.jabref.model.util.DummyFileUpdateMonitor;

import org.apache.http.client.utils.URIBuilder;

/*
 * https://datatracker.ietf.org
 * IETF (Internet Engineering Task Force) datatracker contains data about the documents,
 * working groups, meetings, agendas, minutes, presentations, and more, of the IETF.
 */
public class RfcFetcher implements IdBasedParserFetcher {

    private final ImportFormatPreferences importFormatPreferences;

    public RfcFetcher (ImportFormatPreferences importFormatPreferences) {
        this.importFormatPreferences = importFormatPreferences;
    }

    @Override
    public String getName() {
        return "RFC";
    }

    @Override
    public HelpFile getHelpPage() {
        return HelpFile.FETCHER_RFC;
    }

    @Override
    public URL getURLForID(String identifier) throws URISyntaxException, MalformedURLException, FetcherException {
        // Add "rfc" prefix if user's search entry was numerical
        identifier = (!identifier.toLowerCase().startsWith("rfc")) ? "rfc" + identifier : identifier;

        URIBuilder uriBuilder = new URIBuilder("https://datatracker.ietf.org/doc/" + identifier + "/bibtex/");

        return uriBuilder.build().toURL();
    }

    @Override
    public Parser getParser() {
        return new BibtexParser(importFormatPreferences, new DummyFileUpdateMonitor());
    }
}

@@ -1393,17 +1393,73 @@
         
-i
+String prefixedIdentifier = identifier;%0A        prefixedI
 dentifie
@@ -1514,25 +1514,33 @@
 ) ? %22rfc%22 + 
-i
+prefixedI
 dentifier : 
@@ -1539,17 +1539,25 @@
 ifier : 
-i
+prefixedI
 dentifie
@@ -1645,17 +1645,25 @@
 doc/%22 + 
-i
+prefixedI
 dentifie

Add 'RFC' entry generator ID-type option