Search in sources :

Example 6 with Document

use of com.teamdev.jxbrowser.dom.Document in project convertigo by convertigo.

the class ApplicationComponentEditor method highlightComponent.

public void highlightComponent(MobileComponent mobileComponent, boolean selectPage) {
    C8oBrowser.run(() -> {
        if (selectPage && mobileComponent instanceof UIComponent) {
            PageComponent pageComponent = ((UIComponent) mobileComponent).getPage();
            if (pageComponent != null) {
                selectPage(pageComponent.getSegment());
            }
        }
    });
    C8oBrowser.run(() -> {
        Document doc = browser.mainFrame().get().document().get();
        MobileComponent mc = mobileComponent;
        if (mc instanceof UISharedComponent) {
            UISharedComponent uisc = (UISharedComponent) mc;
            if (uisc != null) {
                try {
                    mc = uisc.getDisplayableComponentList().get(0);
                } catch (IndexOutOfBoundsException ioobe) {
                }
            }
        } else if (mc instanceof UIUseShared) {
            UISharedComponent uisc = ((UIUseShared) mc).getTargetSharedComponent();
            if (uisc != null) {
                try {
                    mc = uisc.getDisplayableComponentList().get(0);
                } catch (IndexOutOfBoundsException ioobe) {
                }
            }
        }
        while (doc.findElementsByClassName("class" + mc.priority).isEmpty()) {
            DatabaseObject parent = mc.getParent();
            if (parent instanceof MobileComponent) {
                mc = (MobileComponent) parent;
            } else {
                return;
            }
        }
        c8oBrowser.executeJavaScriptAndReturnValue("_c8o_highlight_class('class" + mc.priority + "');");
    });
}
Also used : UIUseShared(com.twinsoft.convertigo.beans.ngx.components.UIUseShared) UIComponent(com.twinsoft.convertigo.beans.ngx.components.UIComponent) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) Document(com.teamdev.jxbrowser.dom.Document) UISharedComponent(com.twinsoft.convertigo.beans.ngx.components.UISharedComponent) PageComponent(com.twinsoft.convertigo.beans.ngx.components.PageComponent) MobileComponent(com.twinsoft.convertigo.beans.ngx.components.MobileComponent)

Example 7 with Document

use of com.teamdev.jxbrowser.dom.Document in project JxBrowser-Examples by TeamDev-IP.

the class XPath method main.

public static void main(String[] args) {
    Engine engine = Engine.newInstance(OFF_SCREEN);
    Browser browser = engine.newBrowser();
    SwingUtilities.invokeLater(() -> {
        BrowserView view = BrowserView.newInstance(browser);
        JFrame frame = new JFrame("Evaluate XPath");
        frame.getContentPane().add(view, BorderLayout.CENTER);
        frame.setSize(800, 600);
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
    });
    Navigation navigation = browser.navigation();
    navigation.on(FrameLoadFinished.class, event -> event.frame().document().flatMap(Document::documentElement).ifPresent(element -> {
        try {
            XPathResult result = element.evaluate("count(//div)");
            if (result.isNumber()) {
                System.out.println("Result: " + result.asNumber());
            }
        } catch (XPathException e) {
            System.out.println(e.getMessage());
        }
    }));
    navigation.loadUrl("https://www.teamdev.com/jxbrowser");
}
Also used : XPathResult(com.teamdev.jxbrowser.dom.XPathResult) Navigation(com.teamdev.jxbrowser.navigation.Navigation) SwingUtilities(javax.swing.SwingUtilities) FrameLoadFinished(com.teamdev.jxbrowser.navigation.event.FrameLoadFinished) Document(com.teamdev.jxbrowser.dom.Document) OFF_SCREEN(com.teamdev.jxbrowser.engine.RenderingMode.OFF_SCREEN) Browser(com.teamdev.jxbrowser.browser.Browser) XPathException(com.teamdev.jxbrowser.dom.XPathException) BorderLayout(java.awt.BorderLayout) JFrame(javax.swing.JFrame) BrowserView(com.teamdev.jxbrowser.view.swing.BrowserView) Engine(com.teamdev.jxbrowser.engine.Engine) Navigation(com.teamdev.jxbrowser.navigation.Navigation) JFrame(javax.swing.JFrame) XPathException(com.teamdev.jxbrowser.dom.XPathException) BrowserView(com.teamdev.jxbrowser.view.swing.BrowserView) XPathResult(com.teamdev.jxbrowser.dom.XPathResult) Document(com.teamdev.jxbrowser.dom.Document) Engine(com.teamdev.jxbrowser.engine.Engine) Browser(com.teamdev.jxbrowser.browser.Browser)

Aggregations

Document (com.teamdev.jxbrowser.dom.Document)7 Browser (com.teamdev.jxbrowser.browser.Browser)5 Engine (com.teamdev.jxbrowser.engine.Engine)5 FrameLoadFinished (com.teamdev.jxbrowser.navigation.event.FrameLoadFinished)4 BrowserView (com.teamdev.jxbrowser.view.swing.BrowserView)4 BorderLayout (java.awt.BorderLayout)4 JFrame (javax.swing.JFrame)4 HARDWARE_ACCELERATED (com.teamdev.jxbrowser.engine.RenderingMode.HARDWARE_ACCELERATED)3 SwingUtilities (javax.swing.SwingUtilities)3 WindowConstants (javax.swing.WindowConstants)3 OFF_SCREEN (com.teamdev.jxbrowser.engine.RenderingMode.OFF_SCREEN)2 Frame (com.teamdev.jxbrowser.frame.Frame)2 DatabaseObject (com.twinsoft.convertigo.beans.core.DatabaseObject)2 OptionElement (com.teamdev.jxbrowser.dom.OptionElement)1 SelectElement (com.teamdev.jxbrowser.dom.SelectElement)1 XPathException (com.teamdev.jxbrowser.dom.XPathException)1 XPathResult (com.teamdev.jxbrowser.dom.XPathResult)1 Navigation (com.teamdev.jxbrowser.navigation.Navigation)1 MobileComponent (com.twinsoft.convertigo.beans.mobile.components.MobileComponent)1 PageComponent (com.twinsoft.convertigo.beans.mobile.components.PageComponent)1