use of org.structr.web.property.CustomHtmlAttributeProperty in project structr by structr.
the class DOMNode method renderCustomAttributes.
static void renderCustomAttributes(final DOMNode thisNode, final AsyncBuffer out, final SecurityContext securityContext, final RenderContext renderContext) throws FrameworkException {
final EditMode editMode = renderContext.getEditMode(securityContext.getUser(false));
for (PropertyKey key : thisNode.getDataPropertyKeys()) {
String value = "";
if (EditMode.DEPLOYMENT.equals(editMode)) {
final Object obj = thisNode.getProperty(key);
if (obj != null) {
value = obj.toString();
}
} else {
value = thisNode.getPropertyWithVariableReplacement(renderContext, key);
if (value != null) {
value = value.trim();
}
}
if (!(EditMode.RAW.equals(editMode) || EditMode.WIDGET.equals(editMode))) {
value = escapeForHtmlAttributes(value);
}
if (StringUtils.isNotBlank(value)) {
if (key instanceof CustomHtmlAttributeProperty) {
out.append(" ").append(((CustomHtmlAttributeProperty) key).cleanName()).append("=\"").append(value).append("\"");
} else {
out.append(" ").append(key.dbName()).append("=\"").append(value).append("\"");
}
}
}
if (EditMode.DEPLOYMENT.equals(editMode) || EditMode.RAW.equals(editMode) || EditMode.WIDGET.equals(editMode)) {
if (EditMode.DEPLOYMENT.equals(editMode)) {
// export name property if set
final String name = thisNode.getProperty(AbstractNode.name);
if (name != null) {
out.append(" data-structr-meta-name=\"").append(escapeForHtmlAttributes(name)).append("\"");
}
}
for (final String p : rawProps) {
String htmlName = "data-structr-meta-" + CaseHelper.toUnderscore(p, false).replaceAll("_", "-");
Object value = thisNode.getProperty(p);
if (value != null) {
final PropertyKey key = StructrApp.key(DOMNode.class, p);
final boolean isBoolean = key instanceof BooleanProperty;
final String stringValue = value.toString();
if ((isBoolean && "true".equals(stringValue)) || (!isBoolean && StringUtils.isNotBlank(stringValue))) {
out.append(" ").append(htmlName).append("=\"").append(escapeForHtmlAttributes(stringValue)).append("\"");
}
}
}
}
}
use of org.structr.web.property.CustomHtmlAttributeProperty in project structr by structr.
the class DOMNode method getDataPropertyKeys.
static Set<PropertyKey> getDataPropertyKeys(final DOMNode thisNode) {
final Set<PropertyKey> customProperties = new TreeSet<>();
final org.structr.api.graph.Node dbNode = thisNode.getNode();
final Iterable<String> props = dbNode.getPropertyKeys();
for (final String key : props) {
PropertyKey propertyKey = StructrApp.getConfiguration().getPropertyKeyForJSONName(thisNode.getClass(), key, false);
if (propertyKey == null) {
// support arbitrary data-* attributes
propertyKey = new StringProperty(key);
}
if (key.startsWith("data-")) {
if (propertyKey != null && propertyKey instanceof BooleanProperty && dbNode.hasProperty(key)) {
final Object defaultValue = propertyKey.defaultValue();
final Object nodeValue = dbNode.getProperty(key);
// don't export boolean false values (which is the default)
if (nodeValue != null && Boolean.FALSE.equals(nodeValue) && (defaultValue == null || nodeValue.equals(defaultValue))) {
continue;
}
}
customProperties.add(propertyKey);
} else if (key.startsWith(CustomHtmlAttributeProperty.CUSTOM_HTML_ATTRIBUTE_PREFIX)) {
final CustomHtmlAttributeProperty customProp = new CustomHtmlAttributeProperty(propertyKey);
customProperties.add(customProp);
}
}
return customProperties;
}
Aggregations