Example usage for com.google.gwt.dom.client Node getNodeName

List of usage examples for com.google.gwt.dom.client Node getNodeName

Introduction

In this page you can find the example usage for com.google.gwt.dom.client Node getNodeName.

Prototype

@Override
    public String getNodeName() 

Source Link

Usage

From source file:cc.alcina.framework.gwt.client.util.WidgetUtils.java

License:Apache License

public static Element getElementForPositioning0(Element from) {
    assert tempPositioningText == null;
    if (!isVisibleAncestorChain(from)) {
        return null;
    }/*from w w w  .ja  va  2s . c o  m*/
    boolean hidden = isZeroOffsetDims(from);
    int kidCount = from.getChildCount();
    if (kidCount != 0 && !hidden) {
        return from;
    }
    Node parent = from.getParentNode();
    if (parent != null && parent.getFirstChild() == from && parent.getNodeType() == Node.ELEMENT_NODE
            && !isZeroOffsetDims((Element) parent)) {
        return (Element) parent;
    }
    ClientNodeIterator itr = new ClientNodeIterator(from, ClientNodeIterator.SHOW_ALL);
    Element fromContainingBlock = DomUtils.getContainingBlock(from);
    Node node = from;
    int insertTextIfOffsetMoreThanXChars = 100;
    while ((node = node.getPreviousSibling()) != null) {
        if (node.getNodeType() == Node.TEXT_NODE) {
            insertTextIfOffsetMoreThanXChars -= TextUtils.normalizeWhitespaceAndTrim(node.getNodeValue())
                    .length();
            if (insertTextIfOffsetMoreThanXChars < 0) {
                // this causes a relayout - so we try and avoid. most of the
                // time, positioning elements will contain text (or be from
                // a friendly browser), or be at the start of a block elt)
                tempPositioningText = Document.get().createTextNode("---");
                from.appendChild(tempPositioningText);
                return from;
            }
        }
    }
    // give up after 50 node iterations (big tables maybe)
    int max = 50;
    while ((node = itr.nextNode()) != null && max-- > 0) {
        if (node.getNodeType() == Node.ELEMENT_NODE) {
            if (!isZeroOffsetDims(node.getParentElement()) && node.getNodeName().equalsIgnoreCase("img")) {
                return (Element) node;
            }
            if (!UIObject.isVisible((Element) node)) {
                itr.skipChildren();
            }
        } else {
            // text
            if (!isZeroOffsetDims(node.getParentElement())
                    // we don't want the combined ancestor of everyone...
                    && (!node.getParentElement().isOrHasChild(from) ||
                    // but we do want <p><a><b>*some-text*</b></p>
                            DomUtils.getContainingBlock(node) == fromContainingBlock)) {
                return node.getParentElement();
            }
        }
    }
    return from.getParentElement();
}

From source file:client.net.sf.saxon.ce.dom.HTMLNodeWrapper.java

License:Mozilla Public License

private String getNodeURI(Node lNode, boolean isLocalAttribute) {
    NodeInfo element;//from  w  w  w . j a va 2 s .  c o  m
    // isLocalAttribute is true when method called internally to get uri of
    // an attribute belonging to this element
    if (isLocalAttribute || nodeKind == Type.ELEMENT) {
        element = this;
    } else if (nodeKind == Type.ATTRIBUTE) {
        element = this.getParent();
    } else {
        return "";
    }

    String uri = getNodeNamespace(lNode);
    boolean isHTML = (docWrapper.getDocType() == DocType.HTML);
    // don't return XHTML namespace for HTML docs that have no XHTML namespace declaration
    if (uri == null) {
        if (isHTML)
            return "";
        // some browsers add XHTML namespace to all HTML elements - whether namespace declared or not:
    } else if (isHTML && uri.equals(NamespaceConstant.XHTML)) {
        return "";
    } else {
        return uri;
    }

    // Otherwise we have to work it out the hard way...

    if (lNode.getNodeName().startsWith("xml:")) {
        return NamespaceConstant.XML;
    }

    String[] parts;
    try {
        parts = NameChecker.getQNameParts(lNode.getNodeName());
    } catch (QNameException e) {
        throw new IllegalStateException("Invalid QName in DOM node. " + e);
    }

    if ((isLocalAttribute || nodeKind == Type.ATTRIBUTE) && parts[0].length() == 0) {
        // for an attribute, no prefix means no namespace
        uri = "";
    } else {
        AxisIterator nsiter = element.iterateAxis(Axis.NAMESPACE);
        while (true) {
            NodeInfo ns = (NodeInfo) nsiter.next();
            if (ns == null) {
                break;
            }
            if (ns.getLocalPart().equals(parts[0])) {
                uri = ns.getStringValue();
                break;
            }
        }
        if (uri == null) {
            if (parts[0].length() == 0) {
                uri = "";
            } else {
                throw new IllegalStateException("Undeclared namespace prefix in DOM input: " + parts[0]);
            }
        }
    }

    return uri;
}

From source file:client.net.sf.saxon.ce.dom.HTMLNodeWrapper.java

License:Mozilla Public License

private HTMLAttributeNode[] getMainAttributes(Element elem) {
    JsArray<Node> attributes = getAttributes((Element) node);
    ArrayList<String> nodeNames = new ArrayList<String>();

    int len = attributes.length();
    ArrayList<HTMLAttributeNode> nodeAtts = new ArrayList<HTMLAttributeNode>();
    namespaceBindings = new ArrayList<NamespaceBinding>();
    // assume attributes within HTML doc have no namespace - unless they have a prefix
    boolean getNamespaces = (docWrapper.getDocType() != DocType.HTML);
    for (int i = 0; i < len; i++) {
        Node attNode = attributes.get(i);
        String name = attNode.getNodeName();
        String val = "";
        try {/*from w ww  . ja va 2s .co  m*/
            val = getValue(attNode); // changed for compatibility
        } catch (Exception e) {
            String rp = getTypeOfNodeValue(attNode);
            String a = "a"; //kilroy
        }
        if (name.startsWith("xmlns:")) {
            namespaceBindings.add(new NamespaceBinding(name.substring(6), val));
        } else if (name.equals("xmlns")) {
            namespaceBindings.add(new NamespaceBinding("", val));
        } else {
            if (getNamespaces || name.indexOf(':') > -1) {
                String pfx = getNodePrefix(attNode);
                String uri = getNodeURI(attNode, true);
                String local = getLocalName(attNode);
                if (uri == null) {
                    uri = "";
                } // xhtml attributes use xlink namespace!
                nodeAtts.add(new HTMLAttributeNode(this, local, pfx, uri, val));
            } else {
                nodeAtts.add(new HTMLAttributeNode(this, name, "", "", val));
            }
            nodeNames.add(name);
        }
    }
    HTMLAttributeNode[] nodes = new HTMLAttributeNode[nodeAtts.size()];
    nodeAtts.toArray(nodes);

    attributeList = nodes; // for later use
    attributeNames = nodeNames;
    return nodes;
}

From source file:com.arcbees.chosen.client.SelectParser.java

License:Apache License

private void addGroup(OptGroupElement group) {
    int position = parsed.size();

    GroupItem item = new GroupItem();
    item.arrayIndex = position;//from w  ww.  j a va2 s .c  o m
    item.label = group.getLabel();
    item.children = 0;
    item.disabled = group.isDisabled();

    parsed.add(item);

    NodeList<Node> children = group.getChildNodes();
    for (int i = 0; i < children.getLength(); i++) {
        Node n = children.getItem(i);
        if ("OPTION".equalsIgnoreCase(n.getNodeName())) {
            addOption(OptionElement.as((Element) n), position, group.isDisabled());
        }
    }
}

From source file:com.cgxlib.xq.client.impl.research.SelectorEngineJS.java

License:Apache License

private static void getGeneralSiblingNodes(JsNodeArray matchingElms, JsObjectArray<String> nextTag,
        JsRegexp nextRegExp, Node prevRef) {
    while (JsUtils.truth((prevRef = SelectorEngine.getNextSibling(prevRef))) && !isAdded(prevRef)) {
        if (!JsUtils.truth(nextTag) || nextRegExp.test(prevRef.getNodeName())) {
            setAdded(prevRef, true);/*from   www  .  j  a  va  2  s. c  om*/
            matchingElms.addNode(prevRef);
        }
    }
}

From source file:com.cgxlib.xq.client.impl.research.SelectorEngineJS.java

License:Apache License

private static void getSiblingNodes(JsNodeArray matchingElms, JsObjectArray<String> nextTag,
        JsRegexp nextRegExp, Node prevRef) {
    while (JsUtils.truth(prevRef = SelectorEngine.getNextSibling(prevRef))
            && prevRef.getNodeType() != Node.ELEMENT_NODE) {
    }//from ww  w . j  a  va  2s . c o  m
    if (JsUtils.truth(prevRef)) {
        if (!JsUtils.truth(nextTag) || nextRegExp.test(prevRef.getNodeName())) {
            matchingElms.addNode(prevRef);
        }
    }
}

From source file:com.cgxlib.xq.client.impl.research.SelectorEngineJS.java

License:Apache License

private void getFirstOfTypePseudo(JsNodeArray previousMatch, boolean previousDir, JsNodeArray matchingElms) {
    Node previous;/*  w  w  w  .  j a v  a2  s  . c om*/
    Node next;
    for (int n = 0, nlen = previousMatch.size(); n < nlen; n++) {
        next = previous = previousMatch.getNode(n);

        if (previousDir) {
            while (JsUtils.truth(next = SelectorEngine.getPreviousSibling(next))
                    && !JsUtils.eq(next.getNodeName(), previous.getNodeName())) {
            }
        } else {
            while (JsUtils.truth(next = SelectorEngine.getNextSibling(next))
                    && !JsUtils.eq(next.getNodeName(), previous.getNodeName())) {
            }
        }

        if (!JsUtils.truth(next)) {
            matchingElms.addNode(previous);
        }
    }
}

From source file:com.cgxlib.xq.client.impl.research.SelectorEngineJS.java

License:Apache License

private JsNodeArray getNthChildPseudo(JsNodeArray previousMatch, String pseudoValue, JsNodeArray prevParents,
        JsNodeArray matchingElms) {//  ww  w.j  a  v a 2  s. co  m
    Node previous;
    if (JsUtils.eq(pseudoValue, "n")) {
        matchingElms = previousMatch;
    } else {
        Sequence sequence = getSequence(pseudoValue);
        if (sequence != null) {
            for (int l = 0, llen = previousMatch.size(); l < llen; l++) {
                previous = previousMatch.getNode(l);
                Node prevParent = previous.getParentNode();
                if (!hasChildElms(prevParent)) {
                    int iteratorNext = sequence.start;
                    int childCount = 0;
                    Node childElm = prevParent.getFirstChild();
                    while (childElm != null && (sequence.max < 0 || iteratorNext <= sequence.max)) {
                        if (childElm.getNodeType() == Node.ELEMENT_NODE) {
                            if (++childCount == iteratorNext) {
                                if (JsUtils.eq(childElm.getNodeName(), previous.getNodeName())) {
                                    matchingElms.addNode(childElm);
                                }
                                iteratorNext += sequence.add;
                            }
                        }
                        childElm = SelectorEngine.getNextSibling(childElm);
                    }
                    setHasChildElms(prevParent, true);
                    prevParents.addNode(prevParent);
                }
            }
            clearChildElms(prevParents);
        }
    }
    return matchingElms;
}

From source file:com.cgxlib.xq.client.impl.research.SelectorEngineJS.java

License:Apache License

private JsNodeArray getNthOfTypePseudo(JsNodeArray previousMatch, String pseudoValue, JsNodeArray prevParents,
        JsNodeArray matchingElms) {//from  www . jav  a 2 s.co  m
    Node previous;
    if (pseudoValue.startsWith("n")) {
        matchingElms = previousMatch;
    } else {
        Sequence sequence = getSequence(pseudoValue);
        if (sequence != null) {
            for (int p = 0, plen = previousMatch.size(); p < plen; p++) {
                previous = previousMatch.getNode(p);
                Node prevParent = previous.getParentNode();
                if (!hasChildElms(prevParent)) {
                    int iteratorNext = sequence.start;
                    int childCount = 0;
                    Node childElm = prevParent.getFirstChild();
                    while (JsUtils.truth(childElm) && (sequence.max < 0 || iteratorNext <= sequence.max)) {
                        if (JsUtils.eq(childElm.getNodeName(), previous.getNodeName())) {
                            if (++childCount == iteratorNext) {
                                matchingElms.addNode(childElm);
                                iteratorNext += sequence.add;
                            }
                        }
                        childElm = SelectorEngine.getNextSibling(childElm);
                    }
                    setHasChildElms(prevParent, true);
                    prevParents.addNode(prevParent);
                }
            }
            clearChildElms(prevParents);
        }
    }
    return matchingElms;
}

From source file:com.cgxlib.xq.client.impl.research.SelectorEngineJS.java

License:Apache License

private void getOnlyOfTypePseudo(JsNodeArray previousMatch, JsNodeArray matchingElms) {
    Node previous;//from   w w w. j  a va2  s  . co  m
    Node next;
    Node prev;
    Node oParent = null;
    for (int o = 0, olen = previousMatch.size(); o < olen; o++) {
        prev = next = previous = previousMatch.getNode(o);
        Node prevParent = previous.getParentNode();
        if (prevParent != oParent) {
            while (JsUtils.truth(prev = SelectorEngine.getPreviousSibling(prev))
                    && !JsUtils.eq(prev.getNodeName(), previous.getNodeName())) {
            }
            while (JsUtils.truth(next = SelectorEngine.getNextSibling(next))
                    && !JsUtils.eq(next.getNodeName(), previous.getNodeName())) {
            }
            if (!JsUtils.truth(prev) && !JsUtils.truth(next)) {
                matchingElms.addNode(previous);
            }
            oParent = prevParent;
        }
    }
}