Author: doogie
Date: Mon Aug 2 14:46:09 2010 New Revision: 981531 URL: http://svn.apache.org/viewvc?rev=981531&view=rev Log: StringUtil now has a private constructor; all uses of it must use the singleton static INSTANCE(only one such use is in ofbiz). Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/util/StringUtil.java ofbiz/trunk/framework/base/src/org/ofbiz/base/util/template/FreeMarkerWorker.java ofbiz/trunk/framework/base/src/org/ofbiz/base/util/test/StringUtilTests.java Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/util/StringUtil.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/util/StringUtil.java?rev=981531&r1=981530&r2=981531&view=diff ============================================================================== --- ofbiz/trunk/framework/base/src/org/ofbiz/base/util/StringUtil.java (original) +++ ofbiz/trunk/framework/base/src/org/ofbiz/base/util/StringUtil.java Mon Aug 2 14:46:09 2010 @@ -56,6 +56,7 @@ import org.owasp.esapi.reference.Default */ public class StringUtil { + public static final StringUtil INSTANCE = new StringUtil(); public static final String module = StringUtil.class.getName(); protected static final Map<String, Pattern> substitutionPatternMap; @@ -81,6 +82,9 @@ public class StringUtil { public static final SimpleEncoder xmlEncoder = new XmlEncoder(); public static final SimpleEncoder stringEncoder = new StringEncoder(); + private StringUtil() { + } + public static interface SimpleEncoder { public String encode(String original); } Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/util/template/FreeMarkerWorker.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/util/template/FreeMarkerWorker.java?rev=981531&r1=981530&r2=981531&view=diff ============================================================================== --- ofbiz/trunk/framework/base/src/org/ofbiz/base/util/template/FreeMarkerWorker.java (original) +++ ofbiz/trunk/framework/base/src/org/ofbiz/base/util/template/FreeMarkerWorker.java Mon Aug 2 14:46:09 2010 @@ -86,7 +86,7 @@ public class FreeMarkerWorker { newConfig.setObjectWrapper(wrapper); newConfig.setSharedVariable("Static", wrapper.getStaticModels()); newConfig.setLocalizedLookup(false); - newConfig.setSharedVariable("StringUtil", new BeanModel(new StringUtil(), wrapper)); + newConfig.setSharedVariable("StringUtil", new BeanModel(StringUtil.INSTANCE, wrapper)); newConfig.setTemplateLoader(new FlexibleTemplateLoader()); newConfig.setAutoImports(UtilProperties.getProperties("freemarkerImports")); newConfig.setTemplateExceptionHandler(new FreeMarkerWorker.OFBizTemplateExceptionHandler()); Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/util/test/StringUtilTests.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/util/test/StringUtilTests.java?rev=981531&r1=981530&r2=981531&view=diff ============================================================================== --- ofbiz/trunk/framework/base/src/org/ofbiz/base/util/test/StringUtilTests.java (original) +++ ofbiz/trunk/framework/base/src/org/ofbiz/base/util/test/StringUtilTests.java Mon Aug 2 14:46:09 2010 @@ -44,7 +44,8 @@ public class StringUtilTests extends Gen } public void testStringUtil() throws Exception { - //assertStaticHelperClass(StringUtil.class); + assertStaticHelperClass(StringUtil.class); + assertTrue("correct INSTANCE", StringUtil.INSTANCE instanceof StringUtil); } private static void encoderTest(String label, StringUtil.SimpleEncoder encoder, String wanted, String toEncode) { |
Free forum by Nabble | Edit this page |