Example usage for org.w3c.dom Node getNamespaceURI

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

Introduction

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

Prototype

public String getNamespaceURI();

Source Link

Document

The namespace URI of this node, or null if it is unspecified (see ).

Usage

From source file:org.wso2.carbon.bpel.common.DOMUtils.java

public static Element findChildByName(Element parent, QName name, boolean recurse) {
    if (parent == null) {
        throw new IllegalArgumentException("null parent");
    }//from w  ww . j a  va 2 s  .  co  m
    if (name == null) {
        throw new IllegalArgumentException("null name");
    }

    NodeList nl = parent.getChildNodes();
    for (int i = 0; i < nl.getLength(); ++i) {
        Node c = nl.item(i);
        if (c.getNodeType() != Node.ELEMENT_NODE) {
            continue;
        }
        // For a reason that I can't fathom, when using in-mem DAO we actually get elements with
        // no localname.
        String nodeName = c.getLocalName() != null ? c.getLocalName() : c.getNodeName();
        if (new QName(c.getNamespaceURI(), nodeName).equals(name)) {
            return (Element) c;
        }
    }

    if (recurse) {
        NodeList cnl = parent.getChildNodes();
        for (int i = 0; i < cnl.getLength(); ++i) {
            Node c = cnl.item(i);
            if (c.getNodeType() != Node.ELEMENT_NODE) {
                continue;
            }
            Element result = findChildByName((Element) c, name, recurse);
            if (result != null) {
                return result;
            }
        }
    }
    return null;
}

From source file:org.wso2.carbon.humantask.core.dao.jpa.openjpa.model.provider.ExpressionBasedOrgEntityProvider.java

public List<OrganizationalEntityDAO> getOrganizationalEntities(PeopleQueryEvaluator peopleQueryEvaluator,
        TFrom tFrom, EvaluationContext evaluationContext) {

    String expression = tFrom.newCursor().getTextValue().trim();

    log.debug("Evaluating expression " + expression + " for ExpressionBasedOrgEntityProvider");

    String expLang = (tFrom.getExpressionLanguage() == null) ? HumanTaskConstants.WSHT_EXP_LANG_XPATH20
            : tFrom.getExpressionLanguage();
    ExpressionLanguageRuntime expLangRuntime = HumanTaskServiceComponent.getHumanTaskServer().getTaskEngine()
            .getExpressionLanguageRuntime(expLang);
    List list = expLangRuntime.evaluate(expression, evaluationContext);

    List<OrganizationalEntityDAO> orgEntityList = new ArrayList<OrganizationalEntityDAO>();

    if (list.isEmpty() || list.size() > 1) {
        log.debug(" Organizational Entities evaluated to null or multiple list");
        return orgEntityList;
    }/* ww w.  ja v a 2s .co m*/
    // Returned list should evaluate to an organizationalEntity or a user
    for (Object item : list) {
        if (item instanceof NodeList) {
            for (int i = 0; i < ((NodeList) item).getLength(); i++) {
                Node node = ((NodeList) item).item(i);
                if (node.getNodeType() == Node.ELEMENT_NODE) {
                    if (node.getLocalName().equals(HumanTaskConstants.userQname.getLocalPart())
                            && node.getNamespaceURI().equals(HumanTaskConstants.userQname.getNamespaceURI())) {
                        CommonTaskUtil.addOrgEntityForUserNode(node, peopleQueryEvaluator, orgEntityList);

                    } else if (node.getLocalName().equals(HumanTaskConstants.groupQname.getLocalPart())
                            && node.getNamespaceURI().equals(HumanTaskConstants.groupQname.getNamespaceURI())) {
                        CommonTaskUtil.addOrgEntityForGroupNode(node, peopleQueryEvaluator, orgEntityList);
                    } else if (node.getLocalName().equals("wrapper")) {
                        // Expression evaluator wraps the string with wrapper element name
                        CommonTaskUtil.addOrgEntityForUserNode(node, peopleQueryEvaluator, orgEntityList);
                    } else if (node.getLocalName()
                            .equals(HumanTaskConstants.organizationalEntityQname.getLocalPart())
                            && node.getNamespaceURI()
                                    .equals(HumanTaskConstants.organizationalEntityQname.getNamespaceURI())) {
                        // This is an organizational Entity node, hence parse it as org entity
                        // Most probably this logic wont be required
                        CommonTaskUtil.addOrgEntitiesForOrganizationEntityNode(node, peopleQueryEvaluator,
                                orgEntityList);

                    }
                } else if (node.getNodeType() == Node.TEXT_NODE) {
                    String nodeValue = node.getNodeValue().trim();
                    if (nodeValue.length() > 0) {
                        OrganizationalEntityDAO userOrgEntityForName = peopleQueryEvaluator
                                .createUserOrgEntityForName(nodeValue);
                        if (userOrgEntityForName != null) {
                            orgEntityList.add(userOrgEntityForName);
                        }
                    }
                }
            }
        }
    }
    return orgEntityList;
}

From source file:org.wso2.carbon.humantask.core.engine.runtime.xpath.JaxpFunctionResolver.java

public void parseOrgEntityTypeOrUser(Node node1, Set<String> resoledUsers) {
    if (node1.getNodeType() == Node.ELEMENT_NODE) {
        if (organizationalEntityQname.getNamespaceURI().equals(node1.getNamespaceURI())
                && organizationalEntityQname.getLocalPart().equals(node1.getLocalName())) {
            //Parsing organizationalEntity element
            parseOrgEntity(node1, resoledUsers);
        } else if (userQname.getNamespaceURI().equals(node1.getNamespaceURI())
                && userQname.getLocalPart().equals(node1.getLocalName())) {
            //Parsing user element
            String username = node1.getTextContent();
            if (username != null) {
                username = username.trim();
                if (username.length() > 0) {
                    resoledUsers.add(username);
                }/*ww  w.j  a  v  a  2  s . com*/
            }
        } else if (node1.hasChildNodes()) {
            NodeList nodeList = node1.getChildNodes();
            Node childNode = null;
            for (int j = 0; j < nodeList.getLength(); j++) {
                if (Node.ELEMENT_NODE == nodeList.item(j).getNodeType()) {
                    childNode = nodeList.item(j);
                    break;
                }
            }
            //Parsing tOrganizationalEntity type also to have consistence the expression logic.
            if (childNode != null) {
                if (childNode.getNodeType() == Node.ELEMENT_NODE
                        && organizationalEntityQname.getNamespaceURI().equals(childNode.getNamespaceURI())) {
                    if (userQname.getLocalPart().equals(childNode.getLocalName())
                            || groupQname.getLocalPart().equals(childNode.getLocalName())) {
                        parseOrgEntity(node1, resoledUsers);
                    }
                }
            } else { // No element found. this is text content.
                String username = node1.getTextContent();
                if (username != null) {
                    username = username.trim();
                    if (username.length() > 0) {
                        resoledUsers.add(username);
                    }
                }
            }
        } else {
            throw new HumanTaskRuntimeException(
                    "This function should be provided with htt:organizationalEntity or htt:user element as an argument.");
        }
    }
}

From source file:org.xsystem.bpmn2.formats.xml.XMLParser3.java

void parseAttributes(Object base, Element rootElement) {

    ConvertingWrapDynaBean wrap = new ConvertingWrapDynaBean(base);
    DynaClass danaClass = wrap.getDynaClass();
    NamedNodeMap atts = rootElement.getAttributes();
    String defNamespace = rootElement.getNamespaceURI();
    for (int i = 0; i < atts.getLength(); i++) {
        Node currentAttribute = atts.item(i);
        String ns = currentAttribute.getNamespaceURI();
        if (ns == null) {
            ns = defNamespace;/*from   ww  w .ja  v a  2 s  .  c  om*/
        }
        String attrName = currentAttribute.getLocalName();
        //  getNodeName();
        switch (ns) {
        case BPMN2_NS: {
            DynaProperty dynaProperty = danaClass.getDynaProperty(attrName);
            if (dynaProperty != null) {
                Class clazz = dynaProperty.getType();
                if (clazz.isAssignableFrom(Reference.class)) {
                    String value = currentAttribute.getNodeValue();
                    Reference ref = createReference(value);
                    wrap.set(attrName, ref);
                } else if (clazz.isAssignableFrom(QName.class)) {
                    String value = currentAttribute.getNodeValue();
                    QName ret = createQName(value);
                    wrap.set(attrName, ret);
                } else if (clazz.isAssignableFrom(MultiInstanceBehavior.class)) {
                    String value = currentAttribute.getNodeValue();
                    wrap.set(attrName, MultiInstanceBehavior.valueOf(value));
                } else {
                    String value = currentAttribute.getNodeValue();
                    wrap.set(attrName, value);
                }
            }
            break;
        }
        case BPMNDI_NS:
        case DC_NS:
        case DI_NS: {
            DynaProperty dynaProperty = danaClass.getDynaProperty(attrName);
            if (dynaProperty != null) {
                String value = currentAttribute.getNodeValue();
                wrap.set(attrName, value);
            }
            break;
        }
        }
    }
}