|
|
|
@ -1,25 +1,23 @@
|
|
|
|
|
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.fr.base.BaseFormula; |
|
|
|
|
import com.fr.stable.ParameterProvider; |
|
|
|
|
import com.fanruan.api.cal.ParameterKit; |
|
|
|
|
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.fanruan.api.log.LogKit; |
|
|
|
|
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.fr.stable.ParameterProvider; |
|
|
|
|
import com.fr.stable.StableUtils; |
|
|
|
|
import com.fr.stable.UtilEvalError; |
|
|
|
|
import com.fr.stable.js.WidgetName; |
|
|
|
|
import com.fanruan.api.util.CodeKit; |
|
|
|
|
import com.fanruan.api.cal.FormulaKit; |
|
|
|
|
import com.fanruan.api.err.UtilEvalError; |
|
|
|
|
import com.fr.stable.Nameable; |
|
|
|
|
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,17 +49,17 @@ 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) { |
|
|
|
|
FRLogger.getLogger().error(u.getMessage(), u); |
|
|
|
|
result = GeneralKit.objectToString(FormulaKit.newFormula(url)); |
|
|
|
|
} catch (Exception u) { |
|
|
|
|
LogKit.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); |
|
|
|
|
LogKit.error(e.getMessage(), e); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -73,9 +71,9 @@ public class URLSource extends RHIframeSource {
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public String[] dependence(CalculatorProvider ca) { |
|
|
|
|
Parameter[] parameters = ParameterHelper.analyze4Parameters(url, false); |
|
|
|
|
ParameterProvider[] parameters = ParameterKit.analyze4Parameters(url, false); |
|
|
|
|
List<String> collections = new ArrayList<String>(); |
|
|
|
|
for (Parameter parameter : parameters) { |
|
|
|
|
for (ParameterProvider parameter : parameters) { |
|
|
|
|
collections.addAll(Arrays.asList(parameter.dependence(ca))); |
|
|
|
|
} |
|
|
|
|
return collections.toArray(new String[collections.size()]); |
|
|
|
@ -85,19 +83,21 @@ public class URLSource extends RHIframeSource {
|
|
|
|
|
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(); |
|
|
|
|
if (obj instanceof BaseFormula) { |
|
|
|
|
try { |
|
|
|
|
String content = ((BaseFormula) obj).getContent(); |
|
|
|
|
obj = c.evalValue(content); |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
} |
|
|
|
|
JSONObject jo = JSONObject.create(); |
|
|
|
|
if (obj instanceof String) { |
|
|
|
|
obj = CodeUtils.cjkEncode((String) obj); |
|
|
|
|
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 if (obj instanceof Nameable) { |
|
|
|
|
jo.put("widgetName", ((Nameable) obj).getName()); |
|
|
|
|
} else { |
|
|
|
|
// 还可以是数字啊什么的
|
|
|
|
|
jo.put(parameters[i].getName(), obj); |
|
|
|
@ -106,7 +106,7 @@ public class URLSource extends RHIframeSource {
|
|
|
|
|
ja.put(jo); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
@Override |
|
|
|
|
public String getSourceType() { |
|
|
|
|
return "url"; |
|
|
|
|