2 * Copyright 2014 Hanei Management Co.,Ltd.
\r
4 * This file is part of Jaxcel
\r
6 * Jaxcel is free software: you can redistribute it and/or modify
\r
7 * it under the terms of the GNU Lesser General Public License as published by
\r
8 * the Free Software Foundation, either version 3 of the License, or
\r
9 * (at your option) any later version.
\r
11 * Jaxcel is distributed in the hope that it will be useful,
\r
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
14 * GNU Lesser General Public License for more details.
\r
16 * You should have received a copy of the GNU Lesser General Public License
\r
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
\r
19 package org.hanei.jaxcel.report;
\r
21 import java.util.Map;
\r
22 import java.util.Map.Entry;
\r
24 import org.apache.commons.jexl2.Expression;
\r
25 import org.apache.commons.jexl2.JexlContext;
\r
26 import org.apache.commons.jexl2.JexlEngine;
\r
27 import org.apache.commons.jexl2.MapContext;
\r
28 import org.slf4j.Logger;
\r
29 import org.slf4j.LoggerFactory;
\r
32 * EL式の解析、解析で使用するパラメータオブジェクトの保持を行う。<br>
\r
36 * @author noboru saito
\r
39 public class ELManager {
\r
41 private static final Logger log = LoggerFactory.getLogger(ELManager.class);
\r
43 private final JexlEngine elEngine = new JexlEngine();
\r
44 private final JexlContext elContext = new MapContext();
\r
49 public ELManager() {}
\r
54 * @param parameter テンプレートに挿入するデータ
\r
56 public ELManager(Map<String, Object> parameter) {
\r
57 setParameter(parameter);
\r
61 * EL式解析で使用するオブジェクトをパラメータとしてセット
\r
63 * @param parameter テンプレートに挿入するデータ
\r
65 public void setParameter(Map<String, Object> parameter) {
\r
66 log.trace("setParameter start");
\r
68 if(parameter != null) {
\r
69 if(parameter.entrySet().size() == 0) {
\r
70 log.debug("parameter is no entry");
\r
73 for(Entry<String, Object> p : parameter.entrySet()) {
\r
74 elContext.set(p.getKey(), p.getValue());
\r
75 log.debug("parameter set: [{}]: {} {}", p.getKey(), p.getValue() == null ? "null" : p.getValue().getClass().getName(), p.getValue() == null ? "" : p.getValue().toString());
\r
80 log.debug("parameter is null");
\r
83 log.trace("setParameter end");
\r
89 * @param expression EL式
\r
92 public Object evaluate(String expression) {
\r
93 log.trace("evaluate start");
\r
95 Object object = null;
\r
97 if(expression == null) {
\r
98 log.debug("expression is null");
\r
101 log.debug("expression: {}", expression);
\r
104 expr = elEngine.createExpression(expression);
\r
105 object = expr.evaluate(elContext);
\r
107 catch(Exception e) {
\r
108 log.error("evaluate error: {}", e.getLocalizedMessage(), e);
\r
112 if(object == null) {
\r
113 log.debug("evaluate result is null");
\r
116 log.debug("evaluate result: {}", object.toString());
\r
119 log.trace("evaluate end");
\r