|
|
@ -8,9 +8,10 @@ import com.fr.json.JSONObject; |
|
|
|
import com.fr.log.FineLoggerFactory; |
|
|
|
import com.fr.log.FineLoggerFactory; |
|
|
|
import com.fr.stable.StringUtils; |
|
|
|
import com.fr.stable.StringUtils; |
|
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
|
|
|
import java.util.Arrays; |
|
|
|
import java.util.Arrays; |
|
|
|
|
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.List; |
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
import java.util.Map; |
|
|
|
import java.util.regex.Matcher; |
|
|
|
import java.util.regex.Matcher; |
|
|
|
import java.util.regex.Pattern; |
|
|
|
import java.util.regex.Pattern; |
|
|
|
|
|
|
|
|
|
|
@ -169,7 +170,7 @@ public class TemplateResourceDetail { |
|
|
|
JSONObject resource = embedResources.getJSONObject(i); |
|
|
|
JSONObject resource = embedResources.getJSONObject(i); |
|
|
|
if (resourceId.equals(resource.getString(ID))) { |
|
|
|
if (resourceId.equals(resource.getString(ID))) { |
|
|
|
detail.setInfo(resource.getString(INFO)); |
|
|
|
detail.setInfo(resource.getString(INFO)); |
|
|
|
detail.setHtmlText(resource.getString(DETAIL_INFO)); |
|
|
|
detail.setHtmlText(reformat(resource.getString(DETAIL_INFO))); |
|
|
|
detail.setVendor(resource.getString(VENDOR)); |
|
|
|
detail.setVendor(resource.getString(VENDOR)); |
|
|
|
detail.setPrice(resource.getDouble(PRICE)); |
|
|
|
detail.setPrice(resource.getDouble(PRICE)); |
|
|
|
detail.setResourceUrl(resource.getString(URL)); |
|
|
|
detail.setResourceUrl(resource.getString(URL)); |
|
|
@ -191,7 +192,7 @@ public class TemplateResourceDetail { |
|
|
|
// 1请求详细信息
|
|
|
|
// 1请求详细信息
|
|
|
|
JSONObject info = helper.getTemplateInfoById(resourceId); |
|
|
|
JSONObject info = helper.getTemplateInfoById(resourceId); |
|
|
|
detail.setInfo(info.getString(INFO)); |
|
|
|
detail.setInfo(info.getString(INFO)); |
|
|
|
detail.setHtmlText(info.getString(DETAIL_INFO)); |
|
|
|
detail.setHtmlText(reformat(info.getString(DETAIL_INFO))); |
|
|
|
detail.setVendor(info.getString(VENDOR)); |
|
|
|
detail.setVendor(info.getString(VENDOR)); |
|
|
|
detail.setTagsId(info.getString(TAGS_ID).split(",")); |
|
|
|
detail.setTagsId(info.getString(TAGS_ID).split(",")); |
|
|
|
detail.setPrice(info.getDouble(PRICE)); |
|
|
|
detail.setPrice(info.getDouble(PRICE)); |
|
|
@ -214,25 +215,36 @@ public class TemplateResourceDetail { |
|
|
|
return null; |
|
|
|
return null; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static final String A_TAG_FORMAT = "<a href=%s>%s</a>"; |
|
|
|
|
|
|
|
static final String HTML_TAG_REGX="<[^>]+>"; |
|
|
|
|
|
|
|
static final Pattern A_TAG_PATTERN = Pattern.compile("<a[^>]*href=(\\\"([^\\\"]*)\\\"|\\'([^\\']*)\\'|([^\\\\s>]*))[^>]*>(.*?)</a>"); |
|
|
|
|
|
|
|
static final Pattern HTML_TAG_PATTERN = Pattern.compile(HTML_TAG_REGX); |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 这里做下数据转换 |
|
|
|
* 数据格式转换 |
|
|
|
* 原始数据是html标签写的,如下 |
|
|
|
* 原始数据的格式不统一,纯文本、html都有; 统一转为纯文本,如果有a标签则保留 |
|
|
|
* "<ol style="list-style-type: decimal;" class=" list-paddingleft-2"><li><p>该模板需用10.0及以上版本设计器预览<br/></p></li><li><p>该模板为库存场景解决方案的部分内容,全部内容可下载<a href="https://market.fanruan.com/template/20000733" target="_self">库存场景解决方案</a>查看</p></li><li><p>为保障模板预览效果,建议安装<a href="https://help.fanruan.com/finereport10.0/doc-view-3665.html" target="_self">新自适应插件</a>(FR11.0版本插件已内置,无需手动安装),有使用需求或疑问,请联系帆软技术支持咨询<br/></p></li></ol>",
|
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* 转换的后的数据 是原始数据中所有<p></p>标签内的(包括标签)的字符串(List<String>),如上字符串会转为如下 |
|
|
|
|
|
|
|
* List [<p>该模板需用10.0及以上版本设计器预览<br/></p>, |
|
|
|
|
|
|
|
* <p>该模板为库存场景解决方案的部分内容,全部内容可下载<a href="https://market.fanruan.com/template/20000733" target="_self">库存场景解决方案</a>查看</p>, |
|
|
|
|
|
|
|
* <p>为保障模板预览效果,建议安装<a href="https://help.fanruan.com/finereport10.0/doc-view-3665.html" target="_self">新自适应插件</a>(FR11.0版本插件已内置,无需手动安装),有使用需求或疑问,请联系帆软技术支持咨询<br/></p> |
|
|
|
|
|
|
|
* ] |
|
|
|
|
|
|
|
* */ |
|
|
|
* */ |
|
|
|
static final Pattern htmlPattern = Pattern.compile("<p>(.+?)</p>"); |
|
|
|
static String reformat(String htmlDetailInfo) { |
|
|
|
static List<String> parseDetailInfo(String htmlDetailInfo) { |
|
|
|
String result = HTML_TAG_PATTERN.matcher(htmlDetailInfo).replaceAll(""); |
|
|
|
List<String> infos = new ArrayList<>(); |
|
|
|
Map<String, String> aMap = getLink(htmlDetailInfo); |
|
|
|
Matcher matcher = htmlPattern.matcher(htmlDetailInfo); |
|
|
|
for (Map.Entry<String, String> entry : aMap.entrySet()) { |
|
|
|
|
|
|
|
String aTag = String.format(A_TAG_FORMAT, entry.getValue(), entry.getKey()); |
|
|
|
|
|
|
|
result = result.replace(entry.getKey(), aTag); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return result; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 读取dom中的a标签,转换为map |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
static Map<String, String> getLink(String html) { |
|
|
|
|
|
|
|
Map<String, String> map = new HashMap<>(); |
|
|
|
|
|
|
|
Matcher matcher = A_TAG_PATTERN.matcher(html); |
|
|
|
while (matcher.find()) { |
|
|
|
while (matcher.find()) { |
|
|
|
infos.add(matcher.group()); |
|
|
|
map.put(matcher.group(5), matcher.group(1)); |
|
|
|
} |
|
|
|
} |
|
|
|
return infos; |
|
|
|
return map; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|