Repository: incubator-freemarker Updated Branches: refs/heads/3 8ba7883e5 -> e90480e99
Removed `String Configurable.getSetting(String)` and `Properties getSettings()`. It has never worked well, and is impossible to implement properly. Project: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/commit/e90480e9 Tree: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/tree/e90480e9 Diff: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/diff/e90480e9 Branch: refs/heads/3 Commit: e90480e99ad05904c9a6c26ffad5d8e897bf0850 Parents: 8ba7883 Author: ddekany <[email protected]> Authored: Mon Feb 20 13:07:05 2017 +0100 Committer: ddekany <[email protected]> Committed: Mon Feb 20 13:07:05 2017 +0100 ---------------------------------------------------------------------- .../freemarker/core/ast/Configurable.java | 113 ------------------- .../debug/impl/RmiDebuggedEnvironmentImpl.java | 3 +- src/manual/en_US/FM3-CHANGE-LOG.txt | 4 +- .../freemarker/core/ConfigurationTest.java | 23 ---- 4 files changed, 4 insertions(+), 139 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/e90480e9/src/main/java/org/apache/freemarker/core/ast/Configurable.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/freemarker/core/ast/Configurable.java b/src/main/java/org/apache/freemarker/core/ast/Configurable.java index 3873f57..8023552 100644 --- a/src/main/java/org/apache/freemarker/core/ast/Configurable.java +++ b/src/main/java/org/apache/freemarker/core/ast/Configurable.java @@ -327,7 +327,6 @@ public class Configurable { }; private Configurable parent; - private Properties properties; private HashMap<Object, Object> customAttributes; private Locale locale; @@ -378,59 +377,25 @@ public class Configurable { */ protected Configurable(Version incompatibleImprovements) { _TemplateAPI.checkVersionNotNullAndSupported(incompatibleImprovements); - parent = null; - properties = new Properties(); - locale = Locale.getDefault(); - properties.setProperty(LOCALE_KEY, locale.toString()); - timeZone = TimeZone.getDefault(); - properties.setProperty(TIME_ZONE_KEY, timeZone.getID()); - sqlDataAndTimeTimeZone = null; - properties.setProperty(SQL_DATE_AND_TIME_TIME_ZONE_KEY, String.valueOf(sqlDataAndTimeTimeZone)); - numberFormat = "number"; - properties.setProperty(NUMBER_FORMAT_KEY, numberFormat); - timeFormat = ""; - properties.setProperty(TIME_FORMAT_KEY, timeFormat); - dateFormat = ""; - properties.setProperty(DATE_FORMAT_KEY, dateFormat); - dateTimeFormat = ""; - properties.setProperty(DATETIME_FORMAT_KEY, dateTimeFormat); - templateExceptionHandler = _TemplateAPI.getDefaultTemplateExceptionHandler( incompatibleImprovements); - properties.setProperty(TEMPLATE_EXCEPTION_HANDLER_KEY, templateExceptionHandler.getClass().getName()); - arithmeticEngine = ArithmeticEngine.BIGDECIMAL_ENGINE; - properties.setProperty(ARITHMETIC_ENGINE_KEY, arithmeticEngine.getClass().getName()); - objectWrapper = Configuration.getDefaultObjectWrapper(incompatibleImprovements); - // bug: setProperty missing - autoFlush = Boolean.TRUE; - properties.setProperty(AUTO_FLUSH_KEY, autoFlush.toString()); - newBuiltinClassResolver = TemplateClassResolver.UNRESTRICTED_RESOLVER; - properties.setProperty(NEW_BUILTIN_CLASS_RESOLVER_KEY, newBuiltinClassResolver.getClass().getName()); - showErrorTips = Boolean.TRUE; - properties.setProperty(SHOW_ERROR_TIPS_KEY, showErrorTips.toString()); - apiBuiltinEnabled = Boolean.FALSE; - properties.setProperty(API_BUILTIN_ENABLED_KEY, apiBuiltinEnabled.toString()); - logTemplateExceptions = Boolean.FALSE; - properties.setProperty(LOG_TEMPLATE_EXCEPTIONS_KEY, logTemplateExceptions.toString()); - // outputEncoding and urlEscapingCharset defaults to null, // which means "not specified" - setBooleanFormat(C_TRUE_FALSE); customAttributes = new HashMap(); @@ -454,28 +419,9 @@ public class Configurable { locale = null; numberFormat = null; templateExceptionHandler = null; - properties = new Properties(parent.properties); customAttributes = new HashMap(0); } - @Override - protected Object clone() throws CloneNotSupportedException { - Configurable copy = (Configurable) super.clone(); - if (properties != null) { - copy.properties = new Properties(properties); - } - if (customAttributes != null) { - copy.customAttributes = (HashMap) customAttributes.clone(); - } - if (autoImports != null) { - copy.autoImports = (LinkedHashMap<String, String>) autoImports.clone(); - } - if (autoIncludes != null) { - copy.autoIncludes = (ArrayList<String>) autoIncludes.clone(); - } - return copy; - } - /** * Returns the parent {@link Configurable} object of this object. The parent stores the default setting values for * this {@link Configurable}. For example, the parent of a {@link org.apache.freemarker.core.Template} object is a @@ -516,7 +462,6 @@ public class Configurable { public void setLocale(Locale locale) { _NullArgumentException.check("locale", locale); this.locale = locale; - properties.setProperty(LOCALE_KEY, locale.toString()); } /** @@ -550,7 +495,6 @@ public class Configurable { public void setTimeZone(TimeZone timeZone) { _NullArgumentException.check("timeZone", timeZone); this.timeZone = timeZone; - properties.setProperty(TIME_ZONE_KEY, timeZone.getID()); } /** @@ -633,7 +577,6 @@ public class Configurable { public void setSQLDateAndTimeTimeZone(TimeZone tz) { sqlDataAndTimeTimeZone = tz; sqlDataAndTimeTimeZoneSet = true; - properties.setProperty(SQL_DATE_AND_TIME_TIME_ZONE_KEY, tz != null ? tz.getID() : "null"); } /** @@ -688,7 +631,6 @@ public class Configurable { public void setNumberFormat(String numberFormat) { _NullArgumentException.check("numberFormat", numberFormat); this.numberFormat = numberFormat; - properties.setProperty(NUMBER_FORMAT_KEY, numberFormat); } /** @@ -840,7 +782,6 @@ public class Configurable { } this.booleanFormat = booleanFormat; - properties.setProperty(BOOLEAN_FORMAT_KEY, booleanFormat); if (booleanFormat.equals(C_TRUE_FALSE)) { // C_TRUE_FALSE is the default for BC, but it's not a good default for human audience formatting, so we @@ -949,7 +890,6 @@ public class Configurable { public void setTimeFormat(String timeFormat) { _NullArgumentException.check("timeFormat", timeFormat); this.timeFormat = timeFormat; - properties.setProperty(TIME_FORMAT_KEY, timeFormat); } /** @@ -979,7 +919,6 @@ public class Configurable { public void setDateFormat(String dateFormat) { _NullArgumentException.check("dateFormat", dateFormat); this.dateFormat = dateFormat; - properties.setProperty(DATE_FORMAT_KEY, dateFormat); } /** @@ -1087,7 +1026,6 @@ public class Configurable { public void setDateTimeFormat(String dateTimeFormat) { _NullArgumentException.check("dateTimeFormat", dateTimeFormat); this.dateTimeFormat = dateTimeFormat; - properties.setProperty(DATETIME_FORMAT_KEY, dateTimeFormat); } /** @@ -1206,7 +1144,6 @@ public class Configurable { public void setTemplateExceptionHandler(TemplateExceptionHandler templateExceptionHandler) { _NullArgumentException.check("templateExceptionHandler", templateExceptionHandler); this.templateExceptionHandler = templateExceptionHandler; - properties.setProperty(TEMPLATE_EXCEPTION_HANDLER_KEY, templateExceptionHandler.getClass().getName()); } /** @@ -1233,7 +1170,6 @@ public class Configurable { public void setArithmeticEngine(ArithmeticEngine arithmeticEngine) { _NullArgumentException.check("arithmeticEngine", arithmeticEngine); this.arithmeticEngine = arithmeticEngine; - properties.setProperty(ARITHMETIC_ENGINE_KEY, arithmeticEngine.getClass().getName()); } /** @@ -1260,7 +1196,6 @@ public class Configurable { public void setObjectWrapper(ObjectWrapper objectWrapper) { _NullArgumentException.check("objectWrapper", objectWrapper); this.objectWrapper = objectWrapper; - properties.setProperty(OBJECT_WRAPPER_KEY, objectWrapper.getClass().getName()); } /** @@ -1290,12 +1225,6 @@ public class Configurable { */ public void setOutputEncoding(String outputEncoding) { this.outputEncoding = outputEncoding; - // java.util.Properties doesn't allow null value! - if (outputEncoding != null) { - properties.setProperty(OUTPUT_ENCODING_KEY, outputEncoding); - } else { - properties.remove(OUTPUT_ENCODING_KEY); - } outputEncodingSet = true; } @@ -1322,12 +1251,6 @@ public class Configurable { */ public void setURLEscapingCharset(String urlEscapingCharset) { this.urlEscapingCharset = urlEscapingCharset; - // java.util.Properties doesn't allow null value! - if (urlEscapingCharset != null) { - properties.setProperty(URL_ESCAPING_CHARSET_KEY, urlEscapingCharset); - } else { - properties.remove(URL_ESCAPING_CHARSET_KEY); - } urlEscapingCharsetSet = true; } @@ -1361,8 +1284,6 @@ public class Configurable { public void setNewBuiltinClassResolver(TemplateClassResolver newBuiltinClassResolver) { _NullArgumentException.check("newBuiltinClassResolver", newBuiltinClassResolver); this.newBuiltinClassResolver = newBuiltinClassResolver; - properties.setProperty(NEW_BUILTIN_CLASS_RESOLVER_KEY, - newBuiltinClassResolver.getClass().getName()); } /** @@ -1405,7 +1326,6 @@ public class Configurable { */ public void setAutoFlush(boolean autoFlush) { this.autoFlush = Boolean.valueOf(autoFlush); - properties.setProperty(AUTO_FLUSH_KEY, String.valueOf(autoFlush)); } /** @@ -1436,7 +1356,6 @@ public class Configurable { */ public void setShowErrorTips(boolean showTips) { showErrorTips = Boolean.valueOf(showTips); - properties.setProperty(SHOW_ERROR_TIPS_KEY, String.valueOf(showTips)); } /** @@ -1467,7 +1386,6 @@ public class Configurable { */ public void setAPIBuiltinEnabled(boolean value) { apiBuiltinEnabled = Boolean.valueOf(value); - properties.setProperty(API_BUILTIN_ENABLED_KEY, String.valueOf(value)); } /** @@ -1503,7 +1421,6 @@ public class Configurable { */ public void setLogTemplateExceptions(boolean value) { logTemplateExceptions = Boolean.valueOf(value); - properties.setProperty(LOG_TEMPLATE_EXCEPTIONS_KEY, String.valueOf(value)); } /** @@ -2440,36 +2357,6 @@ public class Configurable { ((BeansWrapper) objectWrapper).setStrict(strict); } - /** - * Returns the textual representation of a setting. - * @param key the setting key. Can be any of standard <tt>XXX_KEY</tt> - * constants, or a custom key. - * - * @deprecated It's not possible in general to convert setting values to string, - * and thus it's impossible to ensure that {@link #setSetting(String, String)} will work with - * the returned value correctly. - */ - @Deprecated - public String getSetting(String key) { - return properties.getProperty(key); - } - - /** - * This meant to return the String-to-String <code>Map</code> of the - * settings. So it actually should return a <code>Properties</code> object, - * but it doesn't by mistake. The returned <code>Map</code> is read-only, - * but it will reflect the further configuration changes (aliasing effect). - * - * @deprecated This method was always defective, and certainly it always - * will be. Don't use it. (Simply, it's hardly possible in general to - * convert setting values to text in a way that ensures that - * {@link #setSettings(Properties)} will work with them correctly.) - */ - @Deprecated - public Map getSettings() { - return Collections.unmodifiableMap(properties); - } - protected Environment getEnvironment() { return this instanceof Environment ? (Environment) this http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/e90480e9/src/main/java/org/apache/freemarker/core/debug/impl/RmiDebuggedEnvironmentImpl.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/freemarker/core/debug/impl/RmiDebuggedEnvironmentImpl.java b/src/main/java/org/apache/freemarker/core/debug/impl/RmiDebuggedEnvironmentImpl.java index 4b798e5..267e224 100644 --- a/src/main/java/org/apache/freemarker/core/debug/impl/RmiDebuggedEnvironmentImpl.java +++ b/src/main/java/org/apache/freemarker/core/debug/impl/RmiDebuggedEnvironmentImpl.java @@ -184,8 +184,7 @@ class RmiDebuggedEnvironmentImpl extends RmiDebugModelImpl implements DebuggedEn @Override public TemplateModel get(String key) throws TemplateModelException { - String s = configurable.getSetting(key); - return s == null ? null : new SimpleScalar(s); + return null; // TODO } } http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/e90480e9/src/manual/en_US/FM3-CHANGE-LOG.txt ---------------------------------------------------------------------- diff --git a/src/manual/en_US/FM3-CHANGE-LOG.txt b/src/manual/en_US/FM3-CHANGE-LOG.txt index 374e845..049c3ed 100644 --- a/src/manual/en_US/FM3-CHANGE-LOG.txt +++ b/src/manual/en_US/FM3-CHANGE-LOG.txt @@ -88,4 +88,6 @@ the FreeMarer 3 changelog here: - Deleted o.a.f.core.util.DOMNodeModel (it has noting to do with the standard XML support, o.a.f.core.model.dom) - All CacheStorage-s must be thread safe from now on (removed ConcurrentCacheStorage marker interface) - Removed support for incompatibleImprovements before 3.0.0. So currently 3.0.0 is the only support value. -- Changed the default of logTemplateExceptions to false. \ No newline at end of file +- Changed the default of logTemplateExceptions to false. +- Removed `String Configurable.getSetting(String)` and `Properties getSettings()`. It has never worked well, + and is impossible to implement properly. \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/e90480e9/src/test/java/org/apache/freemarker/core/ConfigurationTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/freemarker/core/ConfigurationTest.java b/src/test/java/org/apache/freemarker/core/ConfigurationTest.java index b5f2b8b..90d8161 100644 --- a/src/test/java/org/apache/freemarker/core/ConfigurationTest.java +++ b/src/test/java/org/apache/freemarker/core/ConfigurationTest.java @@ -963,18 +963,14 @@ public class ConfigurationTest extends TestCase { Configuration cfg = new Configuration(Configuration.VERSION_3_0_0); assertEquals(sysDefTZ, cfg.getTimeZone()); - assertEquals(sysDefTZ.getID(), cfg.getSetting(Configurable.TIME_ZONE_KEY)); cfg.setSetting(Configurable.TIME_ZONE_KEY, "JVM default"); assertEquals(sysDefTZ, cfg.getTimeZone()); - assertEquals(sysDefTZ.getID(), cfg.getSetting(Configurable.TIME_ZONE_KEY)); TimeZone newSysDefTZ = TimeZone.getTimeZone("GMT+09"); TimeZone.setDefault(newSysDefTZ); assertEquals(sysDefTZ, cfg.getTimeZone()); - assertEquals(sysDefTZ.getID(), cfg.getSetting(Configurable.TIME_ZONE_KEY)); cfg.setSetting(Configurable.TIME_ZONE_KEY, "JVM default"); assertEquals(newSysDefTZ, cfg.getTimeZone()); - assertEquals(newSysDefTZ.getID(), cfg.getSetting(Configurable.TIME_ZONE_KEY)); } finally { TimeZone.setDefault(origSysDefTZ); } @@ -988,19 +984,15 @@ public class ConfigurationTest extends TestCase { Configuration cfg = new Configuration(Configuration.VERSION_3_0_0); assertNull(cfg.getSQLDateAndTimeTimeZone()); - assertEquals("null", cfg.getSetting(Configurable.SQL_DATE_AND_TIME_TIME_ZONE_KEY)); cfg.setSQLDateAndTimeTimeZone(null); assertNull(cfg.getSQLDateAndTimeTimeZone()); - assertEquals("null", cfg.getSetting(Configurable.SQL_DATE_AND_TIME_TIME_ZONE_KEY)); cfg.setSetting(Configurable.SQL_DATE_AND_TIME_TIME_ZONE_KEY, "JVM default"); assertEquals(sysDefTZ, cfg.getSQLDateAndTimeTimeZone()); - assertEquals(sysDefTZ.getID(), cfg.getSetting(Configurable.SQL_DATE_AND_TIME_TIME_ZONE_KEY)); cfg.setSetting(Configurable.SQL_DATE_AND_TIME_TIME_ZONE_KEY, "null"); assertNull(cfg.getSQLDateAndTimeTimeZone()); - assertEquals("null", cfg.getSetting(Configurable.SQL_DATE_AND_TIME_TIME_ZONE_KEY)); } finally { TimeZone.setDefault(origSysDefTZ); } @@ -1015,40 +1007,32 @@ public class ConfigurationTest extends TestCase { // cfg: assertEquals(TimeZone.getDefault(), cfg.getTimeZone()); assertNull(cfg.getSQLDateAndTimeTimeZone()); - assertEquals("null", cfg.getSetting(Configurable.SQL_DATE_AND_TIME_TIME_ZONE_KEY)); // env: assertEquals(TimeZone.getDefault(), env1.getTimeZone()); assertNull(env1.getSQLDateAndTimeTimeZone()); - assertEquals("null", env1.getSetting(Configurable.SQL_DATE_AND_TIME_TIME_ZONE_KEY)); // env 2: assertEquals(TimeZone.getDefault(), env2.getTimeZone()); assertNull(env2.getSQLDateAndTimeTimeZone()); - assertEquals("null", env2.getSetting(Configurable.SQL_DATE_AND_TIME_TIME_ZONE_KEY)); env1.setSQLDateAndTimeTimeZone(_DateUtil.UTC); // cfg: assertEquals(TimeZone.getDefault(), cfg.getTimeZone()); assertNull(cfg.getSQLDateAndTimeTimeZone()); - assertEquals("null", cfg.getSetting(Configurable.SQL_DATE_AND_TIME_TIME_ZONE_KEY)); // env: assertEquals(TimeZone.getDefault(), env1.getTimeZone()); assertEquals(_DateUtil.UTC, env1.getSQLDateAndTimeTimeZone()); - assertEquals(_DateUtil.UTC.getID(), env1.getSetting(Configurable.SQL_DATE_AND_TIME_TIME_ZONE_KEY)); TimeZone localTZ = TimeZone.getTimeZone("Europe/Brussels"); env1.setTimeZone(localTZ); // cfg: assertEquals(TimeZone.getDefault(), cfg.getTimeZone()); assertNull(cfg.getSQLDateAndTimeTimeZone()); - assertEquals("null", cfg.getSetting(Configurable.SQL_DATE_AND_TIME_TIME_ZONE_KEY)); // env: assertEquals(localTZ, env1.getTimeZone()); assertEquals(_DateUtil.UTC, env1.getSQLDateAndTimeTimeZone()); - assertEquals(_DateUtil.UTC.getID(), env1.getSetting(Configurable.SQL_DATE_AND_TIME_TIME_ZONE_KEY)); // env 2: assertEquals(TimeZone.getDefault(), env2.getTimeZone()); assertNull(env2.getSQLDateAndTimeTimeZone()); - assertEquals("null", env2.getSetting(Configurable.SQL_DATE_AND_TIME_TIME_ZONE_KEY)); TimeZone otherTZ1 = TimeZone.getTimeZone("GMT+05"); TimeZone otherTZ2 = TimeZone.getTimeZone("GMT+06"); @@ -1057,17 +1041,12 @@ public class ConfigurationTest extends TestCase { // cfg: assertEquals(otherTZ1, cfg.getTimeZone()); assertEquals(otherTZ2, cfg.getSQLDateAndTimeTimeZone()); - assertEquals(otherTZ1.getID(), cfg.getSetting(Configurable.TIME_ZONE_KEY)); - assertEquals(otherTZ2.getID(), cfg.getSetting(Configurable.SQL_DATE_AND_TIME_TIME_ZONE_KEY)); // env: assertEquals(localTZ, env1.getTimeZone()); assertEquals(_DateUtil.UTC, env1.getSQLDateAndTimeTimeZone()); - assertEquals(_DateUtil.UTC.getID(), env1.getSetting(Configurable.SQL_DATE_AND_TIME_TIME_ZONE_KEY)); // env 2: assertEquals(otherTZ1, env2.getTimeZone()); assertEquals(otherTZ2, env2.getSQLDateAndTimeTimeZone()); - assertEquals(otherTZ1.getID(), env2.getSetting(Configurable.TIME_ZONE_KEY)); - assertEquals(otherTZ2.getID(), env2.getSetting(Configurable.SQL_DATE_AND_TIME_TIME_ZONE_KEY)); try { setTimeZoneToNull(env2); @@ -1078,8 +1057,6 @@ public class ConfigurationTest extends TestCase { env2.setSQLDateAndTimeTimeZone(null); assertEquals(otherTZ1, env2.getTimeZone()); assertNull(env2.getSQLDateAndTimeTimeZone()); - assertEquals(otherTZ1.getID(), env2.getSetting(Configurable.TIME_ZONE_KEY)); - assertEquals("null", env2.getSetting(Configurable.SQL_DATE_AND_TIME_TIME_ZONE_KEY)); } @SuppressFBWarnings(value="NP_NULL_PARAM_DEREF_ALL_TARGETS_DANGEROUS", justification="Expected to fail")
