mirror of
https://codeup.aliyun.com/67762337eccfc218f6110e0e/per-boe/java-servers.git
synced 2025-12-08 02:16:49 +08:00
提交修改
This commit is contained in:
@@ -5,11 +5,16 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.xboe.module.scorm.cam.load.SCORMPackageManager;
|
||||
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.Organization;
|
||||
import com.xboe.module.scorm.cam.model.Resource;
|
||||
import com.xboe.module.scorm.cam.model.datatype.IDRef;
|
||||
import com.xboe.module.scorm.data.ScoItem;
|
||||
|
||||
/**
|
||||
@@ -18,27 +23,94 @@ import com.xboe.module.scorm.data.ScoItem;
|
||||
public class SCORMParser {
|
||||
|
||||
public String parserToJson(String path) throws Exception {
|
||||
System.out.println("test");
|
||||
// System.out.println("test");
|
||||
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();
|
||||
System.out.println(cp.getManifest().getIdentifier());
|
||||
System.out.println(cp.getContent());
|
||||
// System.out.println(cp.getManifest().getIdentifier());
|
||||
// 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());
|
||||
for(Resource res : cp.getManifest().getResources().getResourceList()) {
|
||||
System.out.println(res.getHref());
|
||||
// System.out.println("title="+cp.getManifest().getOrganizations().getOrganizationList().get(0).getTitle());
|
||||
// for(Resource res : cp.getManifest().getResources().getResourceList()) {
|
||||
// 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的版本
|
||||
jsonMap.put("schema",manifest.getMetadata().getSchema());
|
||||
jsonMap.put("version",manifest.getMetadata().getSchemaVersion());
|
||||
jsonMap.put("items", items);//sco共有多少个
|
||||
jsonMap.put("index", "");//打开播放时进入的第一个sco
|
||||
jsonMap.put("items", scoItems);//sco共有多少个
|
||||
//jsonMap.put("index", "");//打开播放时进入的第一个sco
|
||||
|
||||
ObjectMapper om=new ObjectMapper();
|
||||
String json=om.writeValueAsString(jsonMap);
|
||||
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();
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
import org.dom4j.Attribute;
|
||||
import org.dom4j.Document;
|
||||
import org.dom4j.DocumentException;
|
||||
import org.dom4j.Element;
|
||||
@@ -452,11 +453,10 @@ public class ContentPackageGenerator {
|
||||
private void parseResources(Element resourcesNode) {
|
||||
if (resourcesNode != null) {
|
||||
Resources resources = new Resources();
|
||||
String base = resourcesNode.attributeValue(
|
||||
rootQNameGenerator.xml("base", resourcesNode.getNamespace()));
|
||||
String base = resourcesNode.attributeValue(rootQNameGenerator.xml("base", resourcesNode.getNamespace()));
|
||||
resources.setXmlBase(base == null ? null : new AnyURI(base));
|
||||
resourcesNode.elements(rootQNameGenerator.imscp("resource"))
|
||||
.forEach(element -> parseResource(resources, (Element) element));
|
||||
resourcesNode.elements(rootQNameGenerator.imscp("resource")).forEach(element -> parseResource(resources, (Element) element));
|
||||
//resourcesNode.elements("resource").forEach(element -> parseResource(resources, (Element) element));
|
||||
contentPackage.getManifest().setResources(resources);
|
||||
}
|
||||
}
|
||||
@@ -465,13 +465,32 @@ public class ContentPackageGenerator {
|
||||
if (resourceNode != null) {
|
||||
Resource resource = new Resource();
|
||||
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.setType(resourceNode.attributeValue(rootQNameGenerator.imscp("type", pns)));
|
||||
resource.setHref(resourceNode.attributeValue(rootQNameGenerator.imscp("href", pns)));
|
||||
String base = resourceNode.attributeValue(rootQNameGenerator.xml("base", pns));
|
||||
//resource.setType(resourceNode.attributeValue(rootQNameGenerator.imscp("type", pns)));
|
||||
resource.setType(resourceNode.attributeValue(rootQNameGenerator.imscp("type")));
|
||||
//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.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 qNameForDependency = rootQNameGenerator.imscp("dependency");
|
||||
for (Object obj : resourceNode.elements()) {
|
||||
|
||||
Reference in New Issue
Block a user