Search in sources :

Example 21 with TemplateModel

use of freemarker.template.TemplateModel in project be5 by DevelopmentOnTheEdge.

the class FtlToYaml method ftlToHash.

public static LinkedHashMap<String, Object> ftlToHash(TemplateHashModelEx model) throws TemplateModelException {
    LinkedHashMap<String, Object> result = new LinkedHashMap<>();
    TemplateCollectionModel keys = model.keys();
    TemplateModelIterator iterator = keys.iterator();
    while (iterator.hasNext()) {
        TemplateModel next = iterator.next();
        if (!(next instanceof TemplateScalarModel)) {
            throw new TemplateModelException("Invalid key: " + next);
        }
        String key = ((TemplateScalarModel) next).getAsString();
        TemplateModel value = model.get(key);
        try {
            result.put(key, ftlToObject(value));
        } catch (TemplateModelException e) {
            throw new TemplateModelException(key + ": " + e.getMessage(), e);
        }
    }
    return result;
}
Also used : TemplateModelException(freemarker.template.TemplateModelException) TemplateModelIterator(freemarker.template.TemplateModelIterator) TemplateScalarModel(freemarker.template.TemplateScalarModel) TemplateModel(freemarker.template.TemplateModel) TemplateCollectionModel(freemarker.template.TemplateCollectionModel) LinkedHashMap(java.util.LinkedHashMap)

Example 22 with TemplateModel

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

the class UMA method generate.

public void generate() throws UMAException {
    Parser parser = new Parser(this);
    if (!parser.parse()) {
        return;
    }
    modules = parser.getModules();
    platform.decorateModules(modules);
    try {
        Map<String, TemplateModel> map = new HashMap<String, TemplateModel>();
        map.put(FREEMARKER_UMA, new com.ibm.uma.freemarker.UMA());
        for (String tmp : templateLoader.getTemplates()) {
            Template template = freemarkerConfig.getTemplate(tmp);
            String filename = tmp.substring(0, tmp.lastIndexOf(".ftl"));
            StringWriter writer = new StringWriter();
            template.process(map, writer);
            new FileAssistant(this.rootDirectory + filename, writer.getBuffer()).writeToDisk();
        }
    } catch (IOException e) {
        throw new UMAException(e);
    } catch (TemplateException e) {
        throw new UMAException(e);
    }
    writeTargetInformationMacrosFile();
    // top level module is the first in the list.
    Module rootModule = null;
    for (Module module : modules) {
        if (module.isTopLevel()) {
            if (rootModule != null) {
                throw new UMAException("Error: more than one root module " + rootModule.getFullName() + " and " + module.getFullName());
            }
            rootModule = module;
        }
    }
    if (rootModule == null) {
        throw new UMAException("Error: no " + configuration.getMetadataFilename() + " found in the root directory " + getRootDirectory());
    }
    writeDirectoryMakefile(rootModule);
    Logger.getLogger().println(Logger.InformationL1Log, "Complete");
}
Also used : HashMap(java.util.HashMap) TemplateException(freemarker.template.TemplateException) TemplateModel(freemarker.template.TemplateModel) IOException(java.io.IOException) Parser(com.ibm.uma.om.parser.Parser) Template(freemarker.template.Template) FileAssistant(com.ibm.uma.util.FileAssistant) StringWriter(java.io.StringWriter) Module(com.ibm.uma.om.Module)

Example 23 with TemplateModel

use of freemarker.template.TemplateModel 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 24 with TemplateModel

use of freemarker.template.TemplateModel 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 25 with TemplateModel

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

the class Artifact method get.

public TemplateModel get(String arg0) throws TemplateModelException {
    try {
        if (arg0.equals("name")) {
            return new ArtifactName(artifact);
        }
        if (arg0.equals("data")) {
            return new ArtifactData(artifact);
        }
        if (arg0.equals("targetNameWithRelease")) {
            return new SimpleScalar(UMA.getUma().getPlatform().getTargetNameWithRelease(artifact));
        }
        if (arg0.equals("exportNames")) {
            return new ExportNames(artifact);
        }
        if (arg0.equals("bundledArtifacts")) {
            return new Artifacts(artifact.getAllArtifactsInThisBundleInHashtable());
        }
        TemplateModel platformExtension = com.ibm.uma.UMA.getUma().getPlatform().getDataModelExtension("uma.spec.flags." + artifact.getTargetName(), arg0);
        if (platformExtension != null)
            return platformExtension;
        TemplateModel configurationExtension = com.ibm.uma.UMA.getUma().getConfiguration().getDataModelExtension("uma.spec.flags." + artifact.getTargetName(), arg0);
        if (configurationExtension != null)
            return configurationExtension;
        return null;
    } catch (UMAException e) {
        throw new TemplateModelException(e);
    }
}
Also used : TemplateModelException(freemarker.template.TemplateModelException) TemplateModel(freemarker.template.TemplateModel) UMAException(com.ibm.uma.UMAException) SimpleScalar(freemarker.template.SimpleScalar)

Aggregations

TemplateModel (freemarker.template.TemplateModel)108 TemplateModelException (freemarker.template.TemplateModelException)26 Map (java.util.Map)23 TemplateScalarModel (freemarker.template.TemplateScalarModel)18 Test (org.junit.Test)17 ArrayList (java.util.ArrayList)15 TemplateException (freemarker.template.TemplateException)13 HashMap (java.util.HashMap)13 SimpleScalar (freemarker.template.SimpleScalar)11 IOException (java.io.IOException)11 List (java.util.List)11 Template (freemarker.template.Template)9 TemplateSequenceModel (freemarker.template.TemplateSequenceModel)8 TemplateTransformModel (freemarker.template.TemplateTransformModel)8 SimpleHash (freemarker.template.SimpleHash)7 SimpleSequence (freemarker.template.SimpleSequence)7 Writer (java.io.Writer)7 Iterator (java.util.Iterator)7 Environment (freemarker.core.Environment)6 TemplateHashModel (freemarker.template.TemplateHashModel)6