Java Code Examples for org.w3c.dom.Attr#getOwnerElement()

The following examples show how to use org.w3c.dom.Attr#getOwnerElement() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SimpleNamespaceResolver.java    From jaxb2-maven-plugin with Apache License 2.0 6 votes vote down vote up
/**
 * Defines if this visitor should process the provided node.
 *
 * @param aNode The DOM node to process.
 * @return <code>true</code> if the provided Node should be processed by this NodeProcessor.
 */
public boolean accept(final Node aNode) {

    // Correct namespace?
    if (aNode.getNamespaceURI() != null
            && XMLConstants.XMLNS_ATTRIBUTE_NS_URI.equals(aNode.getNamespaceURI())) {
        return true;
    }

    // Is this Node the targetNamespace attribute?
    if (aNode instanceof Attr) {

        final Attr attribute = (Attr) aNode;
        final Element parent = attribute.getOwnerElement();
        if (XMLConstants.W3C_XML_SCHEMA_NS_URI.equals(parent.getNamespaceURI())
                && SCHEMA.equalsIgnoreCase(parent.getLocalName())
                && TARGET_NAMESPACE.equals(attribute.getLocalName())) {

            SimpleNamespaceResolver.this.localNamespaceURI = attribute.getNodeValue();
        }
    }

    // Ignore processing this Node.
    return false;
}
 
Example 2
Source File: IIOMetadataNode.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
public Attr setAttributeNode(Attr newAttr) throws DOMException {
    Element owner = newAttr.getOwnerElement();
    if (owner != null) {
        if (owner == this) {
            return null;
        } else {
            throw new DOMException(DOMException.INUSE_ATTRIBUTE_ERR,
                                   "Attribute is already in use");
        }
    }

    IIOAttr attr;
    if (newAttr instanceof IIOAttr) {
        attr = (IIOAttr)newAttr;
        attr.setOwnerElement(this);
    } else {
        attr = new IIOAttr(this,
                           newAttr.getName(),
                           newAttr.getValue());
    }

    Attr oldAttr = getAttributeNode(attr.getName());
    if (oldAttr != null) {
        removeAttributeNode(oldAttr);
    }

    attributes.add(attr);

    return oldAttr;
}
 
Example 3
Source File: IIOMetadataNode.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public Attr setAttributeNode(Attr newAttr) throws DOMException {
    Element owner = newAttr.getOwnerElement();
    if (owner != null) {
        if (owner == this) {
            return null;
        } else {
            throw new DOMException(DOMException.INUSE_ATTRIBUTE_ERR,
                                   "Attribute is already in use");
        }
    }

    IIOAttr attr;
    if (newAttr instanceof IIOAttr) {
        attr = (IIOAttr)newAttr;
        attr.setOwnerElement(this);
    } else {
        attr = new IIOAttr(this,
                           newAttr.getName(),
                           newAttr.getValue());
    }

    Attr oldAttr = getAttributeNode(attr.getName());
    if (oldAttr != null) {
        removeAttributeNode(oldAttr);
    }

    attributes.add(attr);

    return oldAttr;
}
 
Example 4
Source File: AccessibilityDetector.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void visitAttribute(@NonNull XmlContext context, @NonNull Attr attribute) {
    Element element = attribute.getOwnerElement();
    if (element.hasAttributeNS(ANDROID_URI, ATTR_HINT)) {
        context.report(ISSUE, element, context.getLocation(attribute),
                "Do not set both `contentDescription` and `hint`: the `contentDescription` " +
                "will mask the `hint`");
    }
}
 
Example 5
Source File: IIOMetadataNode.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public Attr setAttributeNode(Attr newAttr) throws DOMException {
    Element owner = newAttr.getOwnerElement();
    if (owner != null) {
        if (owner == this) {
            return null;
        } else {
            throw new DOMException(DOMException.INUSE_ATTRIBUTE_ERR,
                                   "Attribute is already in use");
        }
    }

    IIOAttr attr;
    if (newAttr instanceof IIOAttr) {
        attr = (IIOAttr)newAttr;
        attr.setOwnerElement(this);
    } else {
        attr = new IIOAttr(this,
                           newAttr.getName(),
                           newAttr.getValue());
    }

    Attr oldAttr = getAttributeNode(attr.getName());
    if (oldAttr != null) {
        removeAttributeNode(oldAttr);
    }

    attributes.add(attr);

    return oldAttr;
}
 
Example 6
Source File: IIOMetadataNode.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public Attr setAttributeNode(Attr newAttr) throws DOMException {
    Element owner = newAttr.getOwnerElement();
    if (owner != null) {
        if (owner == this) {
            return null;
        } else {
            throw new DOMException(DOMException.INUSE_ATTRIBUTE_ERR,
                                   "Attribute is already in use");
        }
    }

    IIOAttr attr;
    if (newAttr instanceof IIOAttr) {
        attr = (IIOAttr)newAttr;
        attr.setOwnerElement(this);
    } else {
        attr = new IIOAttr(this,
                           newAttr.getName(),
                           newAttr.getValue());
    }

    Attr oldAttr = getAttributeNode(attr.getName());
    if (oldAttr != null) {
        removeAttributeNode(oldAttr);
    }

    attributes.add(attr);

    return oldAttr;
}
 
Example 7
Source File: IIOMetadataNode.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public Attr setAttributeNode(Attr newAttr) throws DOMException {
    Element owner = newAttr.getOwnerElement();
    if (owner != null) {
        if (owner == this) {
            return null;
        } else {
            throw new DOMException(DOMException.INUSE_ATTRIBUTE_ERR,
                                   "Attribute is already in use");
        }
    }

    IIOAttr attr;
    if (newAttr instanceof IIOAttr) {
        attr = (IIOAttr)newAttr;
        attr.setOwnerElement(this);
    } else {
        attr = new IIOAttr(this,
                           newAttr.getName(),
                           newAttr.getValue());
    }

    Attr oldAttr = getAttributeNode(attr.getName());
    if (oldAttr != null) {
        removeAttributeNode(oldAttr);
    }

    attributes.add(attr);

    return oldAttr;
}
 
Example 8
Source File: IIOMetadataNode.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public Attr setAttributeNode(Attr newAttr) throws DOMException {
    Element owner = newAttr.getOwnerElement();
    if (owner != null) {
        if (owner == this) {
            return null;
        } else {
            throw new DOMException(DOMException.INUSE_ATTRIBUTE_ERR,
                                   "Attribute is already in use");
        }
    }

    IIOAttr attr;
    if (newAttr instanceof IIOAttr) {
        attr = (IIOAttr)newAttr;
        attr.setOwnerElement(this);
    } else {
        attr = new IIOAttr(this,
                           newAttr.getName(),
                           newAttr.getValue());
    }

    Attr oldAttr = getAttributeNode(attr.getName());
    if (oldAttr != null) {
        removeAttributeNode(oldAttr);
    }

    attributes.add(attr);

    return oldAttr;
}
 
Example 9
Source File: ChangeNamespacePrefixProcessor.java    From jaxb2-maven-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * Discovers if the provided attribute is the oldPrefix namespace definition, i.e. if the given attribute is the
 * xmlns:[oldPrefix] within the schema Element.
 *
 * @param attribute the attribute to test.
 * @return <code>true</code> if the provided attribute is the oldPrefix namespace definition, i.e. if the given
 * attribute is the xmlns:[oldPrefix] within the schema Element.
 */
private boolean isNamespaceDefinition(final Attr attribute) {

    final Element parent = attribute.getOwnerElement();

    return XMLConstants.W3C_XML_SCHEMA_NS_URI.equals(parent.getNamespaceURI())
            && SCHEMA.equalsIgnoreCase(parent.getLocalName())
            && oldPrefix.equals(attribute.getLocalName());
}
 
Example 10
Source File: IIOMetadataNode.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public Attr setAttributeNode(Attr newAttr) throws DOMException {
    Element owner = newAttr.getOwnerElement();
    if (owner != null) {
        if (owner == this) {
            return null;
        } else {
            throw new DOMException(DOMException.INUSE_ATTRIBUTE_ERR,
                                   "Attribute is already in use");
        }
    }

    IIOAttr attr;
    if (newAttr instanceof IIOAttr) {
        attr = (IIOAttr)newAttr;
        attr.setOwnerElement(this);
    } else {
        attr = new IIOAttr(this,
                           newAttr.getName(),
                           newAttr.getValue());
    }

    Attr oldAttr = getAttributeNode(attr.getName());
    if (oldAttr != null) {
        removeAttributeNode(oldAttr);
    }

    attributes.add(attr);

    return oldAttr;
}
 
Example 11
Source File: IIOMetadataNode.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
public Attr setAttributeNode(Attr newAttr) throws DOMException {
    Element owner = newAttr.getOwnerElement();
    if (owner != null) {
        if (owner == this) {
            return null;
        } else {
            throw new DOMException(DOMException.INUSE_ATTRIBUTE_ERR,
                                   "Attribute is already in use");
        }
    }

    IIOAttr attr;
    if (newAttr instanceof IIOAttr) {
        attr = (IIOAttr)newAttr;
        attr.setOwnerElement(this);
    } else {
        attr = new IIOAttr(this,
                           newAttr.getName(),
                           newAttr.getValue());
    }

    Attr oldAttr = getAttributeNode(attr.getName());
    if (oldAttr != null) {
        removeAttributeNode(oldAttr);
    }

    attributes.add(attr);

    return oldAttr;
}
 
Example 12
Source File: XMLUtils.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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.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;
}
 
Example 13
Source File: XMLUtils.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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;
}
 
Example 14
Source File: XMLUtils.java    From jdk1.8-source-analysis with Apache License 2.0 4 votes vote down vote up
/**
 * 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;
}
 
Example 15
Source File: XMLUtils.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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.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;
}
 
Example 16
Source File: XMLUtils.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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;
}
 
Example 17
Source File: XMLUtils.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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;
}
 
Example 18
Source File: XMLUtils.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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;
}
 
Example 19
Source File: XMLUtils.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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;
}
 
Example 20
Source File: ChangeNamespacePrefixProcessor.java    From jaxb2-maven-plugin with Apache License 2.0 3 votes vote down vote up
/**
 * Discovers if the provided attribute is a namespace reference to the oldPrefix namespace, on the form
 * <p/>
 * <pre>
 *     <code>&lt;xs:extension base="[oldPrefix]:importItem"&gt;</code>
 * </pre>
 *
 * @param attribute the attribute to test.
 * @return <code>true</code> if the provided attribute is named "extension" and starts with
 * <code>[oldPrefix]:</code>, in which case it is a reference to the oldPrefix namespace.
 */
private boolean isExtension(final Attr attribute) {

    final Element parent = attribute.getOwnerElement();

    return XMLConstants.W3C_XML_SCHEMA_NS_URI.equals(parent.getNamespaceURI())
            && EXTENSION_ELEMENT_NAME.equalsIgnoreCase(parent.getLocalName())
            && EXTENSION_BASE_ATTRIBUTE_NAME.equalsIgnoreCase(attribute.getName())
            && attribute.getValue().startsWith(oldPrefix + ":");
}