Example usage for org.w3c.dom Attr getName

List of usage examples for org.w3c.dom Attr getName

Introduction

In this page you can find the example usage for org.w3c.dom Attr getName.

Prototype

public String getName();

Source Link

Document

Returns the name of this attribute.

Usage

From source file:jp.igapyon.selecrawler.SeleCrawlerWebContentTrimmer.java

public void processElement(final Element element) throws IOException {
    final NodeList nodeList = element.getChildNodes();
    for (int index = nodeList.getLength() - 1; index >= 0; index--) {
        final Node node = nodeList.item(index);
        if (node instanceof Element) {
            final Element lookup = (Element) node;

            if ("script".equals(lookup.getTagName())) {
                // REMOVE script tag.
                element.removeChild(node);
                continue;
            }/*from   www  .  j a  v  a  2 s  .  c  om*/

            if ("noscript".equals(lookup.getTagName())) {
                // REMOVE noscript tag.
                element.removeChild(node);
                continue;
            }

            if ("iframe".equals(lookup.getTagName())) {
                final NamedNodeMap nnm = lookup.getAttributes();
                for (int indexNnm = 0; indexNnm < nnm.getLength(); indexNnm++) {
                    final Attr attr = (Attr) nnm.item(indexNnm);

                    // System.out.println(" " + attr.getName() + " [" +
                    // attr.getValue() + "]");
                    if ("style".equals(attr.getName())) {
                        final String value = attr.getValue().replaceAll(" ", "");
                        if (value.indexOf("display:none") >= 0) {
                            // REMOVE iframe tag which is display:none
                            // style..
                            element.removeChild(node);
                            continue;
                        }
                    }
                }
            }

            processElement(lookup);
        }
    }
}

From source file:com.evolveum.midpoint.util.DOMUtil.java

public static boolean isNamespaceDefinition(Attr attr) {
    if (W3C_XML_SCHEMA_XMLNS_URI.equals(attr.getNamespaceURI())) {
        return true;
    }//from   w w  w.  ja v  a 2 s .c o m
    if (attr.getName().startsWith("xmlns:") || "xmlns".equals(attr.getName())) {
        return true;
    }
    return false;
}

From source file:com.evolveum.midpoint.util.DOMUtil.java

private static boolean isApplicationAttribute(Attr attr) {
    String namespaceURI = attr.getNamespaceURI();
    if (StringUtils.isEmpty(attr.getNamespaceURI()) && HACKED_XSI_TYPE.equals(attr.getName())) {
        return false;
    }/* w w  w. j  a  v a 2s . c  o m*/
    if (namespaceURI == null) {
        return true;
    }
    if (W3C_XML_SCHEMA_XMLNS_URI.equals(namespaceURI)) {
        return false;
    }
    if (W3C_XML_XML_URI.equals(namespaceURI)) {
        return false;
    }
    if (W3C_XML_SCHEMA_INSTANCE_NS_URI.equals(namespaceURI)) {
        return false;
    }
    return true;
}

From source file:com.gargoylesoftware.htmlunit.html.BaseFrameElement.java

/**
 * {@inheritDoc}/*from  w  ww.  j  a v  a2  s.  com*/
 */
@Override
public Attr setAttributeNode(final Attr attribute) {
    final String qualifiedName = attribute.getName();
    String attributeValue = null;
    if ("src".equals(qualifiedName)) {
        attributeValue = attribute.getValue().trim();
    }

    final Attr result = super.setAttributeNode(attribute);

    if ("src".equals(qualifiedName) && WebClient.ABOUT_BLANK != attributeValue) {
        if (isDirectlyAttachedToPage()) {
            loadSrc();
        } else {
            loadSrcWhenAddedToPage_ = true;
        }
    }

    return result;
}

From source file:com.twinsoft.convertigo.engine.util.XMLUtils.java

/**
 * Compute the xpath of a node relative to an anchor.
 * /*from w  ww  . j a  va2  s. c o  m*/
 * @param node
 *            node to find the xpath from.
 * @param anchor
 *            the relative point to fid from.
 * @return the computed xpath.
 */
public static String calcXpath(Node node, Node anchor) {
    String xpath = "";
    Node current = null;

    if (node == null || node.equals(anchor))
        return "";

    // add attribute to xpath
    if (node instanceof Attr) {
        Attr attr = (Attr) node;
        node = attr.getOwnerElement();
        xpath = '@' + attr.getName() + '/';
    }

    while ((current = node.getParentNode()) != anchor) {
        Engine.logEngine.trace("Calc Xpath : current node : " + current.getNodeName());
        NodeList childs = current.getChildNodes();
        int index = 0;
        for (int i = 0; i < childs.getLength(); i++) {
            if (childs.item(i).getNodeType() != Node.ELEMENT_NODE
                    && !childs.item(i).getNodeName().equalsIgnoreCase("#text"))
                continue;

            Engine.logEngine.trace("Calc Xpath : ==== > Child node : " + childs.item(i).getNodeName());

            // Bump the index if we have the same tag names..
            if (childs.item(i).getNodeName().equalsIgnoreCase(node.getNodeName())) {
                // tag names are equal ==> bump the index.
                index++;
                // is our node the one that is listed ?
                if (childs.item(i).equals(node))
                    // We found our node in the parent node list
                    break;
            }
        }
        // count the number of elements having the same tag
        int nbElements = 0;
        for (int i = 0; i < childs.getLength(); i++) {
            if (childs.item(i).getNodeName().equalsIgnoreCase(node.getNodeName())) {
                nbElements++;
            }
        }

        String name = node.getNodeName();
        if (name.equalsIgnoreCase("#text"))
            name = "text()";
        name = xpathEscapeColon(name);

        if (nbElements > 1) {
            xpath = name + "[" + index + "]/" + xpath;
        } else {
            // only one element had the same tag ==> do not compute the [xx]
            // syntax..
            xpath = name + "/" + xpath;
        }
        node = current;
    }
    if (xpath.length() > 0)
        // remove the trailing '/'
        xpath = xpath.substring(0, xpath.length() - 1);

    return xpath;
}

From source file:com.evolveum.midpoint.util.DOMUtil.java

public static String getNamespaceDeclarationPrefix(Attr attr) {
    if (!W3C_XML_SCHEMA_XMLNS_URI.equals(attr.getNamespaceURI())) {
        throw new IllegalStateException(
                "Attempt to get prefix from a attribute that is not a namespace declaration, it has namespace "
                        + attr.getNamespaceURI());
    }// w  w w  .  j  a  v  a 2 s  .  c o  m
    String attrName = attr.getName();
    if (attrName.startsWith("xmlns:")) {
        return attrName.substring(6);
    }
    if ("xmlns".equals(attrName)) {
        return null;
    }
    throw new IllegalStateException(
            "Attempt to get prefix from a attribute that is not a namespace declaration, it is " + attrName);
}

From source file:com.evolveum.midpoint.util.DOMUtil.java

public static String getNamespaceDeclarationNamespace(Attr attr) {
    if (!W3C_XML_SCHEMA_XMLNS_URI.equals(attr.getNamespaceURI())) {
        throw new IllegalStateException(
                "Attempt to get namespace from a attribute that is not a namespace declaration, it has namespace "
                        + attr.getNamespaceURI());
    }/*from w  w  w  . ja  v a 2  s.  c  o m*/
    String attrName = attr.getName();
    if (!attrName.startsWith("xmlns:") && !"xmlns".equals(attr.getName())) {
        throw new IllegalStateException(
                "Attempt to get namespace from a attribute that is not a namespace declaration, it is "
                        + attrName);
    }
    return attr.getValue();
}

From source file:uk.co.markfrimston.tasktree.TaskTree.java

protected boolean nodesEqual(Node a, Node b) {
    if ((a == null) != (b == null)) {
        return false;
    }/*from w  w  w  .  ja v a2 s .  c  o m*/
    if (a != null) {
        if (a.getNodeType() != b.getNodeType()) {
            return false;
        }
        if ((a.getNodeName() == null) != (b.getNodeName() == null)) {
            return false;
        }
        if (a.getNodeName() != null && !a.getNodeName().equals(b.getNodeName())) {
            return false;
        }
        if ((a.getNodeValue() == null) != (b.getNodeValue() == null)) {
            return false;
        }
        if (a.getNodeValue() != null && !a.getNodeValue().equals(b.getNodeValue())) {
            return false;
        }
        NamedNodeMap attrsA = a.getAttributes();
        Map<String, String> attrMapA = new HashMap<String, String>();
        if (attrsA != null) {
            for (int i = 0; i < attrsA.getLength(); i++) {
                Attr att = (Attr) attrsA.item(i);
                attrMapA.put(att.getName(), att.getValue());
            }
        }
        NamedNodeMap attrsB = b.getAttributes();
        Map<String, String> attrMapB = new HashMap<String, String>();
        if (attrsB != null) {
            for (int i = 0; i < attrsB.getLength(); i++) {
                Attr att = (Attr) attrsB.item(i);
                attrMapB.put(att.getName(), att.getValue());
            }
        }
        if (!attrMapA.equals(attrMapB)) {
            return false;
        }

        Node childA = a.getFirstChild();
        Node childB = b.getFirstChild();
        while (childA != null) {
            if (!nodesEqual(childA, childB)) {
                return false;
            }
            childA = childA.getNextSibling();
            childB = childB.getNextSibling();
        }
        if (childB != null) {
            return false;
        }
    }
    return true;
}

From source file:fr.gouv.finances.dgfip.xemelios.utils.TextWriter.java

private void attribute(Writer writer, Attr attr) throws IOException {
    writeText(writer, attr.getName());
    writer.write("=\"");
    //writeEscapedText(writer, attr.getValue(), true);
    writer.write(StringEscapeUtils.escapeXml(attr.getValue()));
    writer.write("\"");
}

From source file:org.dozer.eclipse.plugin.sourcepage.hyperlink.DozerClassHyperlinkDetector.java

@SuppressWarnings("restriction")
public final IHyperlink[] detectHyperlinks(ITextViewer textViewer, IRegion region,
        boolean canShowMultipleHyperlinks) {
    if (region == null || textViewer == null) {
        return null;
    }// www  .  j  a v  a 2 s.  c  om

    IDocument document = textViewer.getDocument();

    Node currentNode = BeansEditorUtils.getNodeByOffset(document, region.getOffset());
    if (currentNode != null) {
        switch (currentNode.getNodeType()) {
        case Node.ELEMENT_NODE:
            // at first try to handle selected attribute value
            Attr currentAttr = BeansEditorUtils.getAttrByOffset(currentNode, region.getOffset());
            IDOMAttr attr = (IDOMAttr) currentAttr;
            if (currentAttr != null && region.getOffset() >= attr.getValueRegionStartOffset()) {
                if (isLinkableAttr(currentAttr)) {
                    IRegion hyperlinkRegion = getHyperlinkRegion(currentAttr);
                    IHyperlink hyperLink = createHyperlink(currentAttr.getName(), currentAttr.getNodeValue(),
                            currentNode, currentNode.getParentNode(), document, textViewer, hyperlinkRegion,
                            region);
                    if (hyperLink != null) {
                        return new IHyperlink[] { hyperLink };
                    }
                }
            }
            break;

        case Node.TEXT_NODE:
            IRegion hyperlinkRegion = getHyperlinkRegion(currentNode);
            Node parentNode = currentNode.getParentNode();
            if (parentNode != null) {
                IHyperlink hyperLink = createHyperlink(parentNode.getNodeName(), currentNode.getNodeValue(),
                        currentNode, parentNode, document, textViewer, hyperlinkRegion, region);
                if (hyperLink != null) {
                    return new IHyperlink[] { hyperLink };
                }
            }
            break;
        }
    }
    return null;
}