Aipo の Velocity テンプレートを編集する際に、Java 側から変数をテンプレート側に受け渡すようにしますが、テンプレートの種類によって、定義する Java ファイルが異なります。
ALBaseAction ALSecureBaseAction ALSessionValidator ALVelocityScreen ALVelocityPortletControl ALVelocityPortletSetControl
ざっとこれだけの種類があります。個別に記述することもできますが、すべてのテンプレートに透過的に値をアサインできるメソッドがあります。
ALOrgUtilsHandler
public Map<String, String> getParameters(String orgId) {
Map<String, String> hash = new HashMap<String, String>();
hash.put("theme", getTheme(orgId));
hash.put("alias", getAlias(orgId));
hash.put("aliasjp", getAliasjp(orgId));
hash.put("copyright", getCopyright(orgId));
hash.put("copyright_short", getCopyrightShort(orgId));
hash.put("alias_copyright", getAliasCopyright(orgId));
hash.put("version", getVersion(orgId));
String url = getExternalResourcesUrl(orgId);
hash.put("external_resources_url", url);
hash.put("unlockeddomain_url", getUnlockedDomainBaseUrl(orgId));
hash.put("context_path", getContextPath(orgId));
hash.put("isXDomain", String.valueOf(url.startsWith("http")));
HttpServletRequest request = HttpServletRequestLocator.get();
String useragent = request.getHeader("User-Agent").trim();
hash.put("client", ALEipUtils.getClient(useragent));
hash.put("clientVer", ALEipUtils.getClientVersion(useragent));
return hash;
}
この HashMap に値をセットしておけば、どの Velocity テンプレートからも値が取り出せるようになります。


