static boolean is2324Bugfixed(Version version) { return version.intValue() >= _TemplateAPI.VERSION_INT_2_3_24; }
static boolean is2321Bugfixed(Version version) { return version.intValue() >= _TemplateAPI.VERSION_INT_2_3_21; }
/** * Getter pair of {@link #setRecognizeStandardFileExtensions(boolean)}. * * @since 2.3.24 */ public boolean getRecognizeStandardFileExtensions() { return recognizeStandardFileExtensions == null ? incompatibleImprovements.intValue() >= _TemplateAPI.VERSION_INT_2_3_24 : recognizeStandardFileExtensions.booleanValue(); }
/** * @deprecated Use {@link #getIncompatibleImprovements()} instead. */ @Deprecated public int getParsedIncompatibleEnhancements() { return getIncompatibleImprovements().intValue(); }
ClassIntrospectorBuilder(Version incompatibleImprovements) { // Warning: incompatibleImprovements must not affect this object at versions increments where there's no // change in the BeansWrapper.normalizeIncompatibleImprovements results. That is, this class may don't react // to some version changes that affects BeansWrapper, but not the other way around. bugfixed = BeansWrapper.is2321Bugfixed(incompatibleImprovements); treatDefaultMethodsAsBeanMembers = incompatibleImprovements.intValue() >= _TemplateAPI.VERSION_INT_2_3_26; }
/** * Returns the lowest version number that is equivalent with the parameter version. * * @since 2.3.22 */ protected static Version normalizeIncompatibleImprovementsVersion(Version incompatibleImprovements) { _TemplateAPI.checkVersionNotNullAndSupported(incompatibleImprovements); Version bwIcI = BeansWrapper.normalizeIncompatibleImprovementsVersion(incompatibleImprovements); return incompatibleImprovements.intValue() < _TemplateAPI.VERSION_INT_2_3_22 || bwIcI.intValue() >= _TemplateAPI.VERSION_INT_2_3_22 ? bwIcI : Configuration.VERSION_2_3_22; }
private static Version normalizeTemplateLanguageVersion(Version incompatibleImprovements) { _TemplateAPI.checkVersionNotNullAndSupported(incompatibleImprovements); int v = incompatibleImprovements.intValue(); if (v < _TemplateAPI.VERSION_INT_2_3_19) { return Configuration.VERSION_2_3_0; } else if (v > _TemplateAPI.VERSION_INT_2_3_21) { return Configuration.VERSION_2_3_21; } else { // if 2.3.19 or 2.3.20 or 2.3.21 return incompatibleImprovements; } }
boolean isIcI2324OrLater() { return configuration.getIncompatibleImprovements().intValue() >= _TemplateAPI.VERSION_INT_2_3_24; }
/** * Converts a version number string to an integer for easy comparison. * The version number must start with numbers separated with * dots. There can be any number of such dot-separated numbers, but only * the first three will be considered. After the numbers arbitrary text can * follow, and will be ignored. * * The string will be trimmed before interpretation. * * @return major * 1000000 + minor * 1000 + micro */ public static int versionStringToInt(String version) { return new Version(version).intValue(); }
private boolean isBeforeIcI2322() { return configuration.getIncompatibleImprovements().intValue() < _TemplateAPI.VERSION_INT_2_3_22; }
/** * Returns the lowest version number that is equivalent with the parameter version. * @since 2.3.21 */ protected static Version normalizeIncompatibleImprovementsVersion(Version incompatibleImprovements) { _TemplateAPI.checkVersionNotNullAndSupported(incompatibleImprovements); if (incompatibleImprovements.intValue() < _TemplateAPI.VERSION_INT_2_3_0) { throw new IllegalArgumentException("Version must be at least 2.3.0."); } return incompatibleImprovements.intValue() >= _TemplateAPI.VERSION_INT_2_3_27 ? Configuration.VERSION_2_3_27 : incompatibleImprovements.intValue() == _TemplateAPI.VERSION_INT_2_3_26 ? Configuration.VERSION_2_3_26 : is2324Bugfixed(incompatibleImprovements) ? Configuration.VERSION_2_3_24 : is2321Bugfixed(incompatibleImprovements) ? Configuration.VERSION_2_3_21 : Configuration.VERSION_2_3_0; }
public static int getTemplateLanguageVersionAsInt(Template t) { return t.getTemplateLanguageVersion().intValue(); }
public static void checkVersionNotNullAndSupported(Version incompatibleImprovements) { NullArgumentException.check("incompatibleImprovements", incompatibleImprovements); int iciV = incompatibleImprovements.intValue(); if (iciV > Configuration.getVersion().intValue()) { throw new IllegalArgumentException("The FreeMarker version requested by \"incompatibleImprovements\" was " + incompatibleImprovements + ", but the installed FreeMarker version is only " + Configuration.getVersion() + ". You may need to upgrade FreeMarker in your project."); } if (iciV < VERSION_INT_2_3_0) { throw new IllegalArgumentException("\"incompatibleImprovements\" must be at least 2.3.0."); } }
protected DefaultObjectWrapperConfiguration(Version incompatibleImprovements) { super(DefaultObjectWrapper.normalizeIncompatibleImprovementsVersion(incompatibleImprovements), true); useAdaptersForContainers = getIncompatibleImprovements().intValue() >= _TemplateAPI.VERSION_INT_2_3_22; forceLegacyNonListCollections = true; // [2.4]: = IcI < _TemplateAPI.VERSION_INT_2_4_0; }
/** * Returns the default object wrapper for a given "incompatible_improvements" version. * * @see #setIncompatibleImprovements(Version) * * @since 2.3.21 */ public static ObjectWrapper getDefaultObjectWrapper(Version incompatibleImprovements) { if (incompatibleImprovements.intValue() < _TemplateAPI.VERSION_INT_2_3_21) { return ObjectWrapper.DEFAULT_WRAPPER; } else { return new DefaultObjectWrapperBuilder(incompatibleImprovements).build(); } }
private static TemplateLoader createDefaultTemplateLoader( Version incompatibleImprovements, TemplateLoader existingTemplateLoader) { if (incompatibleImprovements.intValue() < _TemplateAPI.VERSION_INT_2_3_21) { if (existingTemplateLoader instanceof LegacyDefaultFileTemplateLoader) { return existingTemplateLoader; } try { return new LegacyDefaultFileTemplateLoader(); } catch (Exception e) { CACHE_LOG.warn("Couldn't create legacy default TemplateLoader which accesses the current directory. " + "(Use new Configuration(Configuration.VERSION_2_3_21) or higher to avoid this.)", e); return null; } } else { return null; } }
static boolean shouldWrapUncheckedException(Throwable e, Environment env) { if (FlowControlException.class.isInstance(e)) { return false; } if (env.getWrapUncheckedExceptions()) { return true; } else if (env.getConfiguration().getIncompatibleImprovements().intValue() >= _TemplateAPI.VERSION_INT_2_3_27) { // We have to judge if we dare to wrap this exception, or it's too likely that some applications try to // catch it around the template processing to do something special. For the same reason, we only wrap very // frequent exceptions. // We use "==" instead of "instanceof" deliberately; user defined subclasses must not match. Class<? extends Throwable> c = e.getClass(); return c == NullPointerException.class || c == ClassCastException.class || c == IndexOutOfBoundsException.class || c == InvocationTargetException.class; } else { return false; } }
public Environment(Template template, final TemplateHashModel rootDataModel, Writer out) { super(template); configuration = template.getConfiguration(); incompatibleImprovementsGE2328 = configuration.getIncompatibleImprovements().intValue() >= _TemplateAPI.VERSION_INT_2_3_28; this.globalNamespace = new Namespace(null); this.currentNamespace = mainNamespace = new Namespace(template); this.out = out; this.rootDataModel = rootDataModel; importMacros(template); }
/** * If IcI >= 2.3.21, sets {@link URLTemplateSource#setUseCaches(boolean)} to {@code false} for sources that come * from a {@link TemplateLoader} where {@link URLConnection} cache usage wasn't set explicitly. */ private Object modifyForConfIcI(Object templateSource) { if (templateSource == null) return null; if (config.getIncompatibleImprovements().intValue() < _TemplateAPI.VERSION_INT_2_3_21) { return templateSource; } if (templateSource instanceof URLTemplateSource) { URLTemplateSource urlTemplateSource = (URLTemplateSource) templateSource; if (urlTemplateSource.getUseCaches() == null) { // It was left unset urlTemplateSource.setUseCaches(false); } } else if (templateSource instanceof MultiSource) { modifyForConfIcI(((MultiSource) templateSource).getWrappedSource()); } return templateSource; }
/** * Use {@link #DefaultObjectWrapper(DefaultObjectWrapperConfiguration, boolean)} instead if possible; * it does the same, except that it tolerates a non-{@link DefaultObjectWrapperConfiguration} configuration too. * * @since 2.3.21 */ protected DefaultObjectWrapper(BeansWrapperConfiguration bwCfg, boolean writeProtected) { super(bwCfg, writeProtected, false); DefaultObjectWrapperConfiguration dowDowCfg = bwCfg instanceof DefaultObjectWrapperConfiguration ? (DefaultObjectWrapperConfiguration) bwCfg : new DefaultObjectWrapperConfiguration(bwCfg.getIncompatibleImprovements()) { }; useAdaptersForContainers = dowDowCfg.getUseAdaptersForContainers(); useAdapterForEnumerations = useAdaptersForContainers && getIncompatibleImprovements().intValue() >= _TemplateAPI.VERSION_INT_2_3_26; forceLegacyNonListCollections = dowDowCfg.getForceLegacyNonListCollections(); iterableSupport = dowDowCfg.getIterableSupport(); finalizeConstruction(writeProtected); }