Example usage for org.w3c.dom Element removeChild

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

Introduction

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

Prototype

public Node removeChild(Node oldChild) throws DOMException;

Source Link

Document

Removes the child node indicated by oldChild from the list of children, and returns it.

Usage

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

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

    NodeList children = elementTarget.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_ANYOF.equals(child.getLocalName())) {
                    result = DOMAnyOf.repair(child) || result;
                } else {
                    logger.warn("Unexpected element " + child.getNodeName());
                    elementTarget.removeChild(child);
                    result = true;//from  w w w.j  a va2 s  .com
                }
            }
        }
    }

    return result;
}

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

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

    Element elementExpression = DOMUtil.getFirstChildElement(elementVariableDefinition);
    if (elementExpression != null) {
        if (DOMExpression.isExpression(elementExpression)) {
            result = result || DOMExpression.repair(elementExpression);
        } else {/*w  w  w  .  j a  v  a 2 s  . com*/
            logger.warn("Unexpected element " + elementExpression.getNodeName());
            elementVariableDefinition.removeChild(elementExpression);
            result = true;
        }
    } else {
        throw DOMUtil.newMissingElementException(elementVariableDefinition, XACML3.XMLNS,
                XACML3.ELEMENT_EXPRESSION);
    }

    result = result || DOMUtil.repairStringAttribute(elementVariableDefinition, XACML3.ATTRIBUTE_VARIABLEID,
            "variable", logger);
    return result;
}

From source file:org.apache.openaz.xacml.std.dom.DOMAdvice.java

/**
 * Repairs the given <code>Node</code> representing a XACML Advice element if possible.
 *
 * @param nodeAdvice the <code>Node</code> to repair
 * @return true if the node was altered, else false
 * @throws DOMStructureException if an error occurred while repairing the <code>Node</code>
 *///  www .java2 s. c o  m
public static boolean repair(Node nodeAdvice) throws DOMStructureException {
    Element elementAdvice = DOMUtil.getElement(nodeAdvice);
    boolean result = false;

    result = result || DOMUtil.repairIdentifierAttribute(elementAdvice, XACML3.ATTRIBUTE_ADVICEID, logger);

    NodeList children = elementAdvice.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)) {
                    if (XACML3.ELEMENT_ATTRIBUTEASSIGNMENT.equals(child.getLocalName())) {
                        result = DOMAttributeAssignment.repair(child) || result;
                    } else {
                        logger.warn("Unexpected element " + child.getNodeName());
                        elementAdvice.removeChild(child);
                        result = true;
                    }
                } else {
                    logger.warn("Unexpected element " + child.getNodeName());
                    elementAdvice.removeChild(child);
                    result = true;
                }
            }
        }
    }
    return result;
}

From source file:org.apache.openaz.xacml.std.dom.DOMAdvice.java

public static boolean repairList(Node nodeAssociatedAdvice) throws DOMStructureException {
    Element elementAssociatedAdvice = DOMUtil.getElement(nodeAssociatedAdvice);
    boolean result = false;
    NodeList children = elementAssociatedAdvice.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)) {
                    if (XACML3.ELEMENT_ADVICE.equals(child.getLocalName())) {
                        result = repair(child) || result;
                    } else {
                        logger.warn("Unexpected element " + child.getNodeName());
                        elementAssociatedAdvice.removeChild(child);
                        result = true;/*from   ww w .  j a va 2s .c  o m*/
                    }
                } else {
                    logger.warn("Unexpected element " + child.getNodeName());
                    elementAssociatedAdvice.removeChild(child);
                    result = true;
                }
            }
        }
    }

    return result;
}

From source file:org.apache.openaz.xacml.std.dom.DOMAttribute.java

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

    result = DOMUtil.repairIdentifierAttribute(elementAttribute, XACML3.ATTRIBUTE_ATTRIBUTEID, logger)
            || result;/* w w  w.  j ava 2  s.c om*/
    result = DOMUtil.repairBooleanAttribute(elementAttribute, XACML3.ATTRIBUTE_INCLUDEINRESULT, false, logger)
            || result;

    NodeList children = elementAttribute.getChildNodes();
    int numChildren;
    boolean sawAttributeValue = 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)) {
                    if (XACML3.ELEMENT_ATTRIBUTEVALUE.equals(child.getLocalName())) {
                        result = DOMAttributeValue.repair(child) || result;
                        sawAttributeValue = true;
                    } else {
                        logger.warn("Unexpected element " + child.getNodeName());
                        elementAttribute.removeChild(child);
                        result = true;
                    }
                } else {
                    logger.warn("Unexpected element " + child.getNodeName());
                    elementAttribute.removeChild(child);
                    result = true;
                }
            }
        }
    }

    if (!sawAttributeValue) {
        throw new DOMStructureException(
                DOMUtil.newMissingAttributeException(elementAttribute, XACML3.ELEMENT_ATTRIBUTEVALUE));
    }

    return result;
}

From source file:org.apache.openaz.xacml.std.dom.DOMAttributeCategory.java

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

    result = DOMUtil.repairIdentifierAttribute(elementAttributeCategory, XACML3.ATTRIBUTE_CATEGORY, logger)
            || result;/*from   www.  j  a  v  a 2  s .  c  om*/

    NodeList children = elementAttributeCategory.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)) {
                    if (XACML3.ELEMENT_ATTRIBUTE.equals(child.getLocalName())) {
                        result = DOMAttribute.repair(child) || result;
                    } else {
                        logger.warn("Unexpected element " + child.getNodeName());
                        elementAttributeCategory.removeChild(child);
                        result = true;
                    }
                } else {
                    logger.warn("Unexpected element " + child.getNodeName());
                    elementAttributeCategory.removeChild(child);
                    result = true;
                }
            }
        }
    }

    return result;
}

From source file:org.apache.openaz.xacml.std.dom.DOMObligation.java

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

    result = DOMUtil.repairIdentifierAttribute(elementObligation, XACML3.ATTRIBUTE_OBLIGATIONID, logger)
            || result;//from ww w .  j a v  a2  s.c om

    NodeList children = elementObligation.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)) {
                    if (XACML3.ELEMENT_ATTRIBUTEASSIGNMENT.equals(child.getLocalName())) {
                        result = DOMAttributeAssignment.repair(child) || result;
                    } else {
                        logger.warn("Unexpected element " + child.getNodeName());
                        elementObligation.removeChild(child);
                        result = true;
                    }
                } else {
                    logger.warn("Unexpected element " + child.getNodeName());
                    elementObligation.removeChild(child);
                    result = true;
                }
            }
        }
    }

    return result;
}

From source file:org.apache.openaz.xacml.std.dom.DOMObligation.java

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

    NodeList children = elementObligations.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)) {
                    if (XACML3.ELEMENT_OBLIGATION.equals(child.getLocalName())) {
                        result = result || DOMObligation.repair(child);
                    } else {
                        logger.warn("Unexpected element " + child.getNodeName());
                        elementObligations.removeChild(child);
                        result = true;//  w  ww  .java  2  s  .  co m
                    }
                } else {
                    logger.warn("Unexpected element " + child.getNodeName());
                    elementObligations.removeChild(child);
                    result = true;
                }
            }
        }
    }

    return result;
}

From source file:org.apache.openaz.xacml.std.dom.DOMRequest.java

/**
 * Convert XACML2 into XACML3.//  w  w w .java2  s  .  c om
 *
 * @param nodeRequest
 * @return
 * @throws DOMStructureException
 */
public static boolean repair(Node nodeRequest) throws DOMStructureException {
    Element elementRequest = DOMUtil.getElement(nodeRequest);
    boolean result = false;

    result = DOMUtil.repairBooleanAttribute(elementRequest, XACML3.ATTRIBUTE_RETURNPOLICYIDLIST, false, logger)
            || result;
    result = DOMUtil.repairBooleanAttribute(elementRequest, XACML3.ATTRIBUTE_COMBINEDDECISION, false, logger)
            || result;

    NodeList children = elementRequest.getChildNodes();
    int numChildren;
    boolean sawAttributes = 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)) {
                    String childName = child.getLocalName();
                    if (XACML3.ELEMENT_ATTRIBUTES.equals(childName)) {
                        result = DOMRequestAttributes.repair(child) || result;
                        sawAttributes = true;
                    } else if (XACML3.ELEMENT_REQUESTDEFAULTS.equals(childName)) {
                        result = result || DOMRequestDefaults.repair(child);
                    } else if (XACML3.ELEMENT_MULTIREQUESTS.equals(childName)) {
                        NodeList grandchildren = child.getChildNodes();
                        int numGrandchildren;
                        if (grandchildren != null && (numGrandchildren = grandchildren.getLength()) > 0) {
                            for (int j = 0; j < numGrandchildren; j++) {
                                Node grandchild = grandchildren.item(j);
                                if (DOMUtil.isElement(grandchild)) {
                                    if (DOMUtil.isInNamespace(grandchild, XACML3.XMLNS)) {
                                        if (XACML3.ELEMENT_REQUESTREFERENCE.equals(grandchild.getLocalName())) {
                                            result = DOMRequestReference.repair(grandchild) || result;
                                        } else {
                                            logger.warn("Unexpected element " + grandchild.getNodeName());
                                            child.removeChild(grandchild);
                                            result = true;
                                        }
                                    } else {
                                        logger.warn("Unexpected element " + grandchild.getNodeName());
                                        child.removeChild(grandchild);
                                        result = true;
                                    }
                                }
                            }
                        }
                    } else {
                        logger.warn("Unexpected element " + child.getNodeName());
                        elementRequest.removeChild(child);
                        result = true;
                    }
                } else {
                    logger.warn("Unexpected element " + child.getNodeName());
                    elementRequest.removeChild(child);
                    result = true;
                }
            }
        }
    }
    if (!sawAttributes) {
        throw DOMUtil.newMissingElementException(nodeRequest, XACML3.XMLNS, XACML3.ELEMENT_ATTRIBUTES);
    }

    return result;
}

From source file:org.apache.openaz.xacml.std.dom.DOMRequestAttributes.java

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

    result = DOMUtil.repairIdentifierAttribute(elementRequestAttributes, XACML3.ATTRIBUTE_CATEGORY, logger)
            || result;//from ww  w.jav a  2s.c o  m
    NodeList children = elementRequestAttributes.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)) {
                    String childName = child.getLocalName();
                    if (XACML3.ELEMENT_ATTRIBUTE.equals(childName)) {
                        result = DOMAttribute.repair(child) || result;
                        //} else if (XACML3.ELEMENT_CONTENT.equals(childName)) {
                    } else {
                        logger.warn("Unexpected element " + child.getNodeName());
                        elementRequestAttributes.removeChild(child);
                        result = true;
                    }
                } else {
                    logger.warn("Unexpected element " + child.getNodeName());
                    elementRequestAttributes.removeChild(child);
                    result = true;
                }
            }
        }
    }

    return result;
}