// Path: src/com/noticeditorteam/noticeditor/io/importers/HtmlImportMode.java
// public enum HtmlImportMode {
//     RELAXED("relaxed", Whitelist.relaxed()),
//     ONLY_TEXT("only_text", Whitelist.none()),
//     ORIGINAL("original", null),
//     BASIC("basic", Whitelist.basic()),
//     BASIC_WITH_IMAGES("basic_with_img", Whitelist.basicWithImages()),
//     SIMPLE_TEXT("simple_text", Whitelist.simpleText());
// 
//     private final String name;
//     private final Whitelist whitelist;
// 
//     private HtmlImportMode(String name, Whitelist whitelist) {
//         this.name = name;
//         this.whitelist = whitelist;
//     }
// 
//     public String getName() {
//         return name;
//     }
// 
//     public Whitelist getWhitelist() {
//         return whitelist;
//     }
// }
// 
// Path: src/com/noticeditorteam/noticeditor/io/importers/ImportCallback.java
// @FunctionalInterface
// public interface ImportCallback<R, O> {
// 
//     public void call(R result, O optional);
// }
// 
// Path: src/com/noticeditorteam/noticeditor/io/importers/WebImporter.java
// public class WebImporter extends HtmlImporter {
// 
//     private final Map<String, String> cache = new HashMap<>();
// 
//     @Override
//     protected String cleanHtml(String url, Whitelist whitelist) throws Exception {
//         String html;
//         if (cache.containsKey(url)) {
//             html = cache.get(url);
//         } else {
//             html = IOUtil.stringFromStream(new URL(url).openStream());
//             cache.put(url, html);
//         }
//         return super.cleanHtml(html, whitelist);
//     }
// }


import com.noticeditorteam.noticeditor.io.importers.HtmlImportMode;
import com.noticeditorteam.noticeditor.io.importers.ImportCallback;
import com.noticeditorteam.noticeditor.io.importers.WebImporter;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.Node;
import javafx.scene.control.RadioButton;
import javafx.scene.control.TextField;
import javafx.scene.control.ToggleGroup;
import javafx.scene.layout.VBox;
import javafx.scene.web.WebView;
    private TextField urlField;

    private WebImporter importer;
    private HtmlImportMode importMode;
    private ImportCallback<String, Exception> importCallback;

    @Override
    public void initialize(URL location, ResourceBundle resources) {
        importer = new WebImporter();
        importMode = HtmlImportMode.ORIGINAL;

        ObservableList<Node> nodes = modesBox.getChildren();
        nodes.clear();
        final ToggleGroup modesGroup = new ToggleGroup();
        for (HtmlImportMode value : HtmlImportMode.values()) {
            RadioButton radio = new RadioButton(resources.getString(value.getName()));
            if (value == importMode)
                radio.setSelected(true);
            radio.setOnAction(e -> onModeChanged(value));
            radio.setToggleGroup(modesGroup);
            nodes.add(radio);
        }

        pagePreview.getEngine().loadContent(resources.getString("preview"), "text/html");
    }

    public void setImportCallback(ImportCallback<String, Exception> importCallback) {
        this.importCallback = importCallback;
    }

// Path: src/com/noticeditorteam/noticeditor/io/importers/HtmlImportMode.java
// public enum HtmlImportMode {
//     RELAXED("relaxed", Whitelist.relaxed()),
//     ONLY_TEXT("only_text", Whitelist.none()),
//     ORIGINAL("original", null),
//     BASIC("basic", Whitelist.basic()),
//     BASIC_WITH_IMAGES("basic_with_img", Whitelist.basicWithImages()),
//     SIMPLE_TEXT("simple_text", Whitelist.simpleText());
// 
//     private final String name;
//     private final Whitelist whitelist;
// 
//     private HtmlImportMode(String name, Whitelist whitelist) {
//         this.name = name;
//         this.whitelist = whitelist;
//     }
// 
//     public String getName() {
//         return name;
//     }
// 
//     public Whitelist getWhitelist() {
//         return whitelist;
//     }
// }
// 
// Path: src/com/noticeditorteam/noticeditor/io/importers/ImportCallback.java
// @FunctionalInterface
// public interface ImportCallback<R, O> {
// 
//     public void call(R result, O optional);
// }
// 
// Path: src/com/noticeditorteam/noticeditor/io/importers/WebImporter.java
// public class WebImporter extends HtmlImporter {
// 
//     private final Map<String, String> cache = new HashMap<>();
// 
//     @Override
//     protected String cleanHtml(String url, Whitelist whitelist) throws Exception {
//         String html;
//         if (cache.containsKey(url)) {
//             html = cache.get(url);
//         } else {
//             html = IOUtil.stringFromStream(new URL(url).openStream());
//             cache.put(url, html);
//         }
//         return super.cleanHtml(html, whitelist);
//     }
// }


// Path: src/com/noticeditorteam/noticeditor/controller/WebImportController.java
import com.noticeditorteam.noticeditor.io.importers.HtmlImportMode;
import com.noticeditorteam.noticeditor.io.importers.ImportCallback;
import com.noticeditorteam.noticeditor.io.importers.WebImporter;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.Node;
import javafx.scene.control.RadioButton;
import javafx.scene.control.TextField;
import javafx.scene.control.ToggleGroup;
import javafx.scene.layout.VBox;
import javafx.scene.web.WebView;

    private TextField urlField;

    private WebImporter importer;
    private HtmlImportMode importMode;
    private ImportCallback<String, Exception> importCallback;

    @Override
    public void initialize(URL location, ResourceBundle resources) {
        importer = new WebImporter();
        importMode = HtmlImportMode.ORIGINAL;

        ObservableList<Node> nodes = modesBox.getChildren();
        nodes.clear();
        final ToggleGroup modesGroup = new ToggleGroup();
        for (HtmlImportMode value : HtmlImportMode.values()) {
            RadioButton radio = new RadioButton(resources.getString(value.getName()));
            if (value == importMode)
                radio.setSelected(true);
            radio.setOnAction(e -> onModeChanged(value));
            radio.setToggleGroup(modesGroup);
            nodes.add(radio);
        }

        pagePreview.getEngine().loadContent(resources.getString("preview"), "text/html");
    }

    public void setImportCallback(ImportCallback<String, Exception> importCallback) {
        this.importCallback = importCallback;
    }

    private void onModeChanged(HtmlImportMode mode) {