提交修改

This commit is contained in:
daihh
2022-12-12 13:41:11 +08:00
parent c9985d211e
commit 83a6e2a22d
2 changed files with 110 additions and 19 deletions

View File

@@ -5,11 +5,16 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.apache.commons.lang3.StringUtils;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.xboe.module.scorm.cam.load.SCORMPackageManager; import com.xboe.module.scorm.cam.load.SCORMPackageManager;
import com.xboe.module.scorm.cam.model.ContentPackage; import com.xboe.module.scorm.cam.model.ContentPackage;
import com.xboe.module.scorm.cam.model.Item;
import com.xboe.module.scorm.cam.model.Manifest; import com.xboe.module.scorm.cam.model.Manifest;
import com.xboe.module.scorm.cam.model.Organization;
import com.xboe.module.scorm.cam.model.Resource; import com.xboe.module.scorm.cam.model.Resource;
import com.xboe.module.scorm.cam.model.datatype.IDRef;
import com.xboe.module.scorm.data.ScoItem; import com.xboe.module.scorm.data.ScoItem;
/** /**
@@ -18,27 +23,94 @@ import com.xboe.module.scorm.data.ScoItem;
public class SCORMParser { public class SCORMParser {
public String parserToJson(String path) throws Exception { public String parserToJson(String path) throws Exception {
System.out.println("test"); // System.out.println("test");
Map<String,Object> jsonMap=new HashMap<String,Object>(); Map<String,Object> jsonMap=new HashMap<String,Object>();
ContentPackage cp=SCORMPackageManager.getInstance().loadSCORMContentPackageFromZipFile("1", "E:/Projects/BOEU/scorm/file/ContentPackagingOneFilePerSCO_SCORM12.zip"); ContentPackage cp=SCORMPackageManager.getInstance().loadSCORMContentPackageFromZipFile("1", path);
Manifest manifest= cp.getManifest(); Manifest manifest= cp.getManifest();
System.out.println(cp.getManifest().getIdentifier()); // System.out.println(cp.getManifest().getIdentifier());
System.out.println(cp.getContent()); // System.out.println(cp.getContent());
List<ScoItem> items=new ArrayList<ScoItem>(); List<ScoItem> scoItems=new ArrayList<ScoItem>();
System.out.println("title="+cp.getManifest().getOrganizations().getOrganizationList().get(0).getTitle()); // System.out.println("title="+cp.getManifest().getOrganizations().getOrganizationList().get(0).getTitle());
for(Resource res : cp.getManifest().getResources().getResourceList()) { // for(Resource res : cp.getManifest().getResources().getResourceList()) {
System.out.println(res.getHref()); // System.out.println(res.getHref());
// }
//提取组织菜单
IDRef ref = manifest.getOrganizations().getDefaultOrganizationID();
if(ref!=null){
jsonMap.put("defaultId", ref.getValue());//如果有多个组织目录,默认是的哪个
} }
List<Organization> orgList = manifest.getOrganizations().getOrganizationList();
for(Organization organ :orgList) {
for(Item item : organ.getItemList()) {
if(StringUtils.isNotBlank(item.getIdentifierref())) {
Resource res=findResource(manifest.getResources().getResourceList(),item.getIdentifierref());
if(res!=null) {
//if(res.getScormType().equals("sco")) {
ScoItem sco=new ScoItem();
sco.setId(item.getIdentifier().getValue());
sco.setTitle(item.getTitle());
sco.setScoId(res.getIdentifier().getValue());
sco.setScoUrl(res.getHref());
sco.setScoType(res.getScormType());
scoItems.add(sco);
//}
}
}else { //多个item 的处理
if(item.getItemList()!=null) {
for(Item subItem : item.getItemList()) {
Resource res=findResource(manifest.getResources().getResourceList(),subItem.getIdentifierref());
if(res!=null) {
//if(res.getScormType().equals("sco")) {
ScoItem sco=new ScoItem();
sco.setId(item.getIdentifier().getValue());
sco.setTitle(item.getTitle());
sco.setScoId(res.getIdentifier().getValue());
sco.setScoUrl(res.getHref());
sco.setScoType(res.getScormType());
scoItems.add(sco);
//}
}
}
}
}
}
}
//scorm的版本 //scorm的版本
jsonMap.put("schema",manifest.getMetadata().getSchema()); jsonMap.put("schema",manifest.getMetadata().getSchema());
jsonMap.put("version",manifest.getMetadata().getSchemaVersion()); jsonMap.put("version",manifest.getMetadata().getSchemaVersion());
jsonMap.put("items", items);//sco共有多少个 jsonMap.put("items", scoItems);//sco共有多少个
jsonMap.put("index", "");//打开播放时进入的第一个sco //jsonMap.put("index", "");//打开播放时进入的第一个sco
ObjectMapper om=new ObjectMapper(); ObjectMapper om=new ObjectMapper();
String json=om.writeValueAsString(jsonMap); String json=om.writeValueAsString(jsonMap);
return json; return json;
} }
private Resource findResource(List<Resource> resList,String identifier) {
for(Resource res : resList) {
if(res.getIdentifier().getValue().equals(identifier)) {
return res;
}
}
return null;
}
// public static void main(String[] args) {
// SCORMParser parser=new SCORMParser();
// //String path1="E:/Projects/BOEU/scorm/file/ContentPackagingOneFilePerSCO_SCORM12.zip";
// String path1="E:/Projects/BOEU/scorm/file/7a462dbee222ba62810191d2f512576e.zip";
// try {
// String json= parser.parserToJson(path1);
// System.out.println(json);
// } catch (Exception e) {
//
// e.printStackTrace();
// }
// }
} }

View File

@@ -6,6 +6,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
import org.dom4j.Attribute;
import org.dom4j.Document; import org.dom4j.Document;
import org.dom4j.DocumentException; import org.dom4j.DocumentException;
import org.dom4j.Element; import org.dom4j.Element;
@@ -452,11 +453,10 @@ public class ContentPackageGenerator {
private void parseResources(Element resourcesNode) { private void parseResources(Element resourcesNode) {
if (resourcesNode != null) { if (resourcesNode != null) {
Resources resources = new Resources(); Resources resources = new Resources();
String base = resourcesNode.attributeValue( String base = resourcesNode.attributeValue(rootQNameGenerator.xml("base", resourcesNode.getNamespace()));
rootQNameGenerator.xml("base", resourcesNode.getNamespace()));
resources.setXmlBase(base == null ? null : new AnyURI(base)); resources.setXmlBase(base == null ? null : new AnyURI(base));
resourcesNode.elements(rootQNameGenerator.imscp("resource")) resourcesNode.elements(rootQNameGenerator.imscp("resource")).forEach(element -> parseResource(resources, (Element) element));
.forEach(element -> parseResource(resources, (Element) element)); //resourcesNode.elements("resource").forEach(element -> parseResource(resources, (Element) element));
contentPackage.getManifest().setResources(resources); contentPackage.getManifest().setResources(resources);
} }
} }
@@ -465,13 +465,32 @@ public class ContentPackageGenerator {
if (resourceNode != null) { if (resourceNode != null) {
Resource resource = new Resource(); Resource resource = new Resource();
Namespace pns = resourceNode.getNamespace(); Namespace pns = resourceNode.getNamespace();
String id = resourceNode.attributeValue(rootQNameGenerator.imscp("identifier", pns)); //String id = resourceNode.attributeValue(rootQNameGenerator.imscp("identifier", pns));
String id = resourceNode.attributeValue(rootQNameGenerator.imscp("identifier"));
resource.setIdentifier(id == null ? null : new ID(id)); resource.setIdentifier(id == null ? null : new ID(id));
resource.setType(resourceNode.attributeValue(rootQNameGenerator.imscp("type", pns))); //resource.setType(resourceNode.attributeValue(rootQNameGenerator.imscp("type", pns)));
resource.setHref(resourceNode.attributeValue(rootQNameGenerator.imscp("href", pns))); resource.setType(resourceNode.attributeValue(rootQNameGenerator.imscp("type")));
String base = resourceNode.attributeValue(rootQNameGenerator.xml("base", pns)); //resource.setHref(resourceNode.attributeValue(rootQNameGenerator.imscp("href", pns)));
resource.setHref(resourceNode.attributeValue(rootQNameGenerator.imscp("href")));
//String base = resourceNode.attributeValue(rootQNameGenerator.xml("base", pns));
String base = resourceNode.attributeValue(rootQNameGenerator.xml("base"));
resource.setXmlBase(base == null ? null : new AnyURI(base)); resource.setXmlBase(base == null ? null : new AnyURI(base));
resource.setScormType(resourceNode.attributeValue(rootQNameGenerator.adlcp("scormType", pns))); //resource.setScormType(resourceNode.attributeValue(rootQNameGenerator.adlcp("scormtype", pns)));
resource.setScormType(resourceNode.attributeValue(rootQNameGenerator.adlcp("scormtype")));
// String scormType=rootQNameGenerator.adlcp("scormType");
// //使用此方法无法获取到value值
// //resource.setScormType(resourceNode.attributeValue(scormType));
// //改成这样查询获取
// List<Attribute> attrList=resourceNode.attributes();
// for(Attribute attr :attrList){
// System.out.println(attr.getName()+"="+attr.getValue());
// if(attr.getName().equalsIgnoreCase·(scormType)) {
// resource.setScormType(attr.getValue());
// }
// }
String qNameForFile = rootQNameGenerator.imscp("file"); String qNameForFile = rootQNameGenerator.imscp("file");
String qNameForDependency = rootQNameGenerator.imscp("dependency"); String qNameForDependency = rootQNameGenerator.imscp("dependency");
for (Object obj : resourceNode.elements()) { for (Object obj : resourceNode.elements()) {