From 5d8d243a26f27f809bec7b5699aca8f46a3fdee5 Mon Sep 17 00:00:00 2001 From: "David E. Jones" Date: Mon, 9 Feb 2009 11:55:07 +0000 Subject: [PATCH] A simple StringWrapper object that can be used to get around the general HTML auto-encoding now done in FTL rendered through the Screen Widget; just call the static method to wrap it and it will insert fine and the encoder will leave it alone git-svn-id: https://svn.apache.org/repos/asf/ofbiz/trunk@742412 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/ofbiz/base/util/MessageString.java | 4 +-- .../src/org/ofbiz/base/util/StringUtil.java | 36 +++++++++++++++++++ 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/framework/base/src/org/ofbiz/base/util/MessageString.java b/framework/base/src/org/ofbiz/base/util/MessageString.java index dfbf9c6f1f..4fb30481ad 100644 --- a/framework/base/src/org/ofbiz/base/util/MessageString.java +++ b/framework/base/src/org/ofbiz/base/util/MessageString.java @@ -18,19 +18,19 @@ *******************************************************************************/ package org.ofbiz.base.util; +import java.io.Serializable; import java.util.ArrayList; import java.util.Collections; -import java.util.Iterator; import java.util.List; import java.util.Locale; import java.util.Set; import java.util.TreeSet; -import java.io.Serializable; /** * Contains extra information about Messages * */ +@SuppressWarnings("serial") public class MessageString implements Serializable { public static final String module = MessageString.class.getName(); diff --git a/framework/base/src/org/ofbiz/base/util/StringUtil.java b/framework/base/src/org/ofbiz/base/util/StringUtil.java index cb560fce23..fc30210b35 100644 --- a/framework/base/src/org/ofbiz/base/util/StringUtil.java +++ b/framework/base/src/org/ofbiz/base/util/StringUtil.java @@ -626,5 +626,41 @@ public class StringUtil { return sb.toString(); } + + public static StringWrapper makeStringWrapper(String theString) { + if (theString == null) return null; + if (theString.length() == 0) return StringWrapper.EMPTY_STRING_WRAPPER; + return new StringWrapper(theString); + } + /** + * A super-lightweight object to wrap a String object. Mainly used with FTL templates + * to avoid the general HTML auto-encoding that is now done through the Screen Widget. + */ + public static class StringWrapper { + public static final StringWrapper EMPTY_STRING_WRAPPER = new StringWrapper(""); + + protected String theString; + protected StringWrapper() { } + public StringWrapper(String theString) { + this.theString = theString; + } + + /** + * Fairly simple method used for the plus (+) base concatenation in Groovy. + * + * @param value + * @return + */ + public String plus(Object value) { + return this.theString + value; + } + + /** + * @return The String this object wraps. + */ + public String toString() { + return this.theString; + } + } }