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);
}
}
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);
}
}
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);
}
}
}
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();
}
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);
}
}
Aggregations