Example usage for com.google.gwt.xml.client Node getFirstChild

List of usage examples for com.google.gwt.xml.client Node getFirstChild

Introduction

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

Prototype

Node getFirstChild();

Source Link

Document

This method retrieves the first child.

Usage

From source file:ch.systemsx.cisd.openbis.generic.client.web.client.application.FormPanelListener.java

License:Apache License

private final void extractAndDisplay(final String msg) {
    final Document document = XMLParser.parse(msg);
    final Node message = document.getFirstChild();
    final Node typeNode = message.getAttributes().getNamedItem("type");
    final String messageText = message.getFirstChild().getNodeValue();
    final String type = typeNode.getNodeValue();
    if ("info".equals(type)) {
        infoBox.displayInfo(messageText);
    } else {/*from w w  w.j  av  a  2  s .c o  m*/
        infoBox.displayError(messageText);
    }
}

From source file:com.data2semantics.yasgui.client.tab.results.input.XmlResults.java

License:Open Source License

private HashMap<String, String> getBindingFromNode(Node binding) {
    HashMap<String, String> rdfNode = new HashMap<String, String>();
    NodeList literals = ((Element) binding).getElementsByTagName("literal");
    if (literals.getLength() > 0) {
        rdfNode = extractValuesFromXmlNode(literals.item(0), new String[] { "xml:lang", "datatype" });
        rdfNode.put("type", "literal");
    }// w  w  w.ja va2s . c om
    NodeList bnodes = ((Element) binding).getElementsByTagName("bnode");
    if (bnodes.getLength() > 0) {
        Node bnode = bnodes.item(0);
        rdfNode.put("type", "bnode");
        rdfNode.put("value", bnode.getFirstChild().getNodeValue());
    }
    NodeList uris = ((Element) binding).getElementsByTagName("uri");
    if (uris.getLength() > 0) {
        Node uri = uris.item(0);
        rdfNode.put("type", "uri");
        rdfNode.put("value", uri.getFirstChild().getNodeValue());
    }
    return rdfNode;
}

From source file:com.data2semantics.yasgui.client.tab.results.input.XmlResults.java

License:Open Source License

private HashMap<String, String> extractValuesFromXmlNode(Node xmlNode, String[] attributes) {
    HashMap<String, String> rdfNode = new HashMap<String, String>();
    Node firstChild = xmlNode.getFirstChild();
    if (firstChild != null) {
        String value = firstChild.getNodeValue();
        if (value != null) {
            rdfNode.put("value", value);
            for (String attribute : attributes) {
                String attributeValue = ((Element) xmlNode).getAttribute(attribute);
                if (attributeValue != null)
                    rdfNode.put(attribute, attributeValue);
            }/*from   www.ja v a2  s. co  m*/
        }
    }
    //we want to set something at least.. just put empty string in there if value still isnt set
    if (rdfNode.size() == 0) {
        rdfNode.put("value", "");
    }
    return rdfNode;
}

From source file:com.flatown.client.eutils.EntrezUtility.java

License:Apache License

public static String getNodeText(Node node) {
    if (node.getFirstChild() == null)
        return "";
    return ((Text) node.getFirstChild()).getData();
}

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

License:Open Source License

private String getNodeTextValue(Node node) {
    if (node.getChildNodes().getLength() != 1)
        return null;
    Node textNode = (Node) node.getFirstChild();
    if (textNode.getNodeType() != Node.TEXT_NODE)
        return null;

    return textNode.getNodeValue();
}

From source file:com.garmin.gwt.communicator.client.util.ParseUtils.java

License:Apache License

/**
 * Parse the DeviceXml string into an array of {@link Device} objects
 * /*from  www  .  java 2 s  .  c  om*/
 * @param progressXml
 * @return empty array if none parsed
 */
public static TransferProgress parseProgressXml(final String progressXml) {
    Document dom = XMLParser.parse(progressXml);

    /** Title **/
    Node titleNode = dom.getElementsByTagName("Title").item(0);
    String title = ((Element) titleNode).getFirstChild().getNodeValue();

    /** Percentage **/
    int percentage = 0;
    boolean hasPercentage = false;

    NodeList progressBarNodeList = dom.getElementsByTagName("ProgressBar");
    // not sure why the API reference impl does this check, so doing it for
    // safety sake
    if (progressBarNodeList.getLength() > 0) {
        Node progressBarNode = progressBarNodeList.item(0);
        String progressType = ((Element) progressBarNode).getAttribute("Type");

        // two possible type of processes, if neither, is NULL
        if ("percentage".equalsIgnoreCase(progressType)) {
            percentage = Integer.parseInt(((Element) progressBarNode).getAttribute("Value"));
            hasPercentage = true;
        } else if ("indefinite".equalsIgnoreCase(progressType)) {
            percentage = 100;
            hasPercentage = true;
        }
    }

    /** Text **/
    String textArray[] = new String[] {};

    ArrayList<String> textList = new ArrayList<String>();
    NodeList textNodeList = dom.getElementsByTagName("Text");

    if (textNodeList.getLength() > 0) { // for speed during rapid calls

        for (int n = 0; n < textNodeList.getLength(); n++) {

            Node textNode = textNodeList.item(n);
            if (textNode.hasChildNodes()) {
                String nodeText = textNode.getFirstChild().getNodeValue();
                if (!nodeText.isEmpty()) {
                    textList.add(nodeText);
                }
            }
        }
        textArray = textList.toArray(new String[] {});
    }

    return new TransferProgress(title, textArray, percentage, hasPercentage);
}

From source file:com.sensia.gwt.relaxNG.RNGParser.java

License:Open Source License

protected String getTextValue(Node node) {
    if (!node.hasChildNodes() || node.getFirstChild().getNodeType() != Node.TEXT_NODE)
        return null;

    String textValue = node.getFirstChild().getNodeValue();

    if (textValue != null)
        return textValue.replace("\\s+", " ");
    else/*from   ww  w  .j  a  v  a2 s. c o  m*/
        return null;
}

From source file:de.decidr.modelingtoolbase.client.io.DWDLParser.java

License:Apache License

private void createWorkflowProperties(Element root, WorkflowModel workflow) {

    /* Set workflow name, id and description */
    workflow.setName(root.getAttribute(DWDLNames.name));
    workflow.setId(new Long(root.getAttribute(DWDLNames.id)));
    for (int i = 0; i < root.getChildNodes().getLength(); i++) {
        /*// ww  w  .ja va 2 s  .c o  m
         * Go through all child nodes until node with name "description" is
         * found
         */
        Node childNode = root.getChildNodes().item(i);
        if (childNode.getNodeName().equals(DWDLNames.description) && (childNode.getFirstChild() != null)) {
            workflow.setDescription(childNode.getFirstChild().getNodeValue());
        }
    }
    WorkflowProperties properties = new WorkflowProperties();

    /* parse faultHandlerElement and set fault message id and recipient */
    Element faultHandler = getChildNodesByTagName(root, DWDLNames.faultHandler).get(0);
    properties.setFaultMessageVariableId(getVariableIdFromPropertyElement(faultHandler, DWDLNames.message));
    Element recipient = getChildNodesByTagName(faultHandler, DWDLNames.recipient).get(0);
    properties.setRecipientVariableId(getVariableIdFromPropertyElement(recipient, DWDLNames.to));
    /* For compatibility reasons, also try to read property with its old name. */
    if (properties.getRecipientVariableId() == null) {
        properties.setRecipientVariableId(getVariableIdFromPropertyElement(recipient, DWDLNames.name));
    }

    /*
     * parse endNode and set success message and notification. endNode is a
     * child of the nodes element.
     */
    if (getChildNodesByTagName(getChildNodesByTagName(root, DWDLNames.nodes).get(0),
            DWDLNames.endNode) != null) {
        Element endNode = getChildNodesByTagName(getChildNodesByTagName(root, DWDLNames.nodes).get(0),
                DWDLNames.endNode).get(0);
        // notification of success is optional
        if (getChildNodesByTagName(endNode, DWDLNames.notificationOfSuccess).isEmpty() == false) {
            // if notification is existent, this attribute is always true
            properties.setNotifyOnSuccess(true);

            Element notification = getChildNodesByTagName(endNode, DWDLNames.notificationOfSuccess).get(0);
            properties.setSuccessMessageVariableId(
                    getVariableIdFromPropertyElement(notification, DWDLNames.successMsg));
            // FIXME Read <recipient><setProperty name="to"> ? But this is
            // currently the same as the faultHandler recipient anyways.
        } else {
            properties.setNotifyOnSuccess(false);
        }
    }
    workflow.setProperties(properties);
}

From source file:edu.cudenver.bios.glimmpse.client.panels.BaselineCovariatePanel.java

License:Open Source License

@Override
public void loadFromNode(Node node) {
    if (GlimmpseConstants.TAG_COVARIATE.equalsIgnoreCase(node.getNodeName())) {
        Node valueNode = node.getFirstChild();
        if (valueNode != null) {
            boolean value = Boolean.parseBoolean(valueNode.getNodeValue());
            covariateCheckBox.setValue(value);
            for (CovariateListener listener : listeners)
                listener.onHasCovariate(value);
        }/*from   ww w. j av  a 2  s. com*/
    }
}

From source file:edu.cudenver.bios.glimmpse.client.panels.guided.CategoricalPredictorsPanel.java

License:Open Source License

private void loadCategoriesFromNode(Node node, String predictor) {
    NodeList children = node.getChildNodes();
    ArrayList<String> categories = predictorCategoryMap.get(predictor);
    for (int i = 0; i < children.getLength(); i++) {
        Node child = children.item(i);
        String childName = child.getNodeName();
        if (GlimmpseConstants.TAG_CATEGORY.equalsIgnoreCase(childName)) {
            Node valueNode = child.getFirstChild();
            if (valueNode != null) {
                categories.add(valueNode.getNodeValue());
            }//from ww  w. j  a v  a 2s .c  o m
        }
    }
}