blob: b408c9e11ddea75ba05f4a36100b0fb35bceeaf0 [file] [log] [blame]
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.freemarker.core;
import org.apache.freemarker.core.model.TemplateModel;
import org.apache.freemarker.core.util._NullArgumentException;
/**
* For internal use only; don't depend on this, there's no backward compatibility guarantee at all!
* This class is to work around the lack of module system in Java, i.e., so that other FreeMarker packages can
* access things inside this package that users shouldn't.
*/
public final class _CoreAPI {
// ATTENTION! Don't refer to other classes in the static initializer of this class! Fields that need that must be
// moved into a separate class, to avoid class init deadlocks.
// Can't be instantiated
private _CoreAPI() { }
/**
* ATTENTION: This is used by https://github.com/kenshoo/freemarker-online. Don't break backward
* compatibility without updating that project too!
*/
static public void addThreadInterruptedChecks(Template template) {
try {
new ThreadInterruptionSupportTemplatePostProcessor().postProcess(template);
} catch (TemplatePostProcessorException e) {
throw new RuntimeException("Template post-processing failed", e);
}
}
public static boolean isMacro(Class<? extends TemplateModel> cl) {
return Environment.TemplateLanguageDirective.class.isAssignableFrom(cl);
}
public static boolean isFunction(Class<? extends TemplateModel> cl) {
return Environment.TemplateLanguageFunction.class.isAssignableFrom(cl);
}
public static boolean isTemplateLanguageCallable(Class<? extends TemplateModel> cl) {
return Environment.TemplateLanguageCallable.class.isAssignableFrom(cl);
}
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 < _VersionInts.VERSION_INT_3_0_0) {
throw new IllegalArgumentException("\"incompatibleImprovements\" must be at least 3.0.0, but was "
+ incompatibleImprovements);
}
if (incompatibleImprovements == Configuration.getVersion()) {
throw new IllegalArgumentException("The incompatibleImprovements setting can't be set to the object " +
"returned by Configuration.getVersion(). That would defeat the purpose of " +
"incompatibleImprovements, and make upgrading FreeMarker a potentially breaking change. Instead, " +
"set incompatibleImprovements to the highest concrete version that's known to be compatible with " +
"your application.");
}
}
}