Java Code Examples for freemarker.template.TemplateBooleanModel#FALSE
The following examples show how to use
freemarker.template.TemplateBooleanModel#FALSE .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LangFtlUtil.java From scipio-erp with Apache License 2.0 | 4 votes |
public static TemplateBooleanModel toBooleanModel(boolean value, Environment env) throws TemplateModelException { return value ? TemplateBooleanModel.TRUE : TemplateBooleanModel.FALSE; }
Example 2
Source File: LoopDirective.java From pcgen with GNU Lesser General Public License v2.1 | 4 votes |
@SuppressWarnings("rawtypes") @Override public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body) throws TemplateException, IOException { // Check if no parameters were given: int fromVal = 0; Integer toVal = null; int step = 1; for (Object entryObj : params.entrySet()) { Map.Entry entry = (Entry) entryObj; String paramName = (String) entry.getKey(); TemplateModel paramValue = (TemplateModel) entry.getValue(); switch (paramName) { case "from": if (!(paramValue instanceof TemplateNumberModel)) { throw new TemplateModelException("The \"" + paramName + "\" parameter " + "must be a number."); } fromVal = ((TemplateNumberModel) paramValue).getAsNumber().intValue(); break; case "to": if (!(paramValue instanceof TemplateNumberModel)) { throw new TemplateModelException("The \"" + paramName + "\" parameter " + "must be a number."); } toVal = ((TemplateNumberModel) paramValue).getAsNumber().intValue(); break; case "step": if (!(paramValue instanceof TemplateNumberModel)) { throw new TemplateModelException("The \"" + paramName + "\" parameter " + "must be a number."); } step = ((TemplateNumberModel) paramValue).getAsNumber().intValue(); if (step == 0) { throw new TemplateModelException("The \"" + paramName + "\" parameter must not be 0."); } break; default: //Case not caught, should this cause an error? break; } } if (toVal == null) { throw new TemplateModelException("The \"to\" parameter must be provided."); } if (body == null) { throw new TemplateModelException("This directive must have content."); } if (step > 0) { for (int i = fromVal; i <= toVal; i += step) { // Set the loop variable, if there is one: if (loopVars.length > 0) { loopVars[0] = new SimpleNumber(i); } if (loopVars.length > 1) { loopVars[1] = i + step <= toVal ? TemplateBooleanModel.TRUE : TemplateBooleanModel.FALSE; } // Executes the nested body (same as <#nested> in FTL). In this // case we don't provide a special writer as the parameter: body.render(env.getOut()); } } else { for (int i = fromVal; i >= toVal; i += step) { // Set the loop variable, if there is one: if (loopVars.length > 0) { loopVars[0] = new SimpleNumber(i); } if (loopVars.length > 1) { loopVars[1] = i + step >= toVal ? TemplateBooleanModel.TRUE : TemplateBooleanModel.FALSE; } // Executes the nested body (same as <#nested> in FTL). In this // case we don't provide a special writer as the parameter: body.render(env.getOut()); } } }
Example 3
Source File: LoopDirective.java From pcgen with GNU Lesser General Public License v2.1 | 4 votes |
@SuppressWarnings("rawtypes") @Override public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body) throws TemplateException, IOException { // Check if no parameters were given: int fromVal = 0; Integer toVal = null; int step = 1; for (Object entryObj : params.entrySet()) { Map.Entry entry = (Entry) entryObj; String paramName = (String) entry.getKey(); TemplateModel paramValue = (TemplateModel) entry.getValue(); switch (paramName) { case "from": if (!(paramValue instanceof TemplateNumberModel)) { throw new TemplateModelException("The \"" + paramName + "\" parameter " + "must be a number."); } fromVal = ((TemplateNumberModel) paramValue).getAsNumber().intValue(); break; case "to": if (!(paramValue instanceof TemplateNumberModel)) { throw new TemplateModelException("The \"" + paramName + "\" parameter " + "must be a number."); } toVal = ((TemplateNumberModel) paramValue).getAsNumber().intValue(); break; case "step": if (!(paramValue instanceof TemplateNumberModel)) { throw new TemplateModelException("The \"" + paramName + "\" parameter " + "must be a number."); } step = ((TemplateNumberModel) paramValue).getAsNumber().intValue(); if (step == 0) { throw new TemplateModelException("The \"" + paramName + "\" parameter must not be 0."); } break; default: //Case not caught, should this cause an error? break; } } if (toVal == null) { throw new TemplateModelException("The \"to\" parameter must be provided."); } if (body == null) { throw new TemplateModelException("This directive must have content."); } if (step > 0) { for (int i = fromVal; i <= toVal; i += step) { // Set the loop variable, if there is one: if (loopVars.length > 0) { loopVars[0] = new SimpleNumber(i); } if (loopVars.length > 1) { loopVars[1] = i + step <= toVal ? TemplateBooleanModel.TRUE : TemplateBooleanModel.FALSE; } // Executes the nested body (same as <#nested> in FTL). In this // case we don't provide a special writer as the parameter: body.render(env.getOut()); } } else { for (int i = fromVal; i >= toVal; i += step) { // Set the loop variable, if there is one: if (loopVars.length > 0) { loopVars[0] = new SimpleNumber(i); } if (loopVars.length > 1) { loopVars[1] = i + step >= toVal ? TemplateBooleanModel.TRUE : TemplateBooleanModel.FALSE; } // Executes the nested body (same as <#nested> in FTL). In this // case we don't provide a special writer as the parameter: body.render(env.getOut()); } } }