2009年6月28日日曜日

GAEでVelocity

少しテンプレートエンジンを使いたいなぁ。。。って思ったので
Velocityを使うことにしたんだけど、
GAEはファイルシステムはないので、、、って思ってたら
メモリ上で展開できるみたい。

  1. VelocityContext context = new VelocityContext();  
  2. StringWriter writer = new StringWriter();  
  3. String template =   
  4.  "テンプレートのテストです[${name}]" +   
  5.  "";  
  6. context.put("name""なまえー");    
  7. Velocity.evaluate(context, writer, "vecocityTest", template);  


これでwriterに設定できます。
テンプレートを「com.google.appengine.api.datastore.Text」で
保存すれば使えそうですね。

実行にはVelocity、commons-lang、commons-collectionが必要です。

0 件のコメント: