All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.nutz.lang.util.HtmlToken Maven / Gradle / Ivy

Go to download

Nutz, which is a collections of lightweight frameworks, each of them can be used independently

There is a newer version: 1.r.72
Show newest version
package org.nutz.lang.util;

import java.util.ArrayList;
import java.util.List;

import org.nutz.lang.meta.Pair;

public class HtmlToken {

    HtmlToken() {
        attributes = new ArrayList>();
    }

    private String name;
    private String value;
    private List> attributes;

    public String getTagName() {
        if (null == name)
            return null;
        return name.toUpperCase();
    }

    public String getName() {
        return name;
    }

    public HtmlToken setName(String name) {
        this.name = name;
        return this;
    }

    public String getValue() {
        return value;
    }

    public HtmlToken setValue(String value) {
        this.value = value;
        return this;
    }

    public boolean isElement() {
        return null != name;
    }

    public boolean isText() {
        return null == name && value != null;
    }

    public HtmlToken attr(String name, String value) {
        Pair attr = getAttr(name);
        if (null == attr) {
            attr = new Pair(name, value);
            attributes.add(attr);
        } else {
            attr.setValue(value);
        }
        return this;
    }

    public HtmlToken attr(String name, int value) {
        return attr(name, String.valueOf(value));
    }

    public Pair getAttr(String name) {
        for (Pair attr : attributes)
            if (attr.getName().equals(name))
                return attr;
        return null;
    }

    public String getAttrVal(String name) {
        Pair p = getAttr(name);
        return p == null ? null : p.getValueString();
    }

    public List> getAttributes() {
        return attributes;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy