Search in sources :

Example 76 with OLATRuntimeException

use of org.olat.core.logging.OLATRuntimeException 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 77 with OLATRuntimeException

use of org.olat.core.logging.OLATRuntimeException in project openolat by klemens.

the class ScormPackageHandler method buildSettings.

/**
 * A class to actually do the bulk of the work. It creates an xml file
 * representing the organizations, similar to the imsmanifest, but also
 * modelling the sco/asset attributes needed by the runtime system - ie order
 * of sequence, launch URL...
 *
 * @throws NoItemFoundException
 */
public void buildSettings() throws NoItemFoundException {
    // get the root element of the manifest
    // NOTE: CLONE IT first- must work on a copy of the original JDOM doc.
    Element manifestRoot = (Element) getDocument().getRootElement().clone();
    _sequencerModel.setManifestModifiedDate(super.getFile().lastModified());
    // now get the organizations node
    Element orgs = manifestRoot.getChild(CP_Core.ORGANIZATIONS, manifestRoot.getNamespace());
    // get the identifier for the default organization
    Element defaultOrgNode = getDefaultOrganization(orgs);
    if (defaultOrgNode != null) {
        // and store the default identifier
        String defaultOrgIdentifier = defaultOrgNode.getAttributeValue(CP_Core.IDENTIFIER);
        // set the default organization
        _sequencerModel.setDefaultOrg(defaultOrgIdentifier);
        iterateThruManifest(manifestRoot);
    } else {
        _sequencerModel.setDefaultOrg("");
    }
    try {
        _sequencerModel.saveDocument(true);
    } catch (IOException ex) {
        throw new OLATRuntimeException(this.getClass(), "Could not save package status.", ex);
    }
    // throw an exception if no items were found in the manifest
    if (!_hasItemsToPlay) {
        throw new NoItemFoundException(NoItemFoundException.NO_ITEM_FOUND_MSG);
    }
}
Also used : OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) Element(org.jdom.Element) IOException(java.io.IOException)

Example 78 with OLATRuntimeException

use of org.olat.core.logging.OLATRuntimeException in project openolat by klemens.

the class WikiMainController method createMediaMetadataFile.

private void createMediaMetadataFile(String filename, Long author) {
    VFSContainer mediaFolder = WikiManager.getInstance().getMediaFolder(ores);
    // only create metadatafile if base file exists
    if ((VFSLeaf) mediaFolder.resolve(filename) != null) {
        // metafile may exists when files get overwritten
        VFSLeaf metaFile = (VFSLeaf) mediaFolder.resolve(filename + METADATA_SUFFIX);
        if (metaFile == null) {
            // metafile does not exist => create one
            metaFile = mediaFolder.createChildLeaf(filename + METADATA_SUFFIX);
        }
        Properties p = new Properties();
        p.setProperty(MEDIA_FILE_FILENAME, filename);
        p.setProperty(MEDIA_FILE_CREATIONDATE, String.valueOf(System.currentTimeMillis()));
        p.setProperty(MEDIA_FILE_CREATED_BY, String.valueOf(author));
        try {
            p.store(metaFile.getOutputStream(false), "wiki media files meta properties");
        } catch (IOException e) {
            throw new OLATRuntimeException(WikiManager.class, "failed to save media files properties for file: " + filename + " and olatresource: " + ores.getResourceableId(), e);
        }
    }
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) VFSContainer(org.olat.core.util.vfs.VFSContainer) IOException(java.io.IOException) Properties(java.util.Properties)

Example 79 with OLATRuntimeException

use of org.olat.core.logging.OLATRuntimeException in project openolat by klemens.

the class WikiMainController method refreshTableDataModel.

private void refreshTableDataModel(UserRequest ureq, Wiki wiki) {
    removeAsListenerAndDispose(mediaTableCtr);
    mediaTableCtr = new TableController(new TableGuiConfiguration(), ureq, getWindowControl(), getTranslator());
    listenTo(mediaTableCtr);
    mediaTableCtr.setMultiSelect(true);
    mediaTableCtr.addMultiSelectAction(ACTION_DELETE_MEDIAS, ACTION_DELETE_MEDIAS);
    List<VFSItem> filelist = wiki.getMediaFileListWithMetadata();
    Map<String, MediaFileElement> files = new HashMap<String, MediaFileElement>();
    for (Iterator<VFSItem> iter = filelist.iterator(); iter.hasNext(); ) {
        VFSLeaf elem = (VFSLeaf) iter.next();
        if (elem.getName().endsWith(METADATA_SUFFIX)) {
            // *.metadata files
            // go here
            Properties p = new Properties();
            try {
                p.load(elem.getInputStream());
                MediaFileElement mediaFileElement = new MediaFileElement(elem.getName(), p.getProperty(MEDIA_FILE_CREATED_BY), p.getProperty(MEDIA_FILE_CREATIONDATE));
                mediaFileElement.setDeletedBy(p.getProperty(MEDIA_FILE_DELETED_BY));
                mediaFileElement.setDeletionDate(p.getProperty(MEDIA_FILE_DELETIONDATE));
                files.put(p.getProperty(MEDIA_FILE_FILENAME), mediaFileElement);
            } catch (IOException e) {
                throw new OLATRuntimeException("Could'n read properties from media file: " + elem.getName(), e);
            }
        }
    }
    for (Iterator<VFSItem> iter = filelist.iterator(); iter.hasNext(); ) {
        VFSLeaf elem = (VFSLeaf) iter.next();
        if (!elem.getName().endsWith(METADATA_SUFFIX)) {
            if (!files.containsKey(elem.getName())) {
                // legacy file without metadata
                files.put(elem.getName(), new MediaFileElement(elem.getName(), 0, elem.getLastModified()));
            } else {
                // file with metadata, update name
                MediaFileElement element = files.get(elem.getName());
                element.setFileName(elem.getName());
            }
        }
    }
    mediaFilesTableModel = new MediaFilesTableModel(new ArrayList<MediaFileElement>(files.values()), getTranslator());
    mediaFilesTableModel.addColumnDescriptors(mediaTableCtr);
    mediaTableCtr.setTableDataModel(mediaFilesTableModel);
    mediaTableCtr.setSortColumn(3, false);
    mediaTableCtr.modelChanged();
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) HashMap(java.util.HashMap) TableController(org.olat.core.gui.components.table.TableController) ArrayList(java.util.ArrayList) VFSItem(org.olat.core.util.vfs.VFSItem) IOException(java.io.IOException) Properties(java.util.Properties) OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) TableGuiConfiguration(org.olat.core.gui.components.table.TableGuiConfiguration)

Example 80 with OLATRuntimeException

use of org.olat.core.logging.OLATRuntimeException in project openolat by klemens.

the class WikiManager method saveWikiPageProperties.

private void saveWikiPageProperties(OLATResourceable ores, WikiPage page) {
    VFSContainer wikiContentContainer = getWikiContainer(ores, WIKI_RESOURCE_FOLDER_NAME);
    VFSLeaf leaf = (VFSLeaf) wikiContentContainer.resolve(page.getPageId() + "." + WIKI_PROPERTIES_SUFFIX);
    if (leaf == null)
        leaf = wikiContentContainer.createChildLeaf(page.getPageId() + "." + WIKI_PROPERTIES_SUFFIX);
    Properties p = getPageProperties(page);
    try {
        p.store(leaf.getOutputStream(false), "wiki page meta properties");
    } catch (IOException e) {
        throw new OLATRuntimeException(WikiManager.class, "failed to save wiki page properties for page with id: " + page.getPageId() + " and olatresource: " + ores.getResourceableId(), e);
    }
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) VFSContainer(org.olat.core.util.vfs.VFSContainer) IOException(java.io.IOException) Properties(java.util.Properties)

Aggregations

OLATRuntimeException (org.olat.core.logging.OLATRuntimeException)268 IOException (java.io.IOException)104 File (java.io.File)50 ModuleConfiguration (org.olat.modules.ModuleConfiguration)26 ArrayList (java.util.ArrayList)22 AssertException (org.olat.core.logging.AssertException)22 FileOutputStream (java.io.FileOutputStream)20 OutputStream (java.io.OutputStream)20 Properties (java.util.Properties)20 FileInputStream (java.io.FileInputStream)18 HashMap (java.util.HashMap)18 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)18 QTIItemObject (org.olat.ims.qti.export.helper.QTIItemObject)18 DefaultElement (org.dom4j.tree.DefaultElement)16 Element (org.jdom.Element)16 InputStream (java.io.InputStream)14 BufferedInputStream (java.io.BufferedInputStream)12 List (java.util.List)12 Document (org.dom4j.Document)12 CPItem (org.olat.ims.cp.objects.CPItem)12