-
Notifications
You must be signed in to change notification settings - Fork 4
/
ScormContentParser.js
97 lines (76 loc) · 3.96 KB
/
ScormContentParser.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/**
* Created by thihara on 11/2/16.
*/
/**
* Created by thihara on 11/1/16.
*/
let xmldoc = require('xmldoc'),
ScormModel = require('./Model'),
ScormResource = ScormModel.ScormResource,
ScormFile= ScormModel.ScormFile,
ScormDependency = ScormModel.ScormDependency,
ScormItem = ScormModel.ScormItem,
ScormOrganization = ScormModel.ScormOrganization,
ScormContent = ScormModel.ScormContent;
class ScormContentParser{
constructor() {
}
parse(xmlContent) {
let scormContent = new ScormContent();
let document = new xmldoc.XmlDocument(xmlContent);
let organizationsElement = document.childNamed("organizations");
scormContent.defaultOrganization = organizationsElement.attr.default;
let organizationElements = organizationsElement.childrenNamed("organization");
organizationElements.forEach(function (organizationElement) {
let organization = new ScormOrganization();
organization.identifier = organizationElement.attr.identifier;
organization.title = organizationElement.childNamed("title").val;
let itemElements = organizationElement.childrenNamed("item");
itemElements.forEach(function (itemElement) {
let item = new ScormItem();
item.identifier = itemElement.attr.identifier;
item.isvisible = itemElement.attr.isvisible == undefined ? true : itemElement.attr.isvisible;
item.identifierref = itemElement.attr.identifierref;
item.parameterString = itemElement.attr.parameters;
item.title = itemElement.childNamed("title").val;
let childItemElements = itemElement.childrenNamed("item");
childItemElements.forEach(function (childItemElement) {
let childItem = new ScormItem();
childItem.identifier = childItemElement.attr.identifier;
childItem.isvisible = childItemElement.attr.isvisible == undefined ? true : childItemElement.attr.isvisible;
childItem.identifierref = childItemElement.attr.identifierref;
childItem.parameterString = childItemElement.attr.parameters;
childItem.title = childItemElement.childNamed("title").val;
childItem.parentItem = item;
item.childItems.set(childItem.identifier, childItem);
});
organization.items.set(item.identifier, item);
});
scormContent.organizations.set(organization.identifier, organization);
});
let resourceElements = document.childNamed("resources").childrenNamed("resource");
resourceElements.forEach(function(resourceElement) {
let resource = new ScormResource();
resource.identifier = resourceElement.attr.identifier;
resource.type = resourceElement.attr.type;
resource.scormType = resourceElement.attr["adlcp:scormType"];
resource.base = resourceElement.attr["xml:base"];
resource.href = resourceElement.attr.href;
let files = resourceElement.childrenNamed("directory");
files.forEach(function (fileElement) {
let file = new ScormFile();
file.href = fileElement.attr.href;
resource.files.push(file);
});
let dependencies = resourceElement.childrenNamed("dependency");
dependencies.forEach(function (dependencyElement) {
let dependency = new ScormDependency();
dependency.identifierref = dependencyElement.attr.identifierref;
resource.dependencies.push(dependency);
});
scormContent.resources.set(resource.identifier, resource);
});
return scormContent;
}
}
module.exports.ScormContentParser = ScormContentParser;