Java Code Examples for org.mvel2.templates.TemplateRuntime#eval()

The following examples show how to use org.mvel2.templates.TemplateRuntime#eval() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UpdateSpringBootAutoConfigurationReadmeMojo.java    From camel-spring-boot with Apache License 2.0 7 votes vote down vote up
private String templateAutoConfigurationOptions(List<SpringBootAutoConfigureOptionModel> options, String componentName) throws MojoExecutionException {
    SpringBootModel model = new SpringBootModel();
    model.setGroupId(project.getGroupId());
    model.setArtifactId("camel-" + componentName + "-starter");
    model.setVersion(project.getVersion());
    model.setOptions(options);
    model.setTitle(componentName);

    try {
        String template = loadText(UpdateSpringBootAutoConfigurationReadmeMojo.class.getClassLoader().getResourceAsStream("spring-boot-auto-configure-options.mvel"));
        String out = (String) TemplateRuntime.eval(template, model, Collections.singletonMap("util", MvelHelper.INSTANCE));
        return out;
    } catch (Exception e) {
        throw new MojoExecutionException("Error processing mvel template. Reason: " + e, e);
    }
}
 
Example 2
Source File: UpdateDocComponentsListMojo.java    From camel-spring-boot with Apache License 2.0 6 votes vote down vote up
private String templateComponents(List<ComponentModel> models, int artifacts, long deprecated)
        throws MojoExecutionException {
    try {
        String template = loadText(
                UpdateDocComponentsListMojo.class.getClassLoader().getResourceAsStream("readme-components.mvel"));
        Map<String, Object> map = new HashMap<>();
        map.put("components", models);
        map.put("numberOfArtifacts", artifacts);
        map.put("numberOfDeprecated", deprecated);
        String out = (String) TemplateRuntime.eval(template, map,
                Collections.singletonMap("util", new ExtMvelHelper(getComponentsStarterDocPath())));
        return out;
    } catch (Exception e) {
        throw new MojoExecutionException("Error processing mvel template. Reason: " + e, e);
    }
}
 
Example 3
Source File: UpdateDocComponentsListMojo.java    From camel-spring-boot with Apache License 2.0 6 votes vote down vote up
private String templateDataFormats(List<DataFormatModel> models, int artifacts, long deprecated)
        throws MojoExecutionException {
    try {
        String template = loadText(
                UpdateDocComponentsListMojo.class.getClassLoader().getResourceAsStream("readme-dataformats.mvel"));
        Map<String, Object> map = new HashMap<>();
        map.put("dataformats", models);
        map.put("numberOfArtifacts", artifacts);
        map.put("numberOfDeprecated", deprecated);
        String out = (String) TemplateRuntime.eval(template, map,
                Collections.singletonMap("util", new ExtMvelHelper(getComponentsStarterDocPath())));
        return out;
    } catch (Exception e) {
        throw new MojoExecutionException("Error processing mvel template. Reason: " + e, e);
    }
}
 
Example 4
Source File: CamelKafkaConnectorUpdateMojo.java    From camel-kafka-connector with Apache License 2.0 5 votes vote down vote up
private String templateAutoConfigurationOptions(List<CamelKafkaConnectorOptionModel> options, String componentName, File connectorDir, ConnectorType ct)
    throws MojoExecutionException {

    CamelKafkaConnectorModel model = new CamelKafkaConnectorModel();
    model.setOptions(options);
    model.setArtifactId(getMainDepArtifactId());
    model.setGroupId(getMainDepGroupId());
    model.setVersion(getMainDepVersion());
    if (getMainDepArtifactId().equalsIgnoreCase("camel-coap+tcp")) {
        model.setTitle("camel-coap-tcp");
    } else if (getMainDepArtifactId().equalsIgnoreCase("camel-coaps+tcp")) {
        model.setTitle("camel-coaps-tcp");
    } else {
        model.setTitle(getMainDepArtifactId());
    }

    try {
        String template = null;
        if (ct.name().equals(ConnectorType.SINK.name())) {
            template = loadText(CamelKafkaConnectorUpdateMojo.class.getClassLoader().getResourceAsStream("camel-kafka-connector-sink-options.mvel"));
        } else if (ct.name().equals(ConnectorType.SOURCE.name())) {
            template = loadText(CamelKafkaConnectorUpdateMojo.class.getClassLoader().getResourceAsStream("camel-kafka-connector-source-options.mvel"));
        }
        String out = (String)TemplateRuntime.eval(template, model, Collections.singletonMap("util", MvelHelper.INSTANCE));
        return out;
    } catch (Exception e) {
        throw new MojoExecutionException("Error processing mvel template. Reason: " + e, e);
    }
}
 
Example 5
Source File: UpdateDocComponentsListMojo.java    From camel-kafka-connector with Apache License 2.0 5 votes vote down vote up
private String templateConnnectorsTable(CamelKafkaConnectorTableModel model) throws MojoExecutionException {

        try {
            String template = null;
            template = loadText(UpdateDocComponentsListMojo.class.getClassLoader().getResourceAsStream("connectors.mvel"));
            String out = (String)TemplateRuntime.eval(template, model, Collections.singletonMap("util", MvelHelper.INSTANCE));
            return out;
        } catch (Exception e) {
            throw new MojoExecutionException("Error processing mvel template. Reason: " + e, e);
        }
    }
 
Example 6
Source File: UpdateDocComponentsListMojo.java    From camel-spring-boot with Apache License 2.0 5 votes vote down vote up
private String templateLanguages(List<LanguageModel> models, int artifacts, long deprecated) throws MojoExecutionException {
    try {
        String template = loadText(
                UpdateDocComponentsListMojo.class.getClassLoader().getResourceAsStream("readme-languages.mvel"));
        Map<String, Object> map = new HashMap<>();
        map.put("languages", models);
        map.put("numberOfArtifacts", artifacts);
        map.put("numberOfDeprecated", deprecated);
        String out = (String) TemplateRuntime.eval(template, map,
                Collections.singletonMap("util", new ExtMvelHelper(getComponentsStarterDocPath())));
        return out;
    } catch (Exception e) {
        throw new MojoExecutionException("Error processing mvel template. Reason: " + e, e);
    }
}
 
Example 7
Source File: UpdateDocComponentsListMojo.java    From camel-spring-boot with Apache License 2.0 5 votes vote down vote up
private String templateOthers(List<OtherModel> models, int artifacts, long deprecated) throws MojoExecutionException {
    try {
        String template = loadText(
                UpdateDocComponentsListMojo.class.getClassLoader().getResourceAsStream("readme-others.mvel"));
        Map<String, Object> map = new HashMap<>();
        map.put("others", models);
        map.put("numberOfArtifacts", artifacts);
        map.put("numberOfDeprecated", deprecated);
        String out = (String) TemplateRuntime.eval(template, map,
                Collections.singletonMap("util", new ExtMvelHelper(getComponentsStarterDocPath())));
        return out;
    } catch (Exception e) {
        throw new MojoExecutionException("Error processing mvel template. Reason: " + e, e);
    }
}
 
Example 8
Source File: ParseHelper.java    From zealot with Apache License 2.0 5 votes vote down vote up
/**
 * 通过MVEL来解析模板的值.
 * @param template 待解析表达式
 * @param paramObj 参数对象
 * @return 返回解析后的结果
 */
public static String parseTemplate(String template, Object paramObj) {
    String output;
    try {
        output = (String) TemplateRuntime.eval(template, paramObj);
    } catch (Exception e) {
        throw new ParseExpressionException("解析Mvel模板异常,解析出错的模板为:" + template, e);
    }
    return output;
}