Example usage for org.w3c.dom Element hasChildNodes

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

Introduction

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

Prototype

public boolean hasChildNodes();

Source Link

Document

Returns whether this node has any children.

Usage

From source file:com.twinsoft.convertigo.engine.util.WsReference.java

private static void extractSoapVariables(XmlSchema xmlSchema, List<RequestableHttpVariable> variables,
        Node node, String longName, boolean isMulti, QName variableType) throws EngineException {
    if (node == null)
        return;/*from w w w .j  av a2 s .c om*/
    int type = node.getNodeType();

    if (type == Node.ELEMENT_NODE) {
        Element element = (Element) node;
        if (element != null) {
            String elementName = element.getLocalName();
            if (longName != null)
                elementName = longName + "_" + elementName;

            if (!element.getAttribute("soapenc:arrayType").equals("") && !element.hasChildNodes()) {
                String avalue = element.getAttribute("soapenc:arrayType");
                element.setAttribute("soapenc:arrayType", avalue.replaceAll("\\[\\]", "[1]"));

                Element child = element.getOwnerDocument().createElement("item");
                String atype = avalue.replaceAll("\\[\\]", "");
                child.setAttribute("xsi:type", atype);
                if (atype.startsWith("xsd:")) {
                    String variableName = elementName + "_item";
                    child.appendChild(
                            element.getOwnerDocument().createTextNode("$(" + variableName.toUpperCase() + ")"));
                    RequestableHttpVariable httpVariable = createHttpVariable(true, variableName,
                            new QName(Constants.URI_2001_SCHEMA_XSD, atype.split(":")[1]));
                    variables.add(httpVariable);
                }
                element.appendChild(child);
            }

            // extract from attributes
            NamedNodeMap map = element.getAttributes();
            for (int i = 0; i < map.getLength(); i++) {
                Node child = map.item(i);
                if (child.getNodeName().equals("soapenc:arrayType"))
                    continue;
                if (child.getNodeName().equals("xsi:type"))
                    continue;
                if (child.getNodeName().equals("soapenv:encodingStyle"))
                    continue;

                String variableName = getVariableName(variables, elementName + "_" + child.getLocalName());

                child.setNodeValue("$(" + variableName.toUpperCase() + ")");

                RequestableHttpVariable httpVariable = createHttpVariable(false, variableName,
                        Constants.XSD_STRING);
                variables.add(httpVariable);
            }

            // extract from children nodes
            boolean multi = false;
            QName qname = Constants.XSD_STRING;
            NodeList children = element.getChildNodes();
            if (children.getLength() > 0) {
                Node child = element.getFirstChild();
                while (child != null) {
                    if (child.getNodeType() == Node.COMMENT_NODE) {
                        String value = child.getNodeValue();
                        if (value.startsWith("type:")) {
                            String schemaType = child.getNodeValue().substring("type:".length()).trim();
                            qname = getVariableSchemaType(xmlSchema, schemaType);
                        }
                        if (value.indexOf("repetitions:") != -1) {
                            multi = true;
                        }
                    } else if (child.getNodeType() == Node.TEXT_NODE) {
                        String value = child.getNodeValue().trim();
                        if (value.equals("?") || !value.equals("")) {
                            String variableName = getVariableName(variables, elementName);

                            child.setNodeValue("$(" + variableName.toUpperCase() + ")");

                            RequestableHttpVariable httpVariable = createHttpVariable(isMulti, variableName,
                                    variableType);
                            variables.add(httpVariable);
                        }
                    } else if (child.getNodeType() == Node.ELEMENT_NODE) {
                        extractSoapVariables(xmlSchema, variables, child, elementName, multi, qname);
                        multi = false;
                        qname = Constants.XSD_STRING;
                    }

                    child = child.getNextSibling();
                }
            }

        }
    }
}

From source file:org.drools.container.spring.namespace.KnowledgeSessionDefinitionParser.java

@SuppressWarnings("unchecked")
protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) {

    String id = element.getAttribute("id");
    emptyAttributeCheck(element.getLocalName(), "id", id);

    String kbase = element.getAttribute(KBASE_ATTRIBUTE);
    emptyAttributeCheck(element.getLocalName(), KBASE_ATTRIBUTE, kbase);

    String sessionType = element.getAttribute(TYPE_ATTRIBUTE);
    BeanDefinitionBuilder factory;/*from  w  ww. j  a  va  2  s.  co  m*/

    if ("stateful".equals(sessionType)) {
        factory = BeanDefinitionBuilder.rootBeanDefinition(StatefulKnowledgeSessionBeanFactory.class);
    } else if ("stateless".equals(sessionType)) {
        factory = BeanDefinitionBuilder.rootBeanDefinition(StatelessKnowledgeSessionBeanFactory.class);
    } else {
        throw new IllegalArgumentException(
                "Invalid value for " + TYPE_ATTRIBUTE + " attribute: " + sessionType);
    }

    factory.addPropertyReference("kbase", kbase);

    String node = element.getAttribute(GRID_NODE_ATTRIBUTE);
    if (node != null && node.length() > 0) {
        factory.addPropertyReference("node", node);
    }

    String name = element.getAttribute(NAME_ATTRIBUTE);
    if (StringUtils.hasText(name)) {
        factory.addPropertyValue("name", name);
    } else {
        factory.addPropertyValue("name", id);
    }

    // Additions for JIRA JBRULES-3076
    String listeners = element.getAttribute(LISTENERS_ATTRIBUTE);
    if (StringUtils.hasText(listeners)) {
        factory.addPropertyValue("eventListenersFromGroup", new RuntimeBeanReference(listeners));
    }
    EventListenersUtil.parseEventListeners(parserContext, factory, element);
    // End of Additions for JIRA JBRULES-3076

    Element ksessionConf = DomUtils.getChildElementByTagName(element, "configuration");
    if (ksessionConf != null) {
        Element persistenceElm = DomUtils.getChildElementByTagName(ksessionConf, "jpa-persistence");
        if (persistenceElm != null) {
            BeanDefinitionBuilder beanBuilder = BeanDefinitionBuilder
                    .genericBeanDefinition(JpaConfiguration.class);

            String loadId = persistenceElm.getAttribute("load");
            if (StringUtils.hasText(loadId)) {
                beanBuilder.addPropertyValue("id", Long.parseLong(loadId));
            }

            Element tnxMng = DomUtils.getChildElementByTagName(persistenceElm, TX_MANAGER_ATTRIBUTE);
            String ref = tnxMng.getAttribute("ref");

            beanBuilder.addPropertyReference("platformTransactionManager", ref);

            Element emf = DomUtils.getChildElementByTagName(persistenceElm, EMF_ATTRIBUTE);
            ref = emf.getAttribute("ref");
            beanBuilder.addPropertyReference("entityManagerFactory", ref);

            Element variablePersisters = DomUtils.getChildElementByTagName(persistenceElm,
                    "variable-persisters");
            if (variablePersisters != null && variablePersisters.hasChildNodes()) {
                List<Element> childPersisterElems = DomUtils.getChildElementsByTagName(variablePersisters,
                        "persister");
                ManagedMap persistors = new ManagedMap(childPersisterElems.size());
                for (Element persisterElem : childPersisterElems) {
                    String forClass = persisterElem.getAttribute(FORCLASS_ATTRIBUTE);
                    String implementation = persisterElem.getAttribute(IMPLEMENTATION_ATTRIBUTE);
                    if (!StringUtils.hasText(forClass)) {
                        throw new RuntimeException("persister element must have valid for-class attribute");
                    }
                    if (!StringUtils.hasText(implementation)) {
                        throw new RuntimeException(
                                "persister element must have valid implementation attribute");
                    }
                    persistors.put(forClass, implementation);
                }
                beanBuilder.addPropertyValue("variablePersisters", persistors);
            }

            factory.addPropertyValue("jpaConfiguration", beanBuilder.getBeanDefinition());
        }
        BeanDefinitionBuilder rbaseConfBuilder = BeanDefinitionBuilder
                .rootBeanDefinition(SessionConfiguration.class);
        Element e = DomUtils.getChildElementByTagName(ksessionConf, KEEP_REFERENCE);
        if (e != null && StringUtils.hasText(e.getAttribute("enabled"))) {
            rbaseConfBuilder.addPropertyValue("keepReference", Boolean.parseBoolean(e.getAttribute("enabled")));
        }

        e = DomUtils.getChildElementByTagName(ksessionConf, CLOCK_TYPE);
        if (e != null && StringUtils.hasText(e.getAttribute("type"))) {
            rbaseConfBuilder.addPropertyValue("clockType", ClockType.resolveClockType(e.getAttribute("type")));
        }
        factory.addPropertyValue("conf", rbaseConfBuilder.getBeanDefinition());

        e = DomUtils.getChildElementByTagName(ksessionConf, WORK_ITEMS);
        if (e != null) {
            List<Element> children = DomUtils.getChildElementsByTagName(e, WORK_ITEM);
            if (children != null && !children.isEmpty()) {
                ManagedMap workDefs = new ManagedMap();
                for (Element child : children) {
                    workDefs.put(child.getAttribute("name"),
                            new RuntimeBeanReference(child.getAttribute("ref")));
                }
                factory.addPropertyValue("workItems", workDefs);
            }
        }
    }

    Element batch = DomUtils.getChildElementByTagName(element, "batch");
    if (batch == null) {
        // just temporary legacy suppport
        batch = DomUtils.getChildElementByTagName(element, "script");
    }
    if (batch != null) {
        // we know there can only ever be one
        ManagedList children = new ManagedList();

        for (int i = 0, length = batch.getChildNodes().getLength(); i < length; i++) {
            Node n = batch.getChildNodes().item(i);
            if (n instanceof Element) {
                Element e = (Element) n;

                BeanDefinitionBuilder beanBuilder = null;
                if ("insert-object".equals(e.getLocalName())) {
                    String ref = e.getAttribute("ref");
                    Element nestedElm = getFirstElement(e.getChildNodes());
                    beanBuilder = BeanDefinitionBuilder.genericBeanDefinition(InsertObjectCommand.class);
                    if (StringUtils.hasText(ref)) {
                        beanBuilder.addConstructorArgReference(ref);
                    } else if (nestedElm != null) {
                        beanBuilder.addConstructorArgValue(
                                parserContext.getDelegate().parsePropertySubElement(nestedElm, null, null));
                    } else {
                        throw new IllegalArgumentException(
                                "insert-object must either specify a 'ref' attribute or have a nested bean");
                    }
                } else if ("set-global".equals(e.getLocalName())) {
                    String ref = e.getAttribute("ref");
                    Element nestedElm = getFirstElement(e.getChildNodes());
                    beanBuilder = BeanDefinitionBuilder.genericBeanDefinition(SetGlobalCommand.class);
                    beanBuilder.addConstructorArgValue(e.getAttribute("identifier"));
                    if (StringUtils.hasText(ref)) {
                        beanBuilder.addConstructorArgReference(ref);
                    } else if (nestedElm != null) {
                        beanBuilder.addConstructorArgValue(
                                parserContext.getDelegate().parsePropertySubElement(nestedElm, null, null));
                    } else {
                        throw new IllegalArgumentException(
                                "set-global must either specify a 'ref' attribute or have a nested bean");
                    }
                } else if ("fire-until-halt".equals(e.getLocalName())) {
                    beanBuilder = BeanDefinitionBuilder.genericBeanDefinition(FireUntilHaltCommand.class);
                } else if ("fire-all-rules".equals(e.getLocalName())) {
                    beanBuilder = BeanDefinitionBuilder.genericBeanDefinition(FireAllRulesCommand.class);
                    String max = e.getAttribute("max");
                    if (StringUtils.hasText(max)) {
                        beanBuilder.addPropertyValue("max", max);
                    }
                } else if ("start-process".equals(e.getLocalName())) {

                    beanBuilder = BeanDefinitionBuilder.genericBeanDefinition(StartProcessCommand.class);
                    String processId = e.getAttribute("process-id");
                    if (!StringUtils.hasText(processId)) {
                        throw new IllegalArgumentException("start-process must specify a process-id");
                    }
                    beanBuilder.addConstructorArgValue(processId);

                    List<Element> params = DomUtils.getChildElementsByTagName(e, "parameter");
                    if (!params.isEmpty()) {
                        ManagedMap map = new ManagedMap();
                        for (Element param : params) {
                            String identifier = param.getAttribute("identifier");
                            if (!StringUtils.hasText(identifier)) {
                                throw new IllegalArgumentException(
                                        "start-process paramaters must specify an identifier");
                            }

                            String ref = param.getAttribute("ref");
                            Element nestedElm = getFirstElement(param.getChildNodes());
                            if (StringUtils.hasText(ref)) {
                                map.put(identifier, new RuntimeBeanReference(ref));
                            } else if (nestedElm != null) {
                                map.put(identifier, parserContext.getDelegate()
                                        .parsePropertySubElement(nestedElm, null, null));
                            } else {
                                throw new IllegalArgumentException(
                                        "start-process parameters must either specify a 'ref' attribute or have a nested bean");
                            }
                        }
                        beanBuilder.addPropertyValue("parameters", map);
                    }
                } else if ("signal-event".equals(e.getLocalName())) {
                    beanBuilder = BeanDefinitionBuilder.genericBeanDefinition(SignalEventCommand.class);
                    String processInstanceId = e.getAttribute("process-instance-id");
                    if (StringUtils.hasText(processInstanceId)) {
                        beanBuilder.addConstructorArgValue(processInstanceId);
                    }

                    beanBuilder.addConstructorArgValue(e.getAttribute("event-type"));

                    String ref = e.getAttribute("ref");
                    Element nestedElm = getFirstElement(e.getChildNodes());
                    if (StringUtils.hasText(ref)) {
                        beanBuilder.addConstructorArgReference(ref);
                    } else if (nestedElm != null) {
                        beanBuilder.addConstructorArgValue(
                                parserContext.getDelegate().parsePropertySubElement(nestedElm, null, null));
                    } else {
                        throw new IllegalArgumentException(
                                "signal-event must either specify a 'ref' attribute or have a nested bean");
                    }
                }
                if (beanBuilder == null) {
                    throw new IllegalStateException("Unknow element: " + e.getLocalName());
                }
                children.add(beanBuilder.getBeanDefinition());
            }
        }
        factory.addPropertyValue("batch", children);
    }

    // find any kagent's for the current kbase and assign (only if this 
    // is a stateless session)
    if (sessionType.equals("stateless")) {
        for (String beanName : parserContext.getRegistry().getBeanDefinitionNames()) {
            BeanDefinition def = parserContext.getRegistry().getBeanDefinition(beanName);
            if (KnowledgeAgentBeanFactory.class.getName().equals(def.getBeanClassName())) {
                PropertyValue pvalue = def.getPropertyValues().getPropertyValue("kbase");
                RuntimeBeanReference tbf = (RuntimeBeanReference) pvalue.getValue();
                if (kbase.equals(tbf.getBeanName())) {
                    factory.addPropertyValue("knowledgeAgent", new RuntimeBeanReference(beanName));
                }
            }
        }
    }

    return factory.getBeanDefinition();
}

From source file:com.redhat.rcm.maven.plugin.buildmetadata.io.SdocBuilder.java

private void createOsElement(final Element runtime) {
    final Element parent = document.createElement("os");
    createContentElement("arch", Constant.PROP_NAME_OS_ARCH, parent);
    createContentElement(GI_NAME, Constant.PROP_NAME_OS_NAME, parent);
    createContentElement(GI_VERSION, Constant.PROP_NAME_OS_VERSION, parent);
    if (parent.hasChildNodes()) {
        runtime.appendChild(parent);// w ww  .  j  a  v a2  s  .  co  m
    }
}

From source file:com.redhat.rcm.maven.plugin.buildmetadata.io.SdocBuilder.java

private void createProjectElement(final Element docRoot) {
    final Element parent = document.createElement("project");

    createContentElement("copyright-year", Constant.PROP_NAME_COPYRIGHT_YEAR, parent);
    createContentElement("home-page-url", Constant.PROP_NAME_PROJECT_HOMEPAGE, parent);
    createContentElement("ops-home-page-url", Constant.PROP_NAME_PROJECT_OPS, parent);

    if (parent.hasChildNodes()) {
        docRoot.appendChild(parent);/*w w w.  ja  va2s  .  c  o m*/
    }
}

From source file:com.sqewd.os.maracache.core.Config.java

private ConfigPath load(ConfigNode parent, Element elm) throws ConfigException {
    if (parent instanceof ConfigPath) {
        // Check if there are any attributes.
        // Attributes are treated as Value nodes.
        if (elm.hasAttributes()) {
            NamedNodeMap map = elm.getAttributes();
            if (map.getLength() > 0) {
                for (int ii = 0; ii < map.getLength(); ii++) {
                    Node n = map.item(ii);
                    ((ConfigPath) parent).addValueNode(n.getNodeName(), n.getNodeValue());
                }/*from w  ww.  ja  v  a  2s . co m*/
            }
        }
        if (elm.hasChildNodes()) {
            NodeList children = elm.getChildNodes();
            for (int ii = 0; ii < children.getLength(); ii++) {
                Node cn = children.item(ii);
                if (cn.getNodeType() == Node.ELEMENT_NODE) {
                    Element e = (Element) cn;
                    if (e.hasChildNodes()) {
                        int nc = 0;
                        for (int jj = 0; jj < e.getChildNodes().getLength(); jj++) {
                            Node ccn = e.getChildNodes().item(jj);
                            // Read the text node if there is any.
                            if (ccn.getNodeType() == Node.TEXT_NODE) {
                                String n = e.getNodeName();
                                String v = ccn.getNodeValue();
                                if (!StringUtils.isEmpty(v.trim()))
                                    ((ConfigPath) parent).addValueNode(n, v);
                                nc++;
                            }
                        }
                        // Make sure this in not a text only node.
                        if (e.getChildNodes().getLength() > nc) {
                            // Check if this is a parameter node. Parameters are treated differently.
                            if (e.getNodeName().compareToIgnoreCase(ConfigParams.NODE_NAME) == 0) {
                                ConfigParams cp = ((ConfigPath) parent).addParamNode();
                                setParams(cp, e);
                            } else {
                                ConfigPath cp = ((ConfigPath) parent).addPathNode(e.getNodeName());
                                load(cp, e);
                            }
                        }
                    }
                }
            }
        }
    }
    return (ConfigPath) parent;
}

From source file:com.enonic.esl.xml.XMLTool.java

public static Element renameElement(Element elem, String newName) {
    Document doc = elem.getOwnerDocument();

    // Create an element with the new name
    Element elem2 = doc.createElement(newName);

    // Copy the attributes to the new element
    NamedNodeMap attrs = elem.getAttributes();
    for (int i = 0; i < attrs.getLength(); i++) {
        Attr attr2 = (Attr) doc.importNode(attrs.item(i), true);
        elem2.getAttributes().setNamedItem(attr2);
    }/*  w  w w  .j a  v a  2s  . c o m*/

    // Move all the children
    while (elem.hasChildNodes()) {
        elem2.appendChild(elem.getFirstChild());
    }

    // Replace the old node with the new node
    elem.getParentNode().replaceChild(elem2, elem);

    return elem2;
}

From source file:de.betterform.xml.xforms.action.LoadAction.java

private void handleEmbedding(String absoluteURI, HashMap map, boolean includeCSS, boolean includeScript)
        throws XFormsException {

    //        if(this.targetAttribute == null) return;
    //todo: handle multiple params
    if (absoluteURI.indexOf("?") > 0) {
        String name = absoluteURI.substring(absoluteURI.indexOf("?") + 1);
        String value = name.substring(name.indexOf("=") + 1, name.length());
        name = name.substring(0, name.indexOf("="));
        this.container.getProcessor().setContextParam(name, value);
    }//from  ww w . j  ava 2s. c  o  m
    if (this.targetAttribute == null) {
        map.put("uri", absoluteURI);
        map.put("show", this.showAttribute);

        // dispatch internal betterform event
        this.container.dispatch(this.target, BetterFormEventNames.LOAD_URI, map);
        return;
    }

    if (!("embed".equals(this.showAttribute))) {
        throw new XFormsException("@show must be 'embed' if @target is given but was: '" + this.showAttribute
                + "' on Element " + DOMUtil.getCanonicalPath(this.element));
    }
    //todo: dirty dirty dirty
    String evaluatedTarget = evalAttributeValueTemplates(this.targetAttribute, this.element);
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("targetid evaluated to: " + evaluatedTarget);
    }
    Node embed = getEmbeddedDocument(absoluteURI);
    if (embed == null) {
        //todo: review: context info params containing a '-' fail during access in javascript!
        //todo: the following property should have been 'resource-uri' according to spec
        map.put("resourceUri", absoluteURI);
        this.container.dispatch(this.target, XFormsEventNames.LINK_EXCEPTION, map);
        return;
    }

    // Check for 'ClientSide' events (DOMFocusIN / DOMFocusOUT / xforms-select)
    String utilizedEvents = this.getEventsInSubform(embed);

    // fetch CSS / JavaScript
    String inlineCssRules = "";
    String externalCssRules = "";
    String inlineJavaScript = "";
    String externalJavaScript = "";

    if (includeCSS) {
        inlineCssRules = getInlineCSS(embed);
        externalCssRules = getExternalCSS(embed);
    }
    if (includeScript) {
        inlineJavaScript = getInlineJavaScript(embed);
        externalJavaScript = getExternalJavaScript(embed);
    }

    if (Config.getInstance().getProperty("webprocessor.doIncludes", "false").equals("true")) {
        embed = doIncludes(embed, absoluteURI);
    }

    embed = extractFragment(absoluteURI, embed);
    if (LOGGER.isDebugEnabled()) {
        DOMUtil.prettyPrintDOM(embed);
    }

    Element embeddedNode;
    Element targetElem = getTargetElement(evaluatedTarget);

    //Test if targetElem exist.
    if (targetElem != null) {
        // destroy existing embedded form within targetNode
        if (targetElem.hasChildNodes()) {
            destroyembeddedModels(targetElem);
            Initializer.disposeUIElements(targetElem);
        }

        // import referenced embedded form into host document
        embeddedNode = (Element) this.container.getDocument().importNode(embed, true);

        //import namespaces
        NamespaceResolver.applyNamespaces(targetElem.getOwnerDocument().getDocumentElement(),
                (Element) embeddedNode);

        // keep original targetElem id within hostdoc
        embeddedNode.setAttributeNS(null, "id", targetElem.getAttributeNS(null, "id"));
        //copy all Attributes that might have been on original mountPoint to embedded node
        DOMUtil.copyAttributes(targetElem, embeddedNode, null);
        targetElem.getParentNode().replaceChild(embeddedNode, targetElem);

        //create model for it
        this.container.createEmbeddedForm((Element) embeddedNode);
        // dispatch internal betterform event
        this.container.dispatch((EventTarget) embeddedNode, BetterFormEventNames.EMBED_DONE, map);

        if (getModel().isReady()) {
            map.put("uri", absoluteURI);
            map.put("show", this.showAttribute);
            map.put("targetElement", embeddedNode);
            map.put("nameTarget", evaluatedTarget);
            map.put("xlinkTarget", getXFormsAttribute(targetElem, "id"));
            map.put("inlineCSS", inlineCssRules);
            map.put("externalCSS", externalCssRules);
            map.put("inlineJavascript", inlineJavaScript);
            map.put("externalJavascript", externalJavaScript);
            map.put("utilizedEvents", utilizedEvents);

            this.container.dispatch((EventTarget) embeddedNode, BetterFormEventNames.EMBED, map);
            this.container.dispatch(this.target, BetterFormEventNames.LOAD_URI, map);
        }

        //        storeInContext(absoluteURI, this.showAttribute);
    } else {
        String message = "Element reference for targetid: " + this.targetAttribute + " not found. "
                + DOMUtil.getCanonicalPath(this.element);
        /*
        Element div = this.element.getOwnerDocument().createElementNS("", "div");
        div.setAttribute("class", "bfException");
        div.setTextContent("Element reference for targetid: " + this.targetAttribute + "not found. " + DOMUtil.getCanonicalPath(this.element));
                
        Element body = (Element) this.container.getDocument().getElementsByTagName("body").item(0);
        body.insertBefore(div, DOMUtil.getFirstChildElement(body));
        */
        map.put("message", message);
        map.put("exceptionPath", DOMUtil.getCanonicalPath(this.element));
        this.container.dispatch(this.target, BetterFormEventNames.EXCEPTION, map);
        //throw new XFormsException(message);
    }
}

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

private Set<String> getIdentifierUrnValueSet(Document updateDocument) {
    Set<String> result = new HashSet<>();
    NodeList nl = updateDocument.getElementsByTagName("IdentifierUrn");
    for (int i = 0; i < nl.getLength(); i++) {
        Element e = (Element) nl.item(i);
        if (e.hasChildNodes()) {
            String v = e.getElementsByTagName("Value").item(0).getTextContent();
            result.add(v);/*from   www.  jav  a 2 s  .c om*/
        }
    }
    return result;
}

From source file:com.redhat.rcm.maven.plugin.buildmetadata.io.SdocBuilder.java

private void createJavaElement(final Element runtime) {
    final Element parent = document.createElement("java");
    createContentElement(GI_NAME, Constant.PROP_NAME_JAVA_RUNTIME_NAME, parent);
    createContentElement(GI_VERSION, Constant.PROP_NAME_JAVA_RUNTIME_VERSION, parent);
    createContentElement("vendor", Constant.PROP_NAME_JAVA_VENDOR, parent);
    createContentElement("vm", Constant.PROP_NAME_JAVA_VM, parent);
    createContentElement("compiler", Constant.PROP_NAME_JAVA_COMPILER, parent);
    createContentElement("options", Constant.PROP_NAME_JAVA_OPTS, parent);
    if (parent.hasChildNodes()) {
        runtime.appendChild(parent);// ww w . j  av a  2s  .  c  om
    }
}

From source file:com.cloud.test.regression.ApiCommand.java

public boolean verifyParam() {
    boolean result = true;
    if (this.getCommandType() == CommandType.HTTP) {
        if (this.list == false) {
            Set<?> set = verifyParam.entrySet();
            Iterator<?> it = set.iterator();

            while (it.hasNext()) {
                Map.Entry<?, ?> me = (Map.Entry<?, ?>) it.next();
                String key = (String) me.getKey();
                String value = (String) me.getValue();
                if (value == null) {
                    s_logger.error("Parameter " + key + " is missing in the list of global parameters");
                    return false;
                }/*from   ww w  .  j  a va 2s.  co m*/

                NodeList itemName = this.responseBody.getElementsByTagName(key);
                if ((itemName.getLength() != 0) && (itemName != null)) {
                    Element itemNameElement = (Element) itemName.item(0);
                    if (itemNameElement.hasChildNodes()) {
                        continue;
                    }
                    if (!(verifyParam.get(key).equals("no value"))
                            && !(itemNameElement.getTextContent().equals(verifyParam.get(key)))) {
                        s_logger.error("Incorrect value for the following tag: " + key + ". Expected value is "
                                + verifyParam.get(key) + " while actual value is "
                                + itemNameElement.getTextContent());
                        result = false;
                    }
                } else {
                    s_logger.error("Following xml element is missing in the response: " + key);
                    result = false;
                }
            }
        }
        // for multiple elements
        else {
            Set<?> set = verifyParam.entrySet();
            Iterator<?> it = set.iterator();
            // get list element specified by id
            NodeList returnLst = this.responseBody.getElementsByTagName(this.listName.getTextContent());
            Node requiredNode = returnLst.item(Integer.parseInt(this.listId.getTextContent()));

            if (requiredNode.getNodeType() == Node.ELEMENT_NODE) {
                Element fstElmnt = (Element) requiredNode;

                while (it.hasNext()) {
                    Map.Entry<?, ?> me = (Map.Entry<?, ?>) it.next();
                    String key = (String) me.getKey();
                    String value = (String) me.getValue();
                    if (value == null) {
                        s_logger.error("Parameter " + key + " is missing in the list of global parameters");
                        return false;
                    }
                    NodeList itemName = fstElmnt.getElementsByTagName(key);
                    if ((itemName.getLength() != 0) && (itemName != null)) {
                        Element itemNameElement = (Element) itemName.item(0);
                        if (!(verifyParam.get(key).equals("no value"))
                                && !(itemNameElement.getTextContent().equals(verifyParam.get(key)))) {
                            s_logger.error("Incorrect value for the following tag: " + key
                                    + ". Expected value is " + verifyParam.get(key) + " while actual value is "
                                    + itemNameElement.getTextContent());
                            result = false;
                        }
                    } else {
                        s_logger.error("Following xml element is missing in the response: " + key);
                        result = false;
                    }
                }
            }
        }
    } else if (this.getCommandType() == CommandType.MYSQL) {
        Set<?> set = verifyParam.entrySet();
        Iterator<?> it = set.iterator();

        while (it.hasNext()) {
            Map.Entry<?, ?> me = (Map.Entry<?, ?>) it.next();
            String key = (String) me.getKey();
            String value = (String) me.getValue();
            if (value == null) {
                s_logger.error("Parameter " + key + " is missing in the list of global parameters");
                return false;
            }

            String itemName = null;
            try {
                while (this.result.next()) {
                    itemName = this.result.getString(key);
                }
            } catch (Exception ex) {
                s_logger.error("Unable to get element from result set " + key);
            }

            if (!(value.equals("no value")) && !(itemName.equals(verifyParam.get(key)))) {
                s_logger.error("Incorrect value for the following tag: " + key + ". Expected value is "
                        + verifyParam.get(key) + " while actual value is " + itemName);
                result = false;
            }
        }
    }
    return result;
}