(androidで使えるかもしれない)java系ライブラリ検証メモ<template編


メモ途中)


  • Velocity

現場で使える〔逆引き+実践〕 Androidプログラミングテクニック

現場で使える〔逆引き+実践〕 Androidプログラミングテクニック

の本の 4-3-8 に 動的HTMLをWebViewにしたい で記載されてる

キモの所は

 Velocity.setProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM_CLASS,
                VELOCITY_RUNTIME_LOG_NULLLOGSYSTEM_CLASS);
 Velocity.init();

でログを吐かないようにする *1
 のと

 mVelocityContext = new VelocityContext();
//〜中略〜
mVelocityContext.put(VK_LIST, nodeList); //値のバインド
//〜中略〜

final StringWriter sw = new StringWriter();
//sbはassetsから読み込んだindex.vmのテキストデータ
Velocity.evaluate(mVelocityContext, sw, "", sb.toString());
return sw.toString();

ということ。で表示は下記な感じでレンダリング済みの文字列をそのまま設定と。。

mWebView.loadDataWithBaseURL(null, getHtml(), MIME_TYPE_TEXT_HTML,ENCODE, null);


確かに template.merge(mVelocityContext, sw) は

prop.setProperty("resource.loader","file");
prop.setProperty("file.resource.loader.class",
        		"org.apache.velocity.runtime.resource.loader.FileResourceLoader");
prop.setProperty("file.resource.loader.cache", "true");
prop.setProperty("file.resource.loader.path", "file:///android_asset/");

な指定は無理だから使えないしな。。*2

まあファイルで読込とすると

    • assets
AssetManager assets = getResources().getAssets();
InputStream inputStream = assets.open(”vm/index.vm”);
    • raw
Resources m_r = getResources();
InputStream inputStream = m_r.openRawResource(R.raw.index);

つう書き方になるので泥臭く放っちゃうかも(汗。

あと自分的には

Velocity.setProperty よりも

Properties prop  = new Properties();
prop.setProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM_CLASS,
                VELOCITY_RUNTIME_LOG_NULLLOGSYSTEM_CLASS);

prop.setProperty("input.encoding", "UTF-8");
prop.setProperty("output.encoding", "UTF-8");
Velocity.init(prop);

な書き方のほうがいいかな。。

ちなみに VelocityEngineの方しか使ったことなかったけど
Velocityの方ってシングルトンなんだ。。へー。


  • mixer2

jjugでよく公演されてるテンプレートエンジン




  • FreeMaker

現場で使えるJavaライブラリ

現場で使えるJavaライブラリ

Android Studioでnew projectを作る場合時のテンプレートで使われてる奴



  • jelly

攻略Jakarta Commons

攻略Jakarta Commons

jenkinsのpluginのUIを作るときに使われてるテンプレート

普通に[android jelly]でググると jelly beansのほうが引っかかってしまうので
[apache jelly] で検索かけるほうがいいかと思う

参考)



フルXtendなAndroidクライアントらしい

*1:どッちにしてもデフォルトで容易されてるLogger以外の指定は無理なのでこれでいいのかも。。。

*2:上記の指定が使えるのはloadUrlとかだけらしい