Browse Source

Merge pull request #2 in SL/plugin-iframe from ~YAOH.WU/plugin-iframe:master to master

* commit 'ed9018ea16c124ee69d8e41e22d9870858d40116':
  无JIRA任务,网页框插件中文乱码
  REPORT-11699 网页框插件10 url编码适配
master
richie 7 years ago
parent
commit
da907ecf31
  1. 81
      src/main/java/com/fr/plugin/form/widget/URLUtils.java
  2. 24
      src/main/java/com/fr/plugin/form/widget/core/TemplateSource.java
  3. 26
      src/main/resources/com/fr/plugin/form/widget/web/widget.rh.iframe.js

81
src/main/java/com/fr/plugin/form/widget/URLUtils.java

@ -0,0 +1,81 @@
package com.fr.plugin.form.widget;
import com.fr.third.org.apache.http.NameValuePair;
import com.fr.third.org.apache.http.message.BasicNameValuePair;
import com.fr.third.org.apache.http.message.ParserCursor;
import com.fr.third.org.apache.http.message.TokenParser;
import com.fr.third.org.apache.http.util.Args;
import com.fr.third.org.apache.http.util.CharArrayBuffer;
import java.util.ArrayList;
import java.util.BitSet;
import java.util.Collections;
import java.util.List;
/**
* 参照{@link com.fr.third.org.apache.http.client.utils.URLEncodedUtils}
* 的代码但是不进行解码操作传入的 url 可以是未编码的
*
* @see com.fr.third.org.apache.http.client.utils.URLEncodedUtils
*/
@SuppressWarnings("ALL")
public class URLUtils {
public static List<NameValuePair> parse(String s) {
if (s == null) {
return Collections.emptyList();
} else {
CharArrayBuffer buffer = new CharArrayBuffer(s.length());
buffer.append(s);
return parse(buffer, '&', ';');
}
}
public static List<NameValuePair> parse(String s, char... separators) {
if (s == null) {
return Collections.emptyList();
} else {
CharArrayBuffer buffer = new CharArrayBuffer(s.length());
buffer.append(s);
return parse(buffer, separators);
}
}
public static List<NameValuePair> parse(CharArrayBuffer buf, char... separators) {
Args.notNull(buf, "Char array buffer");
TokenParser tokenParser = TokenParser.INSTANCE;
BitSet delimSet = new BitSet();
int var6 = separators.length;
for (int var7 = 0; var7 < var6; ++var7) {
char separator = separators[var7];
delimSet.set(separator);
}
ParserCursor cursor = new ParserCursor(0, buf.length());
ArrayList<NameValuePair> list = new ArrayList<NameValuePair>();
while (!cursor.atEnd()) {
delimSet.set(61);
String name = tokenParser.parseToken(buf, cursor, delimSet);
String value = null;
if (!cursor.atEnd()) {
int delim = buf.charAt(cursor.getPos());
cursor.updatePos(cursor.getPos() + 1);
if (delim == '=') {
delimSet.clear(61);
value = tokenParser.parseValue(buf, cursor, delimSet);
if (!cursor.atEnd()) {
cursor.updatePos(cursor.getPos() + 1);
}
}
}
if (!name.isEmpty()) {
list.add(new BasicNameValuePair(name, value));
}
}
return list;
}
}

24
src/main/java/com/fr/plugin/form/widget/core/TemplateSource.java

@ -9,20 +9,20 @@ import com.fr.general.FArray;
import com.fr.json.JSONArray; import com.fr.json.JSONArray;
import com.fr.json.JSONException; import com.fr.json.JSONException;
import com.fr.json.JSONObject; import com.fr.json.JSONObject;
import com.fr.plugin.form.widget.URLUtils;
import com.fr.script.Calculator; import com.fr.script.Calculator;
import com.fr.stable.CodeUtils; import com.fr.stable.CodeUtils;
import com.fr.stable.ParameterProvider; import com.fr.stable.ParameterProvider;
import com.fr.stable.ProductConstants; import com.fr.stable.ProductConstants;
import com.fr.stable.StringUtils;
import com.fr.stable.UtilEvalError; import com.fr.stable.UtilEvalError;
import com.fr.stable.js.WidgetName; import com.fr.stable.js.WidgetName;
import com.fr.stable.script.CalculatorProvider; import com.fr.stable.script.CalculatorProvider;
import com.fr.stable.xml.XMLPrintWriter; import com.fr.stable.xml.XMLPrintWriter;
import com.fr.stable.xml.XMLableReader; import com.fr.stable.xml.XMLableReader;
import com.fr.third.org.apache.http.NameValuePair; import com.fr.third.org.apache.http.NameValuePair;
import com.fr.third.org.apache.http.client.utils.URLEncodedUtils;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import java.nio.charset.Charset;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
@ -55,10 +55,10 @@ public class TemplateSource extends RHIframeSource {
public String getCalculatedUrl(Calculator calculator, HttpServletRequest req) { public String getCalculatedUrl(Calculator calculator, HttpServletRequest req) {
try { try {
String realPath = TemplateUtils.render(path, calculator); String realPath = TemplateUtils.render(path, calculator);
List<NameValuePair> pairs = URLEncodedUtils.parse("__emb__=" + realPath, Charset.forName("utf-8")); List<NameValuePair> pairs = URLUtils.parse("__emb__=" + realPath);
List<NameValuePair> extraPairs = new ArrayList<NameValuePair>(); List<NameValuePair> extraPairs = new ArrayList<NameValuePair>();
for (NameValuePair pair : pairs) { for (NameValuePair pair : pairs) {
if (pair.getName().equals("__emb__")) { if ("__emb__".equals(pair.getName())) {
realPath = pair.getValue(); realPath = pair.getValue();
} else { } else {
extraPairs.add(pair); extraPairs.add(pair);
@ -73,7 +73,7 @@ public class TemplateSource extends RHIframeSource {
} }
} else if (realPath.contains(".frm")) { } else if (realPath.contains(".frm")) {
if (isNewerThan9()) { if (isNewerThan9()) {
return NetworkHelper.createServletURL(req) + "/view/form?viewlet=" + CodeUtils.encodeURIComponent(realPath) + createQueryString(extraPairs); return NetworkHelper.createServletURL(req) + "/view/form?viewlet=" + CodeUtils.encodeURIComponent(realPath) + createQueryString(extraPairs);
} }
return NetworkHelper.createServletURL(req) + "?formlet=" + CodeUtils.encodeURIComponent(realPath) + createQueryString(extraPairs); return NetworkHelper.createServletURL(req) + "?formlet=" + CodeUtils.encodeURIComponent(realPath) + createQueryString(extraPairs);
} }
@ -89,12 +89,20 @@ public class TemplateSource extends RHIframeSource {
private String createQueryString(List<NameValuePair> pairs) { private String createQueryString(List<NameValuePair> pairs) {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
for (int i = 0, len = pairs.size(); i < len; i ++) { for (int i = 0, len = pairs.size(); i < len; i++) {
NameValuePair pair = pairs.get(i); NameValuePair pair = pairs.get(i);
sb.append("&"); sb.append("&");
sb.append(CodeUtils.encodeURIComponent(pair.getName())); String key = pair.getName();
if (key == null) {
key = StringUtils.EMPTY;
}
sb.append(CodeUtils.encodeURIComponent(key));
sb.append("="); sb.append("=");
sb.append(CodeUtils.encodeURIComponent(pair.getValue())); String value = pair.getValue();
if (value == null) {
value = StringUtils.EMPTY;
}
sb.append(CodeUtils.encodeURIComponent(value));
} }
return sb.toString(); return sb.toString();
} }

26
src/main/resources/com/fr/plugin/form/widget/web/widget.rh.iframe.js

@ -2,7 +2,7 @@
* @class FR.RHIframe * @class FR.RHIframe
* @extends FR.BaseEditor * @extends FR.BaseEditor
*/ */
(function($){ (function ($) {
FR.RHIframe = FR.extend(FR.BaseEditor, { FR.RHIframe = FR.extend(FR.BaseEditor, {
@ -31,8 +31,8 @@
o.iframeName = o.widgetName || this.createNoRepeatName(); o.iframeName = o.widgetName || this.createNoRepeatName();
this.$iframe = $("<iframe name=" + o.iframeName + " id=" this.$iframe = $("<iframe name=" + o.iframeName + " id="
+ o.iframeName + ">").addClass(o.baseClass).attr({ + o.iframeName + ">").addClass(o.baseClass).attr({
width : '100%', width: '100%',
height : '100%', height: '100%',
frameborder: 0, frameborder: 0,
scrolling: !o.showOverFlowX && !o.showOverFlowY scrolling: !o.showOverFlowX && !o.showOverFlowY
? 'no' ? 'no'
@ -55,6 +55,7 @@
setOverflow($(doc.documentElement)); setOverflow($(doc.documentElement));
setOverflow($(doc.body)); setOverflow($(doc.body));
} }
function setOverflow(cc) { function setOverflow(cc) {
if (!o.showOverFlowX) { if (!o.showOverFlowX) {
cc.css('overflow-x', 'hidden'); cc.css('overflow-x', 'hidden');
@ -68,7 +69,7 @@
console && console.log("error"); console && console.log("error");
} }
} }
} };
// IE里面需要设置rowspan为1才能正常显示....否则会跳过n行不显示,chrome应该是bug,一会儿好一会儿不好 // IE里面需要设置rowspan为1才能正常显示....否则会跳过n行不显示,chrome应该是bug,一会儿好一会儿不好
if ($.browser.msie && (this.$iframe.parent()).is("div") if ($.browser.msie && (this.$iframe.parent()).is("div")
@ -159,16 +160,15 @@
} }
// 模板 // 模板
if (this.options.sourceType == 'tpl') { if (this.options.sourceType == 'tpl') {
var cpParas = {};
$.each(paras, function (pName, pValue) { $.each(paras, function (pName, pValue) {
if (FR.isArray(pValue)) { //后端没有encode,那就前端做
paras[pName] = pValue; cpParas[encodeURIComponent(pName)] = encodeURIComponent(pValue);
} else {
paras[pName] = encodeURIComponent(pValue);
}
}); });
src += "__parameters__=" + FR.cjkEncode(FR.jsonEncode(paras)); src += "__parameters__=" + encodeURIComponent(FR.jsonEncode(cpParas));
} else { } else {
$.each(paras, function (name, value) { $.each(paras, function (name, value) {
// web链接的参数不进行额外处理。
if (typeof(name) === 'string') { if (typeof(name) === 'string') {
src += name + "=" + value + "&"; src += name + "=" + value + "&";
} }
@ -183,7 +183,7 @@
*/ */
_addDisableMask: function () { _addDisableMask: function () {
this.mask = $('<span/>').css({ this.mask = $('<span/>').css({
backgroundColor : '#66B9FF', backgroundColor: '#66B9FF',
height: this.options.height, height: this.options.height,
width: this.options.width, width: this.options.width,
left: this.element.offset().left left: this.element.offset().left
@ -194,7 +194,7 @@
* 设置网页框控件的地址并重新加载页面(保留原参数) * 设置网页框控件的地址并重新加载页面(保留原参数)
* @param {String} v 新的地址 * @param {String} v 新的地址
*/ */
setValue : function(v) { setValue: function (v) {
this.options.src = v; this.options.src = v;
this._loadIframeByGet(); this._loadIframeByGet();
}, },
@ -225,7 +225,7 @@
* 加载指定的url * 加载指定的url
* @param url 网页地址 * @param url 网页地址
*/ */
loadUrl : function(url) { loadUrl: function (url) {
this.$iframe.attr("src", url); this.$iframe.attr("src", url);
}, },

Loading…
Cancel
Save