org.nutz.lang.util.HtmlToken Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of nutz Show documentation
Show all versions of nutz Show documentation
Nutz, which is a collections of lightweight frameworks, each of them can be used independently
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;
}
}