|
|
|
@ -3,23 +3,22 @@ package com.fr.plugin.form.widget.core;
|
|
|
|
|
import com.fr.base.Formula; |
|
|
|
|
import com.fr.base.Parameter; |
|
|
|
|
import com.fr.base.ParameterHelper; |
|
|
|
|
import com.fr.base.TemplateUtils; |
|
|
|
|
import com.fanruan.api.util.RenderKit; |
|
|
|
|
import com.fr.general.FArray; |
|
|
|
|
import com.fr.general.FRLogger; |
|
|
|
|
import com.fr.general.GeneralUtils; |
|
|
|
|
import com.fr.general.Inter; |
|
|
|
|
import com.fr.json.JSONArray; |
|
|
|
|
import com.fr.json.JSONException; |
|
|
|
|
import com.fanruan.api.err.JSONException; |
|
|
|
|
import com.fr.json.JSONObject; |
|
|
|
|
import com.fr.script.Calculator; |
|
|
|
|
import com.fr.stable.CodeUtils; |
|
|
|
|
import com.fanruan.api.util.CodeKit; |
|
|
|
|
import com.fr.stable.ParameterProvider; |
|
|
|
|
import com.fr.stable.StableUtils; |
|
|
|
|
import com.fr.stable.UtilEvalError; |
|
|
|
|
import com.fanruan.api.cal.FormulaKit; |
|
|
|
|
import com.fanruan.api.err.UtilEvalError; |
|
|
|
|
import com.fr.stable.js.WidgetName; |
|
|
|
|
import com.fr.stable.script.CalculatorProvider; |
|
|
|
|
import com.fr.stable.xml.XMLPrintWriter; |
|
|
|
|
import com.fr.stable.xml.XMLableReader; |
|
|
|
|
import com.fanruan.api.util.GeneralKit; |
|
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest; |
|
|
|
|
import java.util.ArrayList; |
|
|
|
@ -51,15 +50,15 @@ public class URLSource extends RHIframeSource {
|
|
|
|
|
@Override |
|
|
|
|
public String getCalculatedUrl(Calculator calculator, HttpServletRequest req) { |
|
|
|
|
String result = null; |
|
|
|
|
if (StableUtils.canBeFormula(url)) { |
|
|
|
|
if (FormulaKit.checkFormulaContent(url)) { |
|
|
|
|
try { |
|
|
|
|
result = GeneralUtils.objectToString(calculator.eval(new Formula(url))); |
|
|
|
|
} catch (UtilEvalError u) { |
|
|
|
|
result = GeneralKit.objectToString(calculator.evalValue(new Formula(url))); |
|
|
|
|
} catch (Exception u) { |
|
|
|
|
FRLogger.getLogger().error(u.getMessage(), u); |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
try { |
|
|
|
|
result = TemplateUtils.render(url, calculator); |
|
|
|
|
result = RenderKit.render(url, calculator); |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
FRLogger.getLogger().error(e.getMessage(), e); |
|
|
|
|
} |
|
|
|
@ -82,31 +81,33 @@ public class URLSource extends RHIframeSource {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void mixCalculatedParameters(Calculator c, JSONArray ja, ParameterProvider[] parameters) throws JSONException, UtilEvalError { |
|
|
|
|
public void mixCalculatedParameters(Calculator c, JSONArray ja, ParameterProvider[] parameters) throws JSONException, UtilEvalError { |
|
|
|
|
for (int i = 0; i < (parameters == null ? 0 : parameters.length); i++) { |
|
|
|
|
Object obj = parameters[i].getValue(); |
|
|
|
|
if (obj instanceof Formula) { |
|
|
|
|
String content = ((Formula) obj).getContent(); |
|
|
|
|
obj = c.evalValue(content); |
|
|
|
|
try { |
|
|
|
|
String content = ((Formula) obj).getContent(); |
|
|
|
|
obj = c.evalValue(content); |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
} |
|
|
|
|
JSONObject jo = JSONObject.create(); |
|
|
|
|
if (obj instanceof String) { |
|
|
|
|
obj = CodeKit.passwordDecode((String) obj); |
|
|
|
|
jo.put(parameters[i].getName(), obj); |
|
|
|
|
} else if (obj instanceof FArray) { |
|
|
|
|
obj = ((FArray) obj).cjkEncode(); |
|
|
|
|
jo.put(parameters[i].getName(), obj); |
|
|
|
|
} else if (obj instanceof WidgetName) { |
|
|
|
|
jo.put("widgetName", ((WidgetName) obj).getName()); |
|
|
|
|
} else { |
|
|
|
|
// 还可以是数字啊什么的
|
|
|
|
|
jo.put(parameters[i].getName(), obj); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
ja.put(jo); |
|
|
|
|
} |
|
|
|
|
JSONObject jo = JSONObject.create(); |
|
|
|
|
if (obj instanceof String) { |
|
|
|
|
obj = CodeUtils.cjkEncode((String) obj); |
|
|
|
|
jo.put(parameters[i].getName(), obj); |
|
|
|
|
} else if (obj instanceof FArray) { |
|
|
|
|
obj = ((FArray) obj).cjkEncode(); |
|
|
|
|
jo.put(parameters[i].getName(), obj); |
|
|
|
|
} else if (obj instanceof WidgetName) { |
|
|
|
|
jo.put("widgetName", ((WidgetName) obj).getName()); |
|
|
|
|
} else { |
|
|
|
|
// 还可以是数字啊什么的
|
|
|
|
|
jo.put(parameters[i].getName(), obj); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
ja.put(jo); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public String getSourceType() { |
|
|
|
|
return "url"; |
|
|
|
|