From e6e7e76b4da6700f15a50af896da5d99e1106fd0 Mon Sep 17 00:00:00 2001 From: "DESKTOP-932OMT8\\REN" Date: Sat, 14 Jun 2025 23:16:45 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E4=BF=AE=E6=94=B9=E3=80=91=20pptx?= =?UTF-8?q?=E8=80=83=E7=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../wps_pptx/JudgementWpsPptxServiceImpl.java | 2 +- .../wps_pptx/SlideAnimationQueryByCursor.java | 74 ++++ .../utils/wps_pptx/WpsPptxUtils.java | 395 ++++++++++++++---- 3 files changed, 379 insertions(+), 92 deletions(-) create mode 100644 exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/wps_pptx/SlideAnimationQueryByCursor.java diff --git a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/service/wps_pptx/JudgementWpsPptxServiceImpl.java b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/service/wps_pptx/JudgementWpsPptxServiceImpl.java index 33cbfd90..09f6c510 100644 --- a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/service/wps_pptx/JudgementWpsPptxServiceImpl.java +++ b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/service/wps_pptx/JudgementWpsPptxServiceImpl.java @@ -99,7 +99,7 @@ public class JudgementWpsPptxServiceImpl implements JudgementWpsPptxService { String[] pptxInfos = examQuestionAnswer.getContent().split("\\?"); String[] chineseName = examQuestionAnswer.getContentIn().split("-"); String[] typeList = examQuestionAnswer.getImage().split("-"); - pptxInfoPointsVo.setName("判分"); + pptxInfoPointsVo.setName(examQuestionAnswer.getContentIn()); pptxInfoPointsVo.setEnglishName(pptxInfos[0]); pptxInfoPointsVo.setFunction(pptxInfos[1]); pptxInfoPointsVo.setType(typeList[0]); diff --git a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/wps_pptx/SlideAnimationQueryByCursor.java b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/wps_pptx/SlideAnimationQueryByCursor.java new file mode 100644 index 00000000..0b86bba6 --- /dev/null +++ b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/wps_pptx/SlideAnimationQueryByCursor.java @@ -0,0 +1,74 @@ +package pc.exam.pp.module.judgement.utils.wps_pptx; + +import org.apache.xmlbeans.XmlCursor; +import org.apache.xmlbeans.XmlObject; + + +public class SlideAnimationQueryByCursor { + + public static String getAnimationInfoForSpid(XmlCursor cursor, String spid, String infoType) { + cursor.toStartDoc(); + cursor.selectPath("declare namespace p='http://schemas.openxmlformats.org/presentationml/2006/main' " + + "declare namespace a='http://schemas.openxmlformats.org/drawingml/2006/main' " + + "declare namespace r='http://schemas.openxmlformats.org/officeDocument/2006/relationships' " + + "$this//p: "); + + while (cursor.toNextSelection()) { + XmlObject spTgtObj = cursor.getObject(); + XmlCursor spTgtCursor = spTgtObj.newCursor(); + String spidAttr = spTgtCursor.getAttributeText(new javax.xml.namespace.QName("", "spid")); + if (!spid.equals(spidAttr)) continue; + + // 当前 spTgt 的祖先就是动画节点(通常为 anim, set, 或 cTn) + XmlCursor animCursor = spTgtObj.newCursor(); + animCursor.toParent(); // tgtEl + animCursor.toParent(); // anim, set, etc. + + String tag = animCursor.getName().getLocalPart(); + String dur = animCursor.getAttributeText(new javax.xml.namespace.QName("", "dur")); + String presetClass = animCursor.getAttributeText(new javax.xml.namespace.QName("", "presetClass")); + + switch (infoType) { + case "效果": + return (presetClass != null && !presetClass.isEmpty()) ? presetClass : tag; + + case "方向": + // 查找 + cursor.toStartDoc(); + cursor.selectPath("declare namespace p='http://schemas.openxmlformats.org/presentationml/2006/main' " + + "$this//p:pull"); + while (cursor.toNextSelection()) { + String dir = cursor.getAttributeText(new javax.xml.namespace.QName("", "dir")); + if (dir != null) return dir; + } + return "无方向设置"; + + case "触发方式": + animCursor.selectPath("declare namespace p='http://schemas.openxmlformats.org/presentationml/2006/main' " + + "$this/p:stCondLst/p:cond"); + while (animCursor.toNextSelection()) { + String evt = animCursor.getAttributeText(new javax.xml.namespace.QName("", "evt")); + String delay = animCursor.getAttributeText(new javax.xml.namespace.QName("", "delay")); + if (evt != null) return evt; + if (delay != null) return "延迟:" + delay; + } + return "无触发信息"; + + case "持续时间": + if (dur != null) return dur + " ms"; + // 也许 有 dur + animCursor.selectPath("declare namespace p='http://schemas.openxmlformats.org/presentationml/2006/main' " + + "$this//p:cTn"); + while (animCursor.toNextSelection()) { + String d = animCursor.getAttributeText(new javax.xml.namespace.QName("", "dur")); + if (d != null) return d + " ms"; + } + return "无持续时间信息"; + + default: + return "不支持的查询类型:" + infoType; + } + } + return "未找到 spid=" + spid + " 的动画"; + } +} \ No newline at end of file diff --git a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/wps_pptx/WpsPptxUtils.java b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/wps_pptx/WpsPptxUtils.java index 0a1dc13a..d5c20ed6 100644 --- a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/wps_pptx/WpsPptxUtils.java +++ b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/wps_pptx/WpsPptxUtils.java @@ -1,7 +1,12 @@ package pc.exam.pp.module.judgement.utils.wps_pptx; +import org.apache.commons.io.IOUtils; +import org.apache.poi.openxml4j.exceptions.InvalidFormatException; +import org.apache.poi.openxml4j.opc.OPCPackage; +import org.apache.poi.openxml4j.opc.PackagePart; import org.apache.poi.xslf.usermodel.XMLSlideShow; import org.apache.poi.xslf.usermodel.XSLFSlide; +import org.apache.poi.xwpf.usermodel.XWPFDocument; import org.apache.xmlbeans.XmlCursor; import org.apache.xmlbeans.XmlException; import org.apache.xmlbeans.XmlObject; @@ -23,6 +28,8 @@ import javax.xml.namespace.QName; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; +import java.io.InputStream; +import java.nio.charset.StandardCharsets; import java.util.*; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -41,40 +48,43 @@ public class WpsPptxUtils { List pptxSlidesOrgVos = new ArrayList<>(); // 获取所有相关res得记录 List> slideList = new ArrayList<>(); - try (ZipFile zipFile = new ZipFile(filePath)) { - Enumeration entries = zipFile.entries(); - while (entries.hasMoreElements()) { - ZipEntry entry = entries.nextElement(); - String entryName = entry.getName(); - if (entryName.startsWith("ppt/slides/_rels") && entryName.endsWith(".xml.rels")) { - PptxSlidesVo pptxSlidesVo = new PptxSlidesVo(); - String[] names = entryName.split("/"); - pptxSlidesVo.setSlideName(names[entryName.split("/").length-1]); - String xmlContent = ZipXmlUtils.readZipEntry(zipFile, entryName); - XmlObject xmlObject = XmlObject.Factory.parse(xmlContent); - XmlCursor cursor = xmlObject.newCursor(); - cursor.selectPath("declare namespace r='http://schemas.openxmlformats.org/package/2006/relationships' .//r:Relationships/r:Relationship"); - // 存放数据 - while (cursor.toNextSelection()) { - Map map = new HashMap<>(); - String rId = cursor.getAttributeText(new QName("Id")); - String target = cursor.getAttributeText(new QName("Target")); - map.put(rId, target); - slideList.add(map); + try (OPCPackage pkg = OPCPackage.open(filePath)) { + for (PackagePart part : pkg.getParts()) { + String entryName = part.getPartName().getName(); + if (entryName.contains("ppt/slides/_rels") && entryName.contains(".xml.rels")) { + try (InputStream is = part.getInputStream()) { + String xmlContent = IOUtils.toString(is, StandardCharsets.UTF_8); + PptxSlidesVo pptxSlidesVo = new PptxSlidesVo(); + String[] names = entryName.split("/"); + pptxSlidesVo.setSlideName(names[entryName.split("/").length-1]); + XmlObject xmlObject = XmlObject.Factory.parse(xmlContent); + XmlCursor cursor = xmlObject.newCursor(); + cursor.selectPath("declare namespace r='http://schemas.openxmlformats.org/package/2006/relationships' .//r:Relationships/r:Relationship"); + // 存放数据 + while (cursor.toNextSelection()) { + Map map = new HashMap<>(); + String rId = cursor.getAttributeText(new QName("Id")); + String target = cursor.getAttributeText(new QName("Target")); + map.put(rId, target); + slideList.add(map); + } + pptxSlidesVo.setSlideResList(slideList); + pptxSlidesOrgVos.add(pptxSlidesVo); } - pptxSlidesVo.setSlideResList(slideList); - pptxSlidesOrgVos.add(pptxSlidesVo); } - if (entryName.startsWith("ppt/slides") && entryName.endsWith(".xml") && !entryName.contains(".rels")) { - String[] names = entryName.split("/"); - Optional result = pptxSlidesOrgVos.stream().filter(pptxSlidesVo -> pptxSlidesVo.getSlideName().contains(names[entryName.split("/").length-1])).findFirst(); - PptxSlidesVo pptxSlidesVo = result.get(); - pptxSlidesVo.setSlideName(names[entryName.split("/").length-1]); - String xmlContent = ZipXmlUtils.readZipEntry(zipFile, entryName); - XmlObject xmlObject = XmlObject.Factory.parse(xmlContent); - XmlCursor cursor = xmlObject.newCursor(); - pptxSlidesVo.setXmlCursor(cursor); - pptxSlidesVos.add(pptxSlidesVo); + if (entryName.contains("ppt/slides") && entryName.contains(".xml") && !entryName.contains(".rels")) { + try (InputStream is = part.getInputStream()) { + String xmlContent = IOUtils.toString(is, StandardCharsets.UTF_8); + String[] names = entryName.split("/"); + Optional result = pptxSlidesOrgVos.stream().filter(pptxSlidesVo -> pptxSlidesVo.getSlideName().contains(names[entryName.split("/").length-1])).findFirst(); + PptxSlidesVo pptxSlidesVo = result.get(); + pptxSlidesVo.setSlideName(names[entryName.split("/").length-1]); + XmlObject xmlObject = XmlObject.Factory.parse(xmlContent); + XmlCursor cursor = xmlObject.newCursor(); + pptxSlidesVo.setXmlCursor(cursor); + pptxSlidesVos.add(pptxSlidesVo); + } + } } for (PptxInfoPointsVo pptxInfoPointsVo : pptxInfoPointsVos) { @@ -86,99 +96,153 @@ public class WpsPptxUtils { String namespace = WpsPptxNameSpaces.getNameSpace(slideCursor.xmlText()); if (pptxInfoPointsVo.getName().contains("动画")) { String[] functions = pptxInfoPointsVo.getFunction().split("#"); + String functionStr = functions[0]; + if (pptxInfoPointsVo.getFunction().contains("pic")) { + functionStr = functionStr.replace("nvSpPr", "nvPicPr"); + } XmlCursor dongCursor = slideCursor; XmlCursor cTnCursor = slideCursor; - dongCursor.selectPath(namespace + functions[0]); + dongCursor.selectPath(namespace + functionStr); if (dongCursor.toNextSelection()) { String number = dongCursor.getTextValue(); cTnCursor.selectPath(namespace + "//p:cTn[@id='"+number+"']"); if (cTnCursor.toNextSelection()) { System.out.println(cTnCursor.xmlText()); if (pptxInfoPointsVo.getName().contains("效果")) { - cTnCursor.selectPath(namespace + "//p:animEffect"); - if (cTnCursor.toNextSelection()) { - String value = ""; - String transition = cTnCursor.getAttributeText(new QName("transition")); - String filter = cTnCursor.getAttributeText(new QName("filter")); + if (pptxInfoPointsVo.getFunction().contains("pic")) { + String results = SlideAnimationQueryByCursor.getAnimationInfoForSpid(cTnCursor, number, "效果"); WpsPptxJudgementDto judgementDto = new WpsPptxJudgementDto(); - if (transition.contains("in")) { - value += "进入效果"; - } - if (filter.contains("strips")) { - value += "->阶梯状"; - } - judgementDto.setContentIn(getStringName(pptxInfoPointsVo.getEnglishName()) + pptxInfoPointsVo.getName() + value); - judgementDto.setContent(pptxInfoPointsVo.getEnglishName()+"?"+pptxInfoPointsVo.getFunction()+"?"+ value); + judgementDto.setContentIn(getStringName(pptxInfoPointsVo.getEnglishName()) + pptxInfoPointsVo.getName() + results); + judgementDto.setContent(pptxInfoPointsVo.getEnglishName()+"?"+pptxInfoPointsVo.getFunction()+"?"+ results); judgementDto.setImage(pptxInfoPointsVo.getType()+"-"+pptxInfoPointsVo.getBelongTo()+"-"+pptxInfoPointsVo.getIsboo()+"-"+pptxInfoPointsVo.getUnit()); judgementDto.setScoreRate("1"); judgementList.add(judgementDto); + } else { + cTnCursor.selectPath(namespace + "//p:animEffect"); + if (cTnCursor.toNextSelection()) { + String value = ""; + String transition = cTnCursor.getAttributeText(new QName("transition")); + String filter = cTnCursor.getAttributeText(new QName("filter")); + WpsPptxJudgementDto judgementDto = new WpsPptxJudgementDto(); + if (transition.contains("in")) { + value += "进入效果"; + } + if (filter.contains("strips")) { + value += "->阶梯状"; + } + judgementDto.setContentIn(getStringName(pptxInfoPointsVo.getEnglishName()) + pptxInfoPointsVo.getName() + value); + judgementDto.setContent(pptxInfoPointsVo.getEnglishName()+"?"+pptxInfoPointsVo.getFunction()+"?"+ value); + judgementDto.setImage(pptxInfoPointsVo.getType()+"-"+pptxInfoPointsVo.getBelongTo()+"-"+pptxInfoPointsVo.getIsboo()+"-"+pptxInfoPointsVo.getUnit()); + judgementDto.setScoreRate("1"); + judgementList.add(judgementDto); + } } } if (pptxInfoPointsVo.getName().contains("方向")) { cTnCursor.selectPath(namespace + "//p:animEffect"); - if (cTnCursor.toNextSelection()) { - String value = ""; - String filter = cTnCursor.getAttributeText(new QName("filter")); + if (pptxInfoPointsVo.getFunction().contains("pic")) { + String results = SlideAnimationQueryByCursor.getAnimationInfoForSpid(cTnCursor, number, "方向"); WpsPptxJudgementDto judgementDto = new WpsPptxJudgementDto(); - if (filter.contains("downRight")) { - value += "右下"; - } - judgementDto.setContentIn(getStringName(pptxInfoPointsVo.getEnglishName()) + pptxInfoPointsVo.getName() + value); - judgementDto.setContent(pptxInfoPointsVo.getEnglishName()+"?"+pptxInfoPointsVo.getFunction()+"?"+ value); + judgementDto.setContentIn(getStringName(pptxInfoPointsVo.getEnglishName()) + pptxInfoPointsVo.getName() + results); + judgementDto.setContent(pptxInfoPointsVo.getEnglishName()+"?"+pptxInfoPointsVo.getFunction()+"?"+ results); judgementDto.setImage(pptxInfoPointsVo.getType()+"-"+pptxInfoPointsVo.getBelongTo()+"-"+pptxInfoPointsVo.getIsboo()+"-"+pptxInfoPointsVo.getUnit()); judgementDto.setScoreRate("1"); judgementList.add(judgementDto); + } else { + if (cTnCursor.toNextSelection()) { + String value = ""; + String filter = cTnCursor.getAttributeText(new QName("filter")); + WpsPptxJudgementDto judgementDto = new WpsPptxJudgementDto(); + if (filter.contains("downRight")) { + value += "右下"; + } + if (filter.contains("plus(out)")) { + value += "十字形扩展"; + } + if (filter.contains("plus(in)")) { + value += "十字形聚合"; + } + if (filter.contains("blinds(vertical)")) { + value += "百叶窗 - 垂直"; + } + if (filter.contains("blinds(horizontal)")) { + value += "百叶窗 - 水平"; + } + if (filter.contains("circle(in)")) { + value += "圆形聚焦进入"; + } + if (filter.contains("circle(out)")) { + value += "圆形扩散"; + } + if (filter.contains("diamond(out)")) { + value += "菱形扩散"; + } + judgementDto.setContentIn(getStringName(pptxInfoPointsVo.getEnglishName()) + pptxInfoPointsVo.getName() + value); + judgementDto.setContent(pptxInfoPointsVo.getEnglishName()+"?"+pptxInfoPointsVo.getFunction()+"?"+ value); + judgementDto.setImage(pptxInfoPointsVo.getType()+"-"+pptxInfoPointsVo.getBelongTo()+"-"+pptxInfoPointsVo.getIsboo()+"-"+pptxInfoPointsVo.getUnit()); + judgementDto.setScoreRate("1"); + judgementList.add(judgementDto); + } } } if (pptxInfoPointsVo.getName().contains("触发方式")) { - cTnCursor.selectPath(namespace + "//p:stCondLst/p:cond"); - if (cTnCursor.toNextSelection()) { - String value = ""; - String evt = cTnCursor.getAttributeText(new QName("evt")); - if (evt == null) { - value = "上一动画之后"; - } else if (evt.contains("onClick")) { - value = "点击触发"; - } else if (evt.contains("onBegin")) { - value = "与上一动画同时触发"; - } else if (evt.contains("onEnd")) { - value = "上一个动画播放完再触发"; - } + if (pptxInfoPointsVo.getFunction().contains("pic")) { + String results = SlideAnimationQueryByCursor.getAnimationInfoForSpid(cTnCursor, number, "触发方式"); WpsPptxJudgementDto judgementDto = new WpsPptxJudgementDto(); - judgementDto.setContentIn(getStringName(pptxInfoPointsVo.getEnglishName()) + pptxInfoPointsVo.getName() + value); - judgementDto.setContent(pptxInfoPointsVo.getEnglishName()+"?"+pptxInfoPointsVo.getFunction()+"?"+ value); + judgementDto.setContentIn(getStringName(pptxInfoPointsVo.getEnglishName()) + pptxInfoPointsVo.getName() + results); + judgementDto.setContent(pptxInfoPointsVo.getEnglishName()+"?"+pptxInfoPointsVo.getFunction()+"?"+ results); judgementDto.setImage(pptxInfoPointsVo.getType()+"-"+pptxInfoPointsVo.getBelongTo()+"-"+pptxInfoPointsVo.getIsboo()+"-"+pptxInfoPointsVo.getUnit()); judgementDto.setScoreRate("1"); judgementList.add(judgementDto); + } else { + } } if (pptxInfoPointsVo.getName().contains("持续时间")) { - cTnCursor.selectPath(namespace + "//p:animEffect/p:cBhvr/p:cTn"); - if (cTnCursor.toNextSelection()) { - String value = ""; - String dur = cTnCursor.getAttributeText(new QName("dur")); - if (dur == null) { - value = "0秒"; - } else { - value = String.valueOf((double) Integer.parseInt(dur) / 1000); - } + if (pptxInfoPointsVo.getFunction().contains("pic")) { + String results = SlideAnimationQueryByCursor.getAnimationInfoForSpid(cTnCursor, number, "持续时间"); WpsPptxJudgementDto judgementDto = new WpsPptxJudgementDto(); - judgementDto.setContentIn(getStringName(pptxInfoPointsVo.getEnglishName()) + pptxInfoPointsVo.getName() + value); - judgementDto.setContent(pptxInfoPointsVo.getEnglishName()+"?"+pptxInfoPointsVo.getFunction()+"?"+ value); + judgementDto.setContentIn(getStringName(pptxInfoPointsVo.getEnglishName()) + pptxInfoPointsVo.getName() + results); + judgementDto.setContent(pptxInfoPointsVo.getEnglishName()+"?"+pptxInfoPointsVo.getFunction()+"?"+ results); judgementDto.setImage(pptxInfoPointsVo.getType()+"-"+pptxInfoPointsVo.getBelongTo()+"-"+pptxInfoPointsVo.getIsboo()+"-"+pptxInfoPointsVo.getUnit()); judgementDto.setScoreRate("1"); judgementList.add(judgementDto); + } else { + cTnCursor.selectPath(namespace + "//p:animEffect/p:cBhvr/p:cTn"); + if (cTnCursor.toNextSelection()) { + String value = ""; + String dur = cTnCursor.getAttributeText(new QName("dur")); + if (dur == null) { + value = "0秒"; + } else { + value = String.valueOf((double) Integer.parseInt(dur) / 1000); + } + WpsPptxJudgementDto judgementDto = new WpsPptxJudgementDto(); + judgementDto.setContentIn(getStringName(pptxInfoPointsVo.getEnglishName()) + pptxInfoPointsVo.getName() + value); + judgementDto.setContent(pptxInfoPointsVo.getEnglishName()+"?"+pptxInfoPointsVo.getFunction()+"?"+ value); + judgementDto.setImage(pptxInfoPointsVo.getType()+"-"+pptxInfoPointsVo.getBelongTo()+"-"+pptxInfoPointsVo.getIsboo()+"-"+pptxInfoPointsVo.getUnit()); + judgementDto.setScoreRate("1"); + judgementList.add(judgementDto); + } } } } } } else if (pptxInfoPointsVo.getUnit().contains("Filling_method")) { // 查询 + XmlCursor otherSlideCurors = slideCursor.newCursor(); slideCursor.selectPath(namespace + pptxInfoPointsVo.getFunction().replace("-", "")); // 判断填充方式的 if (slideCursor.toNextSelection()) { String value = slideCursor.xmlText(); value = getValueType(pptxInfoPointsVo, value); + if (value.contains("未知填充")) { + otherSlideCurors.selectPath(namespace + pptxInfoPointsVo.getFunction().split("]")[0] + "]/p:txBody"); + if (otherSlideCurors.toNextSelection()) { + value = otherSlideCurors.xmlText(); + value = getValueType(pptxInfoPointsVo, value); + } + } WpsPptxJudgementDto judgementDto = new WpsPptxJudgementDto(); judgementDto.setContentIn(getStringName(pptxInfoPointsVo.getEnglishName()) + pptxInfoPointsVo.getName() + value); judgementDto.setContent(pptxInfoPointsVo.getEnglishName()+"?"+pptxInfoPointsVo.getFunction()+"?"+ value); @@ -198,6 +262,47 @@ public class WpsPptxUtils { judgementDto.setScoreRate("1"); judgementList.add(judgementDto); } + } else if (pptxInfoPointsVo.getName().contains("纯色填充-颜色")) { + String[] functionList = pptxInfoPointsVo.getFunction().split("#"); + slideCursor.selectPath(namespace + functionList[0]); + String english = functionList[0].split("]")[0] + "]"; + if (slideCursor.toNextSelection()) { + String value = slideCursor.getTextValue(); + WpsPptxJudgementDto judgementDto = new WpsPptxJudgementDto(); + judgementDto.setContentIn(getStringName(pptxInfoPointsVo.getEnglishName()) + pptxInfoPointsVo.getName() + value); + judgementDto.setContent(pptxInfoPointsVo.getEnglishName()+"?"+pptxInfoPointsVo.getFunction()+"?"+ value); + judgementDto.setImage(pptxInfoPointsVo.getType()+"-"+pptxInfoPointsVo.getBelongTo()+"-"+pptxInfoPointsVo.getIsboo()+"-"+pptxInfoPointsVo.getUnit()); + judgementDto.setScoreRate("1"); + judgementList.add(judgementDto); + } else { + slideCursor.selectPath(namespace + english + functionList[1]); + if (slideCursor.toNextSelection()) { + String value = slideCursor.getTextValue(); + WpsPptxJudgementDto judgementDto = new WpsPptxJudgementDto(); + judgementDto.setContentIn(getStringName(pptxInfoPointsVo.getEnglishName()) + pptxInfoPointsVo.getName() + value); + judgementDto.setContent(pptxInfoPointsVo.getEnglishName()+"?"+pptxInfoPointsVo.getFunction()+"?"+ value); + judgementDto.setImage(pptxInfoPointsVo.getType()+"-"+pptxInfoPointsVo.getBelongTo()+"-"+pptxInfoPointsVo.getIsboo()+"-"+pptxInfoPointsVo.getUnit()); + judgementDto.setScoreRate("1"); + judgementList.add(judgementDto); + } + } + } else if (pptxInfoPointsVo.getName().contains("锁定横纵比")) { + slideCursor.selectPath(namespace + pptxInfoPointsVo.getFunction().replace("-", "")); + String value = ""; + if (slideCursor.toNextSelection()) { + System.out.println(slideCursor.xmlText()); + String values = slideCursor.getTextValue(); + value = values.equals("1") ? "是" : "否"; + } else { + // 没有查询到说明没有 + value = "否"; + } + WpsPptxJudgementDto judgementDto = new WpsPptxJudgementDto(); + judgementDto.setContentIn(getStringName(pptxInfoPointsVo.getEnglishName()) + pptxInfoPointsVo.getName() + value); + judgementDto.setContent(pptxInfoPointsVo.getEnglishName()+"?"+pptxInfoPointsVo.getFunction()+"?"+ value); + judgementDto.setImage(pptxInfoPointsVo.getType()+"-"+pptxInfoPointsVo.getBelongTo()+"-"+pptxInfoPointsVo.getIsboo()+"-"+pptxInfoPointsVo.getUnit()); + judgementDto.setScoreRate("1"); + judgementList.add(judgementDto); } else { slideCursor.selectPath(namespace + pptxInfoPointsVo.getFunction().replace("-", "")); if (slideCursor.toNextSelection()) { @@ -228,6 +333,7 @@ public class WpsPptxUtils { } } } + // 单个幻灯片设置 if ("1".equals(pptxInfoPointsVo.getBelongTo())) { Optional result = pptxSlidesVos.stream().filter(pptxSlidesVo -> pptxSlidesVo.getSlideName().contains(pptxInfoPointsVo.getEnglishName())).findFirst(); PptxSlidesVo pptxSlidesVo = result.get(); @@ -247,27 +353,93 @@ public class WpsPptxUtils { judgementDto.setScoreRate("1"); judgementList.add(judgementDto); } + } else if (pptxInfoPointsVo.getName().contains("幻灯片切换")){ + if (pptxInfoPointsVo.getName().contains("切换效果")) { + slideCursor.selectPath(namespace + "./" + pptxInfoPointsVo.getFunction().split("]")[1]); + if (slideCursor.toNextSelection()) { + String value = slideCursor.xmlText(); + if (value.contains("p:fade")) { + value = "淡入淡出"; + } else if (value.contains("p:push")) { + value = "推入"; + } else if (value.contains("p:wipe")) { + value = " 擦除"; + } else if (value.contains("p:split")) { + value = "分割"; + }else if (value.contains("p:cut")) { + value = "瞬间切换(无动画)"; + } else if (value.contains("p:random")) { + value = " 随机一种切换效果"; + } else if (value.contains("p:pull")) { + value = "拉出"; + } + WpsPptxJudgementDto judgementDto = new WpsPptxJudgementDto(); + judgementDto.setContentIn(getStringName(pptxInfoPointsVo.getEnglishName()) + pptxInfoPointsVo.getName() + value); + judgementDto.setContent(pptxInfoPointsVo.getEnglishName()+"?"+pptxInfoPointsVo.getFunction()+"?"+ value); + judgementDto.setImage(pptxInfoPointsVo.getType()+"-"+pptxInfoPointsVo.getBelongTo()+"-"+pptxInfoPointsVo.getIsboo()+"-"+pptxInfoPointsVo.getUnit()); + judgementDto.setScoreRate("1"); + judgementList.add(judgementDto); + } + } + if (pptxInfoPointsVo.getName().contains("切换声音")) { + slideCursor.selectPath(namespace + "./" + pptxInfoPointsVo.getFunction().split("]")[1]); + if (slideCursor.toNextSelection()) { + String value = slideCursor.getTextValue(); + if (value.contains("wind.wav")) { + value = "风声"; + } else if (value.contains("water.wav")) { + value = "水声"; + } else if (value.contains("fire.wav")) { + value = "火声"; + } else if (value.contains("thunder.wav")) { + value = "雷声"; + } else if (value.contains("applause.wav")) { + value = "掌声"; + } + WpsPptxJudgementDto judgementDto = new WpsPptxJudgementDto(); + judgementDto.setContentIn(getStringName(pptxInfoPointsVo.getEnglishName()) + pptxInfoPointsVo.getName() + value); + judgementDto.setContent(pptxInfoPointsVo.getEnglishName()+"?"+pptxInfoPointsVo.getFunction()+"?"+ value); + judgementDto.setImage(pptxInfoPointsVo.getType()+"-"+pptxInfoPointsVo.getBelongTo()+"-"+pptxInfoPointsVo.getIsboo()+"-"+pptxInfoPointsVo.getUnit()); + judgementDto.setScoreRate("1"); + judgementList.add(judgementDto); + } + } +// if (pptxInfoPointsVo.getName().contains("单机鼠标换片")) { +// +// } + if (pptxInfoPointsVo.getName().contains("换片间隔时间")){ + slideCursor.selectPath(namespace + "./" + pptxInfoPointsVo.getFunction().split("]")[1]); + if (slideCursor.toNextSelection()) { + String value = slideCursor.getTextValue(); + int values = Integer.parseInt(value) / 1000; + WpsPptxJudgementDto judgementDto = new WpsPptxJudgementDto(); + judgementDto.setContentIn(getStringName(pptxInfoPointsVo.getEnglishName()) + pptxInfoPointsVo.getName() + values); + judgementDto.setContent(pptxInfoPointsVo.getEnglishName()+"?"+pptxInfoPointsVo.getFunction()+"?"+ values); + judgementDto.setImage(pptxInfoPointsVo.getType()+"-"+pptxInfoPointsVo.getBelongTo()+"-"+pptxInfoPointsVo.getIsboo()+"-"+pptxInfoPointsVo.getUnit()); + judgementDto.setScoreRate("1"); + judgementList.add(judgementDto); + } + } } } + // 幻灯片设置 if ("2".equals(pptxInfoPointsVo.getBelongTo())) { XmlCursor presentationcursor = null; String namespace = ""; - Enumeration entriess = zipFile.entries(); - while (entriess.hasMoreElements()) { - ZipEntry entry = entriess.nextElement(); - String entryName = entry.getName(); - if (entryName.startsWith("ppt/presentation") && entryName.endsWith(".xml")) { - String xmlContent = ZipXmlUtils.readZipEntry(zipFile, entryName); - XmlObject xmlObject = XmlObject.Factory.parse(xmlContent); - presentationcursor = xmlObject.newCursor(); - namespace = WpsPptxNameSpaces.getNameSpace(presentationcursor.xmlText()); + for (PackagePart part : pkg.getParts()) { + String entryName = part.getPartName().getName(); + if (entryName.contains("ppt/presentation") && entryName.contains(".xml")) { + try (InputStream is = part.getInputStream()) { + String xmlContent = IOUtils.toString(is, StandardCharsets.UTF_8); + XmlObject xmlObject = XmlObject.Factory.parse(xmlContent); + presentationcursor = xmlObject.newCursor(); + namespace = WpsPptxNameSpaces.getNameSpace(presentationcursor.xmlText()); + } } } - if ("1".equals(pptxInfoPointsVo.getType())) { // 如果是外参数 if (pptxInfoPointsVo.getName().contains("幻灯片大小")) { - System.out.println(presentationcursor.xmlText()); presentationcursor.selectPath(namespace + "//p:presentation/p:sldSz"); if (presentationcursor.toNextSelection()) { String value = PageSizeDetector.detectPaperPPTSize(presentationcursor.xmlText()); @@ -279,6 +451,42 @@ public class WpsPptxUtils { judgementList.add(judgementDto); } } + if (pptxInfoPointsVo.getName().contains("放映类型")) { + presentationcursor.selectPath(namespace + "//p:presentation/p:showPr"); + if (presentationcursor.toNextSelection()) { + System.out.println("放映类型" + presentationcursor.xmlText()); + } else { + // 如果没有标签的话说明是默认的ppt方式 + String value = "演示者放映(全屏)"; + WpsPptxJudgementDto judgementDto = new WpsPptxJudgementDto(); + judgementDto.setContentIn(getStringName(pptxInfoPointsVo.getEnglishName()) + pptxInfoPointsVo.getName() +value); + judgementDto.setContent(pptxInfoPointsVo.getEnglishName()+"?"+pptxInfoPointsVo.getFunction()+"?"+ value); + judgementDto.setImage(pptxInfoPointsVo.getType()+"-"+pptxInfoPointsVo.getBelongTo()+"-"+pptxInfoPointsVo.getIsboo()+"-"+pptxInfoPointsVo.getUnit()); + judgementDto.setScoreRate("1"); + judgementList.add(judgementDto); + } + } + if (pptxInfoPointsVo.getName().contains("放映范围")) { + presentationcursor.selectPath(namespace + "//p:presentation/p:showPr"); + if (presentationcursor.toNextSelection()) { + System.out.println("放映范围" + presentationcursor.xmlText()); + } else { + // 说明全页面放映,查询有多少页 + presentationcursor.selectPath(namespace + "//p:presentation/p:sldIdLst/p:sldId"); + int count = 0; + String value = ""; + while (presentationcursor.toNextSelection()) { + count ++; + value += "第" + count + "页 "; + } + WpsPptxJudgementDto judgementDto = new WpsPptxJudgementDto(); + judgementDto.setContentIn(getStringName(pptxInfoPointsVo.getEnglishName()) + pptxInfoPointsVo.getName() + value); + judgementDto.setContent(pptxInfoPointsVo.getEnglishName()+"?"+pptxInfoPointsVo.getFunction()+"?"+ value); + judgementDto.setImage(pptxInfoPointsVo.getType()+"-"+pptxInfoPointsVo.getBelongTo()+"-"+pptxInfoPointsVo.getIsboo()+"-"+pptxInfoPointsVo.getUnit()); + judgementDto.setScoreRate("1"); + judgementList.add(judgementDto); + } + } } } } @@ -287,9 +495,12 @@ public class WpsPptxUtils { e.printStackTrace(); } catch (XmlException e) { throw new RuntimeException(e); + } catch (InvalidFormatException e) { + throw new RuntimeException(e); } return judgementList; } + public static String getValueType(PptxInfoPointsVo pptxInfoPointsVo, String value) { String values = value; if (pptxInfoPointsVo.getUnit().contains("twiptopt")) { @@ -350,6 +561,8 @@ public class WpsPptxUtils { values = "图案填充"; } else if (value.contains("blipFill")) { values = "图片填充"; + } else { + values = "未知填充"; } } return values;