|
|
|
package com.fanruan.api.util;
|
|
|
|
|
|
|
|
import com.fr.base.TemplateUtils;
|
|
|
|
import com.fr.script.Calculator;
|
|
|
|
import com.fr.stable.script.CalculatorProvider;
|
|
|
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 文本动态渲染工具类
|
|
|
|
*/
|
|
|
|
public class RenderKit {
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 计算可扩展的参数, 例如{=ds1.select(id)} + abc
|
|
|
|
* 得到的是数组ArrayProvider {1abc, 2abc....}
|
|
|
|
*
|
|
|
|
* @param ca 算子
|
|
|
|
* @param tpl 需要计算的参数
|
|
|
|
* @return 计算结果
|
|
|
|
*/
|
|
|
|
public static Object renderExtendTpl(CalculatorProvider ca, String tpl) {
|
|
|
|
return TemplateUtils.renderExtendTpl(ca, tpl);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 根据参数, 来计算文档字符串
|
|
|
|
*
|
|
|
|
* @param text 待渲染的文本模板
|
|
|
|
* @param map 参数集合
|
|
|
|
* @return 返回渲染后的文本
|
|
|
|
* @throws Exception 渲染过程中出现错误则抛出此异常
|
|
|
|
*/
|
|
|
|
public static String renderParameter4Tpl(String text, Map<String, Object> map) throws Exception {
|
|
|
|
return TemplateUtils.renderParameter4Tpl(text, map);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 根据参数, 来计算文档字符串
|
|
|
|
*
|
|
|
|
* @param text 待渲染的文本模板
|
|
|
|
* @param c 参数集合
|
|
|
|
* @return 返回渲染后的文本
|
|
|
|
* @throws Exception 渲染过程中出现错误则抛出此异常
|
|
|
|
*/
|
|
|
|
public static String render(String text, Calculator c) throws Exception {
|
|
|
|
return TemplateUtils.render(text, c);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 根据参数, 来计算文档字符串
|
|
|
|
*
|
|
|
|
* @param text 待渲染的文本模板
|
|
|
|
* @return 返回渲染后的文本
|
|
|
|
* @throws Exception 渲染过程中出现错误则抛出此异常
|
|
|
|
*/
|
|
|
|
public static String render(String text) throws Exception {
|
|
|
|
return TemplateUtils.render(text, Calculator.createCalculator());
|
|
|
|
}
|
|
|
|
}
|