xhtml fluent improvements

This commit is contained in:
Grahame Grieve 2023-08-15 19:34:08 +10:00
parent 2b15c545fc
commit cc5069ccb3
2 changed files with 40 additions and 9 deletions

View File

@ -54,7 +54,8 @@ public abstract class XhtmlFluent {
} }
public XhtmlNode td() { public XhtmlNode td() {
return addTag("td"); XhtmlNode x = addTag("td");
return x;
} }
public XhtmlNode td(String clss) { public XhtmlNode td(String clss) {

View File

@ -363,6 +363,10 @@ public class XhtmlNode extends XhtmlFluent implements IBaseXhtml {
return hasAttributes() && getAttributes().containsKey(name); return hasAttributes() && getAttributes().containsKey(name);
} }
public boolean hasAttribute(String name, String value) {
return hasAttributes() && getAttributes().containsKey(name) && value.equals(getAttributes().get(name));
}
public String getAttribute(String name) { public String getAttribute(String name) {
return hasAttributes() ? getAttributes().get(name) : null; return hasAttributes() ? getAttributes().get(name) : null;
} }
@ -569,18 +573,25 @@ public class XhtmlNode extends XhtmlFluent implements IBaseXhtml {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
/** private Map<String, Object> userData;
* NOT SUPPORTED - Throws {@link UnsupportedOperationException}
*/
public Object getUserData(String theName) { public Object getUserData(String theName) {
throw new UnsupportedOperationException(); if (hasUserData(theName)) {
return userData.get(theName);
} else {
return null;
}
}
public boolean hasUserData(String theName) {
return userData != null && userData.containsKey(theName);
} }
/**
* NOT SUPPORTED - Throws {@link UnsupportedOperationException}
*/
public void setUserData(String theName, Object theValue) { public void setUserData(String theName, Object theValue) {
throw new UnsupportedOperationException(); if (userData == null) {
userData = new HashMap<>();
}
userData.put(theName, theValue);
} }
@ -892,4 +903,23 @@ public class XhtmlNode extends XhtmlFluent implements IBaseXhtml {
} }
} }
public boolean isClass(String name) {
return hasAttribute("class", name);
}
public void styleCells(XhtmlNode x) {
setUserData("cells", x);
}
public XhtmlNode td() {
XhtmlNode x = addTag("td");
XhtmlNode t = (XhtmlNode) getUserData("cells");
if (t != null) {
x.copyAllContent(t);
}
return x;
}
} }