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:nl.nn.adapterframework.extensions.bis.BisJmsSender.java

public String sendMessage(String correlationID, String message, ParameterResolutionContext prc)
        throws SenderException, TimeOutException {
    String messageHeader;/*w w  w .  j  ava  2  s. c o m*/
    try {
        messageHeader = bisUtils.prepareMessageHeader(null, isMessageHeaderInSoapBody(),
                (String) prc.getSession().get(getConversationIdSessionKey()),
                (String) prc.getSession().get(getExternalRefToMessageIdSessionKey()));
    } catch (Exception e) {
        throw new SenderException(e);
    }
    String payload;
    try {
        payload = bisUtils.prepareReply(message, isMessageHeaderInSoapBody() ? messageHeader : null, null,
                false);
        if (StringUtils.isNotEmpty(getRequestNamespace())) {
            payload = XmlUtils.addRootNamespace(payload, getRequestNamespace());
        }
    } catch (Exception e) {
        throw new SenderException(e);
    }
    String replyMessage = super.sendMessage(correlationID, payload, prc,
            isMessageHeaderInSoapBody() ? null : messageHeader);
    if (isSynchronous()) {
        String bisError;
        String bisErrorList;
        try {
            bisError = bisErrorTp.transform(replyMessage, null, true);
            bisErrorList = bisErrorListTp.transform(replyMessage, null, true);
        } catch (Exception e) {
            throw new SenderException(e);
        }
        if (Boolean.valueOf(bisError).booleanValue()) {
            log.debug("put in session [" + getErrorListSessionKey() + "] [" + bisErrorList + "]");
            prc.getSession().put(getErrorListSessionKey(), bisErrorList);
            throw new SenderException("bisErrorXPath ["
                    + (isResultInPayload() ? bisUtils.getBisErrorXPath() : bisUtils.getOldBisErrorXPath())
                    + "] returns true");
        }
        try {
            replyMessage = responseTp.transform(replyMessage, null, true);
            if (isRemoveResponseNamespaces()) {
                replyMessage = XmlUtils.removeNamespaces(replyMessage);
            }
            if (isResultInPayload()) {
                Element soapBodyElement = XmlUtils.buildElement(replyMessage, true);
                Element resultElement = XmlUtils.getFirstChildTag(soapBodyElement, "Result");
                if (resultElement != null) {
                    soapBodyElement.removeChild(resultElement);
                }
                replyMessage = XmlUtils.nodeToString(soapBodyElement);
            }
            return replyMessage;

        } catch (Exception e) {
            throw new SenderException(e);
        }

    } else {
        return replyMessage;
    }
}

From source file:org.apache.ode.axis2.AuthenticationHelper.java

public static void setHttpAuthentication(PartnerRoleMessageExchange odeMex, Options options) {
    Element msg = odeMex.getRequest().getMessage();
    if (msg != null) {
        Element part = DOMUtils.getFirstChildElement(msg);
        while (part != null) {
            Element content = DOMUtils.getFirstChildElement(part);
            if (content != null) {
                if (AUTHENTICATION_NS.equals(content.getNamespaceURI())
                        && AUTHENTICATE_ELEMENT.equals(content.getLocalName())) {
                    setOptions(options, content);
                    msg.removeChild(part);
                    break;
                }// w  w  w  .j  a va 2  s  .co m
            }
            part = DOMUtils.getNextSiblingElement(part);
        }
    }
}

From source file:org.apache.ode.bpel.engine.BpelRuntimeContextImpl.java

protected void buildOutgoingMessage(MessageDAO message, Element outgoingElmt) {
    if (outgoingElmt == null)
        return;//from  w w  w  . jav a 2  s .  c  om

    Document doc = DOMUtils.newDocument();
    Element header = doc.createElement("header");
    NodeList parts = outgoingElmt.getChildNodes();
    for (int m = 0; m < parts.getLength(); m++) {
        if (parts.item(m).getNodeType() == Node.ELEMENT_NODE) {
            Element part = (Element) parts.item(m);
            if (part.getAttribute("headerPart") != null && part.getAttribute("headerPart").length() > 0) {
                header.appendChild(doc.importNode(part, true));
                // remove the element from the list AND decrement the index to avoid skipping the next element!!
                outgoingElmt.removeChild(part);
                m--;
            }
        }
    }
    message.setData(outgoingElmt);
    message.setHeader(header);
}

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;//www .  j a v a2  s  . c om
                } 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;
}

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

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

    NodeList children = elementAnyOf.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_ALLOF.equals(child.getLocalName())) {
                    result = DOMAllOf.repair(child) || result;
                } else {
                    logger.warn("Unexpected element " + child.getNodeName());
                    elementAnyOf.removeChild(child);
                    result = true;/*from  w  w w  .  j  ava  2s .co m*/
                }
            }
        }
    }

    return result;
}

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

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

    NodeList children = nodeApply.getChildNodes();
    if (children != null) {
        int numChildren = children.getLength();
        for (int i = 0; i < numChildren; i++) {
            Node child = children.item(i);
            if (child.getNodeType() == Node.ELEMENT_NODE && XACML3.XMLNS.equals(child.getNamespaceURI())) {
                String childName = child.getLocalName();
                if (XACML3.ELEMENT_DESCRIPTION.equals(childName)) { //NOPMD
                    // TODO
                } else if (DOMExpression.isExpression(child)) {
                    result = DOMExpression.repair(child) || result;
                } else {
                    logger.warn("Unexpected element " + child.getNodeName());
                    elementApply.removeChild(child);
                    result = true;/* w  w w. j av a2 s  .  c o  m*/
                }
            }
        }
    }

    result = DOMUtil.repairIdentifierAttribute(elementApply, XACML3.ATTRIBUTE_FUNCTIONID,
            XACML3.ID_FUNCTION_STRING_EQUAL, logger) || result;

    return result;
}

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

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

    if (DOMUtil.getFirstChildElement(elementAttributeAssignmentExpression) == null) {
        /*/*from  w  w  w  .ja  v a2s  .com*/
         * See if we can repair the <AttributeAssignmentExpression
         * DataType="">string</AttributeAssignmentExpression> pattern
         */
        Identifier identifier = DOMUtil.getIdentifierAttribute(elementAttributeAssignmentExpression,
                XACML3.ATTRIBUTE_DATATYPE);
        String textContent = elementAttributeAssignmentExpression.getTextContent();
        if (textContent != null) {
            textContent = textContent.trim();
        }
        if (textContent != null && textContent.length() > 0 && identifier != null) {
            Element attributeValue = elementAttributeAssignmentExpression.getOwnerDocument()
                    .createElementNS(XACML3.XMLNS, XACML3.ELEMENT_ATTRIBUTEVALUE);
            attributeValue.setAttribute(XACML3.ATTRIBUTE_DATATYPE, identifier.stringValue());
            attributeValue.setTextContent(textContent);
            logger.warn("Adding a new AttributeValue using the DataType from the AttributeAssignment");
            elementAttributeAssignmentExpression.removeAttribute(XACML3.ATTRIBUTE_DATATYPE);
            while (elementAttributeAssignmentExpression.hasChildNodes()) {
                elementAttributeAssignmentExpression
                        .removeChild(elementAttributeAssignmentExpression.getFirstChild());
            }
            elementAttributeAssignmentExpression.appendChild(attributeValue);
            result = true;
        } else {
            throw DOMUtil.newMissingElementException(elementAttributeAssignmentExpression, XACML3.XMLNS,
                    XACML3.ELEMENT_EXPRESSION);
        }
    }
    result = DOMUtil.repairIdentifierAttribute(elementAttributeAssignmentExpression,
            XACML3.ATTRIBUTE_ATTRIBUTEID, logger) || result;

    return result;
}

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

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

    NodeList children = elementCombinerParameter.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)
                        && XACML3.ELEMENT_ATTRIBUTEVALUE.equals(child.getLocalName())) {
                    if (sawAttributeValue) {
                        logger.warn("Unexpected element " + child.getNodeName());
                        elementCombinerParameter.removeChild(child);
                        result = true;/*from   ww w.  ja v a 2 s.c  o m*/
                    } else {
                        result = DOMAttributeValue.repair(child) || result;
                        sawAttributeValue = true;
                    }
                } else {
                    logger.warn("Unexpected element " + child.getNodeName());
                    elementCombinerParameter.removeChild(child);
                    result = true;
                }
            }
        }
    }

    if (!sawAttributeValue) {
        throw DOMUtil.newMissingElementException(elementCombinerParameter, XACML3.XMLNS,
                XACML3.ELEMENT_ATTRIBUTEVALUE);
    }

    result = DOMUtil.repairStringAttribute(elementCombinerParameter, XACML3.ATTRIBUTE_PARAMETERNAME,
            "parameter", logger) || result;

    return result;
}

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

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

    NodeList children = elementCombinerParameters.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_COMBINERPARAMETER.equals(child.getLocalName())) {
                    result = DOMCombinerParameter.repair(child) || result;
                } else {
                    logger.warn("Unexpected element " + child.getNodeName());
                    elementCombinerParameters.removeChild(child);
                    result = true;//  ww w . j  av  a  2  s  .  com
                }
            }
        }
    }
    return result;
}

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

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

    NodeList children = elementMatch.getChildNodes();
    int numChildren;
    boolean sawAttributeRetrievalBase = false;
    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)) {
                    String childName = child.getLocalName();
                    if (XACML3.ELEMENT_ATTRIBUTEVALUE.equals(childName)) {
                        if (sawAttributeValue) {
                            logger.warn("Unexpected element " + child.getNodeName());
                            elementMatch.removeChild(child);
                            result = true;
                        } else {
                            result = DOMAttributeValue.repair(child) || result;
                            sawAttributeValue = true;
                        }/* w  ww.  ja v a 2 s  .c om*/
                    } else if (XACML3.ELEMENT_ATTRIBUTEDESIGNATOR.equals(childName)) {
                        if (sawAttributeRetrievalBase) {
                            logger.warn("Unexpected element " + child.getNodeName());
                            elementMatch.removeChild(child);
                            result = true;
                        } else {
                            result = DOMAttributeDesignator.repair(child) || result;
                            sawAttributeRetrievalBase = true;
                        }
                    } else if (XACML3.ELEMENT_ATTRIBUTESELECTOR.equals(childName)) {
                        if (sawAttributeRetrievalBase) {
                            logger.warn("Unexpected element " + child.getNodeName());
                            elementMatch.removeChild(child);
                            result = true;
                        } else {
                            result = DOMAttributeSelector.repair(child) || result;
                            sawAttributeRetrievalBase = true;
                        }
                    } else {
                        logger.warn("Unexpected element " + child.getNodeName());
                        elementMatch.removeChild(child);
                        result = true;
                    }
                } else {
                    logger.warn("Unexpected element " + child.getNodeName());
                    elementMatch.removeChild(child);
                    result = true;
                }
            }
        }
    }

    /*
     * We have to see exactly one of these
     */
    if (!sawAttributeRetrievalBase) {
        throw DOMUtil.newMissingElementException(nodeMatch, XACML3.XMLNS,
                XACML3.ELEMENT_ATTRIBUTEDESIGNATOR + " or " + XACML3.ELEMENT_ATTRIBUTESELECTOR);
    } else if (!sawAttributeValue) {
        throw DOMUtil.newMissingElementException(nodeMatch, XACML3.XMLNS, XACML3.ELEMENT_ATTRIBUTEVALUE);
    }
    result = DOMUtil.repairIdentifierAttribute(elementMatch, XACML3.ATTRIBUTE_MATCHID, logger) || result;

    return result;
}