|
@@ -1,10 +1,13 @@
|
|
package cn.com.qmth.examcloud.support.handler.richText;
|
|
package cn.com.qmth.examcloud.support.handler.richText;
|
|
|
|
|
|
|
|
+import cn.com.qmth.examcloud.commons.util.JsonUtil;
|
|
import cn.com.qmth.examcloud.commons.util.RegExpUtil;
|
|
import cn.com.qmth.examcloud.commons.util.RegExpUtil;
|
|
|
|
+import cn.com.qmth.examcloud.support.enums.BlockType;
|
|
import cn.com.qmth.examcloud.support.handler.richText.bean.BlockBean;
|
|
import cn.com.qmth.examcloud.support.handler.richText.bean.BlockBean;
|
|
import cn.com.qmth.examcloud.support.handler.richText.bean.SectionBean;
|
|
import cn.com.qmth.examcloud.support.handler.richText.bean.SectionBean;
|
|
import cn.com.qmth.examcloud.support.handler.richText.bean.SectionCollectionBean;
|
|
import cn.com.qmth.examcloud.support.handler.richText.bean.SectionCollectionBean;
|
|
import com.mysql.cj.util.StringUtils;
|
|
import com.mysql.cj.util.StringUtils;
|
|
|
|
+import org.apache.commons.lang.StringEscapeUtils;
|
|
import org.apache.commons.logging.Log;
|
|
import org.apache.commons.logging.Log;
|
|
import org.apache.commons.logging.LogFactory;
|
|
import org.apache.commons.logging.LogFactory;
|
|
import org.jsoup.Jsoup;
|
|
import org.jsoup.Jsoup;
|
|
@@ -45,34 +48,31 @@ public class ImageTextHandler implements RichTextHandler {
|
|
//图片文本部分
|
|
//图片文本部分
|
|
String txtStr = getImgTxt(richText);
|
|
String txtStr = getImgTxt(richText);
|
|
if (!StringUtils.isNullOrEmpty(txtStr)) {
|
|
if (!StringUtils.isNullOrEmpty(txtStr)) {
|
|
- BlockBean blockBean = new BlockBean();
|
|
|
|
- blockBean.setType("text");
|
|
|
|
- blockBean.setValue(txtStr);
|
|
|
|
|
|
+ BlockBean blockBean = new BlockBean(BlockType.text.name());
|
|
|
|
+ blockBean.setValue(StringEscapeUtils.unescapeHtml(txtStr));
|
|
blockList.add(blockBean);
|
|
blockList.add(blockBean);
|
|
}
|
|
}
|
|
|
|
|
|
//图片部分
|
|
//图片部分
|
|
if (validateImgAnswer(richText)) {
|
|
if (validateImgAnswer(richText)) {
|
|
String imgSrc = getImgSrc(richText);
|
|
String imgSrc = getImgSrc(richText);
|
|
- if (imgSrc.indexOf("|") > -1) {
|
|
|
|
- String[] imgAnswers = imgSrc.split("\\|");
|
|
|
|
-
|
|
|
|
- for (int i = 0; i < imgAnswers.length; i++) {
|
|
|
|
- BlockBean blockBean = new BlockBean();
|
|
|
|
- blockBean.setType("text");
|
|
|
|
- blockBean.setValue(getPureUrl(imgAnswers[i]));
|
|
|
|
-
|
|
|
|
- //又拍云图片的宽*高
|
|
|
|
- String imgWH = RegExpUtil.find(imgAnswers[i], "(\\d+)x(\\d+)");
|
|
|
|
- if (!StringUtils.isNullOrEmpty(imgWH)) {
|
|
|
|
- Map<String, Object> paramMap = new HashMap<>();
|
|
|
|
- paramMap.put("width", Integer.valueOf(imgWH.split("x")[0]));
|
|
|
|
- paramMap.put("height", Integer.valueOf(imgWH.split("x")[1]));
|
|
|
|
- blockBean.setParam(paramMap);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- blockList.add(blockBean);
|
|
|
|
|
|
+ String[] imgAnswers = imgSrc.split("\\|");
|
|
|
|
+
|
|
|
|
+ for (int i = 0; i < imgAnswers.length; i++) {
|
|
|
|
+ BlockBean blockBean = new BlockBean(BlockType.image.name());
|
|
|
|
+ blockBean.setValue(getPureUrl(imgAnswers[i]));
|
|
|
|
+
|
|
|
|
+ //又拍云图片的宽*高
|
|
|
|
+ String width=RegExpUtil.find(imgAnswers[i], "w_(\\d+)");
|
|
|
|
+ String height=RegExpUtil.find(imgAnswers[i], "h_(\\d+)");
|
|
|
|
+ Map<String, Object> paramMap = new HashMap<>();
|
|
|
|
+ if (!StringUtils.isNullOrEmpty(width) && !StringUtils.isNullOrEmpty(height)) {
|
|
|
|
+ paramMap.put("width", Integer.valueOf(width.replaceAll("w_","")));
|
|
|
|
+ paramMap.put("height", Integer.valueOf(height.replaceAll("h_","")));
|
|
|
|
+ blockBean.setParam(paramMap);
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ blockList.add(blockBean);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -157,4 +157,16 @@ public class ImageTextHandler implements RichTextHandler {
|
|
String regExp = "(ftp|https?)\\:\\/\\/([\\w\\_\\-]+)\\.([\\w\\-]+[\\.]?)*[\\w]+\\.[a-zA-Z]{2,10}(.*)\\.(png|jpg|gif|jpeg)";
|
|
String regExp = "(ftp|https?)\\:\\/\\/([\\w\\_\\-]+)\\.([\\w\\-]+[\\.]?)*[\\w]+\\.[a-zA-Z]{2,10}(.*)\\.(png|jpg|gif|jpeg)";
|
|
return RegExpUtil.find(imgUrl, regExp);
|
|
return RegExpUtil.find(imgUrl, regExp);
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+// public static void main(String[] args) {
|
|
|
|
+//// String testStr = "1111111<div>222<div></div>21000<sup>2</sup></div><div>3333399<sub>3</sub>5555555</div><div><br></div><div>444444</div>";
|
|
|
|
+// String testStr = "{\"mainNumber\":2,\"order\":23,\"questionId\":\"5ebdf1cbcad4db1aee85e907\",\"studentAnswer\":\"发发呆<div>ななぅぅぉてふっふてふ</div><div class='photo-answers-block'><a href='https://ecs-test-static.qmth.com.cn/oe-answer-file/21083/19288/23/21083_19288_23_15895106360336244.jpeg' target='_blank' ><img class='photo-answer' src='https://ecs-test-static.qmth.com.cn/oe-answer-file/21083/19288/23/21083_19288_23_15895106360336244.jpeg?x-oss-process=image/resize,m_lfit,h_200,w_200' /></a></div>\",\"answerType\":null,\"answer\":\"<p><span> えいが</span></p>\",\"body\":\"<p>映画</p>\",\"parentBody\":null,\"questionType\":\"ESSAY\"}";
|
|
|
|
+//
|
|
|
|
+// ImageTextHandler o = new ImageTextHandler();
|
|
|
|
+//
|
|
|
|
+//
|
|
|
|
+// SectionCollectionBean sfds = o.handle(testStr);
|
|
|
|
+//
|
|
|
|
+// System.out.println(JsonUtil.toJson(sfds));
|
|
|
|
+// }
|
|
}
|
|
}
|