aboutsummaryrefslogtreecommitdiffstats
path: root/server/src/com/vaadin/ui/declarative
diff options
context:
space:
mode:
authorMaciej PrzepioĢra <matthew@vaadin.com>2015-09-16 10:48:31 +0200
committerVaadin Code Review <review@vaadin.com>2015-09-24 07:46:38 +0000
commit5c875228d9025f4c779ffc26c3eb0f7b561061e5 (patch)
tree2e3a0d230478ef7d9090db31597e440f3f1738e7 /server/src/com/vaadin/ui/declarative
parent8006d359acce4fb31e7210ed2f20f1da3d7a1cd0 (diff)
downloadvaadin-framework-5c875228d9025f4c779ffc26c3eb0f7b561061e5.tar.gz
vaadin-framework-5c875228d9025f4c779ffc26c3eb0f7b561061e5.zip
Support HTML entities when reading/writing declarative format #18882
Change-Id: I08099673c5dd0d688d3243e5fd169edb05f046f3
Diffstat (limited to 'server/src/com/vaadin/ui/declarative')
-rw-r--r--server/src/com/vaadin/ui/declarative/DesignFormatter.java51
1 files changed, 51 insertions, 0 deletions
diff --git a/server/src/com/vaadin/ui/declarative/DesignFormatter.java b/server/src/com/vaadin/ui/declarative/DesignFormatter.java
index 73c45caed4..db901329cb 100644
--- a/server/src/com/vaadin/ui/declarative/DesignFormatter.java
+++ b/server/src/com/vaadin/ui/declarative/DesignFormatter.java
@@ -28,12 +28,15 @@ import java.util.Set;
import java.util.TimeZone;
import java.util.concurrent.ConcurrentHashMap;
+import org.jsoup.parser.Parser;
+
import com.vaadin.data.util.converter.Converter;
import com.vaadin.data.util.converter.StringToBigDecimalConverter;
import com.vaadin.data.util.converter.StringToDoubleConverter;
import com.vaadin.data.util.converter.StringToFloatConverter;
import com.vaadin.event.ShortcutAction;
import com.vaadin.server.Resource;
+import com.vaadin.ui.AbstractSelect;
import com.vaadin.ui.declarative.converters.DesignDateConverter;
import com.vaadin.ui.declarative.converters.DesignEnumConverter;
import com.vaadin.ui.declarative.converters.DesignObjectConverter;
@@ -360,4 +363,52 @@ public class DesignFormatter implements Serializable {
return findConverterFor(sourceType, false);
}
+ /**
+ * <p>
+ * Encodes <em>some</em> special characters in a given input String to make
+ * it ready to be written as contents of a text node. WARNING: this will
+ * e.g. encode "&lt;someTag&gt;" to "&amp;lt;someTag&amp;gt;" as this method
+ * doesn't do any parsing and assumes that there are no intended HTML
+ * elements in the input. Only some entities are actually encoded:
+ * &amp;,&lt;, &gt; It's assumed that other entities are taken care of by
+ * Jsoup.
+ * </p>
+ * <p>
+ * Typically, this method will be used by components to encode data (like
+ * option items in {@link AbstractSelect}) when dumping to HTML format
+ * </p>
+ *
+ * @since
+ * @param input
+ * String to be encoded
+ * @return String with &amp;,&lt; and &gt; replaced with their HTML entities
+ */
+ public static String encodeForTextNode(String input) {
+ if (input == null) {
+ return null;
+ }
+ return input.replace("&", "&amp;").replace(">", "&gt;")
+ .replace("<", "&lt;");
+ }
+
+ /**
+ * <p>
+ * Decodes HTML entities in a text from text node and replaces them with
+ * actual characters.
+ * </p>
+ *
+ * <p>
+ * Typically this method will be used by components to read back data (like
+ * option items in {@link AbstractSelect}) from HTML. Note that this method
+ * unencodes more characters than {@link #encodeForTextNode(String)} encodes
+ * </p>
+ *
+ * @since
+ * @param input
+ * @return
+ */
+ public static String unencodeFromTextNode(String input) {
+ return Parser.unescapeEntities(input, false);
+ }
+
}