package org.minimalj.frontend.impl.json;

import org.minimalj.model.Rendering;
import org.minimalj.model.Rendering.RenderType;

public class JsonText extends JsonComponent {

	public JsonText(Object object) {
		super("Text");
		if (object != null) {
			put(JsonInputComponent.VALUE, object.toString());
		}
	}

	public JsonText(Rendering rendering) {
		super("Text");
		if (rendering != null) {
			RenderType renderType = rendering.getPreferredRenderType(RenderType.HMTL, RenderType.PLAIN_TEXT);
			String s = rendering.render(renderType);
			// Security: should the rendered string be checked for attacks?
			// the value is later inserted in the html page as innerHtml
			put(renderType == RenderType.HMTL ? "htmlValue" : JsonInputComponent.VALUE, s);
		}
	}
}

@@ -119,16 +119,54 @@
 derType;
+%0Aimport org.minimalj.util.StringUtils;
 %0A%0Apublic
@@ -281,16 +281,134 @@
 null) %7B%0A
+%09%09%09String string = object.toString();%0A%09%09%09if (StringUtils.isHtml(string)) %7B%0A%09%09%09%09put(%22htmlValue%22, string);%0A%09%09%09%7D else %7B%0A%09
 %09%09%09put(J
@@ -436,27 +436,21 @@
 UE, 
-object.toString());
+string);%0A%09%09%09%7D
 %0A%09%09%7D

support html text