/** * @deprecated Use {@link #getIncompatibleImprovements()} instead. */ @Deprecated public int getParsedIncompatibleEnhancements() { return getIncompatibleImprovements().intValue(); }
/** * Returns {@link Configuration#getIncompatibleImprovements()} from the parent {@link Configuration}. This mostly * just exist to satisfy the {@link ParserConfiguration} interface. * * @throws IllegalStateException * If the parent configuration wasn't yet set. */ public Version getIncompatibleImprovements() { return getNonNullParentConfiguration().getIncompatibleImprovements(); }
private boolean getDefaultLogTemplateExceptions() { return getDefaultLogTemplateExceptions(getIncompatibleImprovements()); }
private ObjectWrapper getDefaultObjectWrapper() { return getDefaultObjectWrapper(getIncompatibleImprovements()); }
private TemplateExceptionHandler getDefaultTemplateExceptionHandler() { return getDefaultTemplateExceptionHandler(getIncompatibleImprovements()); }
private AttemptExceptionReporter getDefaultAttemptExceptionReporter() { return getDefaultAttemptExceptionReporter(getIncompatibleImprovements()); }
boolean isIcI2324OrLater() { return configuration.getIncompatibleImprovements().intValue() >= _TemplateAPI.VERSION_INT_2_3_24; }
private boolean getDefaultWrapUncheckedExceptions() { return getDefaultWrapUncheckedExceptions(getIncompatibleImprovements()); }
private boolean isBeforeIcI2322() { return configuration.getIncompatibleImprovements().intValue() < _TemplateAPI.VERSION_INT_2_3_22; }
private TemplateLookupStrategy getDefaultTemplateLookupStrategy() { return getDefaultTemplateLookupStrategy(getIncompatibleImprovements()); }
private TemplateNameFormat getDefaultTemplateNameFormat() { return getDefaultTemplateNameFormat(getIncompatibleImprovements()); }
/** * Override this to specify what the default {@link ObjectWrapper} will be when the * {@code object_wrapper} Servlet init-param wasn't specified. Note that this is called by * {@link #createConfiguration()}, and so if that was also overidden but improperly then this method might won't be * ever called. Also note that if you set the {@code object_wrapper} in {@link #createConfiguration()}, then this * won't be called, since then that has already specified the default. * * <p> * The default implementation calls {@link Configuration#getDefaultObjectWrapper(freemarker.template.Version)}. You * should also pass in the version paramter when creating an {@link ObjectWrapper} that supports that. You can get * the version by calling {@link #getConfiguration()} and then {@link Configuration#getIncompatibleImprovements()}. * * @since 2.3.22 */ protected ObjectWrapper createDefaultObjectWrapper() { return Configuration.getDefaultObjectWrapper(config.getIncompatibleImprovements()); }
private TemplateLoader getDefaultTemplateLoader() { return createDefaultTemplateLoader(getIncompatibleImprovements(), getTemplateLoader()); }
private CacheStorage getDefaultCacheStorage() { return createDefaultCacheStorage(getIncompatibleImprovements(), getCacheStorage()); }
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; } }
/** * Removes all auto-includes, then calls {@link #addAutoInclude(String)} for each {@link List} items. * * <p>Before {@linkplain Configuration#Configuration(Version) incompatible improvements} 2.3.25 it doesn't filter * out duplicates from the list if this method was called on a {@link Configuration} instance. */ public void setAutoIncludes(List templateNames) { NullArgumentException.check("templateNames", templateNames); // "synchronized" is removed from the API as it's not safe to set anything after publishing the Configuration synchronized (this) { if (autoIncludes != null) { autoIncludes.clear(); } for (Object templateName : templateNames) { if (!(templateName instanceof String)) { throw new IllegalArgumentException("List items must be String-s."); } addAutoInclude((String) templateName, this instanceof Configuration && ((Configuration) this) .getIncompatibleImprovements().intValue() < _TemplateAPI.VERSION_INT_2_3_25); } } }
/** * Same as {@link #setParentConfiguration(Configuration)}. */ @Override void setParent(Configurable cfg) { NullArgumentException.check("cfg", cfg); if (!(cfg instanceof Configuration)) { throw new IllegalArgumentException("The parent of a TemplateConfiguration can only be a Configuration"); } if (parentConfigurationSet) { if (getParent() != cfg) { throw new IllegalStateException( "This TemplateConfiguration is already associated with a different Configuration instance."); } return; } if (((Configuration) cfg).getIncompatibleImprovements().intValue() < _TemplateAPI.VERSION_INT_2_3_22 && hasAnyConfigurableSet()) { throw new IllegalStateException( "This TemplateConfiguration can't be associated to a Configuration that has " + "incompatibleImprovements less than 2.3.22, because it changes non-parser settings."); } super.setParent(cfg); parentConfigurationSet = true; }
/** * A prime constructor to which all other constructors should * delegate directly or indirectly. */ private Template(String name, String sourceName, Configuration cfg, ParserConfiguration customParserConfiguration) { super(toNonNull(cfg)); this.name = name; this.sourceName = sourceName; this.templateLanguageVersion = normalizeTemplateLanguageVersion(toNonNull(cfg).getIncompatibleImprovements()); this.parserConfiguration = customParserConfiguration != null ? customParserConfiguration : getConfiguration(); }
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; }