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.DOMRuleCombinerParameters.java

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

    NodeList children = elementRuleCombinerParameters.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());
                        elementRuleCombinerParameters.removeChild(child);
                        result = true;/*from   ww  w.j  av  a 2s .c  om*/
                    } else {
                        sawAttributeValue = true;
                        result = result || DOMAttributeValue.repair(child);
                    }
                } else {
                    logger.warn("Unexpected element " + child.getNodeName());
                    elementRuleCombinerParameters.removeChild(child);
                    result = true;
                }
            }
        }
    }
    if (!sawAttributeValue) {
        throw DOMUtil.newMissingElementException(nodeRuleCombinerParameters, XACML3.XMLNS,
                XACML3.ELEMENT_ATTRIBUTEVALUE);
    }
    result = result || DOMUtil.repairStringAttribute(elementRuleCombinerParameters,
            XACML3.ATTRIBUTE_PARAMETERNAME, "parameter", logger);
    result = result || DOMUtil.repairIdentifierAttribute(elementRuleCombinerParameters,
            XACML3.ATTRIBUTE_RULEIDREF, logger);

    return result;
}

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

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

    DOMTarget domTarget = new DOMTarget();
    try {
        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())) {
                        domTarget.addAnyOf(DOMAnyOf.newInstance(child));
                    } else if (!bLenient) {
                        throw DOMUtil.newUnexpectedElementException(child, nodeTarget);
                    }
                }
            }
        }
    } catch (DOMStructureException ex) {
        domTarget.setStatus(StdStatusCode.STATUS_CODE_SYNTAX_ERROR, ex.getMessage());
        if (DOMProperties.throwsExceptions()) {
            throw ex;
        }
    }

    return domTarget;
}

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 ww  .j a  v  a  2s .co m
                }
            }
        }
    }

    return result;
}

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

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

    mutableAdvice.setId(DOMUtil.getIdentifierAttribute(elementAdvice, XACML3.ATTRIBUTE_ADVICEID, !bLenient));

    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())) {
                        mutableAdvice.addAttributeAssignment(DOMAttributeAssignment.newInstance(child));
                    } else {
                        if (!bLenient) {
                            throw DOMUtil.newUnexpectedElementException(child, nodeAdvice);
                        }
                    }
                } else {
                    if (!bLenient) {
                        throw DOMUtil.newUnexpectedElementException(child, nodeAdvice);
                    }
                }
            }
        }
    }

    return new StdAdvice(mutableAdvice);
}

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>
 *//*from  w ww.  j av  a 2 s. co  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

/**
 * Creates a <code>List</code> of <code>Advice</code> by parsing the given <code>Node</code> representing
 * a XACML AssociatedAdvice element.//from   w ww  .j  av a  2  s.  c om
 *
 * @param nodeAssociatedAdvice the <code>Node</code> representing the XACML AssociatedAdvice element
 * @return a <code>List</code> of <code>Advice</code> parsed from the given <code>Node</code>
 * @throws DOMStructureException if there is an error parsing the <code>Node</code>
 */
public static List<Advice> newList(Node nodeAssociatedAdvice) throws DOMStructureException {
    Element elementAssociatedAdvice = DOMUtil.getElement(nodeAssociatedAdvice);
    List<Advice> listAdvice = new ArrayList<Advice>();
    boolean bLenient = DOMProperties.isLenient();

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

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 www  .j av a  2 s. c om*/
                    }
                } 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

/**
 * Creates a new <code>DOMAttribute</code> by parsing the given {@link org.w3c.dom.Node}.
 *
 * @param category the {@link org.apache.openaz.xacml.common.Identfier} for the category of the new
 *            <code>DOMAttribute</code>.
 * @param nodeAttribute the <code>Node</code> for the <code>DOMAttribute</code>
 * @return a new <code>DOMAttribute</code> parsed from the given <code>Node</code>.
 * @throws IllegalArgumentException if there is an error converting the <code>Node</code> to a
 *             <code>DOMAttribute</code>
 *///from   w w  w . j  a v a2s  .co m
public static Attribute newInstance(Identifier category, Node nodeAttribute) throws DOMStructureException {
    Element elementAttribute = DOMUtil.getElement(nodeAttribute);
    boolean bLenient = DOMProperties.isLenient();
    StdMutableAttribute mutableAttribute = new StdMutableAttribute();

    mutableAttribute.setCategory(category);
    mutableAttribute.setAttributeId(
            DOMUtil.getIdentifierAttribute(nodeAttribute, XACML3.ATTRIBUTE_ATTRIBUTEID, !bLenient));

    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())) {
                        mutableAttribute.addValue(DOMAttributeValue.newInstance(child, category));
                        sawAttributeValue = true;
                    } else {
                        if (!bLenient) {
                            throw DOMUtil.newUnexpectedElementException(child, nodeAttribute);
                        }
                    }
                } else {
                    if (!bLenient) {
                        throw DOMUtil.newUnexpectedElementException(child, nodeAttribute);
                    }
                }
            }
        }
    }

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

    mutableAttribute.setIssuer(DOMUtil.getStringAttribute(nodeAttribute, XACML3.ATTRIBUTE_ISSUER));
    mutableAttribute.setIncludeInResults(
            DOMUtil.getBooleanAttribute(elementAttribute, XACML3.ATTRIBUTE_INCLUDEINRESULT, !bLenient));

    return new StdAttribute(mutableAttribute);
}

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;/*from  w ww.  j a  v a2 s. c o  m*/
    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

/**
 * Creates a new <code>DOMAttributeCategory</code> by parsing the given <code>Node</code> as a XACML
 * Attributes element.// w  w w  .  j  av  a  2 s.c  o  m
 *
 * @param nodeAttributeCategory the root <code>Node</code>
 * @return a new <code>DOMAttributeCategory</code> parsed from the given <code>Node</code>.
 * @throws DOMStructureException if the <code>Node</code> cannot be converted to a
 *             <code>DOMAttributeCategory</code>>
 */
public static AttributeCategory newInstance(Node nodeAttributeCategory) throws DOMStructureException {
    Element elementAttributeCategory = DOMUtil.getElement(nodeAttributeCategory);
    boolean bLenient = DOMProperties.isLenient();

    Identifier identifierCategory = DOMUtil.getIdentifierAttribute(nodeAttributeCategory,
            XACML3.ATTRIBUTE_CATEGORY, !bLenient);
    List<Attribute> listAttributes = new ArrayList<Attribute>();

    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())) {
                        listAttributes.add(DOMAttribute.newInstance(identifierCategory, child));
                    } else {
                        if (!bLenient) {
                            throw DOMUtil.newUnexpectedElementException(child, nodeAttributeCategory);
                        }
                    }
                } else {
                    if (!bLenient) {
                        throw DOMUtil.newUnexpectedElementException(child, nodeAttributeCategory);
                    }
                }
            }
        }
    }

    return new StdAttributeCategory(identifierCategory, listAttributes);
}