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

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

Introduction

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

Prototype

short ELEMENT_NODE

To view the source code for com.google.gwt.xml.client Node ELEMENT_NODE.

Click Source Link

Document

The constant 1 denotes DOM nodes of type Element.

Usage

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

License:Open Source License

void recursiveText(Node node, StringBuffer sb) {
    if (node.getNodeType() == Node.TEXT_NODE) {
        sb.append(node.getNodeValue());//from   w w w .  j  a  v  a  2s  .  co  m
    }
    if (node.getNodeType() == Node.ELEMENT_NODE) {
        NodeList nl = node.getChildNodes();
        for (int i = 0; i < nl.getLength(); i++) {
            this.recursiveText(nl.item(i), sb);
        }
    }
}

From source file:client.net.sf.saxon.ce.xmldom.NodeXml.java

License:Apache License

/**
 * This method creates a new node of the correct type.
 * //w  w  w  . j av  a 2s . co  m
 * @param node - the supplied DOM JavaScript object
 * @return a Node object that corresponds to the DOM object
 */
public static Node build(JavaScriptObject node) {
    if (node == null) {
        return null;
    }
    short nodeType = XMLParserImpl.getNodeType(node);
    switch (nodeType) {
    case Node.ATTRIBUTE_NODE:
        return new AttrImpl(node);
    case Node.CDATA_SECTION_NODE:
        return new CDATASectionImpl(node);
    case Node.COMMENT_NODE:
        return new CommentImpl(node);
    case Node.DOCUMENT_FRAGMENT_NODE:
        return new DocumentFragmentImpl(node);
    case Node.DOCUMENT_NODE:
        return new DocumentImpl(node);
    case Node.ELEMENT_NODE:
        return new ElementImpl(node);
    case Node.PROCESSING_INSTRUCTION_NODE:
        return new ProcessingInstructionImpl(node);
    case Node.TEXT_NODE:
        return new TextImpl(node);
    default:
        return new NodeXml(node);
    }
}

From source file:com.bramosystems.oss.player.playlist.client.impl.SAXParser.java

License:Apache License

private void processNodes(NodeList node) throws ParseException {
    for (int i = 0; i < node.getLength(); i++) {
        Node nd = node.item(i);/*w ww  . ja v a 2s .c  o  m*/
        switch (nd.getNodeType()) {
        case Node.ELEMENT_NODE:
            HashMap<String, String> attr = new HashMap<String, String>();
            NamedNodeMap nnm = nd.getAttributes();
            for (int j = 0; j < nnm.getLength(); j++) {
                Node nm = nnm.item(j);
                attr.put(nm.getNodeName(), nm.getNodeValue());
            }
            handler.onNodeStart(nd.getNodeName(), attr, nd.getNamespaceURI());
            processNodes(nd.getChildNodes());
            handler.onNodeEnd(nd.getNodeName());
            break;
        case Node.TEXT_NODE:
            handler.setNodeValue(nd.getParentNode().getNodeName(), nd.getNodeValue());
        }
    }
}

From source file:com.calclab.emite.base.xml.XMLPacketImplGWT.java

License:Open Source License

@Override
public XMLPacket getFirstChild(final String name, final String namespace) {
    checkNotNull(name);/*ww  w  .  j a v  a 2  s .c  o  m*/
    checkNotNull(namespace);

    final NodeList nodes = element.getChildNodes();
    for (int i = 0; i < nodes.getLength(); i++) {
        final Node node = nodes.item(i);
        if (node.getNodeType() != Node.ELEMENT_NODE) {
            continue;
        }

        final Element element = (Element) node;
        if (!"*".equals(name) && !name.equals(element.getTagName())) {
            continue;
        }

        if (!"*".equals(namespace) && !namespace.equals(element.getNamespaceURI())) {
            continue;
        }

        return new XMLPacketImplGWT(element);
    }

    return null;
}

From source file:com.calclab.emite.base.xml.XMLPacketImplGWT.java

License:Open Source License

@Override
public ImmutableList<XMLPacket> getChildren(final String name, final String namespace) {
    checkNotNull(name);/*from ww w  .j av a2 s . c om*/
    checkNotNull(namespace);

    final ImmutableList.Builder<XMLPacket> result = ImmutableList.builder();

    final NodeList nodes = element.getChildNodes();
    for (int i = 0; i < nodes.getLength(); i++) {
        final Node node = nodes.item(i);
        if (node.getNodeType() != Node.ELEMENT_NODE) {
            continue;
        }

        final Element element = (Element) node;
        if (!"*".equals(name) && !name.equals(element.getTagName())) {
            continue;
        }

        if (!"*".equals(namespace) && !namespace.equals(element.getNamespaceURI())) {
            continue;
        }

        result.add(new XMLPacketImplGWT(element));
    }

    return result.build();
}

From source file:com.calclab.emite.core.client.packet.gwt.GWTPacket.java

License:Open Source License

private List<IPacket> wrap(final NodeList nodes) {
    int length;//from  www.  j av a  2  s. c o m
    if (nodes == null || (length = nodes.getLength()) == 0)
        return EMPTY_LIST;
    final ArrayList<IPacket> selected = new ArrayList<IPacket>();
    for (int index = 0; index < length; index++) {
        final Node node = nodes.item(index);
        if (node.getNodeType() == Node.ELEMENT_NODE) {
            selected.add(new GWTPacket((Element) node));
        } else if (node.getNodeType() == Node.TEXT_NODE) {
        }
    }
    return selected;
}

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

License:Open Source License

private Object getValueNode(Node node) {
    if (!node.getNodeName().equals("value"))
        return new XmlRpcException("Value node must be named <value>, not " + "<" + node.getNodeName() + ">");
    if (getElementNodeCount(node.getChildNodes()) == 0) {
        // If no type is indicated, the type is string.
        String strValue = getNodeTextValue(node);
        return strValue == null ? "" : strValue;
    }/*from   ww  w  . jav  a  2  s.  co m*/
    if (getElementNodeCount(node.getChildNodes()) != 1)
        return new XmlRpcException("A <value> node must have exactly one child");
    Node valueType = getFirstElementChild(node);
    if (valueType.getNodeName().equals("i4") || valueType.getNodeName().equals("int")) {
        String intValueString = getNodeTextValue(valueType);
        if (intValueString == null)
            return new XmlRpcException("Integer child is not a text node");
        try {
            return new Integer(intValueString);
        } catch (NumberFormatException e) {
            return new XmlRpcException("Value \"" + intValueString + "\" is not" + " an integer");
        }
    } else if (valueType.getNodeName().equals("boolean")) {
        String boolValue = getNodeTextValue(valueType);
        if (boolValue == null)
            return new XmlRpcException("Child of <boolean> is not a text node");
        if (boolValue.equals("0"))
            return new Boolean(false);
        else if (boolValue.equals("1"))
            return new Boolean(true);
        else
            return new XmlRpcException("Value \"" + boolValue + "\" must be 0 or 1");
    } else if (valueType.getNodeName().equals("string")) {
        String strValue = getNodeTextValue(valueType);
        if (strValue == null)
            strValue = ""; // Make sure <string/> responses will exist as empty
        return strValue;
    } else if (valueType.getNodeName().equals("double")) {
        String doubleValueString = getNodeTextValue(valueType);
        if (doubleValueString == null)
            return new XmlRpcException("Child of <double> is not a text node");
        try {
            return new Double(doubleValueString);
        } catch (NumberFormatException e) {
            return new XmlRpcException("Value \"" + doubleValueString + "\" is not a double");
        }
    } else if (valueType.getNodeName().equals("dateTime.iso8601")) {
        String dateValue = getNodeTextValue(valueType);
        if (dateValue == null)
            return new XmlRpcException("Child of <dateTime> is not a text node");
        try {
            return iso8601ToDate(dateValue);
        } catch (XmlRpcException e) {
            return new XmlRpcException(e.getMessage());
        }
    } else if (valueType.getNodeName().equals("base64")) {
        String baseValue = getNodeTextValue(valueType);
        if (baseValue == null)
            return new XmlRpcException("Improper XML-RPC response format");
        return new Base64(baseValue);
    } else if (valueType.getNodeName().equals("struct")) {
        @SuppressWarnings("unchecked")
        Map<String, Object> map = new HashMap<String, Object>(getElementNodeCount(valueType.getChildNodes()));
        for (int i = 0; i < valueType.getChildNodes().getLength(); i++) {
            if (valueType.getChildNodes().item(i).getNodeType() != Node.ELEMENT_NODE)
                continue;
            Element memberNode = (Element) valueType.getChildNodes().item(i);
            String name = null;
            Object value = null;
            if (!memberNode.getNodeName().equals("member"))
                return new XmlRpcException("Children of <struct> may only be " + "named <member>");
            // NodeList.getElementsByTagName(String) does a deep search, so we
            // can legally get more than one back.  Therefore, if the response
            // has more than one <name/> and <value/> at it's highest level,
            // we will only process the first one it comes across.
            if (memberNode.getElementsByTagName("name").getLength() < 1)
                return new XmlRpcException("A <struct> element must contain " + "at least one <name> child");
            if (memberNode.getElementsByTagName("value").getLength() < 1)
                return new XmlRpcException("A <struct> element must contain " + "at least one <value> child");

            name = getNodeTextValue(memberNode.getElementsByTagName("name").item(0));
            value = getValueNode(memberNode.getElementsByTagName("value").item(0));
            if (name == null)
                return new XmlRpcException("The <name> element must " + "contain a string value");
            map.put(name, value);
        }

        return map;
    } else if (valueType.getNodeName().equals("array")) {
        if (getElementNodeCount(valueType.getChildNodes()) != 1)
            return new XmlRpcException("An <array> element must contain " + "a single <data> element");
        Node dataNode = getFirstElementChild(valueType);
        if (!dataNode.getNodeName().equals("data"))
            return new XmlRpcException("An <array> element must contain " + "a single <data> element");
        List<Object> list = new ArrayList<Object>();
        for (int i = 0; i < dataNode.getChildNodes().getLength(); i++) {
            Node valueNode = dataNode.getChildNodes().item(i);
            if (valueNode.getNodeType() != Node.ELEMENT_NODE)
                continue;
            if (!valueNode.getNodeName().equals("value"))
                return new XmlRpcException("Children of <data> may only be " + "<value> elements");
            list.add(getValueNode(valueNode));
        }

        return list;
    } else if (valueType.getNodeName().equals("nil")) {
        return null;
    }

    // Not sure what it was supposed to be
    return new XmlRpcException(
            "Improper XML-RPC response format:" + " Unknown node name \"" + valueType.getNodeName() + "\"");
}

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

License:Open Source License

private int getElementNodeCount(NodeList nodeList) {
    int elements = 0;
    for (int i = 0; i < nodeList.getLength(); i++) {
        Node node = nodeList.item(i);
        if (node.getNodeType() == Node.ELEMENT_NODE)
            elements++;//from   www. ja  v  a  2  s. c o m
    }

    return elements;
}

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

License:Open Source License

private Element getFirstElementChild(Node parentNode) {
    NodeList children = parentNode.getChildNodes();
    for (int i = 0; i < children.getLength(); i++) {
        Node node = children.item(i);
        if (node.getNodeType() == Node.ELEMENT_NODE)
            return (Element) node;
    }/* w  ww . j  a  va2 s.  c  om*/

    return null;
}

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

License:Open Source License

@SuppressWarnings("unchecked")
private T getValueNode(Node node) throws XmlRpcException {
    if (!node.getNodeName().equals("value"))
        throw new XmlRpcException("Value node must be named <value>, not " + "<" + node.getNodeName() + ">");
    if (getElementNodeCount(node.getChildNodes()) == 0) {
        // If no type is indicated, the type is string.
        String strValue = getNodeTextValue(node);
        return (T) (strValue == null ? "" : strValue);
    }/*from  w  w  w .  j a v  a  2  s.c  o  m*/
    if (getElementNodeCount(node.getChildNodes()) != 1)
        throw new XmlRpcException("A <value> node must have exactly one child");
    Node valueType = getFirstElementChild(node);
    if (valueType.getNodeName().equals("i4") || valueType.getNodeName().equals("int")) {
        String intValueString = getNodeTextValue(valueType);
        if (intValueString == null)
            throw new XmlRpcException("Integer child is not a text node");
        try {
            return (T) (new Integer(intValueString));
        } catch (NumberFormatException e) {
            throw new XmlRpcException("Value \"" + intValueString + "\" is not" + " an integer");
        }
    } else if (valueType.getNodeName().equals("boolean")) {
        String boolValue = getNodeTextValue(valueType);
        if (boolValue == null)
            throw new XmlRpcException("Child of <boolean> is not a text node");
        if (boolValue.equals("0"))
            return (T) (new Boolean(false));
        else if (boolValue.equals("1"))
            return (T) (new Boolean(true));
        else
            throw new XmlRpcException("Value \"" + boolValue + "\" must be 0 or 1");
    } else if (valueType.getNodeName().equals("string")) {
        String strValue = getNodeTextValue(valueType);
        if (strValue == null)
            strValue = ""; // Make sure <string/> responses will exist as empty
        return (T) strValue;
    } else if (valueType.getNodeName().equals("double")) {
        String doubleValueString = getNodeTextValue(valueType);
        if (doubleValueString == null)
            throw new XmlRpcException("Child of <double> is not a text node");
        try {
            return (T) (new Double(doubleValueString));
        } catch (NumberFormatException e) {
            throw new XmlRpcException("Value \"" + doubleValueString + "\" is not a double");
        }
    } else if (valueType.getNodeName().equals("dateTime.iso8601")) {
        String dateValue = getNodeTextValue(valueType);
        if (dateValue == null)
            throw new XmlRpcException("Child of <dateTime> is not a text node");
        try {
            return (T) iso8601ToDate(dateValue);
        } catch (XmlRpcException e) {
            throw new XmlRpcException(e.getMessage());
        }
    } else if (valueType.getNodeName().equals("base64")) {
        String baseValue = getNodeTextValue(valueType);
        if (baseValue == null)
            throw new XmlRpcException("Improper XML-RPC response format");
        return (T) new Base64(baseValue);
    } else if (valueType.getNodeName().equals("struct")) {
        @SuppressWarnings("unchecked")
        Map<String, Object> map = new HashMap<String, Object>(getElementNodeCount(valueType.getChildNodes()));
        for (int i = 0; i < valueType.getChildNodes().getLength(); i++) {
            if (valueType.getChildNodes().item(i).getNodeType() != Node.ELEMENT_NODE)
                continue;
            Element memberNode = (Element) valueType.getChildNodes().item(i);
            String name = null;
            Object value = null;
            if (!memberNode.getNodeName().equals("member"))
                throw new XmlRpcException("Children of <struct> may only be " + "named <member>");
            // NodeList.getElementsByTagName(String) does a deep search, so we
            // can legally get more than one back.  Therefore, if the response
            // has more than one <name/> and <value/> at it's highest level,
            // we will only process the first one it comes across.
            if (memberNode.getElementsByTagName("name").getLength() < 1)
                throw new XmlRpcException("A <struct> element must contain " + "at least one <name> child");
            if (memberNode.getElementsByTagName("value").getLength() < 1)
                throw new XmlRpcException("A <struct> element must contain " + "at least one <value> child");

            name = getNodeTextValue(memberNode.getElementsByTagName("name").item(0));
            value = getValueNode(memberNode.getElementsByTagName("value").item(0));
            if (name == null)
                throw new XmlRpcException("The <name> element must " + "contain a string value");
            map.put(name, value);
        }

        return (T) map;
    } else if (valueType.getNodeName().equals("array")) {
        if (getElementNodeCount(valueType.getChildNodes()) != 1)
            throw new XmlRpcException("An <array> element must contain " + "a single <data> element");
        Node dataNode = getFirstElementChild(valueType);
        if (!dataNode.getNodeName().equals("data"))
            throw new XmlRpcException("An <array> element must contain " + "a single <data> element");
        List<Object> list = new ArrayList<Object>();
        for (int i = 0; i < dataNode.getChildNodes().getLength(); i++) {
            Node valueNode = dataNode.getChildNodes().item(i);
            if (valueNode.getNodeType() != Node.ELEMENT_NODE)
                continue;
            if (!valueNode.getNodeName().equals("value"))
                throw new XmlRpcException("Children of <data> may only be " + "<value> elements");
            list.add(getValueNode(valueNode));
        }

        return (T) list;
    } else if (valueType.getNodeName().equals("nil")) {
        return null;
    }

    // Not sure what it was supposed to be
    throw new XmlRpcException(
            "Improper XML-RPC response format:" + " Unknown node name \"" + valueType.getNodeName() + "\"");
}