panel, (value != null) ? engine.getLocation() + "\n" + value.getMessage() : engine.getLocation() + "\nUnexpected error.", "Loading error...", JOptionPane.ERROR_MESSAGE);
@Override public void run() { System.out.println("loading in webengine"); webEngine.load(authUrl); System.out.println("loaded"); System.out.println("web location:" + webEngine.getLocation()); } });
private String getTitle(WebEngine webEngine) { Document doc = webEngine.getDocument(); NodeList heads = doc.getElementsByTagName("head"); String titleText = webEngine.getLocation() ; // use location if page does not define a title if (heads.getLength() > 0) { Element head = (Element)heads.item(0); NodeList titles = head.getElementsByTagName("title"); if (titles.getLength() > 0) { Node title = titles.item(0); titleText = title.getTextContent(); } } return titleText ; }
WatchDir(WebEngine eng) throws URISyntaxException, IOException { URI loc = new URI(eng.getLocation()); if (loc.getFragment() != null) { loc = new URI(loc.getScheme(), loc.getHost(), loc.getPath(), null); } dir = Paths.get(loc).getParent(); engine = eng; ws = dir.getFileSystem().newWatchService(); key = dir.register(ws, StandardWatchEventKinds.ENTRY_CREATE, StandardWatchEventKinds.ENTRY_DELETE, StandardWatchEventKinds.ENTRY_MODIFY ); watcher = new Thread(this, "Watching files in " + dir); watcher.setDaemon(true); watcher.setPriority(Thread.MIN_PRIORITY); watcher.start(); }
private String getTitle(WebEngine webEngine) { Document doc = webEngine.getDocument(); NodeList heads = doc.getElementsByTagName("head"); String titleText = webEngine.getLocation(); // use location if page does not define a title return getFirstElement(heads) .map(h -> h.getElementsByTagName("title")) .flatMap(this::getFirstElement) .map(Node::getTextContent).orElse(titleText); } private Optional<Element> getFirstElement(NodeList nodeList) { if (nodeList.getLength() > 0 && nodeList.item(0) instanceof Element) { return Optional.of((Element) nodeList.item(0)); } return Optional.empty(); }
private void listenOnChanges(boolean turnOn) { try { if (watcher != null) { watcher.close(); watcher = null; } final WebEngine eng = webView.getEngine(); if (turnOn && eng.getLocation().startsWith("file:")) { // NOI18N watcher = new WatchDir(eng); } } catch (Exception ex) { FXInspect.LOG.log(Level.SEVERE, null, ex); } } private static void enableFirebug(final WebEngine engine) {
private boolean checkValid() { final String crnt = view.getEngine().getLocation(); if (previous != null && !previous.equals(crnt)) { w.stateProperty().removeListener(this); return false; } previous = crnt; return true; }
private boolean checkValid() { final String crnt = webView.getEngine().getLocation(); if (previous != null && !previous.equals(crnt)) { w.stateProperty().removeListener(this); return false; } previous = crnt; return true; } });
private static WebView webview; public static void someMethod() { try { if (webview == null){ webview = new WebView(); } WebEngine webEngine = webview.getEngine(); webEngine.getLoadWorker().stateProperty().addListener( new ChangeListener<State>() { public void changed(ObservableValue ov, State oldState, State newState) { System.out.println("newState = " + newState); if (newState == State.SUCCEEDED) { System.out.println(webEngine.getLocation()); } } }); webEngine.load("http://javafx.com"); } catch (Exception ex) { System.err.print("error " + ex.getMessage()); ex.printStackTrace(); } }
/** * {@inheritDoc} */ @Override public String getCurrentUrl() { init(); return AppThread.exec(context.get().item().statusCode, () -> context.get().item().view.get().getEngine().getLocation()); }
private void createScene(final String htmlContent) { Platform.setImplicitExit(false); Platform.runLater(() -> { WebView view = new WebView(); engine = view.getEngine(); engine.setOnStatusChanged(event -> SwingUtilities.invokeLater(() -> lblStatus.setText(event.getData()))); engine.getLoadWorker().workDoneProperty() .addListener((ChangeListener<Number>) (observableValue, oldValue, newValue) -> SwingUtilities .invokeLater(() -> progressBar.setValue(newValue.intValue()))); engine.getLoadWorker().exceptionProperty() .addListener((ObservableValue<? extends Throwable> o, Throwable old, final Throwable value) -> { if (engine.getLoadWorker().getState() == State.FAILED) { SwingUtilities.invokeLater(() -> JOptionPane .showMessageDialog( resultsScrollPane, (value != null) ? engine .getLocation() + "\n" + value.getMessage() : engine.getLocation() + "\nUnexpected error.", "Loading error...", JOptionPane.ERROR_MESSAGE)); } }); jfxPanel.setScene(new Scene(view)); }); }
panel, (value != null) ? engine.getLocation() + "\n" + value.getMessage() : engine.getLocation() + "\nUnexpected error.", "Loading error...", JOptionPane.ERROR_MESSAGE);
location.setText(engine.getLocation());
private org.apache.http.cookie.Cookie convert(Cookie in) { BasicClientCookie out = new BasicClientCookie(in.getName(), in.getValue()); String domainStr = null; if (StringUtils.isEmpty(in.getDomain())) { String urlStr = context.item().engine.get().getLocation(); try { URL url = new URL(urlStr); domainStr = url.getHost(); } catch (MalformedURLException e) { Matcher matcher = domain.matcher(urlStr); if (matcher.matches()) { domainStr = matcher.group(1); } } } out.setDomain(domainStr == null ? in.getDomain() : domainStr); if (in.getExpiry() != null) { out.setExpiryDate(in.getExpiry()); } out.setPath(in.getPath()); out.setSecure(in.isSecure()); out.setValue(in.getValue()); out.setVersion(1); return out; }