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.openaz.xacml.pdp.policy.dom.DOMAnyOf.java

/**
 * Creates a new <code>DOMAnyOf</code> by parsing the given <code>Node</code> representing a XACML AnyOf
 * element.//w  w  w . j a v  a2 s  .c o m
 *
 * @param nodeAnyOf the <code>Node</code> representing the XACML AnyOf element
 * @return a new <code>DOMAnyOf</code> parsed from the given <code>Node</code>
 * @throws DOMStructureException if there is an error parsing the given <code>Node</code>.
 */
public static AnyOf newInstance(Node nodeAnyOf) throws DOMStructureException {
    Element elementAnyOf = DOMUtil.getElement(nodeAnyOf);
    boolean bLenient = DOMProperties.isLenient();

    DOMAnyOf domAnyOf = new DOMAnyOf();

    try {
        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())) {
                        domAnyOf.addAllOf(DOMAllOf.newInstance(child));
                    } else if (!bLenient) {
                        throw DOMUtil.newUnexpectedElementException(child, nodeAnyOf);
                    }
                }
            }
        }
    } catch (DOMStructureException ex) {
        domAnyOf.setStatus(StdStatusCode.STATUS_CODE_SYNTAX_ERROR, ex.getMessage());
        if (DOMProperties.throwsExceptions()) {
            throw ex;
        }
    }

    return domAnyOf;
}

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;//  ww w  .jav  a2 s .  c  o  m
                }
            }
        }
    }

    return result;
}

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

/**
 * Creates a new <code>Apply</code> by parsing the given
 * <code>Node</core> representing a XACML Apply element.
 *
 * @param nodeApply the <code>Node</code> representing the XACML Apply element
 * @param policy the <code>Policy</code> encompassing the Apply element
 * @return a new <code>Apply</code> parsed from the given <code>Node</code>
 * @throws DOMStructureException if there is an error parsing the <code>Node</code>
 *///from   ww w. jav  a2s  . co  m
public static Apply newInstance(Node nodeApply, Policy policy) throws DOMStructureException {
    Element elementApply = DOMUtil.getElement(nodeApply);
    boolean bLenient = DOMProperties.isLenient();

    DOMApply domApply = new DOMApply();

    try {
        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)) {
                        domApply.setDescription(child.getTextContent());
                    } else if (DOMExpression.isExpression(child)) {
                        domApply.addArgument(DOMExpression.newInstance(child, policy));
                    } else if (!bLenient) {
                        throw DOMUtil.newUnexpectedElementException(child, nodeApply);
                    }
                }
            }
        }

        domApply.setFunctionId(
                DOMUtil.getIdentifierAttribute(elementApply, XACML3.ATTRIBUTE_FUNCTIONID, !bLenient));
    } catch (DOMStructureException ex) {
        domApply.setStatus(StdStatusCode.STATUS_CODE_SYNTAX_ERROR, ex.getMessage());
        if (DOMProperties.throwsExceptions()) {
            throw ex;
        }
    }

    return domApply;
}

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;//from ww w  .  j  a  v a 2 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.DOMCombinerParameter.java

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

    DOMCombinerParameter combinerParameter = new DOMCombinerParameter();

    try {
        NodeList children = elementCombinerParameter.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_ATTRIBUTEVALUE.equals(child.getLocalName())) {
                        if (combinerParameter.getAttributeValue() != null && !bLenient) {
                            throw DOMUtil.newUnexpectedElementException(child, elementCombinerParameter);
                        } else {
                            combinerParameter.setAttributeValue(DOMAttributeValue.newInstance(child, null));
                        }
                    } else if (!bLenient) {
                        throw DOMUtil.newUnexpectedElementException(child, elementCombinerParameter);
                    }
                }
            }
        }

        if (combinerParameter.getAttributeValue() == null && !bLenient) {
            throw DOMUtil.newMissingElementException(elementCombinerParameter, XACML3.XMLNS,
                    XACML3.ELEMENT_ATTRIBUTEVALUE);
        }
        combinerParameter.setName(DOMUtil.getStringAttribute(elementCombinerParameter,
                XACML3.ATTRIBUTE_PARAMETERNAME, !bLenient));
    } catch (DOMStructureException ex) {
        combinerParameter.setStatus(StdStatusCode.STATUS_CODE_SYNTAX_ERROR, ex.getMessage());
        if (DOMProperties.throwsExceptions()) {
            throw ex;
        }
    }

    return combinerParameter;
}

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   www .jav a2 s .  c om
                    } 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

/**
 * Creates a <code>List</code> of <code>CombinerParameter</code>s by parsing the given <code>Node</code>
 * representing a XACML CombinerParameters element.
 *
 * @param nodeCombinerParameters the <code>Node</code> representing the XACML CombinerParameters element
 * @return a <code>List</code> of <code>CombinerParameter</code>s parsed from the given <code>Node</code>.
 * @throws DOMStructureException if there is an error parsing the <code>Node</code>
 *//*from   w ww  .  j  a v a 2  s .  c o m*/
public static List<CombinerParameter> newList(Node nodeCombinerParameters) throws DOMStructureException {
    Element elementCombinerParameters = DOMUtil.getElement(nodeCombinerParameters);
    boolean bLenient = DOMProperties.isLenient();

    List<CombinerParameter> listCombinerParameters = new ArrayList<CombinerParameter>();

    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())) {
                    listCombinerParameters.add(DOMCombinerParameter.newInstance(child));
                } else if (!bLenient) {
                    throw DOMUtil.newUnexpectedElementException(child, elementCombinerParameters);
                }
            }
        }
    }
    return listCombinerParameters;
}

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;//w w w  .  ja v  a2  s  .co m
                }
            }
        }
    }
    return result;
}

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

public static boolean isExpression(Node nodeExpression) {
    String nodeName = nodeExpression.getLocalName();
    return XACML3.ELEMENT_APPLY.equals(nodeName) || XACML3.ELEMENT_ATTRIBUTEDESIGNATOR.equals(nodeName)
            || XACML3.ELEMENT_ATTRIBUTESELECTOR.equals(nodeName)
            || XACML3.ELEMENT_ATTRIBUTEVALUE.equals(nodeName) || XACML3.ELEMENT_FUNCTION.equals(nodeName)
            || XACML3.ELEMENT_VARIABLEREFERENCE.equals(nodeName);
}

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

/**
 * Creates a new <code>DOMMatch</code> by parsing the given <code>Node</code> representing a XACML Match
 * element./*w ww.j a v  a2  s.c  o m*/
 *
 * @param nodeMatch the <code>Node</code> representing the XACML Match element
 * @return a new <code>DOMMatch</code> parsed from the given <code>Node</code>
 * @throws DOMStructureException if there is an error parsing the given <code>Node</code>
 */
public static Match newInstance(Node nodeMatch) throws DOMStructureException {
    Element elementMatch = DOMUtil.getElement(nodeMatch);
    boolean bLenient = DOMProperties.isLenient();

    DOMMatch domMatch = new DOMMatch();

    try {
        NodeList children = elementMatch.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_ATTRIBUTEVALUE.equals(childName)) {
                            domMatch.setAttributeValue(DOMAttributeValue.newInstance(child, null));
                        } else if (XACML3.ELEMENT_ATTRIBUTEDESIGNATOR.equals(childName)) {
                            if (domMatch.getAttributeRetrievalBase() != null && !bLenient) {
                                throw DOMUtil.newUnexpectedElementException(child, nodeMatch);
                            }
                            domMatch.setAttributeRetrievalBase(DOMAttributeDesignator.newInstance(child));
                        } else if (XACML3.ELEMENT_ATTRIBUTESELECTOR.equals(childName)) {
                            if (domMatch.getAttributeRetrievalBase() != null) {
                                throw DOMUtil.newUnexpectedElementException(child, nodeMatch);
                            }
                            domMatch.setAttributeRetrievalBase(DOMAttributeSelector.newInstance(child));
                        } else if (!bLenient) {
                            throw DOMUtil.newUnexpectedElementException(child, nodeMatch);
                        }
                    } else if (!bLenient) {
                        throw DOMUtil.newUnexpectedElementException(child, nodeMatch);
                    }
                }
            }
        }

        /*
         * We have to see exactly one of these
         */
        if (domMatch.getAttributeRetrievalBase() == null && !bLenient) {
            throw DOMUtil.newMissingElementException(nodeMatch, XACML3.XMLNS,
                    XACML3.ELEMENT_ATTRIBUTEDESIGNATOR + " or " + XACML3.ELEMENT_ATTRIBUTESELECTOR);
        } else if (domMatch.getAttributeValue() == null && !bLenient) {
            throw DOMUtil.newMissingElementException(nodeMatch, XACML3.XMLNS, XACML3.ELEMENT_ATTRIBUTEVALUE);
        }

        domMatch.setMatchId(DOMUtil.getIdentifierAttribute(elementMatch, XACML3.ATTRIBUTE_MATCHID, !bLenient));

    } catch (DOMStructureException ex) {
        domMatch.setStatus(StdStatusCode.STATUS_CODE_SYNTAX_ERROR, ex.getMessage());
        if (DOMProperties.throwsExceptions()) {
            throw ex;
        }
    }
    return domMatch;
}