Example usage for com.google.gwt.dom.client Element getElementsByTagName

List of usage examples for com.google.gwt.dom.client Element getElementsByTagName

Introduction

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

Prototype

@Override
    public NodeList<Element> getElementsByTagName(String name) 

Source Link

Usage

From source file:com.alkacon.geranium.client.util.DomUtil.java

License:Open Source License

/**
 * Returns all elements with the given CSS class and tag name including the root element.<p>
 * //ww w . j  av a2s  . c o m
 * @param className the class name to look for
 * @param tag the tag
 * @param rootElement the root element of the search
 * 
 * @return the matching elements
 */
public static List<Element> getElementsByClass(String className, Tag tag, Element rootElement) {

    if ((rootElement == null) || (className == null) || (className.trim().length() == 0) || (tag == null)) {
        return null;
    }
    className = className.trim();
    List<Element> result = new ArrayList<Element>();
    if (internalHasClass(className, rootElement)) {
        result.add(rootElement);
    }
    NodeList<Element> elements = rootElement.getElementsByTagName(tag.toString());
    for (int i = 0; i < elements.getLength(); i++) {
        if (internalHasClass(className, elements.getItem(i))) {
            result.add(elements.getItem(i));
        }
    }
    return result;
}

From source file:com.alkacon.geranium.client.util.DomUtil.java

License:Open Source License

/**
 * Removes all script tags from the given element.<p>
 * //from w ww . j av a  2  s . com
 * @param element the element to remove the script tags from
 * 
 * @return the resulting element
 */
public static Element removeScriptTags(Element element) {

    NodeList<Element> scriptTags = element.getElementsByTagName(Tag.script.name());
    // iterate backwards over list to ensure all tags get removed
    for (int i = scriptTags.getLength() - 1; i >= 0; i--) {
        scriptTags.getItem(i).removeFromParent();
    }
    return element;
}

From source file:com.anzsoft.client.XMPP.mandioca.rooms.XmppRoom.java

License:Open Source License

XmppRoom(final XmppSession session, final String userInRoomId, final String roomId) {
    super(session, userInRoomId, new XmppIdPacketListener(roomId));
    this.roomId = roomId;
    this.sessionRoomId = userInRoomId;
    this.presenceListeners = new RoomPresenceListenerCollection();

    addPresenceListener(new XmppPresenceListener() {
        public void onPresenceReceived(final XmppPresence presence) {
            String alias = presence.getFromID().getResource();
            String type = presence.getType();
            if (type != null && type.equals(XmppPresence.TYPE_UNAVAILABLE)) {
                presenceListeners.fireUserLeaves(alias);
            } else {
                Element pNode = (Element) presence.getNode();
                Element item = pNode.getElementsByTagName("item").getItem(0);
                MUCItem mucItem = new MUCItem(Role.NoRole, Affiliation.NoAffiliation);
                if (item != null)
                    mucItem.fromXml(item);
                presenceListeners.fireUserEntered(alias, mucItem);
            }/*from  w w w.j a  v  a  2s.c om*/
        }

        public void onPresenceSent(final XmppPresence presence) {
        }
    });
}

From source file:com.brazoft.foundation.gwt.client.component.ElementResolver.java

License:Apache License

public static Element getElementByTagName(Element parent, String tagName) {
    NodeList<Element> nodeList = parent.getElementsByTagName(tagName);

    if (nodeList.getLength() > 0) {
        return nodeList.getItem(0);
    }//ww w  . j  ava2 s .  c  om

    return null;
}

From source file:com.brazoft.foundation.gwt.client.component.ElementResolver.java

License:Apache License

public static NodeIterable<Element> getElementsByTagName(Element parent, String tagName) {
    return new NodeIterable<Element>(parent.getElementsByTagName(tagName));
}

From source file:com.ciplogic.web.codeeditor.render.html.HtmlCodeRenderer.java

License:Open Source License

@Override
public String getCode(Element codeElement) {
    return codeElement.getElementsByTagName("pre").getItem(0).getInnerText();
}

From source file:com.dgzt.html.ButtonFootballGameHtml.java

License:Open Source License

/**
 * Scale the canvas on the html page.//from ww w  .  j av a2 s .c o m
 */
private void scaleCanvas() {
    Element element = Document.get().getElementById("embed-html");
    int width = getWindowInnerWidth();
    int height = getWindowInnerHeight();
    consoleLog(String.valueOf(width) + " x " + String.valueOf(height));
    NodeList<Element> nl = element.getElementsByTagName("canvas");
    if (nl != null && nl.getLength() > 0) {
        Element canvas = nl.getItem(0);
        canvas.setAttribute("width", "" + width + "px");
        canvas.setAttribute("height", "" + height + "px");
        canvas.getStyle().setWidth(width, Style.Unit.PX);
        canvas.getStyle().setHeight(height, Style.Unit.PX);
        canvas.getStyle().setTop(0, Style.Unit.PX);
        canvas.getStyle().setLeft(0, Style.Unit.PX);
        canvas.getStyle().setPosition(Style.Position.ABSOLUTE);
    }
}

From source file:com.dom_distiller.client.ContentExtractor.java

License:Open Source License

private static void makeAllLinksAbsolute(Node rootNode) {
    Element root = Element.as(rootNode);

    // AnchorElement.getHref() and ImageElement.getSrc() both return the
    // absolute URI, so simply set them as the respective attributes.

    NodeList<Element> allLinks = root.getElementsByTagName("A");
    for (int i = 0; i < allLinks.getLength(); i++) {
        AnchorElement link = AnchorElement.as(allLinks.getItem(i));
        if (!link.getHref().isEmpty()) {
            link.setHref(link.getHref());
        }//from w w  w .  j av a 2 s . com
    }
    NodeList<Element> videoTags = root.getElementsByTagName("VIDEO");
    for (int i = 0; i < videoTags.getLength(); i++) {
        VideoElement video = (VideoElement) videoTags.getItem(i);
        if (!video.getPoster().isEmpty()) {
            video.setPoster(video.getPoster());
        }
    }
    makeAllSrcAttributesAbsolute(root);
}

From source file:com.dom_distiller.client.DocumentTitleGetter.java

License:Open Source License

/**
 * @return The title of the distilled document.
 *///w  ww  . j a va 2  s  .  com
public static String getDocumentTitle(Object objTitle, Element root) {
    String currTitle = "", origTitle = "";

    if (objTitle.getClass() == currTitle.getClass()) { // If objTitle is of String type.
        currTitle = origTitle = objTitle.toString();
    } else if (root != null) { // Otherwise, use text of first TITLE element.
        NodeList<Element> titles = root.getElementsByTagName("TITLE");
        if (titles.getLength() > 0) {
            // Use javacript textContent instead of javascript innerText; the latter only returns
            // visible text, but <title> tags are invisible.
            currTitle = origTitle = DomUtil.javascriptTextContent(titles.getItem(0));
        }
    }
    if (currTitle == "")
        return "";

    if (StringUtil.match(currTitle, " [\\|\\-] ")) { // Title has '|' and/or '-'.
        // Get part before last '|' or '-'.
        currTitle = StringUtil.findAndReplace(origTitle, "(.*)[\\|\\-] .*", "$1");
        if (StringUtil.splitLength(currTitle, "\\s+") < 3) { // Part has < 3 words.
            // Get part after first '|' or '-'.
            currTitle = StringUtil.findAndReplace(origTitle, "[^\\|\\-]*[\\|\\-](.*)", "$1");
        }
    } else if (currTitle.indexOf(": ") != -1) { // Title has ':'.
        // Get part after last ':'.
        currTitle = StringUtil.findAndReplace(origTitle, ".*:(.*)", "$1");
        if (StringUtil.splitLength(currTitle, "\\s+") < 3) { // Part has < 3 words.
            // Get part after first ':'.
            currTitle = StringUtil.findAndReplace(origTitle, "[^:]*[:](.*)", "$1");
        }
    } else if (root != null && (currTitle.length() > 150 || currTitle.length() < 15)) {
        // Get plain text from the only H1 element.
        // TODO(kuan): this is what readability does, but this block may make more sense as an
        // if rather than else-if, e.g. currently this else-if block is used when original title
        // is "foo" but not when it is "foo |" or "foo:".
        currTitle = findFirstH1(root);
        if (currTitle.isEmpty())
            currTitle = origTitle;
    }

    currTitle = StringUtil.jsTrim(currTitle);

    if (StringUtil.splitLength(currTitle, "\\s+") <= 4)
        currTitle = origTitle;

    return currTitle;
}

From source file:com.dom_distiller.client.DocumentTitleGetter.java

License:Open Source License

private static String findFirstH1(Element root) {
    NodeList<Element> hOnes = root.getElementsByTagName("H1");
    // Use javacript innerText instead of javascript textContent; the former only returns
    // visible text, and we assume visible H1's are more inclined to being potential titles.
    String h1 = "";
    for (int i = 0; i < hOnes.getLength() && h1.isEmpty(); i++) {
        h1 = DomUtil.getInnerText(hOnes.getItem(i));
    }/*from   w  w w.  j  a  v  a2s . c  o m*/
    return h1;
}