use of org.olat.modules.scorm.server.servermodels.CMI_DataModel in project openolat by klemens.
the class ScormPackageHandler method iterateThruManifest.
/**
* A method to read through the imsmanifest and build our JDOM model in memory
* representing our navigation file.
*
* @param element
*/
public void iterateThruManifest(Element element) {
String name = element.getName();
if (name.equals(CP_Core.ORGANIZATION) && isDocumentNamespace(element)) {
_currentOrgId = element.getAttributeValue(CP_Core.IDENTIFIER);
}
if (name.equals(CP_Core.ITEM) && isDocumentNamespace(element)) {
String id = element.getAttributeValue(CP_Core.IDENTIFIER);
String url = "";
String scoType = "";
Element ref_element = getReferencedElement(element);
if (ref_element != null) {
String ref_name = ref_element.getName();
// A RESOURCE
if (ref_name.equals(CP_Core.RESOURCE)) {
// get the sco type
String theScoType = ref_element.getAttributeValue("scormtype", SCORM12_DocumentHandler.ADLCP_NAMESPACE_12);
if (theScoType != null) {
scoType = theScoType;
}
boolean isVisible = true;
// check that the item is not hidden
String isVisibleAttrib = element.getAttributeValue(CP_Core.ISVISIBLE);
if (isVisibleAttrib != null) {
if (isVisibleAttrib.equals("false")) {
isVisible = false;
}
}
if (!isVisible) {
// add this item to the tracking xml file
_sequencerModel.addTrackedItem(id, _currentOrgId, SequencerModel.ITEM_COMPLETED);
} else {
_sequencerModel.addTrackedItem(id, _currentOrgId, SequencerModel.ITEM_NOT_ATTEMPTED);
}
url = getAbsoluteURL(element);
// an item that references somthing has been found..
_hasItemsToPlay = true;
if (url.startsWith("file:///")) {
String tempHref;
if (GeneralUtils.getOS() == GeneralUtils.MACINTOSH || GeneralUtils.getOS() == GeneralUtils.UNIX) {
// mac & linux
tempHref = url.substring(7, url.length());
} else {
// windows
tempHref = url.substring(8, url.length());
}
tempHref = tempHref.replaceAll("%20", " ");
// String testHref =
// ScormTomcatHandler.getSharedInstance().getScormWebAppPath().toString().replace('\\',
// '/');
String testHref = "bla";
testHref = testHref.replaceAll("%20", " ");
if (tempHref.startsWith(testHref)) {
String localUrlMinusPath = tempHref.substring(// ScormTomcatHandler.getSharedInstance().getScormWebAppPath().toString().length()+1,
3, tempHref.length());
String correctLocalUrl = localUrlMinusPath.replace('\\', '/');
url = correctLocalUrl;
}
}
} else // A sub-MANIFEST
if (ref_name.equals(CP_Core.MANIFEST)) {
// Get ORGANIZATIONS Element
Element orgsElement = ref_element.getChild(CP_Core.ORGANIZATIONS, ref_element.getNamespace());
// Now we have to get the default ORGANIZATION
if (orgsElement != null)
ref_element = getDefaultOrganization(orgsElement);
// clones
if (ref_element != null) {
Iterator it = ref_element.getChildren().iterator();
while (it.hasNext()) {
Element ref_child = (Element) it.next();
element.addContent((Element) ref_child.clone());
}
}
}
}
// next we need to find any MAXTIMEALLOWED entries
String maxTimeText = "";
Element maxTime = element.getChild(SCORM12_Core.MAXTIMEALLOWED, SCORM12_DocumentHandler.ADLCP_NAMESPACE_12);
if (maxTime != null) {
maxTimeText = maxTime.getText();
}
// next find any TIMELIMITACTION entries
String timeLimitText = "";
Element timeLimit = element.getChild(SCORM12_Core.TIMELIMITACTION, SCORM12_DocumentHandler.ADLCP_NAMESPACE_12);
if (timeLimit != null) {
timeLimitText = timeLimit.getText();
}
// next find any DATAFROMLMS entries
String datafromLmsText = "";
Element dataFromLms = element.getChild(SCORM12_Core.DATAFROMLMS, SCORM12_DocumentHandler.ADLCP_NAMESPACE_12);
if (dataFromLms != null) {
datafromLmsText = dataFromLms.getText();
}
// next find any MASTERYSCORE entries
String masteryScoreText = "";
Element masteryScore = element.getChild(SCORM12_Core.MASTERYSCORE, SCORM12_DocumentHandler.ADLCP_NAMESPACE_12);
if (masteryScore != null) {
masteryScoreText = masteryScore.getText();
}
// for it...
if (scoType.equals(SCORM12_Core.SCO)) {
CMI_DataModel scoModel = new CMI_DataModel(settings.getStudentId(), settings.getStudentName(), maxTimeText, timeLimitText, datafromLmsText, masteryScoreText, settings.getLessonMode(), settings.getCreditMode());
scoModel.buildFreshModel();
Document theModel = scoModel.getModel();
File scoFile = settings.getScoDataModelFile(id);
scoFile.getParentFile().mkdirs();
scoModel.setDocument(theModel);
scoModel.setFile(scoFile);
try {
scoModel.saveDocument();
} catch (IOException ex) {
throw new OLATRuntimeException(this.getClass(), "Could not save sco settings.", ex);
}
}
}
Iterator it = element.getChildren().iterator();
while (it.hasNext()) {
Element child = (Element) it.next();
iterateThruManifest(child);
}
}
use of org.olat.modules.scorm.server.servermodels.CMI_DataModel in project OpenOLAT by OpenOLAT.
the class ScormPackageHandler method iterateThruManifest.
/**
* A method to read through the imsmanifest and build our JDOM model in memory
* representing our navigation file.
*
* @param element
*/
public void iterateThruManifest(Element element) {
String name = element.getName();
if (name.equals(CP_Core.ORGANIZATION) && isDocumentNamespace(element)) {
_currentOrgId = element.getAttributeValue(CP_Core.IDENTIFIER);
}
if (name.equals(CP_Core.ITEM) && isDocumentNamespace(element)) {
String id = element.getAttributeValue(CP_Core.IDENTIFIER);
String url = "";
String scoType = "";
Element ref_element = getReferencedElement(element);
if (ref_element != null) {
String ref_name = ref_element.getName();
// A RESOURCE
if (ref_name.equals(CP_Core.RESOURCE)) {
// get the sco type
String theScoType = ref_element.getAttributeValue("scormtype", SCORM12_DocumentHandler.ADLCP_NAMESPACE_12);
if (theScoType != null) {
scoType = theScoType;
}
boolean isVisible = true;
// check that the item is not hidden
String isVisibleAttrib = element.getAttributeValue(CP_Core.ISVISIBLE);
if (isVisibleAttrib != null) {
if (isVisibleAttrib.equals("false")) {
isVisible = false;
}
}
if (!isVisible) {
// add this item to the tracking xml file
_sequencerModel.addTrackedItem(id, _currentOrgId, SequencerModel.ITEM_COMPLETED);
} else {
_sequencerModel.addTrackedItem(id, _currentOrgId, SequencerModel.ITEM_NOT_ATTEMPTED);
}
url = getAbsoluteURL(element);
// an item that references somthing has been found..
_hasItemsToPlay = true;
if (url.startsWith("file:///")) {
String tempHref;
if (GeneralUtils.getOS() == GeneralUtils.MACINTOSH || GeneralUtils.getOS() == GeneralUtils.UNIX) {
// mac & linux
tempHref = url.substring(7, url.length());
} else {
// windows
tempHref = url.substring(8, url.length());
}
tempHref = tempHref.replaceAll("%20", " ");
// String testHref =
// ScormTomcatHandler.getSharedInstance().getScormWebAppPath().toString().replace('\\',
// '/');
String testHref = "bla";
testHref = testHref.replaceAll("%20", " ");
if (tempHref.startsWith(testHref)) {
String localUrlMinusPath = tempHref.substring(// ScormTomcatHandler.getSharedInstance().getScormWebAppPath().toString().length()+1,
3, tempHref.length());
String correctLocalUrl = localUrlMinusPath.replace('\\', '/');
url = correctLocalUrl;
}
}
} else // A sub-MANIFEST
if (ref_name.equals(CP_Core.MANIFEST)) {
// Get ORGANIZATIONS Element
Element orgsElement = ref_element.getChild(CP_Core.ORGANIZATIONS, ref_element.getNamespace());
// Now we have to get the default ORGANIZATION
if (orgsElement != null)
ref_element = getDefaultOrganization(orgsElement);
// clones
if (ref_element != null) {
Iterator it = ref_element.getChildren().iterator();
while (it.hasNext()) {
Element ref_child = (Element) it.next();
element.addContent((Element) ref_child.clone());
}
}
}
}
// next we need to find any MAXTIMEALLOWED entries
String maxTimeText = "";
Element maxTime = element.getChild(SCORM12_Core.MAXTIMEALLOWED, SCORM12_DocumentHandler.ADLCP_NAMESPACE_12);
if (maxTime != null) {
maxTimeText = maxTime.getText();
}
// next find any TIMELIMITACTION entries
String timeLimitText = "";
Element timeLimit = element.getChild(SCORM12_Core.TIMELIMITACTION, SCORM12_DocumentHandler.ADLCP_NAMESPACE_12);
if (timeLimit != null) {
timeLimitText = timeLimit.getText();
}
// next find any DATAFROMLMS entries
String datafromLmsText = "";
Element dataFromLms = element.getChild(SCORM12_Core.DATAFROMLMS, SCORM12_DocumentHandler.ADLCP_NAMESPACE_12);
if (dataFromLms != null) {
datafromLmsText = dataFromLms.getText();
}
// next find any MASTERYSCORE entries
String masteryScoreText = "";
Element masteryScore = element.getChild(SCORM12_Core.MASTERYSCORE, SCORM12_DocumentHandler.ADLCP_NAMESPACE_12);
if (masteryScore != null) {
masteryScoreText = masteryScore.getText();
}
// for it...
if (scoType.equals(SCORM12_Core.SCO)) {
CMI_DataModel scoModel = new CMI_DataModel(settings.getStudentId(), settings.getStudentName(), maxTimeText, timeLimitText, datafromLmsText, masteryScoreText, settings.getLessonMode(), settings.getCreditMode());
scoModel.buildFreshModel();
Document theModel = scoModel.getModel();
File scoFile = settings.getScoDataModelFile(id);
scoFile.getParentFile().mkdirs();
scoModel.setDocument(theModel);
scoModel.setFile(scoFile);
try {
scoModel.saveDocument();
} catch (IOException ex) {
throw new OLATRuntimeException(this.getClass(), "Could not save sco settings.", ex);
}
}
}
Iterator it = element.getChildren().iterator();
while (it.hasNext()) {
Element child = (Element) it.next();
iterateThruManifest(child);
}
}
Aggregations