Examples of TemplateModel


Examples of freemarker.template.TemplateModel

abstract class NumericalBuiltins {
    abstract static class NumberBuiltIn extends BuiltIn {
        TemplateModel _getAsTemplateModel(Environment env)
                throws TemplateException
        {
            TemplateModel model = target.getAsTemplateModel(env);
            return calculateResult(EvaluationUtil.getNumber(model, target, env), model);
        }
View Full Code Here

Examples of freemarker.template.TemplateModel

    // Does both someNumber?long and someDate?long, thus it doesn't extend NumberBuiltIn
    static class longBI extends BuiltIn {
        TemplateModel _getAsTemplateModel(Environment env)
                throws TemplateException
        {
            TemplateModel model = target.getAsTemplateModel(env);
            if (!(model instanceof TemplateNumberModel)
                    && model instanceof TemplateDateModel) {
                Date date = EvaluationUtil.getDate((TemplateDateModel) model, target, env);
                return new SimpleNumber(date.getTime());
            } else {
View Full Code Here

Examples of freemarker.template.TemplateModel

    // Doesn't extend NumberBuiltIn because "calculateResult" would need the Environment.
    static class cBI extends BuiltIn {
        TemplateModel _getAsTemplateModel(Environment env)
                throws TemplateException
        {
            TemplateModel model = target.getAsTemplateModel(env);
            Number num = EvaluationUtil.getNumber(model, target, env);
            if (num instanceof Integer) {
                // We accelerate this fairly common case
                return new SimpleScalar(num.toString());
            } else {
View Full Code Here

Examples of freemarker.template.TemplateModel

    void accept(Environment env) throws TemplateException, IOException {
        if (nestedBlock != null) {
            env.visit(nestedBlock, new CaptureOutput(env), null);
        } else {
      TemplateModel value = new SimpleScalar("");
      if (namespaceExp != null) {
        Environment.Namespace ns = (Environment.Namespace) namespaceExp.getAsTemplateModel(env);
        ns.put(varName, value);
       } else if (scope == Assignment.NAMESPACE) {
        env.setVariable(varName, value);
View Full Code Here

Examples of freemarker.template.TemplateModel

        private final Environment env;
        private final Environment.Namespace fnsModel;
       
        CaptureOutput(Environment env) throws TemplateException {
            this.env = env;
            TemplateModel nsModel = null;
            if(namespaceExp != null) {
                nsModel = namespaceExp.getAsTemplateModel(env);
                if (!(nsModel instanceof Environment.Namespace)) {
                    throw new TemplateException(
                        "namespace parameter does not specify "
                        + "a namespace. It is a "
                        + nsModel.getClass().getName(), env);
                }
            }
            fnsModel = (Environment.Namespace )nsModel;
        }
View Full Code Here

Examples of freemarker.template.TemplateModel

    }
   
    TemplateModel _getAsTemplateModel(Environment env)
            throws TemplateException
    {
        TemplateModel tm = target.getAsTemplateModel(env);
        String classname = null;
        try {
            classname = ((TemplateScalarModel) tm).getAsString();
        }
        catch (ClassCastException cce) {
View Full Code Here

Examples of freemarker.template.TemplateModel

            protected final TemplateCollectionModel m_col;
            protected final Environment m_env;

            private BIMethod(Environment env)
                    throws TemplateException {
                TemplateModel model = target.getAsTemplateModel(env);
                m_seq = model instanceof TemplateSequenceModel
                            && !isBuggySeqButGoodCollection(model)
                        ? (TemplateSequenceModel) model
                        : null;
                // In 2.3.x only, we deny the possibility of collection
View Full Code Here

Examples of freemarker.template.TemplateModel

                if (argcnt != 1 && argcnt != 2) {
                    throw new TemplateModelException(
                            getBuiltinTemplate() + " expects 1 or 2 arguments.");
                }
               
                TemplateModel target = (TemplateModel) args.get(0);
                int foundAtIdx;
                if (argcnt > 1) {
                    Object obj = args.get(1);
                    if (!(obj instanceof TemplateNumberModel)) {
                        throw new TemplateModelException(
View Full Code Here

Examples of freemarker.template.TemplateModel

                int foundAtIdx = -1// -1 is the return value for "not found"
                int idx = 0;
                searchItem: while (it.hasNext()) {
                    if (idx > allowedRangeEnd) break searchItem;
                   
                    TemplateModel current = it.next();
                    if (idx >= allowedRangeStart) {
                        if (modelsEqual(current, target, m_env)) {
                            foundAtIdx = idx;
                            if (m_dir == 1) break searchItem; // "find first"
                            // Otherwise it's "find last".
View Full Code Here

Examples of freemarker.template.TemplateModel

public class SourceReportGenerator implements ReportGenerator {

  private class PrintCostMethod implements TemplateMethodModelEx {
    @SuppressWarnings("unchecked")
    public Object exec(List arguments) throws TemplateModelException {
      TemplateModel model = (TemplateModel) arguments.get(0);
      if (model instanceof SimpleNumber) {
        SimpleNumber number = (SimpleNumber) model;
        return "" + number;
      } else if (model instanceof BeanModel) {
        BeanModel arg0 = (BeanModel) model;
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.