本文整理汇总了Java中org.apache.velocity.app.VelocityEngine.evaluate方法的典型用法代码示例。如果您正苦于以下问题:Java VelocityEngine.evaluate方法的具体用法?Java VelocityEngine.evaluate怎么用?Java VelocityEngine.evaluate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.velocity.app.VelocityEngine
的用法示例。
在下文中一共展示了VelocityEngine.evaluate方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: fromTemplate
import org.apache.velocity.app.VelocityEngine; //导入方法依赖的package包/类
public static String fromTemplate(String velocityTemplate, Map<String, String> mapVariables) {
StringWriter stringWriter = new StringWriter();
try {
VelocityEngine velocityEngine = getVelocityEngine();
VelocityContext velocityContext = new VelocityContext();
for (Map.Entry<String, String> entry : mapVariables.entrySet()) {
velocityContext.put(entry.getKey(), entry.getValue());
}
velocityEngine.evaluate(velocityContext, stringWriter, "PackageTemplatesVelocity", velocityTemplate);
} catch (Exception e) {
Logger.log("fromTemplate Error in Velocity code generator");
return null;
}
return stringWriter.getBuffer().toString();
}
示例2: sqlTemplateService
import org.apache.velocity.app.VelocityEngine; //导入方法依赖的package包/类
public static String sqlTemplateService(String template,Map paramMap,List placeList){
VelocityEngine ve = new VelocityEngine();
ve.addProperty("userdirective", "com.minxin.micro.template.vext.MicroSqlReplace");
ve.init();
VelocityContext context = new VelocityContext();
context.put("param", paramMap);
context.put("placeList", placeList);
StringWriter writer = new StringWriter();
ve.evaluate(context, writer, "", template);
return writer.toString();
}
示例3: format
import org.apache.velocity.app.VelocityEngine; //导入方法依赖的package包/类
public static String format(VelocityEngine ve,String pattern, Object dataModel){
if(ve == null){
ve = VlocityFormat.ve;
}
Context context = createVelocityContext(dataModel);
//raw return
if(context == null){
return pattern;
}
StringWriter writer = new StringWriter();
ve.evaluate(context, writer, "logTag", pattern);
return writer.toString();
}
示例4: main
import org.apache.velocity.app.VelocityEngine; //导入方法依赖的package包/类
public static void main(String[] args) {
VelocityEngine velocityEngine = VelocityFactory.getVelocityEngine();
velocityEngine.loadDirective("com.github.hykes.codegen.directive.LowerCase");
velocityEngine.loadDirective("com.github.hykes.codegen.directive.Split");
String template = "#Split(\"#LowerCase(${NAME})\" '.')";
Map<String, Object> map = new HashMap<>();
map.put("NAME", "HykesIsStrong");
StringWriter writer = new StringWriter();
velocityEngine.evaluate(new VelocityContext(map), writer, "", template);
System.out.println(writer.toString());
}
示例5: evaluateText
import org.apache.velocity.app.VelocityEngine; //导入方法依赖的package包/类
/**
* Method to get a message and let it parse through Velocity.
*
* @param messageKey
* Message key to load.
* @param locale
* The locale.
* @param model
* The model for the Velocity context.
* @return The final text.
*/
public String evaluateText(String messageKey, Locale locale, Map<String, Object> model) {
StringWriter messageWriter = new StringWriter();
VelocityEngine velocityEngine = ServiceLocator.findService(VelocityEngine.class);
try {
velocityEngine.evaluate(new VelocityContext(model), messageWriter, messageKey,
getText(messageKey, locale));
} catch (Exception e) {
throw new RuntimeException(e);
}
return messageWriter.toString().trim();
}
示例6: verify
import org.apache.velocity.app.VelocityEngine; //导入方法依赖的package包/类
public static void verify(String text) throws Exception
{
VelocityEngine engine = getEngine();
VelocityContext vc = new VelocityContext();
vc.put("today", new DateInfo());
StringWriter sw = new StringWriter();
if (text.endsWith("$")) {
text += getVelocitySuffix();
}
engine.evaluate(vc, sw, CopyrightManager.class.getName(), text);
}
示例7: evaluate
import org.apache.velocity.app.VelocityEngine; //导入方法依赖的package包/类
public static String evaluate(PsiFile file, Project project, Module module, String template)
{
VelocityEngine engine = getEngine();
VelocityContext vc = new VelocityContext();
vc.put("today", new DateInfo());
if (file != null) vc.put("file", new FileInfo(file));
if (project != null) vc.put("project", new ProjectInfo(project));
if (module != null) vc.put("module", new ModuleInfo(module));
vc.put("username", System.getProperty("user.name"));
if (file != null) {
final VirtualFile virtualFile = PsiUtilCore.getVirtualFile(file);
if (virtualFile != null) {
final CopyrightVariablesProvider variablesProvider = CopyrightVariablesProviders.INSTANCE.forFileType(virtualFile.getFileType());
if (variablesProvider != null) {
final Map<String, Object> context = new HashMap<String, Object>();
variablesProvider.collectVariables(context, project, module, file);
for (Map.Entry<String, Object> entry : context.entrySet()) {
vc.put(entry.getKey(), entry.getValue());
}
}
}
}
try
{
StringWriter sw = new StringWriter();
boolean stripLineBreak = false;
if (template.endsWith("$")) {
template += getVelocitySuffix();
stripLineBreak = true;
}
engine.evaluate(vc, sw, CopyrightManager.class.getName(), template);
final String result = sw.getBuffer().toString();
return stripLineBreak ? StringUtil.trimEnd(result, getVelocitySuffix()) : result;
}
catch (Exception e)
{
return "";
}
}
示例8: onExchange
import org.apache.velocity.app.VelocityEngine; //导入方法依赖的package包/类
@Override
protected void onExchange(Exchange exchange) throws Exception {
String path = getResourceUri();
ObjectHelper.notNull(path, "resourceUri");
String newResourceUri = exchange.getIn().getHeader(VelocityConstants.VELOCITY_RESOURCE_URI, String.class);
if (newResourceUri != null) {
exchange.getIn().removeHeader(VelocityConstants.VELOCITY_RESOURCE_URI);
log.debug("{} set to {} creating new endpoint to handle exchange", VelocityConstants.VELOCITY_RESOURCE_URI, newResourceUri);
VelocityEndpoint newEndpoint = findOrCreateEndpoint(getEndpointUri(), newResourceUri);
newEndpoint.onExchange(exchange);
return;
}
Reader reader;
String content = exchange.getIn().getHeader(VelocityConstants.VELOCITY_TEMPLATE, String.class);
if (content != null) {
// use content from header
reader = new StringReader(content);
if (log.isDebugEnabled()) {
log.debug("Velocity content read from header {} for endpoint {}", VelocityConstants.VELOCITY_TEMPLATE, getEndpointUri());
}
// remove the header to avoid it being propagated in the routing
exchange.getIn().removeHeader(VelocityConstants.VELOCITY_TEMPLATE);
} else {
if (log.isDebugEnabled()) {
log.debug("Velocity content read from resource {} with resourceUri: {} for endpoint {}", new Object[]{getResourceUri(), path, getEndpointUri()});
}
reader = getEncoding() != null ? new InputStreamReader(getResourceAsInputStream(), getEncoding()) : new InputStreamReader(getResourceAsInputStream());
}
// getResourceAsInputStream also considers the content cache
StringWriter buffer = new StringWriter();
String logTag = getClass().getName();
Context velocityContext = exchange.getIn().getHeader(VelocityConstants.VELOCITY_CONTEXT, Context.class);
if (velocityContext == null) {
Map<String, Object> variableMap = ExchangeHelper.createVariableMap(exchange);
@SuppressWarnings("unchecked")
Map<String, Object> supplementalMap = exchange.getIn().getHeader(VelocityConstants.VELOCITY_SUPPLEMENTAL_CONTEXT, Map.class);
if (supplementalMap != null) {
variableMap.putAll(supplementalMap);
}
velocityContext = new VelocityContext(variableMap);
}
// let velocity parse and generate the result in buffer
VelocityEngine engine = getVelocityEngine();
log.debug("Velocity is evaluating using velocity context: {}", velocityContext);
engine.evaluate(velocityContext, buffer, logTag, reader);
// now lets output the results to the exchange
Message out = exchange.getOut();
out.setBody(buffer.toString());
out.setHeaders(exchange.getIn().getHeaders());
out.setAttachments(exchange.getIn().getAttachments());
}