org.w3c.dom.Attr#isId ( )源码实例Demo

下面列出了org.w3c.dom.Attr#isId ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: lams   文件: AffiliationDescriptorUnmarshaller.java
/** {@inheritDoc} */
protected void processAttribute(XMLObject samlObject, Attr attribute) throws UnmarshallingException {
    AffiliationDescriptor descriptor = (AffiliationDescriptor) samlObject;

    if (attribute.getLocalName().equals(AffiliationDescriptor.OWNER_ID_ATTRIB_NAME)) {
        descriptor.setOwnerID(attribute.getValue());
    } else if (attribute.getLocalName().equals(AffiliationDescriptor.ID_ATTRIB_NAME)) {
        descriptor.setID(attribute.getValue());
        attribute.getOwnerElement().setIdAttributeNode(attribute, true);
    } else if (attribute.getLocalName().equals(TimeBoundSAMLObject.VALID_UNTIL_ATTRIB_NAME)
            && !DatatypeHelper.isEmpty(attribute.getValue())) {
        descriptor.setValidUntil(new DateTime(attribute.getValue(), ISOChronology.getInstanceUTC()));
    } else if (attribute.getLocalName().equals(CacheableSAMLObject.CACHE_DURATION_ATTRIB_NAME)) {
        descriptor.setCacheDuration(XMLHelper.durationToLong(attribute.getValue()));
    } else {
        QName attribQName = XMLHelper.getNodeQName(attribute);
        if (attribute.isId()) {
            descriptor.getUnknownAttributes().registerID(attribQName);
        }
        descriptor.getUnknownAttributes().put(attribQName, attribute.getValue());
    }
}
 
源代码2 项目: lams   文件: EndpointUnmarshaller.java
/** {@inheritDoc} */
protected void processAttribute(XMLObject samlObject, Attr attribute) throws UnmarshallingException {
    Endpoint endpoint = (Endpoint) samlObject;

    if (attribute.getLocalName().equals(Endpoint.BINDING_ATTRIB_NAME)) {
        endpoint.setBinding(attribute.getValue());
    } else if (attribute.getLocalName().equals(Endpoint.LOCATION_ATTRIB_NAME)) {
        endpoint.setLocation(attribute.getValue());
    } else if (attribute.getLocalName().equals(Endpoint.RESPONSE_LOCATION_ATTRIB_NAME)) {
        endpoint.setResponseLocation(attribute.getValue());
    } else {
        QName attribQName = XMLHelper.getNodeQName(attribute);
        if (attribute.isId()) {
            endpoint.getUnknownAttributes().registerID(attribQName);
        }
        endpoint.getUnknownAttributes().put(attribQName, attribute.getValue());
    }
}
 
源代码3 项目: lams   文件: EncryptionPropertyUnmarshaller.java
/** {@inheritDoc} */
protected void processAttribute(XMLObject xmlObject, Attr attribute) throws UnmarshallingException {
    EncryptionProperty ep = (EncryptionProperty) xmlObject;

    if (attribute.getLocalName().equals(EncryptionProperty.ID_ATTRIB_NAME)) {
        ep.setID(attribute.getValue());
        attribute.getOwnerElement().setIdAttributeNode(attribute, true);
    } else if (attribute.getLocalName().equals(EncryptionProperty.TARGET_ATTRIB_NAME)) {
        ep.setTarget(attribute.getValue());
    } else {
        QName attributeName = XMLHelper.getNodeQName(attribute);
        if (attribute.isId()) {
            ep.getUnknownAttributes().registerID(attributeName);
        }
        ep.getUnknownAttributes().put(attributeName, attribute.getValue());
    }
}
 
源代码4 项目: keycloak   文件: XMLSignatureUtil.java
/**
 * Setup the ID attribute into <code>destElement</code> depending on the <code>isId</code> flag of an attribute of
 * <code>sourceNode</code>.
 *
 * @param sourceNode
 */
public static void propagateIDAttributeSetup(Node sourceNode, Element destElement) {
    NamedNodeMap nnm = sourceNode.getAttributes();
    for (int i = 0; i < nnm.getLength(); i++) {
        Attr attr = (Attr) nnm.item(i);
        if (attr.isId()) {
            destElement.setIdAttribute(attr.getName(), true);
            break;
        }
    }
}
 
源代码5 项目: lams   文件: OrganizationUnmarshaller.java
/**
 * {@inheritDoc}
 */
protected void processAttribute(XMLObject samlObject, Attr attribute) throws UnmarshallingException {
    Organization org = (Organization) samlObject;

    QName attribQName = XMLHelper.getNodeQName(attribute);
    if (attribute.isId()) {
        org.getUnknownAttributes().registerID(attribQName);
    }
    org.getUnknownAttributes().put(attribQName, attribute.getValue());
}
 
源代码6 项目: j2objc   文件: ElementImpl.java
/**
 * This implementation walks the entire document looking for an element
 * with the given ID attribute. We should consider adding an index to speed
 * navigation of large documents.
 */
Element getElementById(String name) {
    for (Attr attr : attributes) {
        if (attr.isId() && name.equals(attr.getValue())) {
            return this;
        }
    }

    /*
     * TODO: Remove this behavior.
     * The spec explicitly says that this is a bad idea. From
     * Document.getElementById(): "Attributes with the name "ID"
     * or "id" are not of type ID unless so defined.
     */
    if (name.equals(getAttribute("id"))) {
        return this;
    }

    for (NodeImpl node : children) {
        if (node.getNodeType() == Node.ELEMENT_NODE) {
            Element element = ((ElementImpl) node).getElementById(name);
            if (element != null) {
                return element;
            }
        }
    }

    return null;
}
 
源代码7 项目: lams   文件: DetailUnmarshaller.java
/** {@inheritDoc} */
protected void processAttribute(XMLObject xmlObject, Attr attribute) throws UnmarshallingException {
    Detail detail = (Detail) xmlObject;
    QName attribQName = XMLHelper.constructQName(attribute.getNamespaceURI(), attribute.getLocalName(), attribute
            .getPrefix());
    if (attribute.isId()) {
        detail.getUnknownAttributes().registerID(attribQName);
    }
    detail.getUnknownAttributes().put(attribQName, attribute.getValue());
}
 
源代码8 项目: lams   文件: HeaderUnmarshaller.java
/** {@inheritDoc} */
protected void processAttribute(XMLObject xmlObject, Attr attribute) throws UnmarshallingException {
    Header header = (Header) xmlObject;
    QName attribQName = XMLHelper.constructQName(attribute.getNamespaceURI(), attribute.getLocalName(), attribute
            .getPrefix());
    if (attribute.isId()) {
        header.getUnknownAttributes().registerID(attribQName);
    }
    header.getUnknownAttributes().put(attribQName, attribute.getValue());
}
 
源代码9 项目: lams   文件: XMLHelper.java
/**
 * Unmarshall a DOM Attr to an AttributeMap.
 * 
 * @param attributeMap the target AttributeMap
 * @param attribute the target DOM Attr
 */
public static void unmarshallToAttributeMap(AttributeMap attributeMap, Attr attribute) {
    QName attribQName = XMLHelper.constructQName(attribute.getNamespaceURI(), attribute.getLocalName(), attribute
            .getPrefix());
    attributeMap.put(attribQName, attribute.getValue());
    if (attribute.isId() || Configuration.isIDAttribute(attribQName)) {
        attributeMap.registerID(attribQName);
    }
}
 
源代码10 项目: lams   文件: XSAnyUnmarshaller.java
/** {@inheritDoc} */
protected void processAttribute(XMLObject xmlObject, Attr attribute) throws UnmarshallingException {
    XSAny xsAny = (XSAny) xmlObject;

    QName attribQName = XMLHelper.constructQName(attribute.getNamespaceURI(), attribute.getLocalName(), attribute
            .getPrefix());

    if (attribute.isId()) {
        xsAny.getUnknownAttributes().registerID(attribQName);
    }

    xsAny.getUnknownAttributes().put(attribQName, attribute.getValue());
}
 
源代码11 项目: dragonwell8_jdk   文件: XMLUtils.java
/**
 * This method is a tree-search to help prevent against wrapping attacks. It checks that no
 * two Elements have ID Attributes that match the "value" argument, if this is the case then
 * "false" is returned. Note that a return value of "true" does not necessarily mean that
 * a matching Element has been found, just that no wrapping attack has been detected.
 */
public static boolean protectAgainstWrappingAttack(Node startNode, String value) {
    Node startParent = startNode.getParentNode();
    Node processedNode = null;
    Element foundElement = null;

    String id = value.trim();
    if (!id.isEmpty() && id.charAt(0) == '#') {
        id = id.substring(1);
    }

    while (startNode != null) {
        if (startNode.getNodeType() == Node.ELEMENT_NODE) {
            Element se = (Element) startNode;

            NamedNodeMap attributes = se.getAttributes();
            if (attributes != null) {
                for (int i = 0; i < attributes.getLength(); i++) {
                    Attr attr = (Attr)attributes.item(i);
                    if (attr.isId() && id.equals(attr.getValue())) {
                        if (foundElement == null) {
                            // Continue searching to find duplicates
                            foundElement = attr.getOwnerElement();
                        } else {
                            log.log(java.util.logging.Level.FINE, "Multiple elements with the same 'Id' attribute value!");
                            return false;
                        }
                    }
                }
            }
        }

        processedNode = startNode;
        startNode = startNode.getFirstChild();

        // no child, this node is done.
        if (startNode == null) {
            // close node processing, get sibling
            startNode = processedNode.getNextSibling();
        }

        // no more siblings, get parent, all children
        // of parent are processed.
        while (startNode == null) {
            processedNode = processedNode.getParentNode();
            if (processedNode == startParent) {
                return true;
            }
            // close parent node processing (processed node now)
            startNode = processedNode.getNextSibling();
        }
    }
    return true;
}
 
源代码12 项目: TencentKona-8   文件: XMLUtils.java
/**
 * This method is a tree-search to help prevent against wrapping attacks. It checks that no
 * two Elements have ID Attributes that match the "value" argument, if this is the case then
 * "false" is returned. Note that a return value of "true" does not necessarily mean that
 * a matching Element has been found, just that no wrapping attack has been detected.
 */
public static boolean protectAgainstWrappingAttack(Node startNode, String value) {
    Node startParent = startNode.getParentNode();
    Node processedNode = null;
    Element foundElement = null;

    String id = value.trim();
    if (!id.isEmpty() && id.charAt(0) == '#') {
        id = id.substring(1);
    }

    while (startNode != null) {
        if (startNode.getNodeType() == Node.ELEMENT_NODE) {
            Element se = (Element) startNode;

            NamedNodeMap attributes = se.getAttributes();
            if (attributes != null) {
                for (int i = 0; i < attributes.getLength(); i++) {
                    Attr attr = (Attr)attributes.item(i);
                    if (attr.isId() && id.equals(attr.getValue())) {
                        if (foundElement == null) {
                            // Continue searching to find duplicates
                            foundElement = attr.getOwnerElement();
                        } else {
                            log.log(java.util.logging.Level.FINE, "Multiple elements with the same 'Id' attribute value!");
                            return false;
                        }
                    }
                }
            }
        }

        processedNode = startNode;
        startNode = startNode.getFirstChild();

        // no child, this node is done.
        if (startNode == null) {
            // close node processing, get sibling
            startNode = processedNode.getNextSibling();
        }

        // no more siblings, get parent, all children
        // of parent are processed.
        while (startNode == null) {
            processedNode = processedNode.getParentNode();
            if (processedNode == startParent) {
                return true;
            }
            // close parent node processing (processed node now)
            startNode = processedNode.getNextSibling();
        }
    }
    return true;
}
 
源代码13 项目: TencentKona-8   文件: XMLUtils.java
/**
 * This method is a tree-search to help prevent against wrapping attacks. It checks that no other
 * Element than the given "knownElement" argument has an ID attribute that matches the "value"
 * argument, which is the ID value of "knownElement". If this is the case then "false" is returned.
 */
public static boolean protectAgainstWrappingAttack(
    Node startNode, Element knownElement, String value
) {
    Node startParent = startNode.getParentNode();
    Node processedNode = null;

    String id = value.trim();
    if (!id.isEmpty() && id.charAt(0) == '#') {
        id = id.substring(1);
    }

    while (startNode != null) {
        if (startNode.getNodeType() == Node.ELEMENT_NODE) {
            Element se = (Element) startNode;

            NamedNodeMap attributes = se.getAttributes();
            if (attributes != null) {
                for (int i = 0; i < attributes.getLength(); i++) {
                    Attr attr = (Attr)attributes.item(i);
                    if (attr.isId() && id.equals(attr.getValue()) && se != knownElement) {
                        log.log(java.util.logging.Level.FINE, "Multiple elements with the same 'Id' attribute value!");
                        return false;
                    }
                }
            }
        }

        processedNode = startNode;
        startNode = startNode.getFirstChild();

        // no child, this node is done.
        if (startNode == null) {
            // close node processing, get sibling
            startNode = processedNode.getNextSibling();
        }

        // no more siblings, get parent, all children
        // of parent are processed.
        while (startNode == null) {
            processedNode = processedNode.getParentNode();
            if (processedNode == startParent) {
                return true;
            }
            // close parent node processing (processed node now)
            startNode = processedNode.getNextSibling();
        }
    }
    return true;
}
 
源代码14 项目: jdk8u60   文件: XMLUtils.java
/**
 * This method is a tree-search to help prevent against wrapping attacks. It checks that no other
 * Element than the given "knownElement" argument has an ID attribute that matches the "value"
 * argument, which is the ID value of "knownElement". If this is the case then "false" is returned.
 */
public static boolean protectAgainstWrappingAttack(
    Node startNode, Element knownElement, String value
) {
    Node startParent = startNode.getParentNode();
    Node processedNode = null;

    String id = value.trim();
    if (id.charAt(0) == '#') {
        id = id.substring(1);
    }

    while (startNode != null) {
        if (startNode.getNodeType() == Node.ELEMENT_NODE) {
            Element se = (Element) startNode;

            NamedNodeMap attributes = se.getAttributes();
            if (attributes != null) {
                for (int i = 0; i < attributes.getLength(); i++) {
                    Attr attr = (Attr)attributes.item(i);
                    if (attr.isId() && id.equals(attr.getValue()) && se != knownElement) {
                        log.log(java.util.logging.Level.FINE, "Multiple elements with the same 'Id' attribute value!");
                        return false;
                    }
                }
            }
        }

        processedNode = startNode;
        startNode = startNode.getFirstChild();

        // no child, this node is done.
        if (startNode == null) {
            // close node processing, get sibling
            startNode = processedNode.getNextSibling();
        }

        // no more siblings, get parent, all children
        // of parent are processed.
        while (startNode == null) {
            processedNode = processedNode.getParentNode();
            if (processedNode == startParent) {
                return true;
            }
            // close parent node processing (processed node now)
            startNode = processedNode.getNextSibling();
        }
    }
    return true;
}
 
源代码15 项目: JDKSourceCode1.8   文件: XMLUtils.java
/**
 * This method is a tree-search to help prevent against wrapping attacks. It checks that no
 * two Elements have ID Attributes that match the "value" argument, if this is the case then
 * "false" is returned. Note that a return value of "true" does not necessarily mean that
 * a matching Element has been found, just that no wrapping attack has been detected.
 */
public static boolean protectAgainstWrappingAttack(Node startNode, String value) {
    Node startParent = startNode.getParentNode();
    Node processedNode = null;
    Element foundElement = null;

    String id = value.trim();
    if (!id.isEmpty() && id.charAt(0) == '#') {
        id = id.substring(1);
    }

    while (startNode != null) {
        if (startNode.getNodeType() == Node.ELEMENT_NODE) {
            Element se = (Element) startNode;

            NamedNodeMap attributes = se.getAttributes();
            if (attributes != null) {
                for (int i = 0; i < attributes.getLength(); i++) {
                    Attr attr = (Attr)attributes.item(i);
                    if (attr.isId() && id.equals(attr.getValue())) {
                        if (foundElement == null) {
                            // Continue searching to find duplicates
                            foundElement = attr.getOwnerElement();
                        } else {
                            log.log(java.util.logging.Level.FINE, "Multiple elements with the same 'Id' attribute value!");
                            return false;
                        }
                    }
                }
            }
        }

        processedNode = startNode;
        startNode = startNode.getFirstChild();

        // no child, this node is done.
        if (startNode == null) {
            // close node processing, get sibling
            startNode = processedNode.getNextSibling();
        }

        // no more siblings, get parent, all children
        // of parent are processed.
        while (startNode == null) {
            processedNode = processedNode.getParentNode();
            if (processedNode == startParent) {
                return true;
            }
            // close parent node processing (processed node now)
            startNode = processedNode.getNextSibling();
        }
    }
    return true;
}
 
源代码16 项目: JDKSourceCode1.8   文件: XMLUtils.java
/**
 * This method is a tree-search to help prevent against wrapping attacks. It checks that no other
 * Element than the given "knownElement" argument has an ID attribute that matches the "value"
 * argument, which is the ID value of "knownElement". If this is the case then "false" is returned.
 */
public static boolean protectAgainstWrappingAttack(
    Node startNode, Element knownElement, String value
) {
    Node startParent = startNode.getParentNode();
    Node processedNode = null;

    String id = value.trim();
    if (!id.isEmpty() && id.charAt(0) == '#') {
        id = id.substring(1);
    }

    while (startNode != null) {
        if (startNode.getNodeType() == Node.ELEMENT_NODE) {
            Element se = (Element) startNode;

            NamedNodeMap attributes = se.getAttributes();
            if (attributes != null) {
                for (int i = 0; i < attributes.getLength(); i++) {
                    Attr attr = (Attr)attributes.item(i);
                    if (attr.isId() && id.equals(attr.getValue()) && se != knownElement) {
                        log.log(java.util.logging.Level.FINE, "Multiple elements with the same 'Id' attribute value!");
                        return false;
                    }
                }
            }
        }

        processedNode = startNode;
        startNode = startNode.getFirstChild();

        // no child, this node is done.
        if (startNode == null) {
            // close node processing, get sibling
            startNode = processedNode.getNextSibling();
        }

        // no more siblings, get parent, all children
        // of parent are processed.
        while (startNode == null) {
            processedNode = processedNode.getParentNode();
            if (processedNode == startParent) {
                return true;
            }
            // close parent node processing (processed node now)
            startNode = processedNode.getNextSibling();
        }
    }
    return true;
}
 
源代码17 项目: openjdk-jdk8u   文件: XMLUtils.java
/**
 * This method is a tree-search to help prevent against wrapping attacks. It checks that no other
 * Element than the given "knownElement" argument has an ID attribute that matches the "value"
 * argument, which is the ID value of "knownElement". If this is the case then "false" is returned.
 */
public static boolean protectAgainstWrappingAttack(
    Node startNode, Element knownElement, String value
) {
    Node startParent = startNode.getParentNode();
    Node processedNode = null;

    String id = value.trim();
    if (!id.isEmpty() && id.charAt(0) == '#') {
        id = id.substring(1);
    }

    while (startNode != null) {
        if (startNode.getNodeType() == Node.ELEMENT_NODE) {
            Element se = (Element) startNode;

            NamedNodeMap attributes = se.getAttributes();
            if (attributes != null) {
                for (int i = 0; i < attributes.getLength(); i++) {
                    Attr attr = (Attr)attributes.item(i);
                    if (attr.isId() && id.equals(attr.getValue()) && se != knownElement) {
                        log.log(java.util.logging.Level.FINE, "Multiple elements with the same 'Id' attribute value!");
                        return false;
                    }
                }
            }
        }

        processedNode = startNode;
        startNode = startNode.getFirstChild();

        // no child, this node is done.
        if (startNode == null) {
            // close node processing, get sibling
            startNode = processedNode.getNextSibling();
        }

        // no more siblings, get parent, all children
        // of parent are processed.
        while (startNode == null) {
            processedNode = processedNode.getParentNode();
            if (processedNode == startParent) {
                return true;
            }
            // close parent node processing (processed node now)
            startNode = processedNode.getNextSibling();
        }
    }
    return true;
}
 
源代码18 项目: jdk8u-jdk   文件: XMLUtils.java
/**
 * This method is a tree-search to help prevent against wrapping attacks. It checks that no
 * two Elements have ID Attributes that match the "value" argument, if this is the case then
 * "false" is returned. Note that a return value of "true" does not necessarily mean that
 * a matching Element has been found, just that no wrapping attack has been detected.
 */
public static boolean protectAgainstWrappingAttack(Node startNode, String value) {
    Node startParent = startNode.getParentNode();
    Node processedNode = null;
    Element foundElement = null;

    String id = value.trim();
    if (!id.isEmpty() && id.charAt(0) == '#') {
        id = id.substring(1);
    }

    while (startNode != null) {
        if (startNode.getNodeType() == Node.ELEMENT_NODE) {
            Element se = (Element) startNode;

            NamedNodeMap attributes = se.getAttributes();
            if (attributes != null) {
                for (int i = 0; i < attributes.getLength(); i++) {
                    Attr attr = (Attr)attributes.item(i);
                    if (attr.isId() && id.equals(attr.getValue())) {
                        if (foundElement == null) {
                            // Continue searching to find duplicates
                            foundElement = attr.getOwnerElement();
                        } else {
                            log.log(java.util.logging.Level.FINE, "Multiple elements with the same 'Id' attribute value!");
                            return false;
                        }
                    }
                }
            }
        }

        processedNode = startNode;
        startNode = startNode.getFirstChild();

        // no child, this node is done.
        if (startNode == null) {
            // close node processing, get sibling
            startNode = processedNode.getNextSibling();
        }

        // no more siblings, get parent, all children
        // of parent are processed.
        while (startNode == null) {
            processedNode = processedNode.getParentNode();
            if (processedNode == startParent) {
                return true;
            }
            // close parent node processing (processed node now)
            startNode = processedNode.getNextSibling();
        }
    }
    return true;
}
 
源代码19 项目: jdk8u_jdk   文件: XMLUtils.java
/**
 * This method is a tree-search to help prevent against wrapping attacks. It checks that no
 * two Elements have ID Attributes that match the "value" argument, if this is the case then
 * "false" is returned. Note that a return value of "true" does not necessarily mean that
 * a matching Element has been found, just that no wrapping attack has been detected.
 */
public static boolean protectAgainstWrappingAttack(Node startNode, String value) {
    Node startParent = startNode.getParentNode();
    Node processedNode = null;
    Element foundElement = null;

    String id = value.trim();
    if (!id.isEmpty() && id.charAt(0) == '#') {
        id = id.substring(1);
    }

    while (startNode != null) {
        if (startNode.getNodeType() == Node.ELEMENT_NODE) {
            Element se = (Element) startNode;

            NamedNodeMap attributes = se.getAttributes();
            if (attributes != null) {
                for (int i = 0; i < attributes.getLength(); i++) {
                    Attr attr = (Attr)attributes.item(i);
                    if (attr.isId() && id.equals(attr.getValue())) {
                        if (foundElement == null) {
                            // Continue searching to find duplicates
                            foundElement = attr.getOwnerElement();
                        } else {
                            log.log(java.util.logging.Level.FINE, "Multiple elements with the same 'Id' attribute value!");
                            return false;
                        }
                    }
                }
            }
        }

        processedNode = startNode;
        startNode = startNode.getFirstChild();

        // no child, this node is done.
        if (startNode == null) {
            // close node processing, get sibling
            startNode = processedNode.getNextSibling();
        }

        // no more siblings, get parent, all children
        // of parent are processed.
        while (startNode == null) {
            processedNode = processedNode.getParentNode();
            if (processedNode == startParent) {
                return true;
            }
            // close parent node processing (processed node now)
            startNode = processedNode.getNextSibling();
        }
    }
    return true;
}
 
源代码20 项目: lams   文件: AbstractXMLObjectUnmarshaller.java
/**
 * Check whether the attribute's QName is registered in the global ID attribute registry. If it is, and the
 * specified attribute's DOM Level 3 Attr.isId() is false (due to lack of schema validation, for example), then
 * declare the attribute as an ID type in the DOM on the attribute's owning element. This is to handle cases where
 * the underlying DOM needs to accurately reflect an attribute's ID-ness, for example ID reference resolution within
 * the Apache XML Security library.
 * 
 * @param attribute the DOM attribute to be checked
 */
protected void checkIDAttribute(Attr attribute) {
    QName attribName = XMLHelper.getNodeQName(attribute);
    if (Configuration.isIDAttribute(attribName) && !attribute.isId()) {
        attribute.getOwnerElement().setIdAttributeNode(attribute, true);
    }
}