Package freemarker.template

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


    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

        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

    }
   
    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

            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

                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

                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

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

  }

  private class OverallCostMethod 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

        }
    }

    public static TemplateModel autoWrap(Object obj, Environment env) {
       BeansWrapper wrapper = BeansWrapper.getDefaultInstance();
       TemplateModel templateModelObj = null;
       try {
           templateModelObj = wrapper.wrap(obj);
       } catch (TemplateModelException e) {
           throw new RuntimeException(e.getMessage());
       }
View Full Code Here

TOP

Related Classes of freemarker.template.TemplateModel

Copyright © 2018 www.massapicom. 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.