Example usage for com.google.gwt.dom.client Document getDocumentElement

List of usage examples for com.google.gwt.dom.client Document getDocumentElement

Introduction

In this page you can find the example usage for com.google.gwt.dom.client Document getDocumentElement.

Prototype

public Element getDocumentElement() 

Source Link

Usage

From source file:client.net.sf.saxon.ce.Configuration.java

License:Mozilla Public License

/**
 * Build a document, using specified options for parsing and building.
 * @param url the URL of the document to be fetched and parsed.
 * @throws XPathException if the URL cannot be dereferenced or if parsing fails
 *///from w  ww  .  ja  v a2  s. c  om
public DocumentInfo buildDocument(final String url) throws XPathException {
    if (url.equals("html:document")) {
        // special case this URI
        return getHostPage();
    }

    String xml;
    try {
        xml = XMLDOM.makeHTTPRequest(url);
    } catch (Exception err) {
        throw new XPathException("HTTPRequest error: " + err.getMessage());
    }
    Document jsDoc;
    try {
        jsDoc = (Document) XMLDOM.parseXML(xml);
        if (jsDoc.getDocumentElement() == null) {
            throw new XPathException("null returned for " + url);
        }
    } catch (Exception ec) {
        throw new XPathException("XML parser error: " + ec.getMessage());
    }
    return new HTMLDocumentWrapper(jsDoc, url, Configuration.this, DocType.NONHTML);
}

From source file:client.net.sf.saxon.ce.SaxonceApi.java

License:Mozilla Public License

/**
 * Returns a DocumentInfo object that wraps a XML DOM document.
 * /*from  www . ja va  2 s  .  c om*/
 * If the JavaScript object passed as a parameter is not a DOM document, but
 * simply a place-holder, then the Document is first fetched synchronously
 * before wrapping.
 * 
 * @param obj
 *            the DOM document or a place-holder
 * @param config
 *            The Saxon-CE configuration
 * @return a DocumentInfo object
 */
public static DocumentInfo getDocSynchronously(JavaScriptObject obj, Configuration config)
        throws XPathException {
    String absSourceURI = getAsyncUri(obj);
    Document doc;
    try {
        if (absSourceURI != null) {
            try {
                String xml = XMLDOM.makeHTTPRequest(absSourceURI);
                doc = (Document) XMLDOM.parseXML(xml);
            } catch (Exception e) {
                throw new XPathException("Synchronous HTTP GET failed for: " + absSourceURI);
            }
        } else {
            doc = (Document) obj;
        }
        // check there's a document element
        if (doc.getDocumentElement() == null) {
            throw new XPathException("no document element");
        }
    } catch (Exception e) {
        throw new XPathException("Error resolving document: " + e.getMessage());
    }
    return (DocumentInfo) config.wrapXMLDocument(doc, absSourceURI);
}

From source file:org.ednovo.gooru.client.mvp.assessments.play.resource.body.WebResourceWidget.java

License:Open Source License

@Override
public void onLoad() {
    super.onLoad();
    Scheduler.get().scheduleDeferred(new ScheduledCommand() {
        @Override/*from   w w  w.  ja v a2  s  . c  o  m*/
        public void execute() {
            try {
                Document document = IFrameElement.as(getResourcePreviewFrame().getElement())
                        .getContentDocument();
                BodyElement body = document.getBody();
                Element html = document.getDocumentElement();
                int bodyHeight = Math.max(body.getScrollHeight(), body.getOffsetHeight());
                bodyHeight = Math.max(bodyHeight, html.getOffsetHeight());
                bodyHeight = Math.max(bodyHeight, html.getClientHeight());
                bodyHeight = Math.max(bodyHeight, html.getScrollHeight());
                int scrollHeight = body.getScrollHeight();
                getResourcePreviewFrame().getElement().getStyle().clearPosition();
                getResourcePreviewFrame().getElement().getStyle().setVisibility(Visibility.VISIBLE);
            } catch (Exception e) {
                AppClientFactory.printSevereLogger("WebResourceWidget : onLoad : " + e.getMessage());
            }
        }
    });
}

From source file:org.ednovo.gooru.client.mvp.play.resource.body.WebResourceWidget.java

License:Open Source License

@Override
public void onLoad() {
    super.onLoad();
    Scheduler.get().scheduleDeferred(new ScheduledCommand() {
        @Override//from w  w w. j a  v a 2  s  .c  o  m
        public void execute() {
            //timer.schedule(100); 
            try {
                Document document = IFrameElement.as(getResourcePreviewFrame().getElement())
                        .getContentDocument();
                BodyElement body = document.getBody();
                Element html = document.getDocumentElement();
                /*getResourcePreviewFrame().getElement().getStyle().setVisibility(Visibility.HIDDEN);
                getResourcePreviewFrame().getElement().getStyle().setPosition(Position.ABSOLUTE);*/
                int bodyHeight = Math.max(body.getScrollHeight(), body.getOffsetHeight());
                bodyHeight = Math.max(bodyHeight, html.getOffsetHeight());
                bodyHeight = Math.max(bodyHeight, html.getClientHeight());
                bodyHeight = Math.max(bodyHeight, html.getScrollHeight());
                int scrollHeight = body.getScrollHeight();
                getResourcePreviewFrame().getElement().getStyle().clearPosition();
                getResourcePreviewFrame().getElement().getStyle().setVisibility(Visibility.VISIBLE);
            } catch (Exception e) {

            }
        }
    });
}

From source file:org.jahia.ajax.gwt.client.widget.edit.mainarea.MainModule.java

License:Open Source License

private void parseFrameContent(boolean forceImageRefresh, boolean forceCssRefresh,
        boolean forceJavascriptRefresh) {
    try {//from   w  w  w .  j  a  v a 2 s.c  om
        frameError = null;
        final IFrameElement iframe = IFrameElement.as(frame.getElement());
        Document contentDocument = iframe.getContentDocument();
        Element body = (Element) contentDocument.getElementsByTagName("body").getItem(0);
        Element head = (Element) contentDocument.getElementsByTagName("head").getItem(0);
        setHashMarker(frame.getCurrentFrameUrl());
        if (forceImageRefresh) {
            refreshImages(body);
        }
        if (head != null) {
            if (forceCssRefresh) {
                refreshCSS(head);
            }
            if (forceJavascriptRefresh) {
                refreshScripts(head);
            }
        }
        Hover.getInstance().removeAll();
        List<Element> el = null;
        List<Element> elBody = null;
        if ("true".equals(body.getAttribute("jahia-parse-html"))) {
            Element innerElement = getInnerElement();
            elBody = ModuleHelper.getAllJahiaTypedElementsRec(body);
            if (body.equals(innerElement)) {
                el = elBody;
            } else {
                el = ModuleHelper.getAllJahiaTypedElementsRec(getInnerElement());
            }

        } else if (body.getAttribute("jahia-error-code") != null
                && !"".equals(body.getAttribute("jahia-error-code"))) {
            frameError = body.getAttribute("jahia-error-code");
        } else {
            NodeList<com.google.gwt.dom.client.Element> el1 = body.getElementsByTagName("div");
            int i = 0;
            Element e = null;
            while (i < el1.getLength()) {
                e = (Element) el1.getItem(i);
                if ("mainmodule".equals(e.getAttribute(ModuleHelper.JAHIA_TYPE))) {
                    el = Arrays.asList(e);
                    elBody = Arrays.asList(e);
                    break;
                }
                i++;
            }

        }
        if (contextMenu != null) {
            contextMenu.hide();
        }

        if (el != null && elBody != null) {
            ModuleHelper.tranformLinks((Element) contentDocument.getDocumentElement());
            ModuleHelper.initAllModules(MainModule.this, body, el, elBody, config);
            editLinker.getSidePanel().enable();
        } else {
            // if body empty, this is not a jahia page
            path = "";
            // clear side panel
            editLinker.getSidePanel().disable();
        }
        editLinker.getMainModule().unmask();
        needParseAfterLayout = true;
        layout();
    } catch (Exception e) {
        Log.error("Error in EditFrame: " + e.getMessage(), e);
    }
}

From source file:org.openxdata.sharedlib.client.view.FormRunnerView.java

/**
 * Loads widgets in a given layout xml and populates a list of widgets whose source of
 * allowed option is external to the xform.
 * /*ww  w. java 2s .  c o  m*/
 * @param xml the layout xml.
 * @param externalSourceWidgets the list of external source widgets.
 */
public void loadLayout(String xml, List<RuntimeWidgetWrapper> externalSourceWidgets,
        HashMap<QuestionDef, List<QuestionDef>> calcQtnMappings) {
    tabs.clear();

    if (formDef != null)
        formDef.clearChangeListeners();

    parentBindingWidgetMap = new HashMap<String, RuntimeWidgetWrapper>();
    labelMap = new HashMap<QuestionDef, List<Label>>();
    labelText = new HashMap<Label, String>();
    labelReplaceText = new HashMap<Label, String>();
    checkBoxGroupMap = new HashMap<QuestionDef, List<CheckBox>>();
    validationWidgetsMap = new HashMap<RuntimeWidgetWrapper, List<RuntimeWidgetWrapper>>();
    calcWidgetMap = new HashMap<QuestionDef, List<RuntimeWidgetWrapper>>();
    filtDynOptWidgetMap = new HashMap<QuestionDef, RuntimeWidgetWrapper>();

    //A list of widgets with validation rules.
    List<RuntimeWidgetWrapper> validationRuleWidgets = new ArrayList<RuntimeWidgetWrapper>();

    //A map of parent validation widgets keyed by their QuestionDef.
    //A parent validation widget is one whose QuestionDef is contained in any condition
    //of any validation rule.
    HashMap<QuestionDef, RuntimeWidgetWrapper> qtnParentValidationWidgetMap = new HashMap<QuestionDef, RuntimeWidgetWrapper>();

    //A list of questions for parent validation widgets.
    List<QuestionDef> parentValidationWidgetQtns = new ArrayList<QuestionDef>();

    initValidationWidgetsMap(parentValidationWidgetQtns);

    com.google.gwt.xml.client.Document doc = XMLParser.parse(xml);
    Element root = doc.getDocumentElement();
    NodeList pages = root.getChildNodes();
    for (int i = 0; i < pages.getLength(); i++) {
        if (pages.item(i).getNodeType() != Node.ELEMENT_NODE)
            continue;
        Element node = (Element) pages.item(i);

        addNewTab(node.getAttribute("Text"));
        WidgetEx.loadLabelProperties(node, new RuntimeWidgetWrapper(tabs.getTabBar(), images.error(), this));

        setWidth(node.getAttribute(WidgetEx.WIDGET_PROPERTY_WIDTH));
        setHeight(node.getAttribute(WidgetEx.WIDGET_PROPERTY_HEIGHT));
        setBackgroundColor(node.getAttribute(WidgetEx.WIDGET_PROPERTY_BACKGROUND_COLOR));

        loadPage(node.getChildNodes(), externalSourceWidgets, parentValidationWidgetQtns, validationRuleWidgets,
                qtnParentValidationWidgetMap, calcQtnMappings);
    }

    setValidationWidgetsMap(validationRuleWidgets, qtnParentValidationWidgetMap);

    if (formDef != null) {
        fireSkipRules();
        doCalculations();
    }

    //For those widgets whose answers are now set, lets load their option lists.
    updateDynamicOptions();

    if (tabs.getWidgetCount() > 0)
        tabs.selectTab(0);
}

From source file:org.vectomatic.svg.edit.client.load.RSSReader.java

License:Open Source License

public void load() {

    final String url = "http://www.openclipart.org/rss/new.xml";
    String resourceUrl = FetchUtils.getFetchUrl(url, "text/xml");
    RequestBuilder requestBuilder = new RequestBuilder(RequestBuilder.GET, resourceUrl);
    requestBuilder.setCallback(new RequestCallback() {
        public void onError(Request request, Throwable e) {
            GWT.log("Cannot fetch " + url, e);
            SvgrealApp.getApp().info(AppConstants.INSTANCE.openRssFeedMenuItem(),
                    AppMessages.INSTANCE.loadErrorMessage(url, e.getMessage()));
        }// w ww  . ja  v  a  2  s .co  m

        private void onSuccess(Request request, Response response) {
            // Create a store of BeanModel of RSSEntry
            SVGParserImpl impl = GWT.create(SVGParserImpl.class);
            Document doc = impl.parseFromString(response.getText(), "text/xml").cast();
            OMElement root = OMNode.convert(doc.getDocumentElement());

            Iterator<OMAttr> iterator = DOMHelper.evaluateXPath(root, "//rss/channel/item/enclosure/@url",
                    null);
            while (iterator.hasNext()) {
                RSSEntry rssEntry = new RSSEntry();
                rssEntry.setSvgPath(iterator.next().getValue());
                store.add(beanFactory.createModel(rssEntry));
            }

            iterator = DOMHelper.evaluateXPath(root, "//rss/channel/item/media:thumbnail/@url",
                    new XPathPrefixResolver() {

                        @Override
                        public String resolvePrefix(String prefix) {
                            if ("media".equals(prefix)) {
                                return "http://search.yahoo.com/mrss/";
                            }
                            return null;
                        }
                    });
            int index = 0;
            while (iterator.hasNext()) {
                BeanModel beanModel = store.getAt(index++);
                RSSEntry rssEntry = (RSSEntry) beanModel.getBean();
                rssEntry.setPngPath(iterator.next().getValue());
                store.update(beanModel);
            }
        }

        public void onResponseReceived(Request request, Response response) {
            if (response.getStatusCode() == Response.SC_OK) {
                onSuccess(request, response);
            } else {
                onError(request, new IOException(
                        AppMessages.INSTANCE.httpErrorMessage(Integer.toString(response.getStatusCode()))));
            }
        }
    });
    try {
        requestBuilder.send();
    } catch (RequestException e) {
        GWT.log("Cannot fetch " + url, e);
        SvgrealApp.getApp().info(AppConstants.INSTANCE.openRssFeedMenuItem(),
                AppMessages.INSTANCE.loadErrorMessage(url, e.getMessage()));
    }
}

From source file:org.vectomatic.svg.edit.client.RSSReader.java

License:Open Source License

public void load() {

    final String url = "http://www.openclipart.org/rss/new.xml";
    String resourceUrl = GWT.getHostPageBaseURL() + "fetch?url=" + url + "&type=text/xml";
    RequestBuilder requestBuilder = new RequestBuilder(RequestBuilder.GET, resourceUrl);
    requestBuilder.setCallback(new RequestCallback() {
        public void onError(Request request, Throwable e) {
            GWT.log("Cannot fetch " + url, e);
            VectomaticApp2.APP.info(AppConstants.INSTANCE.openRssFeedMenuItem(),
                    AppMessages.INSTANCE.loadErrorMessage(url, e.getMessage()));
        }/*from  w w w .  j  a  va 2 s. c o  m*/

        private void onSuccess(Request request, Response response) {
            // Create a store of BeanModel of RSSEntry
            SVGParserImpl impl = GWT.create(SVGParserImpl.class);
            Document doc = impl.parseFromString(response.getText(), "text/xml").cast();
            OMElement root = OMNode.convert(doc.getDocumentElement());

            Iterator<OMAttr> iterator = DOMHelper.evaluateXPath(root, "//rss/channel/item/enclosure/@url",
                    null);
            while (iterator.hasNext()) {
                RSSEntry rssEntry = new RSSEntry();
                rssEntry.setSvgPath(iterator.next().getValue());
                store.add(beanFactory.createModel(rssEntry));
            }

            iterator = DOMHelper.evaluateXPath(root, "//rss/channel/item/media:thumbnail/@url",
                    new XPathPrefixResolver() {

                        @Override
                        public String resolvePrefix(String prefix) {
                            if ("media".equals(prefix)) {
                                return "http://search.yahoo.com/mrss/";
                            }
                            return null;
                        }
                    });
            int index = 0;
            while (iterator.hasNext()) {
                BeanModel beanModel = store.getAt(index++);
                RSSEntry rssEntry = (RSSEntry) beanModel.getBean();
                rssEntry.setPngPath(iterator.next().getValue());
                store.update(beanModel);
            }
        }

        public void onResponseReceived(Request request, Response response) {
            if (response.getStatusCode() == Response.SC_OK) {
                onSuccess(request, response);
            } else {
                onError(request, new IOException(
                        AppMessages.INSTANCE.httpErrorMessage(Integer.toString(response.getStatusCode()))));
            }
        }
    });
    try {
        requestBuilder.send();
    } catch (RequestException e) {
        GWT.log("Cannot fetch " + url, e);
        VectomaticApp2.APP.info(AppConstants.INSTANCE.openRssFeedMenuItem(),
                AppMessages.INSTANCE.loadErrorMessage(url, e.getMessage()));
    }
}

From source file:org.xwiki.gwt.wysiwyg.client.plugin.importer.IEPasteManager.java

License:Open Source License

/**
 * {@inheritDoc}//from   w w  w. j  a v  a2 s  .com
 * <p>
 * {@link Document#getScrollTop()} and {@link Document#getScrollLeft()} are broken for nested documents in IE9.
 * </p>
 * 
 * @see <a href="http://code.google.com/p/google-web-toolkit/issues/detail?id=6256">getAbsoluteTop/getScrollTop
 *      returns wrong values for IE9 when body has been scrolled</a>
 * @see <a href="https://gwt-review.googlesource.com/#/c/2260/">Document#getScrollTop() and Document#getScrollLeft()
 *      are broken for nested documents in IE9</a>
 */
@Override
protected void centerPasteContainer(Element pasteContainer) {
    Document document = pasteContainer.getOwnerDocument();
    Element viewport = Element.as(document.isCSS1Compat() ? document.getDocumentElement() : document.getBody());
    pasteContainer.getStyle().setLeft(viewport.getScrollLeft() + document.getClientWidth() / 2, Unit.PX);
    pasteContainer.getStyle().setTop(viewport.getScrollTop() + document.getClientHeight() / 2, Unit.PX);
}