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.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;/* ww  w.j  ava2  s  . com*/

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

/**
 * Creates a new <code>DOMMissingAttributeDetail</code> by parsing the given <code>Node</code> as a XACML
 * MissingAttributeDetail element./*www  . j ava 2  s .c om*/
 *
 * @param nodeMissingAttributeDetail the <code>Node</code> representing the MissingAttributeDetail element
 * @return a new <code>DOMMissingAttributeDetail</code> parsed from the given <code>Node</code>
 * @throws org.apache.openaz.xacml.std.dom.DOMStructureException if the conversion is not possible
 */
public static MissingAttributeDetail newInstance(Node nodeMissingAttributeDetail) throws DOMStructureException {
    Element elementMissingAttributeDetail = DOMUtil.getElement(nodeMissingAttributeDetail);
    boolean bLenient = DOMProperties.isLenient();
    StdMutableMissingAttributeDetail mutableMissingAttributeDetail = new StdMutableMissingAttributeDetail();

    mutableMissingAttributeDetail.setCategory(DOMUtil.getIdentifierAttribute(elementMissingAttributeDetail,
            XACML3.ATTRIBUTE_CATEGORY, !bLenient));
    mutableMissingAttributeDetail.setAttributeId(DOMUtil.getIdentifierAttribute(elementMissingAttributeDetail,
            XACML3.ATTRIBUTE_ATTRIBUTEID, !bLenient));
    mutableMissingAttributeDetail.setDataTypeId(DOMUtil.getIdentifierAttribute(elementMissingAttributeDetail,
            XACML3.ATTRIBUTE_DATATYPE, !bLenient));
    mutableMissingAttributeDetail
            .setIssuer(DOMUtil.getStringAttribute(elementMissingAttributeDetail, XACML3.ATTRIBUTE_ISSUER));

    NodeList children = elementMissingAttributeDetail.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_ATTRIBUTEVALUE.equals(child.getLocalName())) {
                        mutableMissingAttributeDetail.addAttributeValue(DOMAttributeValue.newInstance(child,
                                mutableMissingAttributeDetail.getCategory()));
                    } else {
                        if (!bLenient) {
                            throw DOMUtil.newUnexpectedElementException(child, nodeMissingAttributeDetail);
                        }
                    }
                } else {
                    if (!bLenient) {
                        throw DOMUtil.newUnexpectedElementException(child, nodeMissingAttributeDetail);
                    }
                }
            }
        }
    }

    return new StdMissingAttributeDetail(mutableMissingAttributeDetail);
}

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

/**
 * Creates a new <code>Obligation</code> by parsing the given <code>Node</code> as a XACML Obligation
 * element./*from   w ww  .  j a  v a  2 s .c  o  m*/
 *
 * @param nodeObligation the <code>Node</code> representing the Obligation element
 * @return a new <code>DOMObligation</code> parsed from the given <code>Node</code>
 * @throws DOMStructureException if the conversion cannot be made
 */
public static Obligation newInstance(Node nodeObligation) throws DOMStructureException {
    Element elementObligation = DOMUtil.getElement(nodeObligation);
    boolean bLenient = DOMProperties.isLenient();
    StdMutableObligation mutableObligation = new StdMutableObligation();

    mutableObligation
            .setId(DOMUtil.getIdentifierAttribute(elementObligation, XACML3.ATTRIBUTE_OBLIGATIONID, !bLenient));

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

    return new StdObligation(mutableObligation);
}

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  w w w . j  a  v a2s.c  o m*/

    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

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

    List<Obligation> listObligations = new ArrayList<Obligation>();

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

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;/*from   w  w  w  .  ja  v a 2 s  .c  om*/
                    }
                } 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

/**
 * Read characters from the given <code>InputStream</code> and parse them into an XACML
 * {@link org.apache.openaz.xacml.api.Request} object.
 *
 * @param is//from w  w w . j a  va 2  s .c om
 * @return
 * @throws DOMStructureException
 */
public static Request load(InputStream is) throws DOMStructureException {
    Request request = null;
    try {
        Document document = DOMUtil.loadDocument(is);
        if (document == null) {
            throw new DOMStructureException("Null document returned");
        }

        Node rootNode = DOMUtil.getFirstChildElement(document);
        if (rootNode == null) {
            throw new DOMStructureException("No child in document");
        }

        if (DOMUtil.isInNamespace(rootNode, XACML3.XMLNS)) {
            if (XACML3.ELEMENT_REQUEST.equals(rootNode.getLocalName())) {
                request = DOMRequest.newInstance(rootNode);
                if (request == null) {
                    throw new DOMStructureException("Failed to parse Request");
                }
            } else {
                throw DOMUtil.newUnexpectedElementException(rootNode);
            }
        } else {
            throw DOMUtil.newUnexpectedElementException(rootNode);
        }
    } catch (Exception ex) {
        throw new DOMStructureException("Exception loading Request: " + ex.getMessage(), ex);
    }
    return request;
}

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

/**
 * Creates a new {@link org.apache.openaz.xacml.api.Request} by parsing the given <code>Node</code>
 * representing a XACML Request element.
 *
 * @param nodeRequest the <code>Node</code> representing the XACML Request element.
 * @return a new {@link org.apache.openaz.xacml.std.StdMutableRequest} parsed from the given
 *         <code>Node</code>
 * @throws DOMStructureException if the conversion cannot be made
 *//*  w ww. j  a  v  a2  s.co m*/
public static Request newInstance(Node nodeRequest) throws DOMStructureException {
    Element elementRequest = DOMUtil.getElement(nodeRequest);
    boolean bLenient = DOMProperties.isLenient();

    StdMutableRequest stdMutableRequest = new StdMutableRequest();

    stdMutableRequest.setReturnPolicyIdList(
            DOMUtil.getBooleanAttribute(elementRequest, XACML3.ATTRIBUTE_RETURNPOLICYIDLIST, !bLenient));
    stdMutableRequest.setCombinedDecision(
            DOMUtil.getBooleanAttribute(elementRequest, XACML3.ATTRIBUTE_COMBINEDDECISION, !bLenient));

    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)) {
                        stdMutableRequest.add(DOMRequestAttributes.newInstance(child));
                        sawAttributes = true;
                    } else if (XACML3.ELEMENT_REQUESTDEFAULTS.equals(childName)) {
                        stdMutableRequest.setRequestDefaults(DOMRequestDefaults.newInstance(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())) {
                                            stdMutableRequest.add(DOMRequestReference.newInstance(grandchild));
                                        } else {
                                            if (!bLenient) {
                                                throw DOMUtil.newUnexpectedElementException(grandchild,
                                                        nodeRequest);
                                            }
                                        }
                                    } else {
                                        if (!bLenient) {
                                            throw DOMUtil.newUnexpectedElementException(grandchild,
                                                    nodeRequest);
                                        }
                                    }
                                }
                            }
                        }
                    } else {
                        if (!bLenient) {
                            throw DOMUtil.newUnexpectedElementException(child, nodeRequest);
                        }
                    }
                } else {
                    if (!bLenient) {
                        throw DOMUtil.newUnexpectedElementException(child, nodeRequest);
                    }
                }
            }
        }
    }
    if (!sawAttributes && !bLenient) {
        throw DOMUtil.newMissingElementException(nodeRequest, XACML3.XMLNS, XACML3.ELEMENT_ATTRIBUTES);
    }

    return new StdRequest(stdMutableRequest);
}

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

/**
 * Convert XACML2 into XACML3./*from  ww  w . j  av a  2s  .  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.DOMRequest.java

/**
 * Unit test program to load an XML file containing a XACML Request document.
 *
 * @param args the list of Request files to load and parse
 *//*from  w  ww. j  a va 2s .  co  m*/
public static void main(String[] args) {
    if (args.length > 0) {
        for (String xmlFileName : args) {
            File fileXml = new File(xmlFileName);
            if (!fileXml.exists()) {
                System.err.println("Input file \"" + fileXml.getAbsolutePath() + "\" does not exist.");
                continue;
            } else if (!fileXml.canRead()) {
                System.err
                        .println("Permission denied reading input file \"" + fileXml.getAbsolutePath() + "\"");
                continue;
            }
            System.out.println(fileXml.getAbsolutePath() + ":");
            try {
                Document documentRequest = DOMUtil.loadDocument(fileXml);
                assert documentRequest != null;

                NodeList children = documentRequest.getChildNodes();
                if (children == null || children.getLength() == 0) {
                    System.err.println("No Requests found in \"" + fileXml.getAbsolutePath() + "\"");
                    continue;
                } else if (children.getLength() > 1) {
                    System.err.println("Multiple Requests found in \"" + fileXml.getAbsolutePath() + "\"");
                }
                Node nodeRequest = children.item(0);
                if (!nodeRequest.getLocalName().equals(XACML3.ELEMENT_REQUEST)) {
                    System.err.println("\"" + fileXml.getAbsolutePath() + "\" is not a Request");
                    continue;
                }

                Request domRequest = DOMRequest.newInstance(nodeRequest);
                System.out.println(domRequest.toString());
                System.out.println();
            } catch (Exception ex) {
                ex.printStackTrace(System.err);
            }
        }
    }
}