Search in sources :

Example 86 with TemplateModelException

use of freemarker.template.TemplateModelException in project wombat by PLOS.

the class ThemeConfigDirective method getValue.

@Override
protected Object getValue(Environment env, Map params) throws TemplateException, IOException {
    Object mapNameObj = params.get("map");
    if (mapNameObj == null)
        throw new TemplateModelException("map param required");
    Object valueNameObj = params.get("value");
    if (valueNameObj == null)
        throw new TemplateModelException("value param required");
    Object journalKeyObj = params.get("journal");
    Theme theme = new SitePageContext(siteResolver, env).getSite().getTheme();
    if (journalKeyObj != null) {
        theme = theme.resolveForeignJournalKey(siteSet, journalKeyObj.toString()).getTheme();
    }
    Map<String, Object> configMap = theme.getConfigMap(mapNameObj.toString());
    if (configMap == null) {
        throw new TemplateModelException("No config map exists for: " + mapNameObj);
    }
    return configMap.get(valueNameObj.toString());
}
Also used : TemplateModelException(freemarker.template.TemplateModelException) Theme(org.ambraproject.wombat.config.theme.Theme)

Example 87 with TemplateModelException

use of freemarker.template.TemplateModelException in project openj9 by eclipse.

the class UMA method get.

public TemplateModel get(String arg0) throws TemplateModelException {
    if (arg0.equals("spec")) {
        return new Spec();
    }
    if (arg0.equals("year")) {
        GregorianCalendar calendar = new GregorianCalendar();
        return new SimpleScalar(Integer.toString(calendar.get(Calendar.YEAR)));
    }
    try {
        TemplateModel platformExtension = com.ibm.uma.UMA.getUma().getPlatform().getDataModelExtension(com.ibm.uma.UMA.FREEMARKER_UMA, arg0);
        if (platformExtension != null)
            return platformExtension;
        TemplateModel configurationExtension = com.ibm.uma.UMA.getUma().getConfiguration().getDataModelExtension(com.ibm.uma.UMA.FREEMARKER_UMA, arg0);
        if (configurationExtension != null)
            return configurationExtension;
    } catch (UMAException e) {
        throw new TemplateModelException(e);
    }
    return null;
}
Also used : TemplateModelException(freemarker.template.TemplateModelException) GregorianCalendar(java.util.GregorianCalendar) TemplateModel(freemarker.template.TemplateModel) UMAException(com.ibm.uma.UMAException) SimpleScalar(freemarker.template.SimpleScalar)

Aggregations

TemplateModelException (freemarker.template.TemplateModelException)87 TemplateModel (freemarker.template.TemplateModel)24 IOException (java.io.IOException)21 TemplateScalarModel (freemarker.template.TemplateScalarModel)18 SimpleScalar (freemarker.template.SimpleScalar)17 BeanModel (freemarker.ext.beans.BeanModel)14 Environment (freemarker.core.Environment)13 Writer (java.io.Writer)13 ArrayList (java.util.ArrayList)13 HttpServletRequest (javax.servlet.http.HttpServletRequest)12 Map (java.util.Map)10 List (java.util.List)9 SimpleNumber (freemarker.template.SimpleNumber)7 TemplateHashModel (freemarker.template.TemplateHashModel)7 Iterator (java.util.Iterator)6 freemarker.core._TemplateModelException (freemarker.core._TemplateModelException)5 TemplateHashModelEx (freemarker.template.TemplateHashModelEx)5 TemplateMethodModelEx (freemarker.template.TemplateMethodModelEx)5 TemplateModelIterator (freemarker.template.TemplateModelIterator)5 UMAException (com.ibm.uma.UMAException)4