public JarEntryTldLocation(URL entryUrl, InputStreamFactory fallbackRawJarContentInputStreamFactory, String entryPath) { if (entryUrl == null) { NullArgumentException.check(fallbackRawJarContentInputStreamFactory); NullArgumentException.check(entryPath); } this.entryUrl = entryUrl; this.fallbackRawJarContentInputStreamFactory = fallbackRawJarContentInputStreamFactory; this.entryPath = entryPath != null ? normalizeJarEntryPath(entryPath, false) : null; }
/** * Sets the output format of the template; see {@link Configuration#setOutputFormat(OutputFormat)} for more. */ public void setOutputFormat(OutputFormat outputFormat) { NullArgumentException.check("outputFormat", outputFormat); this.outputFormat = outputFormat; }
void bindToOutputFormat(OutputFormat outputFormat, int autoEscapingPolicy) { NullArgumentException.check(outputFormat); this.outputFormat = outputFormat; this.autoEscapingPolicy = autoEscapingPolicy; }
void bindToMarkupOutputFormat(MarkupOutputFormat outputFormat) { NullArgumentException.check(outputFormat); this.outputFormat = outputFormat; }
/** * When the standard template loading/caching mechanism is used, this forces the charset used for reading the * template "file", overriding everything but the encoding coming from the {@code #ftl} header. This setting * overrides the locale-specific encodings set via {@link Configuration#setEncoding(java.util.Locale, String)}. It * also overrides the {@code encoding} parameter of {@link Configuration#getTemplate(String, String)} (and of its * overloads) and the {@code encoding} parameter of the {@code #include} directive. This works like that because * specifying the encoding where you are requesting the template is error prone and deprecated. * * <p> * If you are developing your own template loading/caching mechanism instead of the standard one, note that the * above behavior is not guaranteed by this class alone; you have to ensure it. Also, read the note on * {@code encoding} in the documentation of {@link #apply(Template)}. */ public void setEncoding(String encoding) { NullArgumentException.check("encoding", encoding); this.encoding = encoding; }
/** * Specifies how exceptions handled (and hence suppressed) by an {@code #attempt} blocks will be logged or otherwise * reported. The default value is {@link AttemptExceptionReporter#LOG_ERROR_REPORTER}. * * <p>Note that {@code #attempt} is not supposed to be a general purpose error handler mechanism, like {@code try} * is in Java. It's for decreasing the impact of unexpected errors, by making it possible that only part of the * page is going down, instead of the whole page. But it's still an error, something that someone should fix. So the * error should be reported, not just ignored in a custom {@link AttemptExceptionReporter}-s. * * <p>The {@link AttemptExceptionReporter} is invoked regardless of the value of the * {@link #setLogTemplateExceptions(boolean) log_template_exceptions} setting. * The {@link AttemptExceptionReporter} is not invoked if the {@link TemplateExceptionHandler} has suppressed the * exception. * * @since 2.3.27 */ public void setAttemptExceptionReporter(AttemptExceptionReporter attemptExceptionReporter) { NullArgumentException.check("attemptExceptionReporter", attemptExceptionReporter); this.attemptExceptionReporter = attemptExceptionReporter; }
/** * Sets the format used to convert {@link java.util.Date}-s that are time (no date part) values to string-s, also * the format that {@code someString?time} will use to parse strings. * * <p>For the possible values see {@link #setDateTimeFormat(String)}. * * <p>Defaults to {@code ""}, which is equivalent to {@code "medium"}. */ public void setTimeFormat(String timeFormat) { NullArgumentException.check("timeFormat", timeFormat); this.timeFormat = timeFormat; properties.setProperty(TIME_FORMAT_KEY, timeFormat); }
/** * Sets the format used to convert {@link java.util.Date}-s that are date-only (no time part) values to string-s, * also the format that {@code someString?date} will use to parse strings. * * <p>For the possible values see {@link #setDateTimeFormat(String)}. * * <p>Defaults to {@code ""} which is equivalent to {@code "medium"}. */ public void setDateFormat(String dateFormat) { NullArgumentException.check("dateFormat", dateFormat); this.dateFormat = dateFormat; properties.setProperty(DATE_FORMAT_KEY, dateFormat); }
/** * @param templateSourceName * The name of the matching template found. This is not necessarily the same as the template name * with which the template was originally requested. For example, one may gets a template for the * {@code "foo.ftl"} name, but due to localized lookup the template is actually loaded from * {@code "foo_de.ftl"}. Then this parameter must be {@code "foo_de.ftl"}, not {@code "foo.ftl"}. Not * {@code null}. * * @param templateSource * See {@link TemplateLoader#findTemplateSource(String)} to understand what that means. Not * {@code null}. */ private PositiveTemplateLookupResult(String templateSourceName, Object templateSource) { NullArgumentException.check("templateName", templateSourceName); NullArgumentException.check("templateSource", templateSource); if (templateSource instanceof TemplateLookupResult) { throw new IllegalArgumentException(); } this.templateSourceName = templateSourceName; this.templateSource = templateSource; }
/** * Sets the arithmetic engine used to perform arithmetic operations. * The default is {@link ArithmeticEngine#BIGDECIMAL_ENGINE}. */ public void setArithmeticEngine(ArithmeticEngine arithmeticEngine) { NullArgumentException.check("arithmeticEngine", arithmeticEngine); this.arithmeticEngine = arithmeticEngine; properties.setProperty(ARITHMETIC_ENGINE_KEY, arithmeticEngine.getClass().getName()); }
/** * Sets the locale used for number and date formatting (among others), also the locale used for searching * localized template variations when no locale was explicitly requested. On the {@link Configuration} level it * defaults to the default locale of system (of the JVM), for server-side application usually you should set it * explicitly in the {@link Configuration} to use the preferred locale of your application instead. * * @see Configuration#getTemplate(String, Locale) */ public void setLocale(Locale locale) { NullArgumentException.check("locale", locale); this.locale = locale; properties.setProperty(LOCALE_KEY, locale.toString()); }
/** * Sets the object wrapper used to wrap objects to {@link TemplateModel}-s. * The default is {@link ObjectWrapper#DEFAULT_WRAPPER}. */ public void setObjectWrapper(ObjectWrapper objectWrapper) { NullArgumentException.check("objectWrapper", objectWrapper); this.objectWrapper = objectWrapper; properties.setProperty(OBJECT_WRAPPER_KEY, objectWrapper.getClass().getName()); }
/** * Sets the time zone to use when formatting date/time values. * Defaults to the system time zone ({@link TimeZone#getDefault()}), regardless of the "locale" FreeMarker setting, * so in a server application you probably want to set it explicitly in the {@link Environment} to match the * preferred time zone of target audience (like the Web page visitor). * * <p>If you or the templates set the time zone, you should probably also set * {@link #setSQLDateAndTimeTimeZone(TimeZone)}! * * @see #setSQLDateAndTimeTimeZone(TimeZone) */ public void setTimeZone(TimeZone timeZone) { NullArgumentException.check("timeZone", timeZone); this.timeZone = timeZone; properties.setProperty(TIME_ZONE_KEY, timeZone.getID()); }
/** * Sets the {@link TemplateClassResolver} that is used when the * <code>new</code> built-in is called in a template. That is, when * a template contains the <code>"com.example.SomeClassName"?new</code> * expression, this object will be called to resolve the * <code>"com.example.SomeClassName"</code> string to a class. The default * value is {@link TemplateClassResolver#UNRESTRICTED_RESOLVER} in * FreeMarker 2.3.x, and {@link TemplateClassResolver#SAFER_RESOLVER} * starting from FreeMarker 2.4.0. If you allow users to upload templates, * it's important to use a custom restrictive {@link TemplateClassResolver}. * * @since 2.3.17 */ public void setNewBuiltinClassResolver(TemplateClassResolver newBuiltinClassResolver) { NullArgumentException.check("newBuiltinClassResolver", newBuiltinClassResolver); this.newBuiltinClassResolver = newBuiltinClassResolver; properties.setProperty(NEW_BUILTIN_CLASS_RESOLVER_KEY, newBuiltinClassResolver.getClass().getName()); }
/** * Creates a new instance that will use the specified template loaders. * * @param templateLoaders * the template loaders that are used to load templates, in the order as they will be searched * (except where {@linkplain #setSticky(boolean) stickiness} says otherwise). */ public MultiTemplateLoader(TemplateLoader[] templateLoaders) { NullArgumentException.check("templateLoaders", templateLoaders); this.templateLoaders = templateLoaders.clone(); }
private ClassTemplateLoader(Class<?> resourceLoaderClass, boolean allowNullResourceLoaderClass, ClassLoader classLoader, String basePackagePath) { if (!allowNullResourceLoaderClass) { NullArgumentException.check("resourceLoaderClass", resourceLoaderClass); } NullArgumentException.check("basePackagePath", basePackagePath); // Either set a non-null resourceLoaderClass or a non-null classLoader, not both: this.resourceLoaderClass = classLoader == null ? (resourceLoaderClass == null ? this.getClass() : resourceLoaderClass) : null; if (this.resourceLoaderClass == null && classLoader == null) { throw new NullArgumentException("classLoader"); } this.classLoader = classLoader; String canonBasePackagePath = canonicalizePrefix(basePackagePath); if (this.classLoader != null && canonBasePackagePath.startsWith("/")) { canonBasePackagePath = canonBasePackagePath.substring(1); } this.basePackagePath = canonBasePackagePath; }
/** * Associates names with formatter factories, which then can be referred by the {@link #setNumberFormat(String) * number_format} setting with values starting with <code>@<i>name</i></code>. Beware, if you specify any custom * formats here, an initial {@code @} followed by a letter will have special meaning in number/date/time/datetime * format strings, even if {@link Configuration#getIncompatibleImprovements() incompatible_improvements} is less * than 2.3.24 (starting with {@link Configuration#getIncompatibleImprovements() incompatible_improvements} 2.3.24 * {@code @} always has special meaning). * * @param customNumberFormats * Can't be {@code null}. The name must start with an UNICODE letter, and can only contain UNICODE * letters and digits (not {@code _}). * * @since 2.3.24 */ public void setCustomNumberFormats(Map<String, ? extends TemplateNumberFormatFactory> customNumberFormats) { NullArgumentException.check("customNumberFormats", customNumberFormats); validateFormatNames(customNumberFormats.keySet()); this.customNumberFormats = customNumberFormats; }
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."); } }
/** * 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); } } }
/** * @param hasSharedInstanceRestrictons * {@code true} exactly if we are creating a new instance with {@link ClassIntrospectorBuilder}. Then * it's {@code true} even if it won't put the instance into the cache. */ ClassIntrospector(ClassIntrospectorBuilder builder, Object sharedLock, boolean hasSharedInstanceRestrictons, boolean shared) { NullArgumentException.check("sharedLock", sharedLock); this.exposureLevel = builder.getExposureLevel(); this.exposeFields = builder.getExposeFields(); this.methodAppearanceFineTuner = builder.getMethodAppearanceFineTuner(); this.methodSorter = builder.getMethodSorter(); this.treatDefaultMethodsAsBeanMembers = builder.getTreatDefaultMethodsAsBeanMembers(); this.bugfixed = builder.isBugfixed(); this.sharedLock = sharedLock; this.hasSharedInstanceRestrictons = hasSharedInstanceRestrictons; this.shared = shared; if (CLASS_CHANGE_NOTIFIER != null) { CLASS_CHANGE_NOTIFIER.subscribe(this); } }