Search in sources :

Example 1 with RealtimeSearchItemVO

use of com.kyj.fx.voeditor.visual.framework.RealtimeSearchItemVO in project Gargoyle by callakrsos.

the class ArticleExtractorComposite method request.

public void request(String url) {
    SingleSelectionModel<Class<? extends ExtractorBase>> selectionModel = cbAlgorisms.getSelectionModel();
    Class<? extends ExtractorBase> selectAlgorism = selectionModel.getSelectedItem();
    if (selectAlgorism != null) {
        RealtimeSearchItemVO vo = new RealtimeSearchItemVO();
        vo.setLink(url);
        request(selectAlgorism, vo);
    }
}
Also used : ExtractorBase(com.kohlschutter.boilerpipe.extractors.ExtractorBase) RealtimeSearchItemVO(com.kyj.fx.voeditor.visual.framework.RealtimeSearchItemVO)

Example 2 with RealtimeSearchItemVO

use of com.kyj.fx.voeditor.visual.framework.RealtimeSearchItemVO in project Gargoyle by callakrsos.

the class NaverRealtimeSearchFactory method parse.

public List<RealtimeSearchVO> parse(String htmlBody) {
    Document doc = Jsoup.parse(htmlBody);
    Elements r = doc.select("[class*='realtime_srch']");
    Elements select = r.select(".lst_realtime_srch");
    List<RealtimeSearchVO> realtimeSearchItems = select.stream().map(e -> {
        RealtimeSearchVO realtimeSearchVO = null;
        Element previousElementSibling = e.previousElementSibling();
        if (previousElementSibling != null) {
            realtimeSearchVO = new RealtimeSearchVO();
            String text = previousElementSibling.text();
            if (text.length() >= 15) {
                realtimeSearchVO.setTitle(text.substring(0, 15) + "...");
            } else {
                realtimeSearchVO.setTitle(text);
            }
            Elements liTags = e.getElementsByTag("li");
            List<RealtimeSearchItemVO> items = liTags.stream().map(li -> {
                RealtimeSearchItemVO item = new RealtimeSearchItemVO();
                Element aTag = li.getElementsByTag("a").first();
                Elements elementsByAttribute = aTag.getElementsByAttribute("href");
                String url = elementsByAttribute.attr("href");
                Element numElement = li.getElementsByClass("num").first();
                String num = numElement.text();
                Element titElement = li.getElementsByClass("tit").first();
                String title = titElement.text();
                item.setRank(Integer.parseInt(num, 10));
                item.setKeyword(title);
                item.setLink(url);
                LOGGER.debug("title [{}] num [{}]  url : [{}] , toString : {}", title, num, url, li.toString());
                return item;
            }).collect(Collectors.toList());
            realtimeSearchVO.setItems(items);
        }
        return realtimeSearchVO;
    }).filter(v -> v != null).collect(Collectors.toList());
    return realtimeSearchItems;
}
Also used : Logger(org.slf4j.Logger) RealtimeSearchVO(com.kyj.fx.voeditor.visual.framework.RealtimeSearchVO) ResponseHandler(com.kyj.fx.voeditor.visual.util.ResponseHandler) MalformedURLException(java.net.MalformedURLException) URL(java.net.URL) RequestUtil(com.kyj.fx.voeditor.visual.util.RequestUtil) LoggerFactory(org.slf4j.LoggerFactory) ValueUtil(com.kyj.fx.voeditor.visual.util.ValueUtil) Supplier(java.util.function.Supplier) Collectors(java.util.stream.Collectors) JSONArray(org.json.simple.JSONArray) RealtimeSearchItemVO(com.kyj.fx.voeditor.visual.framework.RealtimeSearchItemVO) List(java.util.List) Document(org.jsoup.nodes.Document) Element(org.jsoup.nodes.Element) Jsoup(org.jsoup.Jsoup) Elements(org.jsoup.select.Elements) Collections(java.util.Collections) InputStream(java.io.InputStream) RealtimeSearchVO(com.kyj.fx.voeditor.visual.framework.RealtimeSearchVO) Element(org.jsoup.nodes.Element) RealtimeSearchItemVO(com.kyj.fx.voeditor.visual.framework.RealtimeSearchItemVO) Document(org.jsoup.nodes.Document) Elements(org.jsoup.select.Elements)

Example 3 with RealtimeSearchItemVO

use of com.kyj.fx.voeditor.visual.framework.RealtimeSearchItemVO in project Gargoyle by callakrsos.

the class ArticleExtractorComposite method initialize.

@FXML
public void initialize() {
    cbAlgorisms.getItems().addAll(ValueUtil.HTML.getAvaliablesExtractorBase());
    cbAlgorisms.getSelectionModel().select(ArticleExtractor.class);
    cbAlgorisms.setCellFactory(new Callback<ListView<Class<? extends ExtractorBase>>, ListCell<Class<? extends ExtractorBase>>>() {

        @Override
        public ListCell<Class<? extends ExtractorBase>> call(ListView<Class<? extends ExtractorBase>> param) {
            return new TextFieldListCell<>(new StringConverter<Class<? extends ExtractorBase>>() {

                @Override
                public String toString(Class<? extends ExtractorBase> object) {
                    return object.getSimpleName();
                }

                @Override
                public Class<? extends ExtractorBase> fromString(String string) {
                    // TODO Auto-generated method stub
                    return null;
                }
            });
        }
    });
    cbAlgorisms.setConverter(new StringConverter<Class<? extends ExtractorBase>>() {

        @Override
        public String toString(Class<? extends ExtractorBase> object) {
            return object.getSimpleName();
        }

        @Override
        public Class<? extends ExtractorBase> fromString(String string) {
            // TODO Auto-generated method stub
            return null;
        }
    });
    cbAlgorisms.valueProperty().addListener((oba, o, n) -> {
        Class<? extends ExtractorBase> algorism = n;
        // webPreview.getEngine().getDocument().getBaseURI();
        String baseURI = txtUrl.getText();
        if (ValueUtil.isEmpty(baseURI))
            return;
        RealtimeSearchItemVO vo = new RealtimeSearchItemVO();
        vo.setLink(baseURI);
        try {
            URLModel htmlContent = getHTMLContent(vo);
            if (!htmlContent.isEmpty()) {
                String boilderPipe = boilderPipe(algorism, htmlContent.getContent());
                txtResult.setText(boilderPipe);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    });
    cbSmmy.valueProperty().addListener((oba, o, n) -> {
        txtSummary.setText(n.getUrl());
        txtSummary.nextWord();
        txtSummary.appendText(n.getContent());
    });
    StringConverter<URLModel> converter = new StringConverter<URLModel>() {

        @Override
        public String toString(URLModel object) {
            return String.format("[%s] - %s", object.getTitle(), object.getUrl());
        }

        @Override
        public URLModel fromString(String string) {
            return null;
        }
    };
    cbSmmy.setCellFactory(param -> {
        TextFieldListCell<URLModel> textFieldListCell = new TextFieldListCell<>(converter);
        textFieldListCell.setMaxWidth(600d);
        textFieldListCell.setPrefWidth(600d);
        return textFieldListCell;
    });
    /** Size the combo-box drop down list. */
    cbSmmy.setConverter(converter);
    Platform.runLater(() -> {
        request(userData);
    // Platform.runLater(() -> {
    // WebEngine engine = webPreview.getEngine();
    // engine.getLoadWorker().stateProperty().addListener((ChangeListener<State>)
    // (ov, oldState, newState) -> {
    // LOGGER.debug("{} - {}", newState.name(), engine.getLocation());
    //
    // if (newState == Worker.State.RUNNING) {
    // String location = engine.getLocation();
    // if (ValueUtil.isNotEmpty(location)) {
    //
    // Class<? extends ExtractorBase> algorism = cbAlgorisms.getValue();
    // RealtimeSearchItemVO vo = new RealtimeSearchItemVO();
    // vo.setLink(location);
    // try {
    // updateMainContent(algorism, getHTMLContent(vo));
    // } catch (Exception e) {
    // e.printStackTrace();
    // }
    // }
    //
    // }
    // });
    // txtUrl.textProperty().addListener((oba, o, n) -> {
    //
    // if (ValueUtil.isNotEmpty(n)) {
    // RealtimeSearchItemVO realtimeSearchItemVO = new
    // RealtimeSearchItemVO();
    // realtimeSearchItemVO.setLink(n);
    // request(userData);
    // }
    //
    // });
    });
// engine.load(url);
// engine.getLoadWorker().messageProperty().addListener((oba, o, n) -> {
// LOGGER.debug("Browser Message : {}", n);
// });
// engine.setJavaScriptEnabled(true);
// HTML 코드를 engine에서 얻기위한 처리가 필요함.
// org.w3c.dom.Document doc = engine.getDocument();
// try {
// Transformer transformer =
// TransformerFactory.newInstance().newTransformer();
// transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no");
// transformer.setOutputProperty(OutputKeys.METHOD, "xml");
// transformer.setOutputProperty(OutputKeys.INDENT, "yes");
// transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
// transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount",
// "4");
//
// try (ByteArrayOutputStream outputStream = new
// ByteArrayOutputStream()) {
//
// try (OutputStreamWriter writer = new OutputStreamWriter(outputStream,
// "UTF-8")) {
// transformer.transform(new DOMSource(doc), new StreamResult(writer));
// Class<? extends ExtractorBase> algorism = cbAlgorisms.getValue();
// String boilderPipe = boilderPipe(algorism,
// outputStream.toString("UTF-8"));
// txtResult.setText(boilderPipe);
// }
// }
//
// } catch (Exception ex) {
// txtResult.setText(
// String.format("[%s] Something Problems Occured. \n\nStackTrace : {}",
// newState.name(), ValueUtil.toString(ex)));
// }
// } else {
// txtResult.setText("Waitings.... " + newState.name());
// }
// });
}
Also used : TextFieldListCell(javafx.scene.control.cell.TextFieldListCell) ExtractorBase(com.kohlschutter.boilerpipe.extractors.ExtractorBase) ListCell(javafx.scene.control.ListCell) TextFieldListCell(javafx.scene.control.cell.TextFieldListCell) RealtimeSearchItemVO(com.kyj.fx.voeditor.visual.framework.RealtimeSearchItemVO) StringConverter(javafx.util.StringConverter) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) ListView(javafx.scene.control.ListView) URLModel(com.kyj.fx.voeditor.visual.framework.URLModel) FXML(javafx.fxml.FXML)

Example 4 with RealtimeSearchItemVO

use of com.kyj.fx.voeditor.visual.framework.RealtimeSearchItemVO in project Gargoyle by callakrsos.

the class NrchRealtimeSrchFlowComposite method contextMenu.

/**
	 * @작성자 : KYJ
	 * @작성일 : 2016. 11. 21.
	 */
private void contextMenu(Node target) {
    target.setOnMousePressed(ev -> {
        if (MouseButton.SECONDARY == ev.getButton()) {
            if (ev.getClickCount() != 1) {
                return;
            }
            if (ev.getSource() instanceof VBox) {
                VBox tmp = (VBox) ev.getSource();
                Object userData = tmp.getUserData();
                if (userData != null) {
                    ContextMenu contextMenu = new ContextMenu();
                    MenuItem menuGoogleTrend = new MenuItem("구글 트랜드로 조회");
                    menuGoogleTrend.setOnAction(e -> {
                        googleChartSearch((RealtimeSearchItemVO) userData);
                    });
                    MenuItem menuArticleAnalyzer = new MenuItem("기사 분석기 - Preview ver.");
                    menuArticleAnalyzer.setOnAction(e -> {
                        FxUtil.createStageAndShow(new ArticleExtractorComposite((RealtimeSearchItemVO) userData), stage -> {
                            stage.initOwner(FxUtil.getWindow(getParent()));
                            stage.setTitle(ArticleExtractorComposite.TITLE);
                            stage.sizeToScene();
                        });
                    });
                    contextMenu.getItems().addAll(menuGoogleTrend, menuArticleAnalyzer);
                    contextMenu.show(this.getParent().getScene().getWindow(), ev.getScreenX(), ev.getScreenY());
                }
            }
        }
    });
}
Also used : RealtimeSearchItemVO(com.kyj.fx.voeditor.visual.framework.RealtimeSearchItemVO) ContextMenu(javafx.scene.control.ContextMenu) MenuItem(javafx.scene.control.MenuItem) VBox(javafx.scene.layout.VBox)

Aggregations

RealtimeSearchItemVO (com.kyj.fx.voeditor.visual.framework.RealtimeSearchItemVO)4 ExtractorBase (com.kohlschutter.boilerpipe.extractors.ExtractorBase)2 MalformedURLException (java.net.MalformedURLException)2 RealtimeSearchVO (com.kyj.fx.voeditor.visual.framework.RealtimeSearchVO)1 URLModel (com.kyj.fx.voeditor.visual.framework.URLModel)1 RequestUtil (com.kyj.fx.voeditor.visual.util.RequestUtil)1 ResponseHandler (com.kyj.fx.voeditor.visual.util.ResponseHandler)1 ValueUtil (com.kyj.fx.voeditor.visual.util.ValueUtil)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 URL (java.net.URL)1 Collections (java.util.Collections)1 List (java.util.List)1 Supplier (java.util.function.Supplier)1 Collectors (java.util.stream.Collectors)1 FXML (javafx.fxml.FXML)1 ContextMenu (javafx.scene.control.ContextMenu)1 ListCell (javafx.scene.control.ListCell)1 ListView (javafx.scene.control.ListView)1 MenuItem (javafx.scene.control.MenuItem)1