|
@@ -1,19 +1,13 @@
|
|
package cn.com.qmth.examcloud.core.questions.service.temp;
|
|
package cn.com.qmth.examcloud.core.questions.service.temp;
|
|
|
|
|
|
-import java.io.File;
|
|
|
|
-import java.io.UnsupportedEncodingException;
|
|
|
|
-import java.math.BigDecimal;
|
|
|
|
-import java.util.ArrayList;
|
|
|
|
-import java.util.HashMap;
|
|
|
|
-import java.util.List;
|
|
|
|
-import java.util.Map;
|
|
|
|
-import java.util.UUID;
|
|
|
|
-import java.util.regex.Matcher;
|
|
|
|
-import java.util.regex.Pattern;
|
|
|
|
-
|
|
|
|
-import javax.xml.parsers.DocumentBuilder;
|
|
|
|
-import javax.xml.parsers.DocumentBuilderFactory;
|
|
|
|
-
|
|
|
|
|
|
+import cn.com.qmth.examcloud.core.questions.base.CommonUtils;
|
|
|
|
+import cn.com.qmth.examcloud.core.questions.base.enums.PaperStatus;
|
|
|
|
+import cn.com.qmth.examcloud.core.questions.base.enums.PaperType;
|
|
|
|
+import cn.com.qmth.examcloud.core.questions.base.question.enums.QuesStructType;
|
|
|
|
+import cn.com.qmth.examcloud.core.questions.base.word.DocxProcessUtil;
|
|
|
|
+import cn.com.qmth.examcloud.core.questions.dao.*;
|
|
|
|
+import cn.com.qmth.examcloud.core.questions.dao.entity.*;
|
|
|
|
+import cn.com.qmth.examcloud.core.questions.service.impl.CourseService;
|
|
import org.apache.commons.collections4.map.HashedMap;
|
|
import org.apache.commons.collections4.map.HashedMap;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.docx4j.openpackaging.packages.WordprocessingMLPackage;
|
|
import org.docx4j.openpackaging.packages.WordprocessingMLPackage;
|
|
@@ -24,68 +18,58 @@ import org.w3c.dom.NamedNodeMap;
|
|
import org.w3c.dom.Node;
|
|
import org.w3c.dom.Node;
|
|
import org.w3c.dom.NodeList;
|
|
import org.w3c.dom.NodeList;
|
|
|
|
|
|
-import cn.com.qmth.examcloud.core.questions.base.CommonUtils;
|
|
|
|
-import cn.com.qmth.examcloud.core.questions.base.enums.PaperStatus;
|
|
|
|
-import cn.com.qmth.examcloud.core.questions.base.enums.PaperType;
|
|
|
|
-import cn.com.qmth.examcloud.core.questions.base.question.enums.QuesStructType;
|
|
|
|
-import cn.com.qmth.examcloud.core.questions.base.word.DocxProcessUtil;
|
|
|
|
-import cn.com.qmth.examcloud.core.questions.dao.PaperDetailRepo;
|
|
|
|
-import cn.com.qmth.examcloud.core.questions.dao.PaperDetailUnitRepo;
|
|
|
|
-import cn.com.qmth.examcloud.core.questions.dao.PaperRepo;
|
|
|
|
-import cn.com.qmth.examcloud.core.questions.dao.QuesPkgPathRepo;
|
|
|
|
-import cn.com.qmth.examcloud.core.questions.dao.QuesRepo;
|
|
|
|
-import cn.com.qmth.examcloud.core.questions.dao.entity.Course;
|
|
|
|
-import cn.com.qmth.examcloud.core.questions.dao.entity.Paper;
|
|
|
|
-import cn.com.qmth.examcloud.core.questions.dao.entity.PaperDetail;
|
|
|
|
-import cn.com.qmth.examcloud.core.questions.dao.entity.PaperDetailUnit;
|
|
|
|
-import cn.com.qmth.examcloud.core.questions.dao.entity.QuesOption;
|
|
|
|
-import cn.com.qmth.examcloud.core.questions.dao.entity.Question;
|
|
|
|
-import cn.com.qmth.examcloud.core.questions.dao.entity.QuestionPkgPath;
|
|
|
|
-import cn.com.qmth.examcloud.core.questions.service.impl.CourseService;
|
|
|
|
|
|
+import javax.xml.parsers.DocumentBuilder;
|
|
|
|
+import javax.xml.parsers.DocumentBuilderFactory;
|
|
|
|
+import java.io.File;
|
|
|
|
+import java.io.UnsupportedEncodingException;
|
|
|
|
+import java.math.BigDecimal;
|
|
|
|
+import java.util.*;
|
|
|
|
+import java.util.regex.Matcher;
|
|
|
|
+import java.util.regex.Pattern;
|
|
|
|
|
|
@Component
|
|
@Component
|
|
public class CqdxService {
|
|
public class CqdxService {
|
|
|
|
|
|
- @Autowired
|
|
|
|
- CourseService courseService;
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ CourseService courseService;
|
|
|
|
|
|
- public void test() {
|
|
|
|
|
|
+ public void test() {
|
|
|
|
|
|
- System.out.println("wwh");
|
|
|
|
- }
|
|
|
|
|
|
+ System.out.println("wwh");
|
|
|
|
+ }
|
|
|
|
|
|
- @Autowired
|
|
|
|
- private QuesRepo quesRepo;
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ private QuesRepo quesRepo;
|
|
|
|
|
|
- @Autowired
|
|
|
|
- private PaperRepo paperRepo;
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ private PaperRepo paperRepo;
|
|
|
|
|
|
- @Autowired
|
|
|
|
- private PaperDetailRepo paperDetailRepo;
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ private PaperDetailRepo paperDetailRepo;
|
|
|
|
|
|
- @Autowired
|
|
|
|
- private PaperDetailUnitRepo paperDetailUnitRepo;
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ private PaperDetailUnitRepo paperDetailUnitRepo;
|
|
|
|
|
|
- @Autowired
|
|
|
|
- private QuesPkgPathRepo quesPkgPathRepo;
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ private QuesPkgPathRepo quesPkgPathRepo;
|
|
|
|
|
|
- public void bulidPaper() throws Exception {
|
|
|
|
- // 获取所有xml的路径
|
|
|
|
- List<String> files = filePath();
|
|
|
|
- int i = 1;
|
|
|
|
- System.out.println("总文件个数:"+files.size());
|
|
|
|
- for (String file : files) {
|
|
|
|
- Map<Object, Object> paperInfoMap = readXml(file);
|
|
|
|
- // 查询课程
|
|
|
|
- Course course = courseService.getCourse(1407l, paperInfoMap.get("courseCode").toString());
|
|
|
|
- // 初始化试卷
|
|
|
|
- Paper paper = initPaper(paperInfoMap, course);
|
|
|
|
- // 大题集合
|
|
|
|
- List<PaperDetail> paperDetails = initPaperDetails(paperInfoMap,paper);
|
|
|
|
- // 试题---资源 对应关系
|
|
|
|
- Map<Question, QuestionPkgPath> map2 = new HashMap<Question, QuestionPkgPath>();
|
|
|
|
- // 定义小题集合
|
|
|
|
- List<PaperDetailUnit> paperDetailUnits = initpaperDetailUnits(paper, paperDetails, map2, paperInfoMap, course);
|
|
|
|
|
|
+ public void bulidPaper() throws Exception {
|
|
|
|
+ // 获取所有xml的路径
|
|
|
|
+ List<String> files = filePath();
|
|
|
|
+ int i = 1;
|
|
|
|
+ System.out.println("总文件个数:" + files.size());
|
|
|
|
+ for (String file : files) {
|
|
|
|
+ Map<Object, Object> paperInfoMap = readXml(file);
|
|
|
|
+ // 查询课程
|
|
|
|
+ Course course = courseService.getCourse(1407l, paperInfoMap.get("courseCode").toString());
|
|
|
|
+ // 初始化试卷
|
|
|
|
+ Paper paper = initPaper(paperInfoMap, course);
|
|
|
|
+ // 大题集合
|
|
|
|
+ List<PaperDetail> paperDetails = initPaperDetails(paperInfoMap, paper);
|
|
|
|
+ // 试题---资源 对应关系
|
|
|
|
+ Map<Question, QuestionPkgPath> map2 = new HashMap<Question, QuestionPkgPath>();
|
|
|
|
+ // 定义小题集合
|
|
|
|
+ List<PaperDetailUnit> paperDetailUnits = initpaperDetailUnits(paper, paperDetails, map2, paperInfoMap, course);
|
|
/*List<PaperDetailUnit> paperDetailUnits = new ArrayList<PaperDetailUnit>();
|
|
/*List<PaperDetailUnit> paperDetailUnits = new ArrayList<PaperDetailUnit>();
|
|
try {
|
|
try {
|
|
paperDetailUnits = initpaperDetailUnits(paper, paperDetails, map2, paperInfoMap, course);
|
|
paperDetailUnits = initpaperDetailUnits(paper, paperDetails, map2, paperInfoMap, course);
|
|
@@ -97,535 +81,535 @@ public class CqdxService {
|
|
System.out.println("有问题的xml:"+file);
|
|
System.out.println("有问题的xml:"+file);
|
|
continue;
|
|
continue;
|
|
}*/
|
|
}*/
|
|
- // 保存试题资源
|
|
|
|
- quesPkgPathRepo.save(map2.values());
|
|
|
|
- for (Map.Entry<Question, QuestionPkgPath> entry : map2.entrySet()) {
|
|
|
|
- entry.getKey().setQuesPkgPathId(entry.getValue().getId());
|
|
|
|
- }
|
|
|
|
- quesRepo.save(map2.keySet());
|
|
|
|
- paperRepo.save(paper);
|
|
|
|
- paperDetailRepo.save(paperDetails);
|
|
|
|
- paperDetailUnitRepo.save(paperDetailUnits);
|
|
|
|
- System.out.println("第"+i+"个xml文件已经处理完,文件名为:"+file);
|
|
|
|
- i++;
|
|
|
|
- }
|
|
|
|
- System.out.println("保存成功...");
|
|
|
|
- }
|
|
|
|
|
|
+ // 保存试题资源
|
|
|
|
+ quesPkgPathRepo.save(map2.values());
|
|
|
|
+ for (Map.Entry<Question, QuestionPkgPath> entry : map2.entrySet()) {
|
|
|
|
+ entry.getKey().setQuesPkgPathId(entry.getValue().getId());
|
|
|
|
+ }
|
|
|
|
+ quesRepo.save(map2.keySet());
|
|
|
|
+ paperRepo.save(paper);
|
|
|
|
+ paperDetailRepo.save(paperDetails);
|
|
|
|
+ paperDetailUnitRepo.save(paperDetailUnits);
|
|
|
|
+ System.out.println("第" + i + "个xml文件已经处理完,文件名为:" + file);
|
|
|
|
+ i++;
|
|
|
|
+ }
|
|
|
|
+ System.out.println("保存成功...");
|
|
|
|
+ }
|
|
|
|
|
|
- // 初始化试卷
|
|
|
|
- private Paper initPaper(Map<Object, Object> paperInfoMap, Course course) {
|
|
|
|
- Paper paper = new Paper();
|
|
|
|
- paper.setName((String) paperInfoMap.get("name"));
|
|
|
|
- paper.setTitle((String) paperInfoMap.get("name"));
|
|
|
|
- paper.setPaperType(PaperType.IMPORT);
|
|
|
|
- paper.setPaperStatus(PaperStatus.DRAFT);
|
|
|
|
- paper.setOrgId(course.getOrgId());
|
|
|
|
- paper.setCreator("wei");
|
|
|
|
- paper.setTotalScore(Double.valueOf((String) paperInfoMap
|
|
|
|
- .get("totalScore")));
|
|
|
|
- paper.setCourse(course);
|
|
|
|
- paper.setCourseName(course.getName());
|
|
|
|
- paper.setCourseNo(course.getCode());
|
|
|
|
- paper.setCreateTime(CommonUtils.getCurDateTime());
|
|
|
|
- paper.setPaperDetailCount(Integer.valueOf((String) paperInfoMap
|
|
|
|
- .get("detailCount")));
|
|
|
|
- paper.setUnitCount(Integer.valueOf((String) paperInfoMap
|
|
|
|
- .get("unitCount")));
|
|
|
|
- paper.setDifficultyDegree(0.5);
|
|
|
|
- return paper;
|
|
|
|
- }
|
|
|
|
|
|
+ // 初始化试卷
|
|
|
|
+ private Paper initPaper(Map<Object, Object> paperInfoMap, Course course) {
|
|
|
|
+ Paper paper = new Paper();
|
|
|
|
+ paper.setName((String) paperInfoMap.get("name"));
|
|
|
|
+ paper.setTitle((String) paperInfoMap.get("name"));
|
|
|
|
+ paper.setPaperType(PaperType.IMPORT);
|
|
|
|
+ paper.setPaperStatus(PaperStatus.DRAFT);
|
|
|
|
+ paper.setOrgId(course.getOrgId());
|
|
|
|
+ paper.setCreator("feng");
|
|
|
|
+ paper.setTotalScore(Double.valueOf((String) paperInfoMap
|
|
|
|
+ .get("totalScore")));
|
|
|
|
+ paper.setCourse(course);
|
|
|
|
+ paper.setCourseName(course.getName());
|
|
|
|
+ paper.setCourseNo(course.getCode());
|
|
|
|
+ paper.setCreateTime(CommonUtils.getCurDateTime());
|
|
|
|
+ paper.setPaperDetailCount(Integer.valueOf((String) paperInfoMap
|
|
|
|
+ .get("detailCount")));
|
|
|
|
+ paper.setUnitCount(Integer.valueOf((String) paperInfoMap
|
|
|
|
+ .get("unitCount")));
|
|
|
|
+ paper.setDifficultyDegree(0.5);
|
|
|
|
+ return paper;
|
|
|
|
+ }
|
|
|
|
|
|
- // 初始化大题集合
|
|
|
|
- private List<PaperDetail> initPaperDetails(
|
|
|
|
- Map<Object, Object> paperInfoMap, Paper paper) {
|
|
|
|
- // 定义大题集合
|
|
|
|
- List<PaperDetail> paperDetails = new ArrayList<PaperDetail>();
|
|
|
|
- int length = paperInfoMap.size() - 5;
|
|
|
|
- for (int i = 0; i < length; i++) {
|
|
|
|
- QuestionsTemp detailInfo = (QuestionsTemp) paperInfoMap.get(String
|
|
|
|
- .valueOf(i + 1));
|
|
|
|
- PaperDetail paperDetail = new PaperDetail();
|
|
|
|
- paperDetail.setPaper(paper);
|
|
|
|
- paperDetail.setNumber(Integer.valueOf(detailInfo.getNumber()));
|
|
|
|
- paperDetail.setName(detailInfo.getName());
|
|
|
|
- paperDetail.setScore(Double.valueOf(detailInfo.getTotalScore()));
|
|
|
|
- paperDetail.setUnitCount(Integer.valueOf(detailInfo.getCount()));
|
|
|
|
- paperDetail.setCreator("wei");
|
|
|
|
- paperDetail.setCreateTime(CommonUtils.getCurDateTime());
|
|
|
|
- paperDetails.add(paperDetail);
|
|
|
|
- }
|
|
|
|
- return paperDetails;
|
|
|
|
- }
|
|
|
|
|
|
+ // 初始化大题集合
|
|
|
|
+ private List<PaperDetail> initPaperDetails(
|
|
|
|
+ Map<Object, Object> paperInfoMap, Paper paper) {
|
|
|
|
+ // 定义大题集合
|
|
|
|
+ List<PaperDetail> paperDetails = new ArrayList<PaperDetail>();
|
|
|
|
+ int length = paperInfoMap.size() - 5;
|
|
|
|
+ for (int i = 0; i < length; i++) {
|
|
|
|
+ QuestionsTemp detailInfo = (QuestionsTemp) paperInfoMap.get(String
|
|
|
|
+ .valueOf(i + 1));
|
|
|
|
+ PaperDetail paperDetail = new PaperDetail();
|
|
|
|
+ paperDetail.setPaper(paper);
|
|
|
|
+ paperDetail.setNumber(Integer.valueOf(detailInfo.getNumber()));
|
|
|
|
+ paperDetail.setName(detailInfo.getName());
|
|
|
|
+ paperDetail.setScore(Double.valueOf(detailInfo.getTotalScore()));
|
|
|
|
+ paperDetail.setUnitCount(Integer.valueOf(detailInfo.getCount()));
|
|
|
|
+ paperDetail.setCreator("wei");
|
|
|
|
+ paperDetail.setCreateTime(CommonUtils.getCurDateTime());
|
|
|
|
+ paperDetails.add(paperDetail);
|
|
|
|
+ }
|
|
|
|
+ return paperDetails;
|
|
|
|
+ }
|
|
|
|
|
|
- public Map<Object, Object> readXml(String xmlPath) throws Exception {
|
|
|
|
- Map<Object, Object> paperInfoMap = new HashedMap<Object, Object>();
|
|
|
|
- DocumentBuilderFactory a = DocumentBuilderFactory.newInstance();
|
|
|
|
- DocumentBuilder b = a.newDocumentBuilder();
|
|
|
|
- Document document = b.parse(xmlPath);
|
|
|
|
- NodeList exerciseDocuments = document
|
|
|
|
- .getElementsByTagName("ExerciseDocument");
|
|
|
|
- // 遍历exerciseDocument节点
|
|
|
|
- for (int i = 0; i < exerciseDocuments.getLength(); i++) {
|
|
|
|
- // 获取第一个exerciseDocument
|
|
|
|
- Node node = exerciseDocuments.item(i);
|
|
|
|
- // 获取exerciseDocument节点下的所有属性
|
|
|
|
- NamedNodeMap namedNodeMap = node.getAttributes();
|
|
|
|
- // 课程代码
|
|
|
|
- paperInfoMap.put("courseCode", namedNodeMap.getNamedItem("CourseId").getTextContent());
|
|
|
|
- // 试卷名称
|
|
|
|
- paperInfoMap.put("name",namedNodeMap.getNamedItem("CourseName").getTextContent() + namedNodeMap.getNamedItem("ProblemDocumentName").getTextContent());
|
|
|
|
- // 试卷总分
|
|
|
|
- paperInfoMap.put("totalScore", namedNodeMap.getNamedItem("Score").getTextContent());
|
|
|
|
- // 大题数量
|
|
|
|
- paperInfoMap.put("detailCount",namedNodeMap.getNamedItem("ProblemCollectionCount").getTextContent());
|
|
|
|
- // 小题数量
|
|
|
|
- paperInfoMap.put("unitCount",namedNodeMap.getNamedItem("ProblemCount").getTextContent());
|
|
|
|
- // 获取ProblemCollection所有节点
|
|
|
|
- NodeList problemList = node.getChildNodes();
|
|
|
|
- for (int j = 0; j < problemList.getLength(); j++) {
|
|
|
|
- // 大题节点
|
|
|
|
- Node detailNode = problemList.item(j);
|
|
|
|
- if (detailNode.getNodeName().equals("ProblemCollection")) {
|
|
|
|
- Map<Object, Object> detailInfoMap = new HashedMap<Object, Object>();
|
|
|
|
- QuestionsTemp detailInfo = new QuestionsTemp();
|
|
|
|
- // 大题序号
|
|
|
|
- detailInfo.setNumber(detailNode.getAttributes().getNamedItem("Index").getTextContent());
|
|
|
|
- // 大题名称
|
|
|
|
- detailInfo.setName(detailNode.getAttributes().getNamedItem("ProblemTypeName").getTextContent());
|
|
|
|
- // 大题总分
|
|
|
|
- detailInfo.setTotalScore(detailNode.getAttributes().getNamedItem("Score").getTextContent());
|
|
|
|
- // 大题总数
|
|
|
|
- detailInfo.setCount(detailNode.getAttributes().getNamedItem("ProblemCount").getTextContent());
|
|
|
|
- // 获取所有Problem节点
|
|
|
|
- NodeList unitList = detailNode.getChildNodes();
|
|
|
|
- for (int k = 0; k < unitList.getLength(); k++) {
|
|
|
|
- Node unitNode = unitList.item(k);
|
|
|
|
- if (unitNode.getNodeName().equals("Problem")) {
|
|
|
|
- QuestionsTemp unitInfo = new QuestionsTemp();
|
|
|
|
- // 小题分数
|
|
|
|
- unitInfo.setScore(unitNode.getAttributes().getNamedItem("Score").getTextContent());
|
|
|
|
- // 小题序号
|
|
|
|
- unitInfo.setNumber(unitNode.getAttributes().getNamedItem("Index").getTextContent());
|
|
|
|
- // 小题题型
|
|
|
|
- String type = unitNode.getAttributes().getNamedItem("ProblemClassType").getTextContent();
|
|
|
|
- // 获取题目文本节点
|
|
|
|
- NodeList unitInfoList = unitNode.getChildNodes();
|
|
|
|
- for (int z = 0; z < unitInfoList.getLength(); z++) {
|
|
|
|
- Node unitInfoNode = unitInfoList.item(z);
|
|
|
|
- if (unitInfoNode.getNodeName().equals("Content")) {
|
|
|
|
- // 小题题干
|
|
|
|
- unitInfo.setBody(unitInfoNode.getTextContent());
|
|
|
|
- }
|
|
|
|
- // 选择题
|
|
|
|
- if (unitInfoNode.getNodeName().equals("ChoiceItem")) {
|
|
|
|
- NodeList optionsInfoList = unitInfoNode.getChildNodes();
|
|
|
|
- String answer = "";
|
|
|
|
- if (type.equals("MonomialChoice")) {
|
|
|
|
- unitInfo.setType(QuesStructType.SINGLE_ANSWER_QUESTION);
|
|
|
|
- }
|
|
|
|
- if (type.equals("MultipleChoice")) {
|
|
|
|
- unitInfo.setType(QuesStructType.MULTIPLE_ANSWER_QUESTION);
|
|
|
|
- }
|
|
|
|
- Map<Object, Object> options = new HashedMap<Object, Object>();
|
|
|
|
- for (int u = 0; u < optionsInfoList.getLength(); u++) {
|
|
|
|
- Node optionsInfoNode = optionsInfoList.item(u);
|
|
|
|
- if (optionsInfoNode.getNodeName().equals("Options")) {
|
|
|
|
- // 所有选项节点
|
|
|
|
- NodeList optionInfoList = optionsInfoNode.getChildNodes();
|
|
|
|
- for (int r = 0; r < optionInfoList.getLength(); r++) {
|
|
|
|
- Node optionInfoNode = optionInfoList.item(r);
|
|
|
|
- if (optionInfoNode.getNodeName().equals("Option")) {
|
|
|
|
- // 选项序号,内容
|
|
|
|
- options.put(optionInfoNode.getAttributes().getNamedItem("Index").getTextContent(),optionInfoNode.getTextContent());
|
|
|
|
- if (optionInfoNode.getAttributes().getNamedItem("Selected").getTextContent().equals("True")) {
|
|
|
|
- if (StringUtils.isBlank(answer)) {
|
|
|
|
- answer = optionInfoNode.getAttributes().getNamedItem("Index").getTextContent();
|
|
|
|
- } else {
|
|
|
|
- answer = answer+ ","+ optionInfoNode.getAttributes().getNamedItem("Index").getTextContent();
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- // 小题选项
|
|
|
|
- unitInfo.setOptions(options);
|
|
|
|
- unitInfo.setAnswer(answer);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- // 完形填空,单选类的阅读理解
|
|
|
|
- if (unitInfoNode.getNodeName().equals("ChoiceItems")) {
|
|
|
|
- unitInfo.setType(QuesStructType.NESTED_ANSWER_QUESTION);
|
|
|
|
- Map<Object, Object> subQues = new HashedMap<Object, Object>();
|
|
|
|
- Map<Object, Object> subOptions = new HashedMap<Object, Object>();
|
|
|
|
- NodeList choiceItemsList = unitInfoNode.getChildNodes();
|
|
|
|
- int number = 1;
|
|
|
|
- for (int h = 0; h < choiceItemsList.getLength(); h++) {
|
|
|
|
- Node subUnitInfoNode = choiceItemsList.item(h);
|
|
|
|
- String answer = "";
|
|
|
|
- if (subUnitInfoNode.getNodeName().equals("ChoiceItem")) {
|
|
|
|
- // 每一个子题选项
|
|
|
|
- QuestionsTemp subUnit = new QuestionsTemp();
|
|
|
|
- NodeList subOptionsInfoList = subUnitInfoNode.getChildNodes();
|
|
|
|
- for (int hu = 0; hu < subOptionsInfoList.getLength(); hu++) {
|
|
|
|
- Node subOptionsInfoNode = subOptionsInfoList.item(hu);
|
|
|
|
- if (subOptionsInfoNode.getNodeName().equals("Options")) {
|
|
|
|
- // 所有选项节点
|
|
|
|
- NodeList subOptionInfoList = subOptionsInfoNode.getChildNodes();
|
|
|
|
- for (int hr = 0; hr < subOptionInfoList.getLength(); hr++) {
|
|
|
|
- Node subOptionInfoNode = subOptionInfoList.item(hr);
|
|
|
|
- if (subOptionInfoNode.getNodeName().equals("Option")) {
|
|
|
|
- // 子题选项序号,内容
|
|
|
|
- subOptions.put(subOptionInfoNode.getAttributes().getNamedItem("Index").getTextContent(),subOptionInfoNode.getTextContent());
|
|
|
|
- if (subOptionInfoNode.getAttributes().getNamedItem("Selected").getTextContent().equals("True")) {
|
|
|
|
- if (StringUtils.isBlank(answer)) {
|
|
|
|
- answer = subOptionInfoNode.getAttributes().getNamedItem("Index").getTextContent();
|
|
|
|
- } else {
|
|
|
|
- answer = answer+ ","+ subOptionInfoNode.getAttributes().getNamedItem("Index").getTextContent();
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- // 子题选项
|
|
|
|
- subUnit.setOptions(subOptions);
|
|
|
|
- // 子题答案
|
|
|
|
- subUnit.setAnswer(answer);
|
|
|
|
- if (answer.contains(",")) {
|
|
|
|
- subUnit.setType(QuesStructType.MULTIPLE_ANSWER_QUESTION);
|
|
|
|
- } else {
|
|
|
|
- subUnit.setType(QuesStructType.SINGLE_ANSWER_QUESTION);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- if (subOptionsInfoNode.getNodeName().equals("Content")) {
|
|
|
|
- subUnit.setBody(subOptionsInfoNode.getTextContent());
|
|
|
|
- }
|
|
|
|
- if (subOptionsInfoNode.getNodeName().equals("Answer")) {
|
|
|
|
- subUnit.setType(QuesStructType.TEXT_ANSWER_QUESTION);
|
|
|
|
- subUnit.setAnswer(subOptionsInfoNode.getTextContent());
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- if (StringUtils.isBlank(subUnit.getBody())) {
|
|
|
|
- subUnit.setBody("__________");
|
|
|
|
- }
|
|
|
|
- subUnit.setNumber(String.valueOf(number));
|
|
|
|
- subQues.put(subUnit.getNumber(),subUnit);
|
|
|
|
- number++;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- unitInfo.setSubQues(subQues);
|
|
|
|
- }
|
|
|
|
- // 普通答案
|
|
|
|
- if (unitInfoNode.getNodeName().equals("Answer")) {
|
|
|
|
- // 判断题
|
|
|
|
- if (type.equals("TrueOrFalse")) {
|
|
|
|
- unitInfo.setType(QuesStructType.BOOL_ANSWER_QUESTION);
|
|
|
|
- String answerString = unitInfoNode.getTextContent();
|
|
|
|
- if (answerString.contains("False")) {
|
|
|
|
- unitInfo.setAnswer("错误");
|
|
|
|
- } else {
|
|
|
|
- unitInfo.setAnswer("正确");
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- // 主观题
|
|
|
|
- if (type.equals("EssayQuestion")) {
|
|
|
|
- unitInfo.setType(QuesStructType.TEXT_ANSWER_QUESTION);
|
|
|
|
- unitInfo.setAnswer(unitInfoNode.getTextContent());
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- // 添加小题到大题
|
|
|
|
- detailInfoMap.put(unitInfo.getNumber(), unitInfo);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- detailInfo.setQues(detailInfoMap);
|
|
|
|
- // 添加大题到试卷
|
|
|
|
- paperInfoMap.put(detailInfo.getNumber(), detailInfo);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- return paperInfoMap;
|
|
|
|
- }
|
|
|
|
|
|
+ public Map<Object, Object> readXml(String xmlPath) throws Exception {
|
|
|
|
+ Map<Object, Object> paperInfoMap = new HashedMap<Object, Object>();
|
|
|
|
+ DocumentBuilderFactory a = DocumentBuilderFactory.newInstance();
|
|
|
|
+ DocumentBuilder b = a.newDocumentBuilder();
|
|
|
|
+ Document document = b.parse(xmlPath);
|
|
|
|
+ NodeList exerciseDocuments = document
|
|
|
|
+ .getElementsByTagName("ExerciseDocument");
|
|
|
|
+ // 遍历exerciseDocument节点
|
|
|
|
+ for (int i = 0; i < exerciseDocuments.getLength(); i++) {
|
|
|
|
+ // 获取第一个exerciseDocument
|
|
|
|
+ Node node = exerciseDocuments.item(i);
|
|
|
|
+ // 获取exerciseDocument节点下的所有属性
|
|
|
|
+ NamedNodeMap namedNodeMap = node.getAttributes();
|
|
|
|
+ // 课程代码
|
|
|
|
+ paperInfoMap.put("courseCode", namedNodeMap.getNamedItem("CourseId").getTextContent());
|
|
|
|
+ // 试卷名称
|
|
|
|
+ paperInfoMap.put("name", namedNodeMap.getNamedItem("CourseName").getTextContent() + namedNodeMap.getNamedItem("ProblemDocumentName").getTextContent());
|
|
|
|
+ // 试卷总分
|
|
|
|
+ paperInfoMap.put("totalScore", namedNodeMap.getNamedItem("Score").getTextContent());
|
|
|
|
+ // 大题数量
|
|
|
|
+ paperInfoMap.put("detailCount", namedNodeMap.getNamedItem("ProblemCollectionCount").getTextContent());
|
|
|
|
+ // 小题数量
|
|
|
|
+ paperInfoMap.put("unitCount", namedNodeMap.getNamedItem("ProblemCount").getTextContent());
|
|
|
|
+ // 获取ProblemCollection所有节点
|
|
|
|
+ NodeList problemList = node.getChildNodes();
|
|
|
|
+ for (int j = 0; j < problemList.getLength(); j++) {
|
|
|
|
+ // 大题节点
|
|
|
|
+ Node detailNode = problemList.item(j);
|
|
|
|
+ if (detailNode.getNodeName().equals("ProblemCollection")) {
|
|
|
|
+ Map<Object, Object> detailInfoMap = new HashedMap<Object, Object>();
|
|
|
|
+ QuestionsTemp detailInfo = new QuestionsTemp();
|
|
|
|
+ // 大题序号
|
|
|
|
+ detailInfo.setNumber(detailNode.getAttributes().getNamedItem("Index").getTextContent());
|
|
|
|
+ // 大题名称
|
|
|
|
+ detailInfo.setName(detailNode.getAttributes().getNamedItem("ProblemTypeName").getTextContent());
|
|
|
|
+ // 大题总分
|
|
|
|
+ detailInfo.setTotalScore(detailNode.getAttributes().getNamedItem("Score").getTextContent());
|
|
|
|
+ // 大题总数
|
|
|
|
+ detailInfo.setCount(detailNode.getAttributes().getNamedItem("ProblemCount").getTextContent());
|
|
|
|
+ // 获取所有Problem节点
|
|
|
|
+ NodeList unitList = detailNode.getChildNodes();
|
|
|
|
+ for (int k = 0; k < unitList.getLength(); k++) {
|
|
|
|
+ Node unitNode = unitList.item(k);
|
|
|
|
+ if (unitNode.getNodeName().equals("Problem")) {
|
|
|
|
+ QuestionsTemp unitInfo = new QuestionsTemp();
|
|
|
|
+ // 小题分数
|
|
|
|
+ unitInfo.setScore(unitNode.getAttributes().getNamedItem("Score").getTextContent());
|
|
|
|
+ // 小题序号
|
|
|
|
+ unitInfo.setNumber(unitNode.getAttributes().getNamedItem("Index").getTextContent());
|
|
|
|
+ // 小题题型
|
|
|
|
+ String type = unitNode.getAttributes().getNamedItem("ProblemClassType").getTextContent();
|
|
|
|
+ // 获取题目文本节点
|
|
|
|
+ NodeList unitInfoList = unitNode.getChildNodes();
|
|
|
|
+ for (int z = 0; z < unitInfoList.getLength(); z++) {
|
|
|
|
+ Node unitInfoNode = unitInfoList.item(z);
|
|
|
|
+ if (unitInfoNode.getNodeName().equals("Content")) {
|
|
|
|
+ // 小题题干
|
|
|
|
+ unitInfo.setBody(unitInfoNode.getTextContent());
|
|
|
|
+ }
|
|
|
|
+ // 选择题
|
|
|
|
+ if (unitInfoNode.getNodeName().equals("ChoiceItem")) {
|
|
|
|
+ NodeList optionsInfoList = unitInfoNode.getChildNodes();
|
|
|
|
+ String answer = "";
|
|
|
|
+ if (type.equals("MonomialChoice")) {
|
|
|
|
+ unitInfo.setType(QuesStructType.SINGLE_ANSWER_QUESTION);
|
|
|
|
+ }
|
|
|
|
+ if (type.equals("MultipleChoice")) {
|
|
|
|
+ unitInfo.setType(QuesStructType.MULTIPLE_ANSWER_QUESTION);
|
|
|
|
+ }
|
|
|
|
+ Map<Object, Object> options = new HashedMap<Object, Object>();
|
|
|
|
+ for (int u = 0; u < optionsInfoList.getLength(); u++) {
|
|
|
|
+ Node optionsInfoNode = optionsInfoList.item(u);
|
|
|
|
+ if (optionsInfoNode.getNodeName().equals("Options")) {
|
|
|
|
+ // 所有选项节点
|
|
|
|
+ NodeList optionInfoList = optionsInfoNode.getChildNodes();
|
|
|
|
+ for (int r = 0; r < optionInfoList.getLength(); r++) {
|
|
|
|
+ Node optionInfoNode = optionInfoList.item(r);
|
|
|
|
+ if (optionInfoNode.getNodeName().equals("Option")) {
|
|
|
|
+ // 选项序号,内容
|
|
|
|
+ options.put(optionInfoNode.getAttributes().getNamedItem("Index").getTextContent(), optionInfoNode.getTextContent());
|
|
|
|
+ if (optionInfoNode.getAttributes().getNamedItem("Selected").getTextContent().equals("True")) {
|
|
|
|
+ if (StringUtils.isBlank(answer)) {
|
|
|
|
+ answer = optionInfoNode.getAttributes().getNamedItem("Index").getTextContent();
|
|
|
|
+ } else {
|
|
|
|
+ answer = answer + "," + optionInfoNode.getAttributes().getNamedItem("Index").getTextContent();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ // 小题选项
|
|
|
|
+ unitInfo.setOptions(options);
|
|
|
|
+ unitInfo.setAnswer(answer);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ // 完形填空,单选类的阅读理解
|
|
|
|
+ if (unitInfoNode.getNodeName().equals("ChoiceItems")) {
|
|
|
|
+ unitInfo.setType(QuesStructType.NESTED_ANSWER_QUESTION);
|
|
|
|
+ Map<Object, Object> subQues = new HashedMap<Object, Object>();
|
|
|
|
+ Map<Object, Object> subOptions = new HashedMap<Object, Object>();
|
|
|
|
+ NodeList choiceItemsList = unitInfoNode.getChildNodes();
|
|
|
|
+ int number = 1;
|
|
|
|
+ for (int h = 0; h < choiceItemsList.getLength(); h++) {
|
|
|
|
+ Node subUnitInfoNode = choiceItemsList.item(h);
|
|
|
|
+ String answer = "";
|
|
|
|
+ if (subUnitInfoNode.getNodeName().equals("ChoiceItem")) {
|
|
|
|
+ // 每一个子题选项
|
|
|
|
+ QuestionsTemp subUnit = new QuestionsTemp();
|
|
|
|
+ NodeList subOptionsInfoList = subUnitInfoNode.getChildNodes();
|
|
|
|
+ for (int hu = 0; hu < subOptionsInfoList.getLength(); hu++) {
|
|
|
|
+ Node subOptionsInfoNode = subOptionsInfoList.item(hu);
|
|
|
|
+ if (subOptionsInfoNode.getNodeName().equals("Options")) {
|
|
|
|
+ // 所有选项节点
|
|
|
|
+ NodeList subOptionInfoList = subOptionsInfoNode.getChildNodes();
|
|
|
|
+ for (int hr = 0; hr < subOptionInfoList.getLength(); hr++) {
|
|
|
|
+ Node subOptionInfoNode = subOptionInfoList.item(hr);
|
|
|
|
+ if (subOptionInfoNode.getNodeName().equals("Option")) {
|
|
|
|
+ // 子题选项序号,内容
|
|
|
|
+ subOptions.put(subOptionInfoNode.getAttributes().getNamedItem("Index").getTextContent(), subOptionInfoNode.getTextContent());
|
|
|
|
+ if (subOptionInfoNode.getAttributes().getNamedItem("Selected").getTextContent().equals("True")) {
|
|
|
|
+ if (StringUtils.isBlank(answer)) {
|
|
|
|
+ answer = subOptionInfoNode.getAttributes().getNamedItem("Index").getTextContent();
|
|
|
|
+ } else {
|
|
|
|
+ answer = answer + "," + subOptionInfoNode.getAttributes().getNamedItem("Index").getTextContent();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ // 子题选项
|
|
|
|
+ subUnit.setOptions(subOptions);
|
|
|
|
+ // 子题答案
|
|
|
|
+ subUnit.setAnswer(answer);
|
|
|
|
+ if (answer.contains(",")) {
|
|
|
|
+ subUnit.setType(QuesStructType.MULTIPLE_ANSWER_QUESTION);
|
|
|
|
+ } else {
|
|
|
|
+ subUnit.setType(QuesStructType.SINGLE_ANSWER_QUESTION);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (subOptionsInfoNode.getNodeName().equals("Content")) {
|
|
|
|
+ subUnit.setBody(subOptionsInfoNode.getTextContent());
|
|
|
|
+ }
|
|
|
|
+ if (subOptionsInfoNode.getNodeName().equals("Answer")) {
|
|
|
|
+ subUnit.setType(QuesStructType.TEXT_ANSWER_QUESTION);
|
|
|
|
+ subUnit.setAnswer(subOptionsInfoNode.getTextContent());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (StringUtils.isBlank(subUnit.getBody())) {
|
|
|
|
+ subUnit.setBody("__________");
|
|
|
|
+ }
|
|
|
|
+ subUnit.setNumber(String.valueOf(number));
|
|
|
|
+ subQues.put(subUnit.getNumber(), subUnit);
|
|
|
|
+ number++;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ unitInfo.setSubQues(subQues);
|
|
|
|
+ }
|
|
|
|
+ // 普通答案
|
|
|
|
+ if (unitInfoNode.getNodeName().equals("Answer")) {
|
|
|
|
+ // 判断题
|
|
|
|
+ if (type.equals("TrueOrFalse")) {
|
|
|
|
+ unitInfo.setType(QuesStructType.BOOL_ANSWER_QUESTION);
|
|
|
|
+ String answerString = unitInfoNode.getTextContent();
|
|
|
|
+ if (answerString.contains("False")) {
|
|
|
|
+ unitInfo.setAnswer("错误");
|
|
|
|
+ } else {
|
|
|
|
+ unitInfo.setAnswer("正确");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ // 主观题
|
|
|
|
+ if (type.equals("EssayQuestion")) {
|
|
|
|
+ unitInfo.setType(QuesStructType.TEXT_ANSWER_QUESTION);
|
|
|
|
+ unitInfo.setAnswer(unitInfoNode.getTextContent());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ // 添加小题到大题
|
|
|
|
+ detailInfoMap.put(unitInfo.getNumber(), unitInfo);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ detailInfo.setQues(detailInfoMap);
|
|
|
|
+ // 添加大题到试卷
|
|
|
|
+ paperInfoMap.put(detailInfo.getNumber(), detailInfo);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return paperInfoMap;
|
|
|
|
+ }
|
|
|
|
|
|
- // 初始化小题集合
|
|
|
|
- private List<PaperDetailUnit> initpaperDetailUnits(Paper paper,
|
|
|
|
- List<PaperDetail> paperDetails, Map<Question, QuestionPkgPath> map,
|
|
|
|
- Map<Object, Object> paperInfoMap, Course course) throws Exception {
|
|
|
|
- List<PaperDetailUnit> paperDetailUnits = new ArrayList<PaperDetailUnit>();
|
|
|
|
- int detailCount = paperDetails.size();
|
|
|
|
- int nm = 0;
|
|
|
|
- for (int i = 0; i < detailCount; i++) {
|
|
|
|
- PaperDetail detail = paperDetails.get(i);
|
|
|
|
- QuestionsTemp detailTemp = (QuestionsTemp) paperInfoMap.get(String
|
|
|
|
- .valueOf(i + 1));
|
|
|
|
- Map<Object, Object> detailInfoMap = detailTemp.getQues();
|
|
|
|
- int quesCount = detailInfoMap.size();
|
|
|
|
- for (int j = 0; j < quesCount; j++) {
|
|
|
|
- WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage
|
|
|
|
- .createPackage();
|
|
|
|
- QuestionsTemp quesTemp = (QuestionsTemp) detailInfoMap
|
|
|
|
- .get(String.valueOf(j + 1));
|
|
|
|
- Question question = new Question();
|
|
|
|
- question.setCreateTime(CommonUtils.getCurDateTime());
|
|
|
|
- question.setScore(Double.valueOf(quesTemp.getScore()));
|
|
|
|
- question.setCourse(course);
|
|
|
|
- question.setOrgId(course.getOrgId());
|
|
|
|
- question.setHasAudio(false);
|
|
|
|
- question.setDifficulty("中");
|
|
|
|
- question.setDifficultyDegree(0.5);
|
|
|
|
- question.setPublicity(true);
|
|
|
|
- question.setQuestionType(quesTemp.getType());
|
|
|
|
- question.setQuesBody(imgList(quesTemp.getBody()));
|
|
|
|
- try {
|
|
|
|
- question.setQuesBodyWord(DocxProcessUtil.html2Docx(wordMLPackage,CommonUtils.formatHtml(question.getQuesBody())));
|
|
|
|
- } catch (Exception e) {
|
|
|
|
- System.out.println("错误题干信息:"+question.getQuesBody());
|
|
|
|
- }
|
|
|
|
- if(question.getQuestionType() == QuesStructType.BOOL_ANSWER_QUESTION){
|
|
|
|
- question.setQuesAnswer(quesTemp.getAnswer());
|
|
|
|
- question.setQuesAnswerWord(DocxProcessUtil.html2Docx(wordMLPackage,CommonUtils.formatHtml("<p>"+question.getQuesAnswer()+"</p>")));
|
|
|
|
- }else {
|
|
|
|
- question.setQuesAnswer(imgList(quesTemp.getAnswer()));
|
|
|
|
- try {
|
|
|
|
- question.setQuesAnswerWord(DocxProcessUtil.html2Docx(wordMLPackage,CommonUtils.formatHtml(question.getQuesAnswer())));
|
|
|
|
- } catch (Exception e) {
|
|
|
|
- System.out.println("错误题干信息:"+question.getQuesAnswer());
|
|
|
|
- return null;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- // 存在选项
|
|
|
|
- if (question.getQuestionType() == QuesStructType.SINGLE_ANSWER_QUESTION
|
|
|
|
- || question.getQuestionType() == QuesStructType.MULTIPLE_ANSWER_QUESTION) {
|
|
|
|
- List<QuesOption> quesOptions = new ArrayList<QuesOption>();
|
|
|
|
- Map<Object, Object> optionMap = quesTemp.getOptions();
|
|
|
|
- int optionCount = optionMap.size();
|
|
|
|
- for (int k = 0; k < optionCount; k++) {
|
|
|
|
- QuesOption quesOption = new QuesOption();
|
|
|
|
- quesOption.setNumber(String.valueOf(k + 1));
|
|
|
|
- quesOption.setOptionBody(imgList((String) optionMap.get(String.valueOf(k + 1))));
|
|
|
|
- try {
|
|
|
|
- quesOption.setOptionBodyWord(DocxProcessUtil.html2Docx(wordMLPackage, CommonUtils.formatHtml(quesOption.getOptionBody())));
|
|
|
|
- } catch (Exception e) {
|
|
|
|
- System.out.println("错误的选项:"+quesOption.getOptionBody());
|
|
|
|
- }
|
|
|
|
- if (question.getQuesAnswer().contains(String.valueOf(k+1))) {
|
|
|
|
- quesOption.setIsCorrect((short) 1);
|
|
|
|
- } else {
|
|
|
|
- quesOption.setIsCorrect((short) 0);
|
|
|
|
- }
|
|
|
|
- quesOptions.add(quesOption);
|
|
|
|
- }
|
|
|
|
- question.setQuesOptions(quesOptions);
|
|
|
|
- String[] answers = question.getQuesAnswer()
|
|
|
|
- .replaceAll("<p>", "").replaceAll("</p>", "")
|
|
|
|
- .replaceAll("<P>", "").replaceAll("</P>", "")
|
|
|
|
- .split(",");
|
|
|
|
- String answer = "";
|
|
|
|
- for (int a = 0; a < answers.length; a++) {
|
|
|
|
- char c1 = (char) (Integer.valueOf(answers[a]) + 64);
|
|
|
|
- if (a == 0) {
|
|
|
|
- answer = String.valueOf(c1);
|
|
|
|
- } else {
|
|
|
|
- answer = answer + "," + c1;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- question.setQuesAnswer("<p>" + answer + "</p>");
|
|
|
|
- question.setQuesAnswerWord(DocxProcessUtil.html2Docx(wordMLPackage,CommonUtils.formatHtml(question.getQuesAnswer())));
|
|
|
|
- }
|
|
|
|
- // 存在子题
|
|
|
|
- if (question.getQuestionType() == QuesStructType.NESTED_ANSWER_QUESTION) {
|
|
|
|
- List<Question> subQuestions = new ArrayList<Question>();
|
|
|
|
- int subQuesCount = quesTemp.getSubQues().size();
|
|
|
|
- BigDecimal totalScore = new BigDecimal(question.getScore());
|
|
|
|
- BigDecimal sum = new BigDecimal(subQuesCount);
|
|
|
|
- double score = totalScore.divide(sum).doubleValue();
|
|
|
|
- for (int s = 0; s < subQuesCount; s++) {
|
|
|
|
- QuestionsTemp subQuesTmp = (QuestionsTemp) quesTemp.getSubQues().get(String.valueOf(s+1));
|
|
|
|
- Question subQuestion = new Question();
|
|
|
|
- subQuestion.setId(UUID.randomUUID().toString());
|
|
|
|
- subQuestion.setQuestionType(subQuesTmp.getType());
|
|
|
|
- subQuestion.setDifficulty("中");
|
|
|
|
- subQuestion.setDifficultyDegree(0.5);
|
|
|
|
- subQuestion.setPublicity(true);
|
|
|
|
- subQuestion.setScore(score);
|
|
|
|
- subQuestion.setQuesBody(imgList(subQuesTmp.getBody()));
|
|
|
|
- subQuestion.setQuesBodyWord(DocxProcessUtil.html2Docx(wordMLPackage,CommonUtils.formatHtml(subQuestion.getQuesBody())));
|
|
|
|
- subQuestion.setQuesAnswer(imgList(subQuesTmp.getAnswer()));
|
|
|
|
- subQuestion.setQuesBodyWord(DocxProcessUtil.html2Docx(wordMLPackage, CommonUtils.formatHtml(subQuestion.getQuesAnswer())));
|
|
|
|
- // 存在选项
|
|
|
|
- if (subQuestion.getQuestionType() == QuesStructType.SINGLE_ANSWER_QUESTION
|
|
|
|
- || subQuestion.getQuestionType() == QuesStructType.MULTIPLE_ANSWER_QUESTION) {
|
|
|
|
- List<QuesOption> subQuesOptions = new ArrayList<QuesOption>();
|
|
|
|
- Map<Object, Object> subOptionMap = subQuesTmp.getOptions();
|
|
|
|
- int subOptionCount = subOptionMap.size();
|
|
|
|
- for (int k = 0; k < subOptionCount; k++) {
|
|
|
|
- QuesOption subQuesOption = new QuesOption();
|
|
|
|
- subQuesOption.setNumber(String.valueOf(k));
|
|
|
|
- subQuesOption.setOptionBody(imgList((String) subOptionMap.get(String.valueOf(k+1))));
|
|
|
|
- subQuesOption.setOptionBodyWord(DocxProcessUtil.html2Docx(wordMLPackage, CommonUtils.formatHtml(subQuesOption.getOptionBody())));
|
|
|
|
- if (subQuestion.getQuesAnswer().contains(String.valueOf(k+1))) {
|
|
|
|
- subQuesOption.setIsCorrect((short) 1);
|
|
|
|
- } else {
|
|
|
|
- subQuesOption.setIsCorrect((short) 0);
|
|
|
|
- }
|
|
|
|
- subQuesOptions.add(subQuesOption);
|
|
|
|
- }
|
|
|
|
- subQuestion.setQuesOptions(subQuesOptions);
|
|
|
|
- String[] answers = subQuestion.getQuesAnswer()
|
|
|
|
- .replaceAll("<p>", "").replaceAll("</p>", "")
|
|
|
|
- .replaceAll("<P>", "").replaceAll("</P>", "")
|
|
|
|
- .split(",");
|
|
|
|
- String answer = "";
|
|
|
|
- for (int a = 0; a < answers.length; a++) {
|
|
|
|
- char c1 = (char) (Integer.valueOf(answers[a]) + 64);
|
|
|
|
- if (a == 0) {
|
|
|
|
- answer = String.valueOf(c1);
|
|
|
|
- } else {
|
|
|
|
- answer = answer + "," + c1;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- subQuestion.setQuesAnswer(answer);
|
|
|
|
- subQuestion.setQuesAnswerWord(DocxProcessUtil.html2Docx(wordMLPackage,CommonUtils.formatHtml("<p>" + subQuestion.getQuesAnswer() + "</p>")));
|
|
|
|
- }
|
|
|
|
- subQuestions.add(subQuestion);
|
|
|
|
- }
|
|
|
|
- question.setSubQuestions(subQuestions);
|
|
|
|
- }
|
|
|
|
- byte[] pkgByte = DocxProcessUtil.getPkgByte(wordMLPackage);
|
|
|
|
- QuestionPkgPath quesPkgPath = new QuestionPkgPath(pkgByte);
|
|
|
|
- map.put(question, quesPkgPath);
|
|
|
|
- // 包装小题
|
|
|
|
- PaperDetailUnit paperDetailUnit = new PaperDetailUnit();
|
|
|
|
- paperDetailUnit.setPaper(paper);
|
|
|
|
- paperDetailUnit.setNumber(nm + 1);
|
|
|
|
- paperDetailUnit.setScore(question.getScore());
|
|
|
|
- paperDetailUnit.setPaperDetail(detail);
|
|
|
|
- paperDetailUnit.setQuestionType(question.getQuestionType());
|
|
|
|
- paperDetailUnit.setCreator("wei");
|
|
|
|
- paperDetailUnit.setCreateTime(CommonUtils.getCurDateTime());
|
|
|
|
- paperDetailUnit.setQuestion(question);
|
|
|
|
- paperDetailUnits.add(paperDetailUnit);
|
|
|
|
- nm++;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- return paperDetailUnits;
|
|
|
|
- }
|
|
|
|
|
|
+ // 初始化小题集合
|
|
|
|
+ private List<PaperDetailUnit> initpaperDetailUnits(Paper paper,
|
|
|
|
+ List<PaperDetail> paperDetails, Map<Question, QuestionPkgPath> map,
|
|
|
|
+ Map<Object, Object> paperInfoMap, Course course) throws Exception {
|
|
|
|
+ List<PaperDetailUnit> paperDetailUnits = new ArrayList<PaperDetailUnit>();
|
|
|
|
+ int detailCount = paperDetails.size();
|
|
|
|
+ int nm = 0;
|
|
|
|
+ for (int i = 0; i < detailCount; i++) {
|
|
|
|
+ PaperDetail detail = paperDetails.get(i);
|
|
|
|
+ QuestionsTemp detailTemp = (QuestionsTemp) paperInfoMap.get(String
|
|
|
|
+ .valueOf(i + 1));
|
|
|
|
+ Map<Object, Object> detailInfoMap = detailTemp.getQues();
|
|
|
|
+ int quesCount = detailInfoMap.size();
|
|
|
|
+ for (int j = 0; j < quesCount; j++) {
|
|
|
|
+ WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage
|
|
|
|
+ .createPackage();
|
|
|
|
+ QuestionsTemp quesTemp = (QuestionsTemp) detailInfoMap
|
|
|
|
+ .get(String.valueOf(j + 1));
|
|
|
|
+ Question question = new Question();
|
|
|
|
+ question.setCreateTime(CommonUtils.getCurDateTime());
|
|
|
|
+ question.setScore(Double.valueOf(quesTemp.getScore()));
|
|
|
|
+ question.setCourse(course);
|
|
|
|
+ question.setOrgId(course.getOrgId());
|
|
|
|
+ question.setHasAudio(false);
|
|
|
|
+ question.setDifficulty("中");
|
|
|
|
+ question.setDifficultyDegree(0.5);
|
|
|
|
+ question.setPublicity(true);
|
|
|
|
+ question.setQuestionType(quesTemp.getType());
|
|
|
|
+ question.setQuesBody(imgList(quesTemp.getBody()));
|
|
|
|
+ try {
|
|
|
|
+ question.setQuesBodyWord(DocxProcessUtil.html2Docx(wordMLPackage, CommonUtils.formatHtml(question.getQuesBody())));
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ System.out.println("错误题干信息:" + question.getQuesBody());
|
|
|
|
+ }
|
|
|
|
+ if (question.getQuestionType() == QuesStructType.BOOL_ANSWER_QUESTION) {
|
|
|
|
+ question.setQuesAnswer(quesTemp.getAnswer());
|
|
|
|
+ question.setQuesAnswerWord(DocxProcessUtil.html2Docx(wordMLPackage, CommonUtils.formatHtml("<p>" + question.getQuesAnswer() + "</p>")));
|
|
|
|
+ } else {
|
|
|
|
+ question.setQuesAnswer(imgList(quesTemp.getAnswer()));
|
|
|
|
+ try {
|
|
|
|
+ question.setQuesAnswerWord(DocxProcessUtil.html2Docx(wordMLPackage, CommonUtils.formatHtml(question.getQuesAnswer())));
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ System.out.println("错误题干信息:" + question.getQuesAnswer());
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ // 存在选项
|
|
|
|
+ if (question.getQuestionType() == QuesStructType.SINGLE_ANSWER_QUESTION
|
|
|
|
+ || question.getQuestionType() == QuesStructType.MULTIPLE_ANSWER_QUESTION) {
|
|
|
|
+ List<QuesOption> quesOptions = new ArrayList<QuesOption>();
|
|
|
|
+ Map<Object, Object> optionMap = quesTemp.getOptions();
|
|
|
|
+ int optionCount = optionMap.size();
|
|
|
|
+ for (int k = 0; k < optionCount; k++) {
|
|
|
|
+ QuesOption quesOption = new QuesOption();
|
|
|
|
+ quesOption.setNumber(String.valueOf(k + 1));
|
|
|
|
+ quesOption.setOptionBody(imgList((String) optionMap.get(String.valueOf(k + 1))));
|
|
|
|
+ try {
|
|
|
|
+ quesOption.setOptionBodyWord(DocxProcessUtil.html2Docx(wordMLPackage, CommonUtils.formatHtml(quesOption.getOptionBody())));
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ System.out.println("错误的选项:" + quesOption.getOptionBody());
|
|
|
|
+ }
|
|
|
|
+ if (question.getQuesAnswer().contains(String.valueOf(k + 1))) {
|
|
|
|
+ quesOption.setIsCorrect((short) 1);
|
|
|
|
+ } else {
|
|
|
|
+ quesOption.setIsCorrect((short) 0);
|
|
|
|
+ }
|
|
|
|
+ quesOptions.add(quesOption);
|
|
|
|
+ }
|
|
|
|
+ question.setQuesOptions(quesOptions);
|
|
|
|
+ String[] answers = question.getQuesAnswer()
|
|
|
|
+ .replaceAll("<p>", "").replaceAll("</p>", "")
|
|
|
|
+ .replaceAll("<P>", "").replaceAll("</P>", "")
|
|
|
|
+ .split(",");
|
|
|
|
+ String answer = "";
|
|
|
|
+ for (int a = 0; a < answers.length; a++) {
|
|
|
|
+ char c1 = (char) (Integer.valueOf(answers[a]) + 64);
|
|
|
|
+ if (a == 0) {
|
|
|
|
+ answer = String.valueOf(c1);
|
|
|
|
+ } else {
|
|
|
|
+ answer = answer + "," + c1;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ question.setQuesAnswer("<p>" + answer + "</p>");
|
|
|
|
+ question.setQuesAnswerWord(DocxProcessUtil.html2Docx(wordMLPackage, CommonUtils.formatHtml(question.getQuesAnswer())));
|
|
|
|
+ }
|
|
|
|
+ // 存在子题
|
|
|
|
+ if (question.getQuestionType() == QuesStructType.NESTED_ANSWER_QUESTION) {
|
|
|
|
+ List<Question> subQuestions = new ArrayList<Question>();
|
|
|
|
+ int subQuesCount = quesTemp.getSubQues().size();
|
|
|
|
+ BigDecimal totalScore = new BigDecimal(question.getScore());
|
|
|
|
+ BigDecimal sum = new BigDecimal(subQuesCount);
|
|
|
|
+ double score = totalScore.divide(sum).doubleValue();
|
|
|
|
+ for (int s = 0; s < subQuesCount; s++) {
|
|
|
|
+ QuestionsTemp subQuesTmp = (QuestionsTemp) quesTemp.getSubQues().get(String.valueOf(s + 1));
|
|
|
|
+ Question subQuestion = new Question();
|
|
|
|
+ subQuestion.setId(UUID.randomUUID().toString());
|
|
|
|
+ subQuestion.setQuestionType(subQuesTmp.getType());
|
|
|
|
+ subQuestion.setDifficulty("中");
|
|
|
|
+ subQuestion.setDifficultyDegree(0.5);
|
|
|
|
+ subQuestion.setPublicity(true);
|
|
|
|
+ subQuestion.setScore(score);
|
|
|
|
+ subQuestion.setQuesBody(imgList(subQuesTmp.getBody()));
|
|
|
|
+ subQuestion.setQuesBodyWord(DocxProcessUtil.html2Docx(wordMLPackage, CommonUtils.formatHtml(subQuestion.getQuesBody())));
|
|
|
|
+ subQuestion.setQuesAnswer(imgList(subQuesTmp.getAnswer()));
|
|
|
|
+ subQuestion.setQuesBodyWord(DocxProcessUtil.html2Docx(wordMLPackage, CommonUtils.formatHtml(subQuestion.getQuesAnswer())));
|
|
|
|
+ // 存在选项
|
|
|
|
+ if (subQuestion.getQuestionType() == QuesStructType.SINGLE_ANSWER_QUESTION
|
|
|
|
+ || subQuestion.getQuestionType() == QuesStructType.MULTIPLE_ANSWER_QUESTION) {
|
|
|
|
+ List<QuesOption> subQuesOptions = new ArrayList<QuesOption>();
|
|
|
|
+ Map<Object, Object> subOptionMap = subQuesTmp.getOptions();
|
|
|
|
+ int subOptionCount = subOptionMap.size();
|
|
|
|
+ for (int k = 0; k < subOptionCount; k++) {
|
|
|
|
+ QuesOption subQuesOption = new QuesOption();
|
|
|
|
+ subQuesOption.setNumber(String.valueOf(k));
|
|
|
|
+ subQuesOption.setOptionBody(imgList((String) subOptionMap.get(String.valueOf(k + 1))));
|
|
|
|
+ subQuesOption.setOptionBodyWord(DocxProcessUtil.html2Docx(wordMLPackage, CommonUtils.formatHtml(subQuesOption.getOptionBody())));
|
|
|
|
+ if (subQuestion.getQuesAnswer().contains(String.valueOf(k + 1))) {
|
|
|
|
+ subQuesOption.setIsCorrect((short) 1);
|
|
|
|
+ } else {
|
|
|
|
+ subQuesOption.setIsCorrect((short) 0);
|
|
|
|
+ }
|
|
|
|
+ subQuesOptions.add(subQuesOption);
|
|
|
|
+ }
|
|
|
|
+ subQuestion.setQuesOptions(subQuesOptions);
|
|
|
|
+ String[] answers = subQuestion.getQuesAnswer()
|
|
|
|
+ .replaceAll("<p>", "").replaceAll("</p>", "")
|
|
|
|
+ .replaceAll("<P>", "").replaceAll("</P>", "")
|
|
|
|
+ .split(",");
|
|
|
|
+ String answer = "";
|
|
|
|
+ for (int a = 0; a < answers.length; a++) {
|
|
|
|
+ char c1 = (char) (Integer.valueOf(answers[a]) + 64);
|
|
|
|
+ if (a == 0) {
|
|
|
|
+ answer = String.valueOf(c1);
|
|
|
|
+ } else {
|
|
|
|
+ answer = answer + "," + c1;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ subQuestion.setQuesAnswer(answer);
|
|
|
|
+ subQuestion.setQuesAnswerWord(DocxProcessUtil.html2Docx(wordMLPackage, CommonUtils.formatHtml("<p>" + subQuestion.getQuesAnswer() + "</p>")));
|
|
|
|
+ }
|
|
|
|
+ subQuestions.add(subQuestion);
|
|
|
|
+ }
|
|
|
|
+ question.setSubQuestions(subQuestions);
|
|
|
|
+ }
|
|
|
|
+ byte[] pkgByte = DocxProcessUtil.getPkgByte(wordMLPackage);
|
|
|
|
+ QuestionPkgPath quesPkgPath = new QuestionPkgPath(pkgByte);
|
|
|
|
+ map.put(question, quesPkgPath);
|
|
|
|
+ // 包装小题
|
|
|
|
+ PaperDetailUnit paperDetailUnit = new PaperDetailUnit();
|
|
|
|
+ paperDetailUnit.setPaper(paper);
|
|
|
|
+ paperDetailUnit.setNumber(nm + 1);
|
|
|
|
+ paperDetailUnit.setScore(question.getScore());
|
|
|
|
+ paperDetailUnit.setPaperDetail(detail);
|
|
|
|
+ paperDetailUnit.setQuestionType(question.getQuestionType());
|
|
|
|
+ paperDetailUnit.setCreator("wei");
|
|
|
|
+ paperDetailUnit.setCreateTime(CommonUtils.getCurDateTime());
|
|
|
|
+ paperDetailUnit.setQuestion(question);
|
|
|
|
+ paperDetailUnits.add(paperDetailUnit);
|
|
|
|
+ nm++;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return paperDetailUnits;
|
|
|
|
+ }
|
|
|
|
|
|
- public String imgList(String str) throws Exception {
|
|
|
|
- if (StringUtils.isBlank(str)) {
|
|
|
|
- str = "<p></p>";
|
|
|
|
- }
|
|
|
|
- str = str.trim().replace("<br>", "").replace("</br>", "");
|
|
|
|
- if (!str.contains("<p>") && !str.contains("</P>")) {
|
|
|
|
- str = "<p>" + str + "</p>";
|
|
|
|
- }
|
|
|
|
- //先处理span标签
|
|
|
|
- List<String> spans = parseSpans(str);
|
|
|
|
- if(spans != null && spans.size() > 0){
|
|
|
|
- for(String span:spans){
|
|
|
|
- str = str.replace(span, "").replace("</span>", "").replace("</SPAN>", "");
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- str = str.replace("<o:p>", "").replace("</o:p>", "").replace("border=0", "").replace("class=MsoNormal", "").replace("ϕ", "").replace("</SPAN>", "");
|
|
|
|
- // 获取img标签
|
|
|
|
- List<String> srcList = ImgDataUtils.parseImages(str);
|
|
|
|
- if (srcList != null && srcList.size() > 0) {
|
|
|
|
- for (String img : srcList) {
|
|
|
|
- // 获取height,width值
|
|
|
|
- List<String> height = getTagAHei(img);
|
|
|
|
- List<String> width = getTagAWid(img);
|
|
|
|
- List<String> parseImageSrc = ImgDataUtils.parseImageSrc(img);
|
|
|
|
- if (parseImageSrc != null && parseImageSrc.size() > 0) {
|
|
|
|
- String src = parseImageSrc.get(0).replace("{ResourcePath}",
|
|
|
|
- "http://file.5any.com/UniversityV4.0");
|
|
|
|
- String url = regexCH(src);
|
|
|
|
- String base64 = ImgDataUtils.loadImageToBase64(url);
|
|
|
|
- if (base64 == null) {
|
|
|
|
- throw new Exception("图片下载失败" + url);
|
|
|
|
- } else {
|
|
|
|
- if (src.contains("jpg")) {
|
|
|
|
- str = str.replace(parseImageSrc.get(0),
|
|
|
|
- "data:image/jpg;base64," + base64);
|
|
|
|
- } else {
|
|
|
|
- str = str.replace(parseImageSrc.get(0),
|
|
|
|
- "data:image/png;base64," + base64);
|
|
|
|
- }
|
|
|
|
- if (height != null && height.size() > 0) {
|
|
|
|
- str = str.replace("height=" + height.get(0),
|
|
|
|
- "height=\"" + height.get(0) + "\"");
|
|
|
|
- }
|
|
|
|
- if (width != null && width.size() > 0) {
|
|
|
|
- str = str.replace("width=" + width.get(0),
|
|
|
|
- "width=\"" + width.get(0) + "\"");
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- return str.replace("<IMG", "<img");
|
|
|
|
- }
|
|
|
|
|
|
+ public String imgList(String str) throws Exception {
|
|
|
|
+ if (StringUtils.isBlank(str)) {
|
|
|
|
+ str = "<p></p>";
|
|
|
|
+ }
|
|
|
|
+ str = str.trim().replace("<br>", "").replace("</br>", "");
|
|
|
|
+ if (!str.contains("<p>") && !str.contains("</P>")) {
|
|
|
|
+ str = "<p>" + str + "</p>";
|
|
|
|
+ }
|
|
|
|
+ //先处理span标签
|
|
|
|
+ List<String> spans = parseSpans(str);
|
|
|
|
+ if (spans != null && spans.size() > 0) {
|
|
|
|
+ for (String span : spans) {
|
|
|
|
+ str = str.replace(span, "").replace("</span>", "").replace("</SPAN>", "");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ str = str.replace("<o:p>", "").replace("</o:p>", "").replace("border=0", "").replace("class=MsoNormal", "").replace("ϕ", "").replace("</SPAN>", "");
|
|
|
|
+ // 获取img标签
|
|
|
|
+ List<String> srcList = ImgDataUtils.parseImages(str);
|
|
|
|
+ if (srcList != null && srcList.size() > 0) {
|
|
|
|
+ for (String img : srcList) {
|
|
|
|
+ // 获取height,width值
|
|
|
|
+ List<String> height = getTagAHei(img);
|
|
|
|
+ List<String> width = getTagAWid(img);
|
|
|
|
+ List<String> parseImageSrc = ImgDataUtils.parseImageSrc(img);
|
|
|
|
+ if (parseImageSrc != null && parseImageSrc.size() > 0) {
|
|
|
|
+ String src = parseImageSrc.get(0).replace("{ResourcePath}",
|
|
|
|
+ "http://file.5any.com/UniversityV4.0");
|
|
|
|
+ String url = regexCH(src);
|
|
|
|
+ String base64 = ImgDataUtils.loadImageToBase64(url);
|
|
|
|
+ if (base64 == null) {
|
|
|
|
+ throw new Exception("图片下载失败" + url);
|
|
|
|
+ } else {
|
|
|
|
+ if (src.contains("jpg")) {
|
|
|
|
+ str = str.replace(parseImageSrc.get(0),
|
|
|
|
+ "data:image/jpg;base64," + base64);
|
|
|
|
+ } else {
|
|
|
|
+ str = str.replace(parseImageSrc.get(0),
|
|
|
|
+ "data:image/png;base64," + base64);
|
|
|
|
+ }
|
|
|
|
+ if (height != null && height.size() > 0) {
|
|
|
|
+ str = str.replace("height=" + height.get(0),
|
|
|
|
+ "height=\"" + height.get(0) + "\"");
|
|
|
|
+ }
|
|
|
|
+ if (width != null && width.size() > 0) {
|
|
|
|
+ str = str.replace("width=" + width.get(0),
|
|
|
|
+ "width=\"" + width.get(0) + "\"");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return str.replace("<IMG", "<img");
|
|
|
|
+ }
|
|
|
|
|
|
- // 將url路徑中的中文转码
|
|
|
|
- public String regexCH(String str) throws UnsupportedEncodingException {
|
|
|
|
- StringBuffer s = new StringBuffer();
|
|
|
|
- Pattern pat = Pattern.compile("[\u4E00-\u9FA5]");
|
|
|
|
- Matcher mat = pat.matcher(str);
|
|
|
|
- while (mat.find()) {
|
|
|
|
- s.append(mat.group());
|
|
|
|
- }
|
|
|
|
- String url = java.net.URLEncoder.encode(s.toString(), "utf-8");
|
|
|
|
- return str.replace(s.toString(), url);
|
|
|
|
- }
|
|
|
|
|
|
+ // 將url路徑中的中文转码
|
|
|
|
+ public String regexCH(String str) throws UnsupportedEncodingException {
|
|
|
|
+ StringBuffer s = new StringBuffer();
|
|
|
|
+ Pattern pat = Pattern.compile("[\u4E00-\u9FA5]");
|
|
|
|
+ Matcher mat = pat.matcher(str);
|
|
|
|
+ while (mat.find()) {
|
|
|
|
+ s.append(mat.group());
|
|
|
|
+ }
|
|
|
|
+ String url = java.net.URLEncoder.encode(s.toString(), "utf-8");
|
|
|
|
+ return str.replace(s.toString(), url);
|
|
|
|
+ }
|
|
|
|
|
|
- // 获取所有xml的路径
|
|
|
|
- public List<String> filePath() {
|
|
|
|
- List<String> files = new ArrayList<String>();
|
|
|
|
- File file = new File("D:\\paper");
|
|
|
|
- File[] fileList = file.listFiles();
|
|
|
|
- for (int i = 0; i < fileList.length; i++) {
|
|
|
|
- if (fileList[i].isFile()) {
|
|
|
|
- String fileName = fileList[i].getName();
|
|
|
|
- files.add("file:///D:\\paper\\" + fileName);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- return files;
|
|
|
|
- }
|
|
|
|
|
|
+ // 获取所有xml的路径
|
|
|
|
+ public List<String> filePath() {
|
|
|
|
+ List<String> files = new ArrayList<String>();
|
|
|
|
+ File file = new File("D:\\paper");
|
|
|
|
+ File[] fileList = file.listFiles();
|
|
|
|
+ for (int i = 0; i < fileList.length; i++) {
|
|
|
|
+ if (fileList[i].isFile()) {
|
|
|
|
+ String fileName = fileList[i].getName();
|
|
|
|
+ files.add("file:///D:\\paper\\" + fileName);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return files;
|
|
|
|
+ }
|
|
|
|
|
|
- public static List<String> parseSpans(String content) {
|
|
|
|
- if (content == null) {
|
|
|
|
- return new ArrayList<>();
|
|
|
|
- }
|
|
|
|
- List<String> spans = new ArrayList<>();
|
|
|
|
- String reg = "<(span|SPAN)(.*?)(/>|>)";
|
|
|
|
- Pattern pattern = Pattern.compile(reg, Pattern.CASE_INSENSITIVE);
|
|
|
|
- Matcher matcher = pattern.matcher(content);
|
|
|
|
- while (matcher.find()) {
|
|
|
|
- String span = matcher.group();
|
|
|
|
- spans.add(span);
|
|
|
|
- }
|
|
|
|
- return spans;
|
|
|
|
- }
|
|
|
|
|
|
+ public static List<String> parseSpans(String content) {
|
|
|
|
+ if (content == null) {
|
|
|
|
+ return new ArrayList<>();
|
|
|
|
+ }
|
|
|
|
+ List<String> spans = new ArrayList<>();
|
|
|
|
+ String reg = "<(span|SPAN)(.*?)(/>|>)";
|
|
|
|
+ Pattern pattern = Pattern.compile(reg, Pattern.CASE_INSENSITIVE);
|
|
|
|
+ Matcher matcher = pattern.matcher(content);
|
|
|
|
+ while (matcher.find()) {
|
|
|
|
+ String span = matcher.group();
|
|
|
|
+ spans.add(span);
|
|
|
|
+ }
|
|
|
|
+ return spans;
|
|
|
|
+ }
|
|
|
|
|
|
- public List<String> getTagAHei(String htmlString) {
|
|
|
|
- List<String> list = new ArrayList<String>();
|
|
|
|
- Pattern p = Pattern
|
|
|
|
- .compile("<IMG[^<>]*\\s+height=([0-9A-Za-z-_.]+)\\s*");
|
|
|
|
- Matcher m = p.matcher(htmlString);
|
|
|
|
- while (m.find()) {
|
|
|
|
- String str = m.group(1);
|
|
|
|
- list.add(str);
|
|
|
|
- }
|
|
|
|
- return list;
|
|
|
|
- }
|
|
|
|
|
|
+ public List<String> getTagAHei(String htmlString) {
|
|
|
|
+ List<String> list = new ArrayList<String>();
|
|
|
|
+ Pattern p = Pattern
|
|
|
|
+ .compile("<IMG[^<>]*\\s+height=([0-9A-Za-z-_.]+)\\s*");
|
|
|
|
+ Matcher m = p.matcher(htmlString);
|
|
|
|
+ while (m.find()) {
|
|
|
|
+ String str = m.group(1);
|
|
|
|
+ list.add(str);
|
|
|
|
+ }
|
|
|
|
+ return list;
|
|
|
|
+ }
|
|
|
|
|
|
- public List<String> getTagAWid(String htmlString) {
|
|
|
|
- List<String> list = new ArrayList<String>();
|
|
|
|
- Pattern p = Pattern
|
|
|
|
- .compile("<IMG[^<>]*\\s+width=([0-9A-Za-z-_.]+)\\s*");
|
|
|
|
- Matcher m = p.matcher(htmlString);
|
|
|
|
- while (m.find()) {
|
|
|
|
- String str = m.group(1);
|
|
|
|
- list.add(str);
|
|
|
|
- }
|
|
|
|
- return list;
|
|
|
|
- }
|
|
|
|
|
|
+ public List<String> getTagAWid(String htmlString) {
|
|
|
|
+ List<String> list = new ArrayList<String>();
|
|
|
|
+ Pattern p = Pattern
|
|
|
|
+ .compile("<IMG[^<>]*\\s+width=([0-9A-Za-z-_.]+)\\s*");
|
|
|
|
+ Matcher m = p.matcher(htmlString);
|
|
|
|
+ while (m.find()) {
|
|
|
|
+ String str = m.group(1);
|
|
|
|
+ list.add(str);
|
|
|
|
+ }
|
|
|
|
+ return list;
|
|
|
|
+ }
|
|
|
|
|
|
}
|
|
}
|