Example usage for org.w3c.dom Node hasChildNodes

List of usage examples for org.w3c.dom Node hasChildNodes

Introduction

In this page you can find the example usage for org.w3c.dom Node hasChildNodes.

Prototype

public boolean hasChildNodes();

Source Link

Document

Returns whether this node has any children.

Usage

From source file:org.exist.xquery.modules.jfreechart.Configuration.java

/**
 *  Read configuration from node and initialize configuration.
 * @throws XPathException Thrown when an element cannot be read.
 *///from   w w  w.j  a  va2 s.  com
public void parse(Node configuration) throws XPathException {

    if (configuration.getNodeType() == Node.ELEMENT_NODE
            && configuration.getLocalName().equals("configuration")) {

        //Get the First Child
        Node child = configuration.getFirstChild();
        while (child != null) {
            //Parse each of the child nodes
            if (child.getNodeType() == Node.ELEMENT_NODE && child.hasChildNodes()) {
                if (child.getLocalName().equals("title")) {
                    String value = getValue(child);
                    if (value == null) {
                        throw new XPathException("Value for 'title' cannot be parsed");
                    } else {
                        title = value;
                    }

                } else if (child.getLocalName().equals("categoryAxisLabel")) {
                    String value = getValue(child);
                    if (value == null) {
                        throw new XPathException("Value for 'categoryAxisLabel' cannot be parsed");
                    } else {
                        categoryAxisLabel = value;
                    }

                } else if (child.getLocalName().equals("categoryAxisColor")) {
                    Color value = Colour.getColor(getValue(child));
                    if (value == null) {
                        throw new XPathException("Value for 'categoryAxisColor' cannot be parsed");
                    } else {
                        categoryAxisColor = value;
                    }

                } else if (child.getLocalName().equals("valueAxisLabel")) {
                    String value = getValue(child);
                    if (value == null) {
                        throw new XPathException("Value for 'valueAxisLabel' cannot be parsed");
                    } else {
                        valueAxisLabel = value;
                    }

                } else if (child.getLocalName().equals("valueAxisColor")) {
                    Color value = Colour.getColor(getValue(child));
                    if (value == null) {
                        throw new XPathException("Value for 'valueAxisColor' cannot be parsed");
                    } else {
                        valueAxisColor = value;
                    }

                } else if (child.getLocalName().equals("timeAxisLabel")) {
                    String value = getValue(child);
                    if (value == null) {
                        throw new XPathException("Value for 'timeAxisLabel' cannot be parsed");
                    } else {
                        timeAxisLabel = value;
                    }

                } else if (child.getLocalName().equals("timeAxisColor")) {
                    Color value = Colour.getColor(getValue(child));
                    if (value == null) {
                        throw new XPathException("Value for 'timeAxisColor' cannot be parsed");
                    } else {
                        timeAxisColor = value;
                    }

                } else if (child.getLocalName().equals("domainAxisLabel")) {
                    String value = getValue(child);
                    if (value == null) {
                        throw new XPathException("Value for 'domainAxisLabel' cannot be parsed");
                    } else {
                        domainAxisLabel = value;
                    }

                } else if (child.getLocalName().equals("rangeAxisLabel")) {
                    String value = getValue(child);
                    if (value == null) {
                        throw new XPathException("Value for 'rangeAxisLabel' cannot be parsed");
                    } else {
                        rangeAxisLabel = value;
                    }

                } else if (child.getLocalName().equals("pieSectionLabel")) {
                    String value = getValue(child);
                    if (value == null) {
                        throw new XPathException("Value for 'pieSectionLabel' cannot be parsed");
                    } else {
                        pieSectionLabel = value;
                    }

                } else if (child.getLocalName().equals("pieSectionNumberFormat")) {
                    String value = getValue(child);
                    if (value == null) {
                        throw new XPathException("Value for 'pieSectionNumberFormat' cannot be parsed");
                    } else {
                        pieSectionNumberFormat = value;
                    }

                } else if (child.getLocalName().equals("pieSectionPercentFormat")) {
                    String value = getValue(child);
                    if (value == null) {
                        throw new XPathException("Value for 'pieSectionPercentFormat' cannot be parsed");
                    } else {
                        pieSectionPercentFormat = value;
                    }

                } else if (child.getLocalName().equals("orientation")) {
                    String value = getValue(child);
                    if (value == null) {
                        throw new XPathException("Value for 'orientation' cannot be parsed");

                    } else if ("HORIZONTAL".equalsIgnoreCase(value)) {
                        orientation = PlotOrientation.HORIZONTAL;

                    } else if ("VERTICAL".equalsIgnoreCase(value)) {
                        orientation = PlotOrientation.VERTICAL;

                    } else {
                        throw new XPathException("Wrong value for 'orientation'");
                    }

                } else if (child.getLocalName().equals("tableOrder")) {
                    String value = getValue(child);
                    if (value == null) {
                        throw new XPathException("Value for 'tableOrder' cannot be parsed");

                    } else if ("COLUMN".equalsIgnoreCase(value)) {
                        order = TableOrder.BY_COLUMN;

                    } else if ("ROW".equalsIgnoreCase(value)) {
                        order = TableOrder.BY_ROW;

                    } else {
                        throw new XPathException("Wrong value for 'tableOrder'");
                    }

                } else if (child.getLocalName().equals("legend")) {
                    Boolean value = parseBoolean(getValue(child));
                    if (value == null) {
                        throw new XPathException("Value for 'legend' cannot be parsed");
                    } else {
                        generateLegend = value;
                    }

                } else if (child.getLocalName().equals("tooltips")) {
                    Boolean value = parseBoolean(getValue(child));
                    if (value == null) {
                        throw new XPathException("Value for 'tooltips' cannot be parsed");
                    } else {
                        generateTooltips = value;
                    }

                } else if (child.getLocalName().equals("urls")) {
                    Boolean value = parseBoolean(getValue(child));
                    if (value == null) {
                        throw new XPathException("Value for 'urls' cannot be parsed");
                    } else {
                        generateUrls = value;
                    }

                } else if (child.getLocalName().equals("width")) {
                    Integer value = parseInteger(getValue(child));
                    if (value == null) {
                        throw new XPathException("Value for 'width' cannot be parsed");
                    } else {
                        imageWidth = value;
                    }

                } else if (child.getLocalName().equals("height")) {
                    Integer value = parseInteger(getValue(child));
                    if (value == null) {
                        throw new XPathException("Value for 'height' cannot be parsed");
                    } else {
                        imageHeight = value;
                    }

                } else if (child.getLocalName().equals("titleColor")) {
                    Color value = Colour.getColor(getValue(child));
                    if (value == null) {
                        throw new XPathException("Value for 'titleColor' cannot be parsed");
                    } else {
                        titleColor = value;
                    }

                } else if (child.getLocalName().equals("chartBackgroundColor")) {
                    Color value = Colour.getColor(getValue(child));
                    if (value == null) {
                        throw new XPathException("Value for 'chartBackgroundColor' cannot be parsed");
                    } else {
                        chartBackgroundColor = value;
                    }

                } else if (child.getLocalName().equals("plotBackgroundColor")) {
                    Color value = Colour.getColor(getValue(child));
                    if (value == null) {
                        throw new XPathException("Value for 'plotBackgroundColor' cannot be parsed");
                    } else {
                        plotBackgroundColor = value;
                    }

                } else if (child.getLocalName().equals("seriesColors")) {
                    String value = getValue(child);
                    if (value == null) {
                        throw new XPathException("Value for 'seriesColors' cannot be parsed");
                    } else {
                        seriesColors = value;
                    }

                } else if (child.getLocalName().equals("sectionColors")) {
                    String value = getValue(child);
                    if (value == null) {
                        throw new XPathException("Value for 'sectionColors' cannot be parsed");
                    } else {
                        sectionColors = value;
                    }

                } else if (child.getLocalName().equals("sectionColorsDelimiter")) {
                    String value = getValue(child);
                    if (value == null) {
                        throw new XPathException("Value for 'sectionColorsDelimiter' cannot be parsed");
                    } else {
                        sectionColorsDelimiter = value;
                    }

                } else if (child.getLocalName().equals("rangeLowerBound")) {
                    Double value = parseDouble(getValue(child));
                    if (value == null) {
                        throw new XPathException("Value for 'rangeLowerBound' cannot be parsed");
                    } else {
                        rangeLowerBound = value;
                    }

                } else if (child.getLocalName().equals("rangeUpperBound")) {
                    Double value = parseDouble(getValue(child));
                    if (value == null) {
                        throw new XPathException("Value for 'rangeUpperBound' cannot be parsed");
                    } else {
                        rangeUpperBound = value;
                    }

                } else if (child.getLocalName().equals("categoryItemLabelGeneratorClass")) {
                    String value = getValue(child);
                    if (value == null) {
                        throw new XPathException(
                                "Value for 'categoryItemLabelGeneratorClass' cannot be parsed");
                    } else {
                        categoryItemLabelGeneratorClass = value;
                    }

                } else if (child.getLocalName().equals("categoryItemLabelGeneratorParameter")) {
                    String value = getValue(child);
                    if (value == null) {
                        throw new XPathException(
                                "Value for 'categoryItemLabelGeneratorParameter' cannot be parsed");
                    } else {
                        categoryItemLabelGeneratorParameter = value;
                    }

                } else if (child.getLocalName().equals("categoryItemLabelGeneratorNumberFormat")) {
                    String value = getValue(child);
                    if (value == null) {
                        throw new XPathException(
                                "Value for 'categoryItemLabelGeneratorNumberFormat' cannot be parsed");
                    } else {
                        categoryItemLabelGeneratorNumberFormat = value;
                    }

                } else if (child.getLocalName().equals("imageType")) {
                    String value = getValue(child);
                    if (value == null) {
                        throw new XPathException("Value for 'imageType' cannot be parsed");
                    } else {
                        imageType = value;
                    }
                }

            }

            //next node
            child = child.getNextSibling();

        }

    }
}

From source file:it.polito.tellmefirst.web.rest.clients.ClientEpub.java

private void findNavMap(NodeList nodeList) {

    LOG.debug("[findNavMap] - BEGIN");

    for (int count = 0; count < nodeList.getLength(); count++) {
        Node tempNode = nodeList.item(count);
        if (tempNode.getNodeType() == Node.ELEMENT_NODE) {
            if (tempNode.getNodeName().equals("navMap")) {
                getFirstChildElement(tempNode);
                break;
            }/*  w  w  w  .jav  a2s.c o  m*/
            if (tempNode.hasChildNodes()) {
                findNavMap(tempNode.getChildNodes());
            }
        }
    }

    LOG.debug("[findNavMap] - END");
}

From source file:de.qucosa.webapi.v1.DocumentResource.java

private Tuple<Collection<String>> updateWith(Document targetDocument, final Document updateDocument,
        List<FileUpdateOperation> fileUpdateOperations)
        throws XPathExpressionException, IOException, FedoraClientException {
    Element targetRoot = (Element) targetDocument.getElementsByTagName("Opus_Document").item(0);
    Element updateRoot = (Element) updateDocument.getElementsByTagName("Opus_Document").item(0);

    Set<String> distinctUpdateFieldList = new LinkedHashSet<>();
    NodeList updateFields = updateRoot.getChildNodes();
    for (int i = 0; i < updateFields.getLength(); i++) {
        distinctUpdateFieldList.add(updateFields.item(i).getNodeName());
    }//from   www . j  a va2  s  . co  m

    for (String fn : distinctUpdateFieldList) {
        // cannot use getElementsByTagName() here because it searches recursively
        for (Node victim : getChildNodesByName(targetRoot, fn)) {
            if (!victim.getLocalName().equals("File")) {
                targetRoot.removeChild(victim);
            }
        }
    }

    for (int i = 0; i < updateFields.getLength(); i++) {
        // Update node needs to be cloned, otherwise it will
        // be removed from updateFields by adoptNode().
        Node updateNode = updateFields.item(i).cloneNode(true);
        if (updateNode.hasChildNodes() && !updateNode.getLocalName().equals("File")) {
            targetDocument.adoptNode(updateNode);
            targetRoot.appendChild(updateNode);
        }
    }

    List<String> purgeDatastreamList = new LinkedList<>();
    if ((Boolean) xPath.evaluate("//File", updateDocument, XPathConstants.BOOLEAN)) {
        updateFileElementsInPlace(targetDocument, updateDocument, fileUpdateOperations, targetRoot, updateRoot,
                purgeDatastreamList);
    }

    targetDocument.normalizeDocument();
    return new Tuple<>(distinctUpdateFieldList, purgeDatastreamList);
}

From source file:org.dasein.cloud.ibm.sce.compute.vm.SCEVirtualMachine.java

@Override
public @Nonnull String getConsoleOutput(@Nonnull String vmId) throws InternalException, CloudException {
    ProviderContext ctx = provider.getContext();

    if (ctx == null) {
        throw new SCEConfigException("No context was configured for this request");
    }/*from  w  w w  .jav a  2 s.  c  o  m*/
    SCEMethod method = new SCEMethod(provider);

    Document xml = method.getAsXML("instances/" + vmId + "/logs");

    if (xml == null) {
        return "";
    }
    NodeList locations = xml.getElementsByTagName("Logs");
    StringBuilder console = new StringBuilder();

    for (int i = 0; i < locations.getLength(); i++) {
        Node item = locations.item(i);

        if (item.hasChildNodes()) {
            console.append(item.getFirstChild().getNodeValue());
            console.append("\n");
        }
    }
    return console.toString();
}

From source file:Main.java

public static void copyInto(Node src, Node dest) throws DOMException {

    Document factory = dest.getOwnerDocument();

    //Node start = src;
    Node parent = null;/*w w  w. j  av a  2  s . c om*/
    Node place = src;

    // traverse source tree
    while (place != null) {

        // copy this node
        Node node = null;
        int type = place.getNodeType();
        switch (type) {
        case Node.CDATA_SECTION_NODE: {
            node = factory.createCDATASection(place.getNodeValue());
            break;
        }
        case Node.COMMENT_NODE: {
            node = factory.createComment(place.getNodeValue());
            break;
        }
        case Node.ELEMENT_NODE: {
            Element element = factory.createElement(place.getNodeName());
            node = element;
            NamedNodeMap attrs = place.getAttributes();
            int attrCount = attrs.getLength();
            for (int i = 0; i < attrCount; i++) {
                Attr attr = (Attr) attrs.item(i);
                String attrName = attr.getNodeName();
                String attrValue = attr.getNodeValue();
                element.setAttribute(attrName, attrValue);
            }
            break;
        }
        case Node.ENTITY_REFERENCE_NODE: {
            node = factory.createEntityReference(place.getNodeName());
            break;
        }
        case Node.PROCESSING_INSTRUCTION_NODE: {
            node = factory.createProcessingInstruction(place.getNodeName(), place.getNodeValue());
            break;
        }
        case Node.TEXT_NODE: {
            node = factory.createTextNode(place.getNodeValue());
            break;
        }
        default: {
            throw new IllegalArgumentException(
                    "can't copy node type, " + type + " (" + place.getNodeName() + ')');
        }
        }
        dest.appendChild(node);

        // iterate over children
        if (place.hasChildNodes()) {
            parent = place;
            place = place.getFirstChild();
            dest = node;
        } else if (parent == null) {
            place = null;
        } else {
            // advance
            place = place.getNextSibling();
            while (place == null && parent != null) {
                place = parent.getNextSibling();
                parent = parent.getParentNode();
                dest = dest.getParentNode();
            }
        }

    }

}

From source file:com.stratelia.webactiv.util.XMLConfigurationStore.java

/**
 * This method returns all children nodes (at any depth, that is, children, grazndchildren, and so
 * on) from the node <strong>node</strong> whose name matches the <strong>name</strong> string. If
 * <strong>node</strong> is null, the method returns null<br> If <strong>name</strong> is null or
 * empty, the method returns null<br> If no children of the node <strong>node</strong> match the
 * <strong>name</strong> string, the method returns null<br>
 */// w  ww. j  a  v a2s  .  c o m
public Node[] findNodes(Node node, String name) {
    if (node == null) {
        return (null);
    }
    if (!StringUtil.isDefined(name)) {
        return (null);
    }
    List<Node> v = new ArrayList<Node>(10);
    if (node.getNodeName().equals(name)) {
        Node[] res = new Node[1];
        res[0] = node;
        return (res);
    }
    if (node.hasChildNodes()) {
        NodeList list = node.getChildNodes();
        int size = list.getLength();
        for (int i = 0; i < size; i++) {
            Node found = findNode(list.item(i), name);
            if (found != null) {
                v.add(found);
            }
        }
    }
    if (v.isEmpty()) {
        return (null);
    }
    return v.toArray(new Node[v.size()]);
}

From source file:org.apache.zeppelin.sap.universe.UniverseClient.java

private List<UniverseQueryPrompt> parseParameters(NodeList parametersNodeList) {
    List<UniverseQueryPrompt> parameters = new ArrayList<>();
    if (parametersNodeList != null) {
        int count = parametersNodeList.getLength();
        for (int i = 0; i < count; i++) {
            Node parameterNode = parametersNodeList.item(i);
            Node type = parameterNode.getAttributes().getNamedItem("type");
            if (type != null && type.getTextContent().equalsIgnoreCase("prompt")
                    && parameterNode.hasChildNodes()) {
                NodeList parameterInfoNodes = parameterNode.getChildNodes();
                int childNodesCount = parameterInfoNodes.getLength();
                String name = null;
                Integer id = null;
                String cardinality = null;
                String constrained = null;
                String valueType = null;
                String technicalName = null;
                String keepLastValues = null;
                for (int j = 0; j < childNodesCount; j++) {
                    Node childNode = parameterInfoNodes.item(j);
                    String childNodeName = childNode.getNodeName();
                    if (childNodeName.equalsIgnoreCase(EL_NAME)) {
                        name = childNode.getTextContent();
                        continue;
                    }/*from   w  ww.j a v a2s . c o  m*/
                    if (childNodeName.equalsIgnoreCase(EL_ID)) {
                        id = Integer.parseInt(childNode.getTextContent());
                        continue;
                    }
                    if (childNodeName.equalsIgnoreCase(EL_TECH_NAME)) {
                        technicalName = childNode.getTextContent();
                        continue;
                    }
                    if (childNodeName.equalsIgnoreCase(EL_ANSWER)) {
                        NamedNodeMap answerAttributes = childNode.getAttributes();
                        if (answerAttributes.getNamedItem("constrained") != null) {
                            constrained = answerAttributes.getNamedItem("constrained").getTextContent();
                        }
                        if (answerAttributes.getNamedItem("type") != null) {
                            valueType = answerAttributes.getNamedItem("type").getTextContent();
                        }
                        NodeList answerNodes = childNode.getChildNodes();
                        int answerCount = answerNodes.getLength();
                        for (int k = 0; k < answerCount; k++) {
                            Node answerChildNode = answerNodes.item(k);
                            String answerChildNodeName = answerChildNode.getNodeName();
                            if (answerChildNodeName.equalsIgnoreCase(EL_INFO)) {
                                NamedNodeMap infoAttributes = answerChildNode.getAttributes();
                                if (infoAttributes.getNamedItem("cardinality") != null) {
                                    cardinality = infoAttributes.getNamedItem("cardinality").getTextContent();
                                }
                                if (infoAttributes.getNamedItem("keepLastValues") != null) {
                                    keepLastValues = infoAttributes.getNamedItem("keepLastValues")
                                            .getTextContent();
                                }
                                break;
                            }
                        }
                        continue;
                    }
                }
                if (name != null && id != null && cardinality != null) {
                    parameters.add(new UniverseQueryPrompt(id, name, cardinality, constrained, valueType,
                            technicalName, keepLastValues));
                    break;
                }
            }
        }
    }

    return parameters;
}

From source file:org.dasein.cloud.ibm.sce.compute.vm.SCEVirtualMachine.java

private @Nonnull String parseAddress(@Nonnull Node ipNode) {
    NodeList attrs = ipNode.getChildNodes();
    String address = null;/*from  w w w .  j a v  a2  s.  co  m*/

    for (int j = 0; j < attrs.getLength(); j++) {
        Node attr = attrs.item(j);
        if (attr.getNodeName().equalsIgnoreCase("IP") && attr.hasChildNodes()) {
            address = attr.getFirstChild().getNodeValue().trim();
        }

    }
    return address;
}

From source file:org.dasein.cloud.ibm.sce.compute.vm.SCEVirtualMachine.java

public @Nullable ResourceStatus toStatus(@Nullable Node node) throws CloudException, InternalException {
    if (node == null) {
        return null;
    }// ww  w  .j a v  a  2s . co  m
    NodeList nodes = node.getChildNodes();
    VmState state = null;
    String vmId = null;

    for (int i = 0; i < nodes.getLength(); i++) {
        Node attr = nodes.item(i);
        String nodeName = attr.getNodeName();

        if (nodeName.equalsIgnoreCase("ID") && attr.hasChildNodes()) {
            vmId = attr.getFirstChild().getNodeValue().trim();
        } else if (nodeName.equalsIgnoreCase("Status") && attr.hasChildNodes()) {
            String status = attr.getFirstChild().getNodeValue().trim();

            state = toVmState(status);
        }
        if (state != null && vmId != null) {
            break;
        }
    }
    if (vmId == null) {
        return null;
    }
    return new ResourceStatus(vmId, state == null ? VmState.PENDING : state);
}

From source file:DOMDump.java

private void dump(Node root, String prefix) {
    if (root instanceof Element) {
        System.out.println(prefix + ((Element) root).getTagName() + " / " + root.getClass().getName());
    } else if (root instanceof CharacterData) {
        String data = ((CharacterData) root).getData().trim();
        if (!data.equals("")) {
            System.out.println(prefix + "CharacterData: " + data);
        }//from   w  ww. j  av  a  2 s  .  c  o  m
    } else {
        System.out.println(prefix + root.getClass().getName());
    }
    NamedNodeMap attrs = root.getAttributes();
    if (attrs != null) {
        int len = attrs.getLength();
        for (int i = 0; i < len; i++) {
            Node attr = attrs.item(i);
            System.out.print(prefix + HALF_INDENT + "attribute " + i + ": " + attr.getNodeName());
            if (attr instanceof Attr) {
                System.out.print(" = " + ((Attr) attr).getValue());
            }
            System.out.println();
        }
    }

    if (root.hasChildNodes()) {
        NodeList children = root.getChildNodes();
        if (children != null) {
            int len = children.getLength();
            for (int i = 0; i < len; i++) {
                dump(children.item(i), prefix + INDENT);
            }
        }
    }
}