Example usage for org.w3c.dom Node getLocalName

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

Introduction

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

Prototype

public String getLocalName();

Source Link

Document

Returns the local part of the qualified name of this node.

Usage

From source file:org.apache.ode.bpel.runtime.ASSIGN.java

private void replaceEndpointRefence(PartnerLinkInstance plval, Node rvalue) throws FaultException {
    if (rvalue.getNodeType() == Node.ATTRIBUTE_NODE) {
        rvalue = rvalue.getOwnerDocument().createTextNode(((Attr) rvalue).getValue());
    }/*  www .java 2  s.c o  m*/
    // Eventually wrapping with service-ref element if we've been directly assigned some
    // value that isn't wrapped.
    if (rvalue.getNodeType() == Node.TEXT_NODE
            || (rvalue.getNodeType() == Node.ELEMENT_NODE && !rvalue.getLocalName().equals("service-ref"))) {
        Document doc = DOMUtils.newDocument();
        Element serviceRef = doc.createElementNS(Namespaces.WSBPEL2_0_FINAL_SERVREF, "service-ref");
        doc.appendChild(serviceRef);
        serviceRef.appendChild(doc.importNode(rvalue, true));
        rvalue = serviceRef;
    }

    getBpelRuntimeContext().writeEndpointReference(plval, (Element) rvalue);
}

From source file:org.apache.ode.utils.DOMUtils.java

public static QName getNodeQName(Node el) {
    String localName = el.getLocalName();
    String namespaceUri = el.getNamespaceURI();
    if (localName == null) {
        String nodeName = el.getNodeName();
        int colonIndex = nodeName.indexOf(":");
        if (colonIndex > 0) {
            localName = nodeName.substring(0, colonIndex);
            namespaceUri = nodeName.substring(colonIndex + 1);
        } else {//from ww  w.  java2 s .c  om
            localName = nodeName;
            namespaceUri = null;
        }
    }
    return new QName(namespaceUri, localName);
}

From source file:org.apache.ode.utils.DOMUtils.java

public static Element findChildByName(Element parent, QName name, boolean recurse) {
    if (parent == null)
        throw new IllegalArgumentException("null parent");
    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;
    }/*from   ww w. j a v  a  2s .co m*/

    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.apache.ode.utils.DOMUtils.java

public static List<Element> findChildrenByName(Element parent, QName name) {
    if (parent == null)
        throw new IllegalArgumentException("null parent");
    if (name == null)
        throw new IllegalArgumentException("null name");

    LinkedList<Element> ret = new LinkedList<Element>();
    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))
            ret.add((Element) c);
    }//from w w w  . jav  a2  s  .c  o  m

    return ret;
}

From source file:org.apache.openaz.xacml.pdp.policy.dom.DOMAdviceExpression.java

/**
 * Creates a new <code>AdviceExpression</code> by parsing the given <code>Node</code> representing a XACML
 * AdviceExpression element./*w  ww.ja v a 2 s.  co  m*/
 *
 * @param nodeAdviceExpression the <code>Node</code> representing the XACML AdviceExpression element
 * @param policy the {@link org.apache.openaz.xacml.pdp.policy.Policy} encompassing the AdviceExpression
 *            element
 * @return a new <code>AdviceExpression</code> parsed from the given <code>Node</code>
 * @throws DOMStructureException if there is an error parsing the <code>Node</code>
 */
public static AdviceExpression newInstance(Node nodeAdviceExpression, Policy policy)
        throws DOMStructureException {
    Element elementAdviceExpression = DOMUtil.getElement(nodeAdviceExpression);
    boolean bLenient = DOMProperties.isLenient();

    DOMAdviceExpression domAdviceExpression = new DOMAdviceExpression();

    try {
        NodeList children = elementAdviceExpression.getChildNodes();
        int numChildren;
        if (children != null && (numChildren = children.getLength()) > 0) {
            for (int i = 0; i < numChildren; i++) {
                Node child = children.item(i);
                if (DOMUtil.isElement(child)) {
                    if (DOMUtil.isInNamespace(child, XACML3.XMLNS)
                            && XACML3.ELEMENT_ATTRIBUTEASSIGNMENTEXPRESSION.equals(child.getLocalName())) {
                        domAdviceExpression.addAttributeAssignmentExpression(
                                DOMAttributeAssignmentExpression.newInstance(child, policy));
                    } else if (!bLenient) {
                        throw DOMUtil.newUnexpectedElementException(child, nodeAdviceExpression);
                    }
                }
            }
        }

        domAdviceExpression.setAdviceId(
                DOMUtil.getIdentifierAttribute(elementAdviceExpression, XACML3.ATTRIBUTE_ADVICEID, !bLenient));

        String string = DOMUtil.getStringAttribute(elementAdviceExpression, XACML3.ATTRIBUTE_APPLIESTO,
                !bLenient);
        RuleEffect ruleEffect = RuleEffect.getRuleEffect(string);
        if (ruleEffect == null && !bLenient) {
            throw new DOMStructureException(nodeAdviceExpression, "Unknown EffectType \"" + string + "\"");
        } else {
            domAdviceExpression.setAppliesTo(ruleEffect);
        }
    } catch (DOMStructureException ex) {
        domAdviceExpression.setStatus(StdStatusCode.STATUS_CODE_SYNTAX_ERROR, ex.getMessage());
        if (DOMProperties.throwsExceptions()) {
            throw ex;
        }
    }

    return domAdviceExpression;
}

From source file:org.apache.openaz.xacml.pdp.policy.dom.DOMAdviceExpression.java

public static boolean repair(Node nodeAdviceExpression) throws DOMStructureException {
    Element elementAdviceExpression = DOMUtil.getElement(nodeAdviceExpression);
    boolean result = false;

    NodeList children = elementAdviceExpression.getChildNodes();
    int numChildren;
    if (children != null && (numChildren = children.getLength()) > 0) {
        for (int i = 0; i < numChildren; i++) {
            Node child = children.item(i);
            if (DOMUtil.isElement(child)) {
                if (DOMUtil.isInNamespace(child, XACML3.XMLNS)
                        && XACML3.ELEMENT_ATTRIBUTEASSIGNMENTEXPRESSION.equals(child.getLocalName())) {
                    result = DOMAttributeAssignmentExpression.repair(child) || result;
                } else {
                    logger.warn("Unexpected element " + child.getNodeName());
                    nodeAdviceExpression.removeChild(child);
                    result = true;/* w w  w. j a v  a2 s. c  o m*/
                }
            }
        }
    }

    result = DOMUtil.repairIdentifierAttribute(elementAdviceExpression, XACML3.ATTRIBUTE_ADVICEID, logger)
            || result;
    result = DOMUtil.repairStringAttribute(elementAdviceExpression, XACML3.ATTRIBUTE_APPLIESTO,
            RuleEffect.DENY.getName(), logger) || result;
    String stringRuleEffect = DOMUtil.getStringAttribute(elementAdviceExpression, XACML3.ATTRIBUTE_APPLIESTO);
    RuleEffect ruleEffect = RuleEffect.getRuleEffect(stringRuleEffect);
    if (ruleEffect == null) {
        logger.warn("Setting invalid RuleEffect " + stringRuleEffect + " to " + RuleEffect.DENY.getName());
        elementAdviceExpression.setAttribute(XACML3.ATTRIBUTE_APPLIESTO, RuleEffect.DENY.getName());
        result = true;
    }
    return result;
}

From source file:org.apache.openaz.xacml.pdp.policy.dom.DOMAdviceExpression.java

/**
 * Creates a <code>List</code> of <code>AdviceExpression</code>s by parsing the given <code>Node</code>
 * representing a XACML AdviceExpressions element.
 *
 * @param nodeAdviceExpressions the <code>Node</code> representing the XACML AdviceExpressions element
 * @param policy the <code>Policy</code> encompassing the AdviceExpressions element
 * @return a new <code>List</code> of <code>AdviceExpression</code>s parsed from the given
 *         <code>Node</code>.
 * @throws DOMStructureException if there is an error parsing the <code>Node</code>
 *//*  w w  w  .j  av a  2 s  .c o  m*/
public static List<AdviceExpression> newList(Node nodeAdviceExpressions, Policy policy)
        throws DOMStructureException {
    Element elementAdviceExpressions = DOMUtil.getElement(nodeAdviceExpressions);
    boolean bLenient = DOMProperties.isLenient();

    List<AdviceExpression> listAdviceExpressions = new ArrayList<AdviceExpression>();

    NodeList children = elementAdviceExpressions.getChildNodes();
    int numChildren;
    if (children != null && (numChildren = children.getLength()) > 0) {
        for (int i = 0; i < numChildren; i++) {
            Node child = children.item(i);
            if (DOMUtil.isElement(child)) {
                if (DOMUtil.isInNamespace(child, XACML3.XMLNS)
                        && XACML3.ELEMENT_ADVICEEXPRESSION.equals(child.getLocalName())) {
                    listAdviceExpressions.add(DOMAdviceExpression.newInstance(child, policy));
                } else if (!bLenient) {
                    throw DOMUtil.newUnexpectedElementException(child, nodeAdviceExpressions);
                }
            }
        }
    }

    if (listAdviceExpressions.size() == 0 && !bLenient) {
        throw DOMUtil.newMissingElementException(nodeAdviceExpressions, XACML3.XMLNS,
                XACML3.ELEMENT_ADVICEEXPRESSION);
    }
    return listAdviceExpressions;
}

From source file:org.apache.openaz.xacml.pdp.policy.dom.DOMAdviceExpression.java

public static boolean repairList(Node nodeAdviceExpressions) throws DOMStructureException {
    Element elementAdviceExpressions = DOMUtil.getElement(nodeAdviceExpressions);
    boolean result = false;

    boolean sawAdviceExpression = false;
    NodeList children = elementAdviceExpressions.getChildNodes();
    int numChildren;
    if (children != null && (numChildren = children.getLength()) > 0) {
        for (int i = 0; i < numChildren; i++) {
            Node child = children.item(i);
            if (DOMUtil.isElement(child)) {
                if (DOMUtil.isInNamespace(child, XACML3.XMLNS)
                        && XACML3.ELEMENT_ADVICEEXPRESSION.equals(child.getLocalName())) {
                    sawAdviceExpression = true;
                    result = result || DOMAdviceExpression.repair(child);
                } else {
                    logger.warn("Unexpected element " + child.getNodeName());
                    nodeAdviceExpressions.removeChild(child);
                    result = true;/* ww  w  .j  ava2s  .  c om*/
                }
            }
        }
    }

    if (!sawAdviceExpression) {
        throw DOMUtil.newMissingElementException(nodeAdviceExpressions, XACML3.XMLNS,
                XACML3.ELEMENT_ADVICEEXPRESSION);
    }

    return result;
}

From source file:org.apache.openaz.xacml.pdp.policy.dom.DOMAllOf.java

/**
 * Creates a new <code>DOMAllOf</code> by parsing the given <code>Node</code> representing a XACML AllOf
 * element.//from w ww  . jav a  2s.c o  m
 *
 * @param nodeAllOf the <code>Node</code> representing the XACML AllOf element
 * @return a new <code>DOMAllOf</code> parsed from the given <code>Node</code>
 * @throws DOMStructureException if there is an error parsing the given <code>Node</code>
 */
public static AllOf newInstance(Node nodeAllOf) throws DOMStructureException {
    Element elementAllOf = DOMUtil.getElement(nodeAllOf);
    boolean bLenient = DOMProperties.isLenient();

    DOMAllOf domAllOf = new DOMAllOf();

    try {
        NodeList children = elementAllOf.getChildNodes();
        int numChildren;
        boolean sawMatch = false;
        if (children != null && (numChildren = children.getLength()) > 0) {
            for (int i = 0; i < numChildren; i++) {
                Node child = children.item(i);
                if (DOMUtil.isElement(child)) {
                    if (DOMUtil.isInNamespace(child, XACML3.XMLNS)
                            && XACML3.ELEMENT_MATCH.equals(child.getLocalName())) {
                        domAllOf.addMatch(DOMMatch.newInstance(child));
                        sawMatch = true;
                    } else if (!bLenient) {
                        throw DOMUtil.newUnexpectedElementException(child, nodeAllOf);
                    }
                }
            }
        }
        if (!sawMatch && !bLenient) {
            throw DOMUtil.newMissingElementException(nodeAllOf, XACML3.XMLNS, XACML3.ELEMENT_MATCH);
        }
    } catch (DOMStructureException ex) {
        domAllOf.setStatus(StdStatusCode.STATUS_CODE_SYNTAX_ERROR, ex.getMessage());
        if (DOMProperties.throwsExceptions()) {
            throw ex;
        }
    }
    return domAllOf;
}

From source file:org.apache.openaz.xacml.pdp.policy.dom.DOMAllOf.java

public static boolean repair(Node nodeAllOf) throws DOMStructureException {
    Element elementAllOf = DOMUtil.getElement(nodeAllOf);
    boolean result = false;

    NodeList children = elementAllOf.getChildNodes();
    int numChildren;
    boolean sawMatch = false;
    if (children != null && (numChildren = children.getLength()) > 0) {
        for (int i = 0; i < numChildren; i++) {
            Node child = children.item(i);
            if (DOMUtil.isElement(child)) {
                if (DOMUtil.isInNamespace(child, XACML3.XMLNS)
                        && XACML3.ELEMENT_MATCH.equals(child.getLocalName())) {
                    result = DOMMatch.repair(child) || result;
                    sawMatch = true;/* w ww  .  j a va2  s  .  c o  m*/
                } else {
                    logger.warn("Unexpected element " + child.getNodeName());
                    elementAllOf.removeChild(child);
                    result = true;
                }
            }
        }
    }
    if (!sawMatch) {
        throw DOMUtil.newMissingElementException(nodeAllOf, XACML3.XMLNS, XACML3.ELEMENT_MATCH);
    }

    return result;
}