Search in sources :

Example 1 with CMI_DataModel

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);
    }
}
Also used : CMI_DataModel(org.olat.modules.scorm.server.servermodels.CMI_DataModel) OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) Element(org.jdom.Element) Iterator(java.util.Iterator) IOException(java.io.IOException) XMLDocument(uk.ac.reload.jdom.XMLDocument) Document(org.jdom.Document) File(java.io.File)

Example 2 with CMI_DataModel

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);
    }
}
Also used : CMI_DataModel(org.olat.modules.scorm.server.servermodels.CMI_DataModel) OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) Element(org.jdom.Element) Iterator(java.util.Iterator) IOException(java.io.IOException) XMLDocument(uk.ac.reload.jdom.XMLDocument) Document(org.jdom.Document) File(java.io.File)

Aggregations

File (java.io.File)2 IOException (java.io.IOException)2 Iterator (java.util.Iterator)2 Document (org.jdom.Document)2 Element (org.jdom.Element)2 OLATRuntimeException (org.olat.core.logging.OLATRuntimeException)2 CMI_DataModel (org.olat.modules.scorm.server.servermodels.CMI_DataModel)2 XMLDocument (uk.ac.reload.jdom.XMLDocument)2