Search in sources :

Example 41 with TemplateModelException

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

the class Flag method get.

public TemplateModel get(String arg0) throws TemplateModelException {
    if (arg0.equals("name")) {
        return new SimpleScalar(flag);
    }
    if (arg0.equals("enabled")) {
        return new BooleanModel(UMA.getUma().getConfiguration().isFlagSet(flag), new BeansWrapper());
    }
    try {
        TemplateModel platformExtension = com.ibm.uma.UMA.getUma().getPlatform().getDataModelExtension("uma.spec.flags." + flag, arg0);
        if (platformExtension != null)
            return platformExtension;
        TemplateModel configurationExtension = com.ibm.uma.UMA.getUma().getConfiguration().getDataModelExtension("uma.spec.flags." + flag, arg0);
        if (configurationExtension != null)
            return configurationExtension;
    } catch (UMAException e) {
        throw new TemplateModelException(e);
    }
    return null;
}
Also used : TemplateModelException(freemarker.template.TemplateModelException) BooleanModel(freemarker.ext.beans.BooleanModel) BeansWrapper(freemarker.ext.beans.BeansWrapper) TemplateModel(freemarker.template.TemplateModel) UMAException(com.ibm.uma.UMAException) SimpleScalar(freemarker.template.SimpleScalar)

Example 42 with TemplateModelException

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

the class Spec method get.

public TemplateModel get(String arg0) throws TemplateModelException {
    if (arg0.equals("flags")) {
        return new Flags();
    }
    if (arg0.equals("tools")) {
        return new Tools();
    }
    if (arg0.equals("properties")) {
        return new Properties();
    }
    if (arg0.equals("artifacts")) {
        return new Artifacts(UMA.getUma().getArtifacts());
    }
    if (arg0.equals("type")) {
        return new Type();
    }
    if (arg0.equals("processor")) {
        return new Processor();
    }
    try {
        TemplateModel platformExtension = com.ibm.uma.UMA.getUma().getPlatform().getDataModelExtension("uma.spec", arg0);
        if (platformExtension != null)
            return platformExtension;
        TemplateModel configurationExtension = com.ibm.uma.UMA.getUma().getConfiguration().getDataModelExtension("uma.spec", arg0);
        if (configurationExtension != null)
            return configurationExtension;
    } catch (UMAException e) {
        throw new TemplateModelException(e);
    }
    return null;
}
Also used : TemplateModelException(freemarker.template.TemplateModelException) TemplateModel(freemarker.template.TemplateModel) UMAException(com.ibm.uma.UMAException)

Example 43 with TemplateModelException

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

the class TemplateModelUtil method getAsMap.

static ImmutableMap<String, TemplateModel> getAsMap(TemplateModel value) throws TemplateModelException {
    if (value == null)
        return ImmutableMap.of();
    if (value instanceof TemplateHashModelEx) {
        TemplateHashModelEx ftlHash = (TemplateHashModelEx) value;
        ImmutableMap.Builder<String, TemplateModel> builder = ImmutableMap.builder();
        for (TemplateModelIterator iterator = ftlHash.keys().iterator(); iterator.hasNext(); ) {
            String key = iterator.next().toString();
            builder.put(key, ftlHash.get(key));
        }
        return builder.build();
    }
    throw new TemplateModelException("Hash type expected");
}
Also used : TemplateModelException(freemarker.template.TemplateModelException) TemplateModelIterator(freemarker.template.TemplateModelIterator) TemplateHashModelEx(freemarker.template.TemplateHashModelEx) TemplateModel(freemarker.template.TemplateModel) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 44 with TemplateModelException

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

the class TemplateModelUtil method getAsMultimap.

static ImmutableListMultimap<String, TemplateModel> getAsMultimap(TemplateModel value) throws TemplateModelException {
    if (value == null)
        return ImmutableListMultimap.of();
    if (value instanceof TemplateHashModelEx) {
        TemplateHashModelEx ftlHash = (TemplateHashModelEx) value;
        ImmutableListMultimap.Builder<String, TemplateModel> builder = ImmutableListMultimap.builder();
        for (TemplateModelIterator iterator = ftlHash.keys().iterator(); iterator.hasNext(); ) {
            String key = iterator.next().toString();
            TemplateModel model = ftlHash.get(key);
            if (model instanceof TemplateSequenceModel) {
                TemplateSequenceModel sequenceModel = (TemplateSequenceModel) model;
                int size = sequenceModel.size();
                for (int i = 0; i < size; i++) {
                    builder.put(key, sequenceModel.get(i));
                }
            } else {
                builder.put(key, model);
            }
        }
        return builder.build();
    }
    throw new TemplateModelException("Hash type expected");
}
Also used : TemplateModelException(freemarker.template.TemplateModelException) TemplateSequenceModel(freemarker.template.TemplateSequenceModel) TemplateModelIterator(freemarker.template.TemplateModelIterator) TemplateHashModelEx(freemarker.template.TemplateHashModelEx) ImmutableListMultimap(com.google.common.collect.ImmutableListMultimap) TemplateModel(freemarker.template.TemplateModel)

Example 45 with TemplateModelException

use of freemarker.template.TemplateModelException in project solo by b3log.

the class FillTagArticles method exec.

@Override
public Object exec(final List arguments) throws TemplateModelException {
    if (arguments.size() != ARG_SIZE) {
        LOGGER.debug("FillTagArticles with wrong arguments!");
        throw new TemplateModelException("Wrong arguments!");
    }
    final String tagTitle = (String) arguments.get(0);
    final int currentPageNum = Integer.parseInt((String) arguments.get(1));
    final int pageSize = Integer.parseInt((String) arguments.get(2));
    try {
        final JSONObject result = tagQueryService.getTagByTitle(tagTitle);
        if (null == result) {
            return new ArrayList<JSONObject>();
        }
        final JSONObject tag = result.getJSONObject(Tag.TAG);
        final String tagId = tag.getString(Keys.OBJECT_ID);
        final List<JSONObject> list = articleQueryService.getArticlesByTag(tagId, currentPageNum, pageSize);
        return list;
    } catch (final ServiceException e) {
        e.printStackTrace();
    } catch (final JSONException e) {
        e.printStackTrace();
    }
    return null;
}
Also used : TemplateModelException(freemarker.template.TemplateModelException) JSONObject(org.json.JSONObject) ServiceException(org.b3log.latke.service.ServiceException) ArrayList(java.util.ArrayList) JSONException(org.json.JSONException)

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