use of org.structr.web.entity.html.Textarea in project structr by structr.
the class Content method renderContent.
/*
@Override
public String getIdHash() {
final DOMNode _parent = getProperty(DOMNode.parent);
if (_parent != null) {
String dataHash = _parent.getProperty(DOMNode.dataHashProperty);
if (dataHash == null) {
dataHash = _parent.getIdHash();
}
return dataHash + "Content" + treeGetChildPosition(this);
}
return super.getIdHash();
}
*/
public static void renderContent(final Content thisNode, final RenderContext renderContext, final int depth) throws FrameworkException {
final SecurityContext securityContext = thisNode.getSecurityContext();
try {
final EditMode edit = renderContext.getEditMode(securityContext.getUser(false));
if (EditMode.DEPLOYMENT.equals(edit)) {
final AsyncBuffer buf = renderContext.getBuffer();
// output ownership comments
DOMNode.renderDeploymentExportComments(thisNode, buf, true);
// EditMode "deployment" means "output raw content, do not interpret in any way
buf.append(escapeForHtml(thisNode.getContent()));
return;
}
if (thisNode.isDeleted() || thisNode.isHidden() || !thisNode.displayForLocale(renderContext) || !thisNode.displayForConditions(renderContext)) {
return;
}
final String id = thisNode.getUuid();
final boolean inBody = renderContext.inBody();
final AsyncBuffer out = renderContext.getBuffer();
final String _contentType = thisNode.getContentType();
// apply configuration for shared component if present
final String _sharedComponentConfiguration = thisNode.getSharedComponentConfiguration();
if (StringUtils.isNotBlank(_sharedComponentConfiguration)) {
Scripting.evaluate(renderContext, thisNode, "${" + _sharedComponentConfiguration + "}", "shared component configuration");
}
// fetch content with variable replacement
String _content = thisNode.getPropertyWithVariableReplacement(renderContext, StructrApp.key(Content.class, "content"));
if (!(EditMode.RAW.equals(edit) || EditMode.WIDGET.equals(edit)) && (_contentType == null || ("text/plain".equals(_contentType)))) {
_content = escapeForHtml(_content);
}
if (EditMode.CONTENT.equals(edit) && inBody && thisNode.isGranted(Permission.write, securityContext)) {
if ("text/javascript".equals(_contentType)) {
// Javascript will only be given some local vars
out.append("// data-structr-type='").append(thisNode.getType()).append("'\n// data-structr-id='").append(id).append("'\n");
} else if ("text/css".equals(_contentType)) {
// CSS will only be given some local vars
out.append("/* data-structr-type='").append(thisNode.getType()).append("'*/\n/* data-structr-id='").append(id).append("'*/\n");
} else {
// In edit mode, add an artificial comment tag around content nodes within body to make them editable
final String cleanedContent = StringUtils.remove(StringUtils.remove(org.apache.commons.lang3.StringUtils.replace(thisNode.getContent(), "\n", "\\\\n"), "<!--"), "-->");
out.append("<!--data-structr-id=\"".concat(id).concat("\" data-structr-raw-value=\"").concat(escapeForHtmlAttributes(cleanedContent)).concat("\"-->"));
}
}
// examine content type and apply converter
if (_contentType != null) {
final Adapter<String, String> converter = ContentConverters.getConverterForType(_contentType);
if (converter != null) {
try {
// apply adapter
_content = converter.adapt(_content);
} catch (FrameworkException fex) {
logger.warn("Unable to convert content: {}", fex.getMessage());
}
}
}
// replace newlines with <br /> for rendering
if (((_contentType == null) || _contentType.equals("text/plain")) && (_content != null) && !_content.isEmpty()) {
final DOMNode _parent = thisNode.getParent();
if (_parent == null || !(_parent instanceof Textarea)) {
_content = _content.replaceAll("[\\n]{1}", "<br>");
}
}
if (_content != null) {
// insert whitespace to make element clickable
if (EditMode.CONTENT.equals(edit) && _content.length() == 0) {
_content = "--- empty ---";
}
out.append(_content);
}
if (EditMode.CONTENT.equals(edit) && inBody && !("text/javascript".equals(_contentType) && !("text/css".equals(_contentType)))) {
out.append("<!---->");
}
} catch (Throwable t) {
// catch exception to prevent ugly status 500 error pages in frontend.
logger.error("", t);
}
}
Aggregations