Package com.psddev.dari.util

Examples of com.psddev.dari.util.HtmlElement


        for (HtmlNode node : getHeadNodes()) {
            if (!(node instanceof HtmlElement)) {
                continue;
            }

            HtmlElement element = (HtmlElement) node;

            if (name.equals(element.getName()) &&
                    element.hasAttributes(attributes)) {
                return element;
            }
        }

        return null;
View Full Code Here


     * @param name Can't be blank.
     * @param attributes May be {@code null}.
     * @return Never {@code null}.
     */
    public HtmlElement findOrCreateHeadElement(String name, Object... attributes) {
        HtmlElement element = findHeadElement(name, attributes);

        if (element == null) {
            element = new HtmlElement();

            element.setName(name);
            element.addAttributes(attributes);

            List<HtmlNode> nodes = getHeadNodes();

            if (ObjectUtils.isBlank(nodes)) {
                nodes.add(element);

            } else {

                // JS goes last.
                if ("script".equals(name)) {
                    nodes.add(element);

                // CSS goes first.
                } else if ("link".equals(name) &&
                        "text/css".equals(element.getAttributes().get("type"))) {
                    int insertIndex = 0;

                    for (ListIterator<HtmlNode> i = nodes.listIterator(); i.hasNext();) {
                        HtmlNode node = i.next();

                        if (!(node instanceof HtmlElement)) {
                            continue;
                        }

                        HtmlElement iElement = (HtmlElement) node;

                        if ("link".equals(iElement.getName()) &&
                                "text/css".equals(iElement.getAttributes().get("type"))) {
                            continue;

                        } else {
                            insertIndex = i.previousIndex();
                            break;
                        }
                    }

                    nodes.add(insertIndex, element);

                // Everything else in between.
                } else {
                    int insertIndex = 0;

                    for (ListIterator<HtmlNode> i = nodes.listIterator(); i.hasNext();) {
                        HtmlNode node = i.next();

                        if (!(node instanceof HtmlElement)) {
                            continue;
                        }

                        HtmlElement iElement = (HtmlElement) node;

                        if ("script".equals(iElement.getName())) {
                            insertIndex = i.previousIndex();
                            break;

                        } else {
                            insertIndex = i.nextIndex();
View Full Code Here

            if (!(node instanceof HtmlElement)) {
                continue;
            }

            HtmlElement element = (HtmlElement) node;

            if (name.equals(element.getName()) &&
                    element.hasAttributes(attributes)) {
                i.remove();
            }
        }
    }
View Full Code Here

     *
     * @return Never {@code null}.
     */
    public String getTitle() {
        StringBuilder titleText = new StringBuilder();
        HtmlElement titleElement = findHeadElement("title");

        if (titleElement != null) {
            for (HtmlNode child : titleElement.getChildren()) {
                if (child instanceof HtmlText) {
                    titleText.append(((HtmlText) child).getText());
                }
            }
        }
View Full Code Here

     * {@code <meta property="og:description">}).
     *
     * @return Never {@code null}.
     */
    public String getDescription() {
        HtmlElement descriptionElement = findHeadElement("meta", "name", "description");

        if (descriptionElement == null) {
            descriptionElement = findHeadElement("meta", "property", "og:description");
        }

        if (descriptionElement != null) {
            String description = descriptionElement.getAttributes().get("content");

            if (description != null) {
                return description;
            }
        }
View Full Code Here

     * in {@code <link rel="canonical">}.
     *
     * @return May be {@code null}.
     */
    public String getCanonicalUrl() {
        HtmlElement urlElement = findHeadElement("link", "rel", "canonical");

        return urlElement != null ?
                urlElement.getAttributes().get("href") :
                null;
    }
View Full Code Here

        Conditional conditional = new Conditional();
        conditional.setCondition(condition);

        List<HtmlNode> nodes = new ArrayList<HtmlNode>();

        HtmlElement script = new HtmlElement();
        script.setName("script");
        script.addAttributes("type", "text/javascript",
                "src", ElFunctionUtils.resource(src));

        nodes.add(script);

        conditional.setNodes(nodes);
View Full Code Here

TOP

Related Classes of com.psddev.dari.util.HtmlElement

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.