Package freemarker.template

Examples of freemarker.template.TemplateException$PrintWriterStackTraceWriter


    if (result != null) {
      try {
        env.getOut().write(result);
      } catch (IOException ex) {
        throw new TemplateException("Error writing [" + result + "] to Freemarker.", ex, env);
      }
    } else {
      renderBody(env, body);
    }
  }
View Full Code Here


    public Object getBeanObject(Environment environment, Map params, String directiveName) throws TemplateException {
        Object beanParam = params.get("bean");

        if(beanParam == null) {
            if(params.containsKey("bean")) {
                throw new TemplateException("Mandatory <@" + directiveName + "> directive parameter 'bean' is defined, but the bean is not visible in the model.  Should be a valid model object reference (no quotes) e.g. <@" + directiveName + " bean=customer.address />.", environment);
            } else {
                throw new TemplateException("Mandatory <@" + directiveName + "> directive parameter 'bean' is not defined.  Should be a valid model object reference (no quotes) e.g. <@" + directiveName + " bean=customer.address />.", environment);
            }
        }

        if(!(beanParam instanceof StringModel)) {
            throw new TemplateException("Mandatory <@" + directiveName + "> directive parameter 'bean' not defined properly.  Should be a valid model object reference (no quotes) e.g. <@" + directiveName + " bean=customer.address />.", environment);
        }

        StringModel beanModel = (StringModel) beanParam;

        return beanModel.getWrappedObject();
View Full Code Here

            Template template = new Template(parentTemplate.getName() + "$" + id, new StringReader(interpretString), parentTemplate.getConfiguration());
            template.setLocale(env.getLocale());
            return new TemplateProcessorModel(template);
        }
        catch(IOException e) {
            throw new TemplateException("", e, env);
        }
    }
View Full Code Here

            }
            // unknown and datetime can be coerced into any date type
            if(dtype == TemplateDateModel.UNKNOWN || dtype == TemplateDateModel.DATETIME) {
                return new SimpleDate(dmodel.getAsDate(), dateType);
            }
            throw new TemplateException(
                    "Cannot convert " + TemplateDateModel.TYPE_NAMES.get(dtype)
                    + " into " + TemplateDateModel.TYPE_NAMES.get(dateType), env);
        }
        else if (model instanceof TemplateScalarModel) {
            return new DateParser(((TemplateScalarModel) model).getAsString(),
View Full Code Here

    throws TemplateException {
        final Number num;
        try {
            num = ((TemplateNumberModel) model).getAsNumber();
        } catch (ClassCastException e) {
            throw new TemplateException(
                    "Expecting a number on the left side of ?c", env);
        } catch (NullPointerException e) {
            throw new InvalidReferenceException("Undefined number", env);
        }
        if (num instanceof Integer) {
View Full Code Here

        Expression exp = null;
        try {
            exp = parser.Exp();
        } catch (ParseException pe) {
            pe.setTemplateName(caller.getTemplate().getName());
            throw new TemplateException(pe, env);
        }
        return exp.getAsTemplateModel(env);
    }
View Full Code Here

                    return null;
                }
            });
        }
        catch(IOException e) {
            throw new TemplateException(e, env);
        }
    }
View Full Code Here

            result.add(args.getValueAt(i, env));
        }
        if(commonSize < argsSize) {
            // More actual args than formal args -- use catchall if present
            if (catchall == null) {
                throw new TemplateException("Extraneous parameters provided; expected " +
                        paramsSize + ", got " + argsSize, env);
            }
            for (int i = commonSize; i < argsSize; i++) {
                result.add(args.getValueAt(i, env));
            }
View Full Code Here

        int argsSize = args.size();
        int paramsSize = params.size();
        if(argsSize > paramsSize) {
            Collection<String> l = new LinkedHashSet<String>(args.getArgs().keySet());
            l.removeAll(params);
            throw new TemplateException("Extraneous parameters " + l, env);
        }
        final List<TemplateModel> result = new ArrayList<TemplateModel>();
        List<String> unresolvedParamNames = null;
        Map<String, Expression> argsMap = args.getCopyOfMap();
        for (String paramName : params) {
View Full Code Here

    {
        final int argsSize = args.size();
        final int paramsSize = params.size();
        final Map<String, TemplateModel> result = new HashMap<String, TemplateModel>();
        if (catchall == null && argsSize > paramsSize && !ignoreExtraParams) {
            throw new TemplateException("Expecting exactly " + paramsSize +
                    " arguments, received " + argsSize + ".", env);
        }
        int min = Math.min(paramsSize, argsSize);
        for (int i=0; i < min; i++) {
            result.put(params.get(i), args.getValueAt(i, env));
View Full Code Here

TOP

Related Classes of freemarker.template.TemplateException$PrintWriterStackTraceWriter

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.