2012-06-14 67 views

回答

4

隨着速度/ Java的一部分,這或多或少是你需要做的:

// factory and an engine instance 
VelocityEngineFactory velocityEngineFactory = new VelocityEngineFactory(); 
VelocityEngine engine = velocityEngineFactory.createVelocityEngine(); 
// now you need to give the variables you wanna have access from velocity script 
VelocityContext context = new VelocityContext(properties); 

ByteArrayOutputStream temp = new ByteArrayOutputStream(); 
BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(temp)); 
// generate the result, where scriptString is the velocity script 
engine.evaluate(context, bufferedWriter, null, scriptString); 
bufferedWriter.flush(); 
textResultant = temp.toString(); 

所以你可以創建一個腳本,加載它並以編程方式處理它。

相關問題