本文整理汇总了Java中freemarker.template.TemplateBooleanModel类的典型用法代码示例。如果您正苦于以下问题:Java TemplateBooleanModel类的具体用法?Java TemplateBooleanModel怎么用?Java TemplateBooleanModel使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TemplateBooleanModel类属于freemarker.template包,在下文中一共展示了TemplateBooleanModel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createTagRenderer
import freemarker.template.TemplateBooleanModel; //导入依赖的package包/类
@Override
@SuppressWarnings("nls")
protected TagRenderer createTagRenderer(HtmlMutableListState state, Environment env, Map<?, ?> params,
TemplateDirectiveBody body, TemplateModel[] loopVars) throws TemplateModelException
{
String tag = "div";
if( params.containsKey("tag") )
{
tag = ((SimpleScalar) params.get("tag")).getAsString();
}
boolean hideDisabledOptions = false;
if( params.containsKey("hideDisabledOptions") )
{
hideDisabledOptions = ((TemplateBooleanModel) params.get("hideDisabledOptions")).getAsBoolean();
}
return new ButtonListTagRenderer(tag, (HtmlListState) state, env, body, loopVars, hideDisabledOptions);
}
示例2: getBooleanArg
import freemarker.template.TemplateBooleanModel; //导入依赖的package包/类
/**
* Gets boolean arg.
* <p>
* Will automatically interpret string true/false as boolean.
*/
public static Boolean getBooleanArg(TemplateModel obj, Boolean defaultValue) throws TemplateModelException {
if (obj instanceof TemplateBooleanModel) {
return ((TemplateBooleanModel) obj).getAsBoolean();
}
else if (obj instanceof TemplateScalarModel) {
TemplateScalarModel s = (TemplateScalarModel) obj;
String val = s.getAsString();
// SCIPIO: empty check is desirable and makes it so caller can request default by specifying ""
if (!val.isEmpty()) {
return "true".equalsIgnoreCase(s.getAsString());
}
} else if (obj != null) {
throw new TemplateModelException("Expected boolean model or string model representation of boolean, but got a " +
obj.getClass() + " instead");
}
return defaultValue;
}
示例3: getBooleanOrStringArg
import freemarker.template.TemplateBooleanModel; //导入依赖的package包/类
public static Object getBooleanOrStringArg(TemplateModel obj, Object defaultValue, boolean useDefaultWhenEmpty, boolean nonEscaping) throws TemplateModelException {
Object result = null;
if (obj instanceof TemplateBooleanModel) {
return ((TemplateBooleanModel) obj).getAsBoolean();
} else if (obj instanceof TemplateScalarModel) {
TemplateScalarModel s = (TemplateScalarModel) obj;
result = LangFtlUtil.getAsString(s, nonEscaping);
} else if (obj != null) {
result = obj.toString();
} else {
return defaultValue;
}
if (useDefaultWhenEmpty && (result instanceof String) && ((String) result).isEmpty()) {
return defaultValue;
}
return result;
}
示例4: getBoolParam
import freemarker.template.TemplateBooleanModel; //导入依赖的package包/类
public static boolean getBoolParam(final Environment env,Map params,String key,boolean def) throws TemplateException
{
final TemplateModel tv = (TemplateModel)params.get(key);
if(tv == null)
{
return def;
}
if(tv instanceof TemplateBooleanModel)
{
return ((TemplateBooleanModel)tv).getAsBoolean();
//throw new TemplateException(
// String.format("Expected a boolean model. '%s' is instead %s", key,tv.getClass().getName())
// , env);
}
return Convert.parseBool(tv.toString());
}
示例5: exec
import freemarker.template.TemplateBooleanModel; //导入依赖的package包/类
@Override
public Object exec(List<Object> args) throws Exception {
if (args != null && !args.isEmpty()) {
Object value = args.get(0);
if (value != null) {
if (value instanceof TemplateModel) {
if (value instanceof TemplateBooleanModel) {
return String.valueOf(((TemplateBooleanModel) value).getAsBoolean());
}
} else if (value instanceof Enum) {
}
return value.toString();
}
}
return "";
}
示例6: getBool
import freemarker.template.TemplateBooleanModel; //导入依赖的package包/类
public static Boolean getBool(String name, Map<String, TemplateModel> params)
throws TemplateException {
TemplateModel model = params.get(name);
if (model == null) {
return null;
}
if (model instanceof TemplateBooleanModel) {
return ((TemplateBooleanModel) model).getAsBoolean();
} else if (model instanceof TemplateNumberModel) {
return !(((TemplateNumberModel) model).getAsNumber().intValue() == 0);
} else if (model instanceof TemplateScalarModel) {
String s = ((TemplateScalarModel) model).getAsString();
// 空串应该返回null还是true呢?
if (!StringUtils.isBlank(s)) {
return !(s.equals("0") || s.equalsIgnoreCase("false") || s
.equalsIgnoreCase("f"));
} else {
return null;
}
} else {
throw new MustBooleanException(name);
}
}
示例7: getBooleanParameter
import freemarker.template.TemplateBooleanModel; //导入依赖的package包/类
/**
* 获取Boolean类型的参数值
*
* @return 参数值
*/
public static Boolean getBooleanParameter(String name, Map<String, TemplateModel> params) throws TemplateModelException {
TemplateModel templateModel = params.get(name);
if (templateModel == null) {
return null;
}
if (templateModel instanceof TemplateScalarModel) {
String value = ((TemplateScalarModel) templateModel).getAsString();
if (StringUtils.isEmpty(value)) {
return null;
} else {
return Boolean.valueOf(value);
}
} else if ((templateModel instanceof TemplateBooleanModel)) {
return ((TemplateBooleanModel) templateModel).getAsBoolean();
} else {
throw new TemplateModelException("The \"" + name + "\" parameter " + "must be a boolean.");
}
}
示例8: getAsRawSequence
import freemarker.template.TemplateBooleanModel; //导入依赖的package包/类
@SuppressWarnings("unchecked")
static Collection<String> getAsRawSequence(TemplateModel elems) throws TemplateModelException {
if (elems == null || elems instanceof TemplateBooleanModel) {
return Collections.emptyList();
} else if (elems instanceof TemplateCollectionModel || elems instanceof TemplateSequenceModel) {
return (Collection<String>) LangFtlUtil.unwrapAlways(elems);
} else if (elems instanceof TemplateHashModelEx) {
return (Collection<String>) LangFtlUtil.getMapKeys(elems);
} else {
throw new TemplateModelException("invalid parameter type, can't interpret as sequence: " + elems.getClass());
}
}
示例9: escapeVal
import freemarker.template.TemplateBooleanModel; //导入依赖的package包/类
public static String escapeVal(String value, String lang, Boolean strict, Environment env) throws TemplateModelException {
if (value == null || value.isEmpty() || lang == null || lang.isEmpty()) {
return value;
}
if (strict != null) {
return execEscapeValFunction(new SimpleScalar(value), new SimpleScalar(lang),
strict ? TemplateBooleanModel.TRUE : TemplateBooleanModel.FALSE, env).getAsString();
} else {
return execEscapeValFunction(new SimpleScalar(value), new SimpleScalar(lang), env).getAsString();
}
}
示例10: escapeFullUrl
import freemarker.template.TemplateBooleanModel; //导入依赖的package包/类
public static String escapeFullUrl(String value, String lang, Boolean strict, Environment env) throws TemplateModelException {
if (value == null || value.isEmpty() || lang == null || lang.isEmpty()) {
return value;
}
if (strict != null) {
return execEscapeFullUrlFunction(new SimpleScalar(value), new SimpleScalar(lang),
strict ? TemplateBooleanModel.TRUE : TemplateBooleanModel.FALSE, env).getAsString();
} else {
return execEscapeFullUrlFunction(new SimpleScalar(value), new SimpleScalar(lang), env).getAsString();
}
}
示例11: execOneArg
import freemarker.template.TemplateBooleanModel; //导入依赖的package包/类
private Object execOneArg(Object arg) throws TemplateModelException {
if (arg instanceof TemplateScalarModel) {
String name = ((TemplateScalarModel) arg).getAsString();
try {
Severity severity = Severity.valueOf(name);
return exec(reportIssues.stream().filter(i -> isSeverityEquals(i, severity)));
} catch (IllegalArgumentException e) {
throw new TemplateModelException("Failed call 1 Severity arg (INFO,MINOR,MAJOR,CRITICAL,BLOCKER)", e);
}
} else if (arg instanceof TemplateBooleanModel) {
boolean r = ((TemplateBooleanModel) arg).getAsBoolean();
return exec(reportIssues.stream().filter(i -> isSameReportedOnDiff(i, r)));
}
throw new TemplateModelException("Failed call accept boolean or Severity");
}
开发者ID:gabrie-allaigre,项目名称:sonar-gitlab-plugin,代码行数:16,代码来源:AbstractIssuesTemplateMethodModelEx.java
示例12: execTwoArg
import freemarker.template.TemplateBooleanModel; //导入依赖的package包/类
private Object execTwoArg(Object arg1, Object arg2) throws TemplateModelException {
if (arg1 instanceof TemplateScalarModel && arg2 instanceof TemplateBooleanModel) {
String name = ((TemplateScalarModel) arg1).getAsString();
boolean r = ((TemplateBooleanModel) arg2).getAsBoolean();
try {
Severity severity = Severity.valueOf(name);
return exec(reportIssues.stream().filter(i -> isSeverityEquals(i, severity) && isSameReportedOnDiff(i, r)));
} catch (IllegalArgumentException e) {
throw new TemplateModelException("Failed call Severity arg (INFO,MINOR,MAJOR,CRITICAL,BLOCKER)", e);
}
}
throw new TemplateModelException("Failed call accept 2 args boolean or Severity");
}
开发者ID:gabrie-allaigre,项目名称:sonar-gitlab-plugin,代码行数:14,代码来源:AbstractIssuesTemplateMethodModelEx.java
示例13: testSuccess
import freemarker.template.TemplateBooleanModel; //导入依赖的package包/类
@Test
public void testSuccess() {
Assertions.assertThat(list(Collections.emptyList())).isEmpty();
Assertions.assertThat(list(Collections.singletonList(new SimpleScalar("MAJOR")))).isEmpty();
Assertions.assertThat(list(Collections.singletonList(TemplateBooleanModel.FALSE))).isEmpty();
Assertions.assertThat(list(Arrays.asList(new SimpleScalar("MAJOR"), TemplateBooleanModel.FALSE))).isEmpty();
}
示例14: testFailed
import freemarker.template.TemplateBooleanModel; //导入依赖的package包/类
@Test
public void testFailed() {
Assertions.assertThatThrownBy(() -> list(Collections.singletonList(null))).hasCauseInstanceOf(TemplateModelException.class);
Assertions.assertThatThrownBy(() -> list(Collections.singletonList(new SimpleScalar("TOTO")))).hasCauseInstanceOf(TemplateModelException.class);
Assertions.assertThatThrownBy(() -> list(Arrays.asList(TemplateBooleanModel.FALSE, new SimpleScalar("MAJOR")))).hasCauseInstanceOf(TemplateModelException.class);
Assertions.assertThatThrownBy(() -> list(Arrays.asList(new SimpleScalar("TOTO"), TemplateBooleanModel.FALSE))).hasCauseInstanceOf(TemplateModelException.class);
Assertions.assertThatThrownBy(() -> list(Arrays.asList(new SimpleScalar("TOTO"), TemplateBooleanModel.FALSE, TemplateBooleanModel.FALSE))).hasCauseInstanceOf(TemplateModelException.class);
}
示例15: testSuccess
import freemarker.template.TemplateBooleanModel; //导入依赖的package包/类
@Test
public void testSuccess() {
Assertions.assertThat(count(Collections.emptyList())).isEqualTo(0);
Assertions.assertThat(count(Collections.singletonList(new SimpleScalar("MAJOR")))).isEqualTo(0);
Assertions.assertThat(count(Collections.singletonList(TemplateBooleanModel.FALSE))).isEqualTo(0);
Assertions.assertThat(count(Arrays.asList(new SimpleScalar("MAJOR"), TemplateBooleanModel.FALSE))).isEqualTo(0);
}