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

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

Introduction

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

Prototype

Element getDocumentElement();

Source Link

Document

This method retrieves the document element.

Usage

From source file:bz.davide.dmxmljson.unmarshalling.xml.gwt.GWTXMLStructure.java

License:Open Source License

static ElementAndSubtype domParser(String xmlText) {

    Document doc = XMLParser.parse(xmlText);

    ElementAndSubtype elementAndSubtype = new ElementAndSubtype();
    Element documentElement = doc.getDocumentElement();
    elementAndSubtype.element = documentElement;
    String[] parts = extractNameAndSubtype(documentElement.getTagName());
    elementAndSubtype.subtype = parts[1];

    return elementAndSubtype;
}

From source file:carteirainveste.client.DateUtil.java

License:Creative Commons License

void updateXmlDb() {
    Document doc = XMLParser.createDocument();
    Element parent = doc.getDocumentElement();

    if (parent == null) {
        parent = doc.createElement("database");
        doc.appendChild(parent);/*w ww . jav  a 2  s .c  o  m*/
    }

    // Add preferences to DOM
    Preference.appendChildNode(doc, parent);

    // Add quotes to DOM
    for (Object element : quoteTable.values()) {
        Quote quote = (Quote) element;
        quote.appendChildNode(doc, parent);
    }

    // Add operations to DOM
    for (int i = 0; i < operationList.size(); ++i) {
        Operation op = (Operation) operationList.get(i);
        op.appendChildNode(doc, parent);
    }

    // Convert DOM to XML
    currXmlTextDb = Constant.XML_HEADER + doc.toString();

    // Display XML
    dbText.setText(currXmlTextDb);
}

From source file:carteirainveste.client.DateUtil.java

License:Creative Commons License

public void onChange(ChangeEvent event) {
    String text = CarteiraInveste.carteiraAtual.dbText.getText();
    Document messageDom;

    Carteira curr = CarteiraInveste.carteiraAtual;

    // parse the XML document into a DOM
    try {//from w  ww  .ja  v a 2 s .com
        messageDom = XMLParser.parse(text);
    } catch (DOMException e) {
        curr.dbLog("Could not parse XML document: " + text);

        // Revert change
        curr.dbText.setText(CarteiraInveste.carteiraAtual.currXmlTextDb);
        return;
    }

    Element parent = messageDom.getDocumentElement();
    curr.loadDb(parent.getChildNodes());

    // Save change
    curr.currXmlTextDb = text;
}

From source file:com.anzsoft.client.XMPP.impl.JsJacPresence.java

License:Open Source License

public String getNick() {
    String xml = toXML();/* w ww  .j ava  2 s.c om*/
    Document doc = XMLParser.parse(xml);
    Element rootEl = doc.getDocumentElement();
    if (!rootEl.getTagName().equals("presence"))
        return "";
    Element nickEl = XMLHelper.findSubTag(rootEl, "nick");
    if (nickEl != null && nickEl.getAttribute("xmlns").equals("http://jabber.org/protocol/nick"))
        return nickEl.getNodeValue();
    return "";
}

From source file:com.anzsoft.client.XMPP.mandioca.XmppRoster.java

License:Open Source License

private void parseRoster(String xml) {
    contacts.clear();/* w ww  .j  a v a2s  .c  o m*/
    Document doc = XMLParser.parse(xml);
    Element query = XMLHelper.queryTag(doc.getDocumentElement());
    if (query != null && query.getAttribute("xmlns").equals("jabber:iq:roster")) {
        NodeList itemList = query.getElementsByTagName("item");
        for (int index = 0; index < itemList.getLength(); index++) {
            Element item = (Element) itemList.item(index);
            XmppContact contact = XmppContact.fromXml(item);
            contacts.put(contact.getJID().toString(), contact);
        }
    }
    if (!contacts.isEmpty())
        fireOnRoster();
}

From source file:com.fredhat.gwt.xmlrpc.client.XmlRpcClient.java

License:Open Source License

private Object buildResponse(String responseText) {
    if (debugMessages)
        System.out.println("** Response **\n" + responseText + "\n**************");
    Document doc = null;
    try {//from  w ww .j  a v a2 s  .  c o  m
        doc = XMLParser.parse(responseText);
    } catch (DOMParseException e) {
        return new XmlRpcException("Unparsable response", e);
    }

    Element methodResponse = doc.getDocumentElement();
    if (!methodResponse.getNodeName().equals("methodResponse"))
        return new XmlRpcException("The document element must be named \"methodResponse\" " + "(this is "
                + methodResponse.getNodeName() + ")");
    if (getElementNodeCount(methodResponse.getChildNodes()) != 1)
        return new XmlRpcException("There may be only one element under <methodResponse> " + "(this has "
                + getElementNodeCount(methodResponse.getChildNodes()) + ")");

    Element forkNode = getFirstElementChild(methodResponse);
    if (forkNode.getNodeName().equals("fault")) {
        if (getElementNodeCount(forkNode.getChildNodes()) != 1)
            return new XmlRpcException("The <fault> element must have " + "exactly one child");
        Element valueNode = getFirstElementChild(forkNode);
        Object faultDetailsObj = getValueNode(valueNode);
        if (!(faultDetailsObj instanceof Map))
            return new XmlRpcException("The <fault> element must be a <struct>");
        @SuppressWarnings("unchecked")
        Map<String, Object> faultDetails = (Map<String, Object>) faultDetailsObj;
        if (faultDetails.get("faultCode") == null || faultDetails.get("faultString") == null
                || !(faultDetails.get("faultCode") instanceof Integer))
            return new XmlRpcException("The <fault> element must contain "
                    + "exactly one <struct> with an integer \"faultCode\" and "
                    + "a string \"faultString\" value");
        int faultCode = ((Integer) faultDetails.get("faultCode")).intValue();
        return new XmlRpcException(faultCode, faultDetails.get("faultString").toString(), null);
    } else if (!forkNode.getNodeName().equals("params"))
        return new XmlRpcException(
                "The <methodResponse> must contain either " + "a <params> or <fault> element.");

    // No return object is allowed
    Element paramNode = getFirstElementChild(forkNode);
    if (paramNode == null)
        return null;
    if (!paramNode.getNodeName().equals("param") || getElementNodeCount(paramNode.getChildNodes()) < 1)
        return new XmlRpcException("The <params> element must contain " + "one <param> element");
    Node valueNode = getFirstElementChild(paramNode);

    return getValueNode(valueNode);
}

From source file:com.fredhat.gwt.xmlrpc.client.XmlRpcRequest.java

License:Open Source License

private T buildResponse(String responseText) throws XmlRpcException {
    if (client.getDebugMode())
        System.out.println("** Response **\n" + responseText + "\n**************");
    Document doc = null;
    try {//  w  w  w.j a v a2s.c  om
        doc = XMLParser.parse(responseText);
    } catch (DOMParseException e) {
        throw new XmlRpcException("Unparsable response", e);
    }

    Element methodResponse = doc.getDocumentElement();
    if (!methodResponse.getNodeName().equals("methodResponse"))
        throw new XmlRpcException("The document element must be named \"methodResponse\" " + "(this is "
                + methodResponse.getNodeName() + ")");
    if (getElementNodeCount(methodResponse.getChildNodes()) != 1)
        throw new XmlRpcException("There may be only one element under <methodResponse> " + "(this has "
                + getElementNodeCount(methodResponse.getChildNodes()) + ")");

    Element forkNode = getFirstElementChild(methodResponse);
    if (forkNode.getNodeName().equals("fault")) {
        if (getElementNodeCount(forkNode.getChildNodes()) != 1)
            throw new XmlRpcException("The <fault> element must have " + "exactly one child");
        Element valueNode = getFirstElementChild(forkNode);
        Object faultDetailsObj = getValueNode(valueNode);
        if (!(faultDetailsObj instanceof Map))
            throw new XmlRpcException("The <fault> element must be a <struct>");
        @SuppressWarnings("unchecked")
        Map<String, Object> faultDetails = (Map<String, Object>) faultDetailsObj;
        if (faultDetails.get("faultCode") == null || faultDetails.get("faultString") == null
                || !(faultDetails.get("faultCode") instanceof Integer))
            throw new XmlRpcException("The <fault> element must contain "
                    + "exactly one <struct> with an integer \"faultCode\" and "
                    + "a string \"faultString\" value");
        int faultCode = ((Integer) faultDetails.get("faultCode")).intValue();
        throw new XmlRpcException(faultCode, faultDetails.get("faultString").toString(), null);
    } else if (!forkNode.getNodeName().equals("params"))
        throw new XmlRpcException(
                "The <methodResponse> must contain either " + "a <params> or <fault> element.");

    // No return object is allowed
    Element paramNode = getFirstElementChild(forkNode);
    if (paramNode == null)
        return null;
    if (!paramNode.getNodeName().equals("param") || getElementNodeCount(paramNode.getChildNodes()) < 1)
        throw new XmlRpcException("The <params> element must contain " + "one <param> element");
    Node valueNode = getFirstElementChild(paramNode);

    return getValueNode(valueNode);
}

From source file:com.google.gwt.sample.simplexml.client.SimpleXML.java

License:Apache License

/**
 * Creates the xml representation of xmlText. xmlText is assumed to have been
 * validated for structure on the server.
 * //from   w ww  .ja  v  a  2 s . co m
 * @param xmlText xml text
 * @param xmlParsed panel to display customer record
 */
private void customerPane(String xmlText, FlowPanel xmlParsed) {
    Document customerDom = XMLParser.parse(xmlText);
    Element customerElement = customerDom.getDocumentElement();
    // Must do this if you ever use a raw node list that you expect to be
    // all elements.
    XMLParser.removeWhitespace(customerElement);

    // Customer Name
    String nameValue = getElementTextValue(customerElement, "name");
    String title = "<h1>" + nameValue + "</h1>";
    HTML titleHTML = new HTML(title);
    xmlParsed.add(titleHTML);

    // Customer Notes
    String notesValue = getElementTextValue(customerElement, "notes");
    Label notesText = new Label();
    notesText.setStyleName(NOTES_STYLE);
    notesText.setText(notesValue);
    xmlParsed.add(notesText);

    // Pending orders UI setup
    FlexTable pendingTable = createOrderTable(xmlParsed, "Pending Orders");
    FlexTable completedTable = createOrderTable(xmlParsed, "Completed");
    completedTable.setText(0, 7, "Shipped by");

    // Fill Orders Table
    NodeList orders = customerElement.getElementsByTagName("order");
    int pendingRowPos = 0;
    int completedRowPos = 0;
    for (int i = 0; i < orders.getLength(); i++) {
        Element order = (Element) orders.item(i);
        HTMLTable table;
        int rowPos;
        if (order.getAttribute("status").equals("pending")) {
            table = pendingTable;
            rowPos = ++pendingRowPos;
        } else {
            table = completedTable;
            rowPos = ++completedRowPos;
        }
        int columnPos = 0;
        fillInOrderTableRow(customerElement, order, table, rowPos, columnPos);
    }
}

From source file:com.gwtext.client.widgets.tree.XMLTreeLoader.java

License:Open Source License

private static void requestData(final JavaScriptObject treeLoaderJS, final TreeNode root,
        final XMLTreeLoader treeLoader, String method, String url, final JavaScriptObject success,
        final JavaScriptObject failure, final JavaScriptObject callback, String params) {
    //build side nav tree from xml data
    RequestBuilder.Method httpMethod = "post".equalsIgnoreCase(method) ? RequestBuilder.POST
            : RequestBuilder.GET;//from  w  ww  . java2 s  . co m

    RequestBuilder builder = new RequestBuilder(httpMethod, url);
    builder.setHeader("Content-type", "application/x-www-form-urlencoded");
    try {
        builder.sendRequest(params, new RequestCallback() {

            public void onResponseReceived(Request request, Response response) {
                if (response.getStatusCode() == 200) {
                    Document xml = null;
                    try {
                        xml = XMLParser.parse(response.getText());
                    } catch (Exception e) {
                        call(failure, treeLoaderJS, root.getJsObj(), callback, e.getMessage());
                        return;
                    }
                    String rootTag = treeLoader.getRootTag();
                    Node rootNode = null;
                    if (rootTag == null) {
                        rootNode = xml.getDocumentElement().getParentNode().getChildNodes().item(0);
                    } else {
                        rootNode = xml.getElementsByTagName(rootTag).item(0);
                    }
                    load(treeLoader, root, rootNode.getChildNodes());
                    call(success, treeLoaderJS, root.getJsObj(), callback, response.getText());

                } else {
                    call(failure, treeLoaderJS, root.getJsObj(), callback,
                            response.getStatusCode() + ":" + response.getText());
                }
            }

            public void onError(Request request, Throwable throwable) {
                call(failure, treeLoaderJS, root.getJsObj(), callback, throwable.getMessage());
            }
        });
    } catch (RequestException e) {
        call(failure, treeLoaderJS, root.getJsObj(), callback, e.getMessage());
    }
}

From source file:com.lorepo.icf.utils.XMLLoader.java

License:Open Source License

/**
 * Init object from DOM. return initialized object
 * @param dom/*from  w w w. j  a v  a  2 s  . co m*/
 * @param document
 */
private void initContentFromDOM(Document dom, String url) {
    model.load(dom.getDocumentElement(), url);
}