use of org.olat.core.commons.modules.bc.meta.MetaInfo in project openolat by klemens.
the class ZipUtil method unzipNonStrict.
/**
* Unzip with jazzlib
* @param in
* @param targetDir
* @param identity
* @param versioning
* @return
*/
private static boolean unzipNonStrict(InputStream in, VFSContainer targetDir, Identity identity, boolean versioning) {
net.sf.jazzlib.ZipInputStream oZip = new net.sf.jazzlib.ZipInputStream(in);
try {
// unzip files
net.sf.jazzlib.ZipEntry oEntr = oZip.getNextEntry();
while (oEntr != null) {
if (oEntr.getName() != null && !oEntr.getName().startsWith(DIR_NAME__MACOSX)) {
if (oEntr.isDirectory()) {
// skip MacOSX specific metadata directory
// create directories
getAllSubdirs(targetDir, oEntr.getName(), identity, true);
} else {
// create file
VFSContainer createIn = targetDir;
String name = oEntr.getName();
// check if entry has directories which did not show up as
// directories above
int dirSepIndex = name.lastIndexOf('/');
if (dirSepIndex == -1) {
// try it windows style, backslash is also valid format
dirSepIndex = name.lastIndexOf('\\');
}
if (dirSepIndex > 0) {
// create subdirs
createIn = getAllSubdirs(targetDir, name.substring(0, dirSepIndex), identity, true);
if (createIn == null) {
if (log.isDebug())
log.debug("Error creating directory structure for zip entry: " + oEntr.getName());
return false;
}
name = name.substring(dirSepIndex + 1);
}
if (versioning) {
VFSLeaf newEntry = (VFSLeaf) createIn.resolve(name);
if (newEntry == null) {
newEntry = createIn.createChildLeaf(name);
OutputStream out = newEntry.getOutputStream(false);
if (!FileUtils.copy(oZip, out))
return false;
FileUtils.closeSafely(out);
} else if (newEntry instanceof Versionable) {
Versionable versionable = (Versionable) newEntry;
if (versionable.getVersions().isVersioned()) {
versionable.getVersions().addVersion(identity, "", oZip);
}
}
if (newEntry instanceof MetaTagged) {
MetaInfo info = ((MetaTagged) newEntry).getMetaInfo();
if (info != null) {
info.setAuthor(identity);
info.write();
}
}
} else {
VFSLeaf newEntry = createIn.createChildLeaf(name);
if (newEntry != null) {
OutputStream out = newEntry.getOutputStream(false);
if (!FileUtils.copy(oZip, out))
return false;
FileUtils.closeSafely(out);
}
if (newEntry instanceof MetaTagged) {
MetaInfo info = ((MetaTagged) newEntry).getMetaInfo();
if (info != null && identity != null) {
info.setAuthor(identity);
info.write();
}
}
}
}
}
oZip.closeEntry();
oEntr = oZip.getNextEntry();
}
} catch (IOException e) {
return false;
} finally {
FileUtils.closeSafely(oZip);
}
return true;
}
use of org.olat.core.commons.modules.bc.meta.MetaInfo in project openolat by klemens.
the class GTASampleSolutionsEditController method doCreateSolutionEditor.
private void doCreateSolutionEditor(UserRequest ureq, Solution solution) {
String documentName = solution.getFilename();
VFSItem item = solutionContainer.resolve(documentName);
if (item == null) {
item = solutionContainer.createChildLeaf(documentName);
} else {
documentName = VFSManager.rename(solutionContainer, documentName);
item = solutionContainer.createChildLeaf(documentName);
}
if (item instanceof MetaTagged) {
MetaInfo metaInfo = ((MetaTagged) item).getMetaInfo();
if (metaInfo != null) {
metaInfo.setAuthor(getIdentity());
}
metaInfo.write();
}
newSolutionEditorCtrl = WysiwygFactory.createWysiwygController(ureq, getWindowControl(), solutionContainer, documentName, "media", true, true);
newSolutionEditorCtrl.getRichTextConfiguration().disableMedia();
newSolutionEditorCtrl.getRichTextConfiguration().setAllowCustomMediaFactory(false);
newSolutionEditorCtrl.setNewFile(true);
newSolutionEditorCtrl.setUserObject(solution);
listenTo(newSolutionEditorCtrl);
cmc = new CloseableModalController(getWindowControl(), "close", newSolutionEditorCtrl.getInitialComponent());
listenTo(cmc);
cmc.activate();
}
use of org.olat.core.commons.modules.bc.meta.MetaInfo in project openolat by klemens.
the class GTASampleSolutionsEditController method updateModel.
private void updateModel() {
List<Solution> solutionList = gtaManager.getSolutions(courseEnv, gtaNode);
List<SolutionRow> rows = new ArrayList<>(solutionList.size());
for (Solution solution : solutionList) {
String filename = solution.getFilename();
String author = null;
VFSItem item = solutionContainer.resolve(filename);
if (item instanceof MetaTagged) {
MetaInfo metaInfo = ((MetaTagged) item).getMetaInfo();
if (metaInfo != null && metaInfo.getAuthorIdentityKey() != null) {
author = userManager.getUserDisplayName(metaInfo.getAuthorIdentityKey());
}
}
DownloadLink downloadLink = null;
if (item instanceof VFSLeaf) {
downloadLink = uifactory.addDownloadLink("file_" + (++linkCounter), filename, null, (VFSLeaf) item, solutionTable);
}
rows.add(new SolutionRow(solution, author, downloadLink));
}
solutionModel.setObjects(rows);
solutionTable.reset();
}
use of org.olat.core.commons.modules.bc.meta.MetaInfo in project openolat by klemens.
the class SubmitDocumentsController method updateModel.
private void updateModel() {
File[] documents = documentsDir.listFiles(new SystemFileFilter(true, false));
List<SubmittedSolution> docList = new ArrayList<>(documents.length);
for (File document : documents) {
String filename = document.getName();
String uploadedBy = null;
VFSItem item = documentsContainer.resolve(filename);
if (item instanceof MetaTagged) {
MetaInfo metaInfo = ((MetaTagged) item).getMetaInfo();
if (metaInfo != null && metaInfo.getAuthorIdentityKey() != null) {
uploadedBy = userManager.getUserDisplayName(metaInfo.getAuthorIdentityKey());
}
}
FormItem download;
if (filename.endsWith(".html")) {
download = uifactory.addFormLink("view-" + CodeHelper.getRAMUniqueID(), "view", filename, null, flc, Link.LINK | Link.NONTRANSLATED);
download.setUserObject(filename);
} else {
download = uifactory.addDownloadLink("view-" + CodeHelper.getRAMUniqueID(), filename, null, document, tableEl);
}
docList.add(new SubmittedSolution(document, uploadedBy, download));
}
model.setObjects(docList);
tableEl.reset();
if (maxDocs > 0 && docList.size() >= maxDocs) {
if (uploadDocButton != null) {
uploadDocButton.setEnabled(false);
}
if (createDocButton != null) {
createDocButton.setEnabled(false);
}
String msg = translate("error.max.documents", new String[] { Integer.toString(maxDocs) });
flc.contextPut("maxDocsWarning", msg);
} else {
if (uploadDocButton != null) {
uploadDocButton.setEnabled(true);
}
if (createDocButton != null) {
createDocButton.setEnabled(true);
}
flc.contextPut("maxDocsWarning", Boolean.FALSE);
}
flc.contextPut("hasDocuments", Boolean.valueOf(hasUploadDocuments()));
}
use of org.olat.core.commons.modules.bc.meta.MetaInfo in project openolat by klemens.
the class SubmitDocumentsController method doUpload.
private void doUpload(UserRequest ureq, File file, String filename) {
try {
Path documentPath = documentsDir.toPath().resolve(filename);
Files.move(file.toPath(), documentPath, StandardCopyOption.REPLACE_EXISTING);
VFSItem downloadedFile = documentsContainer.resolve(filename);
if (downloadedFile instanceof MetaTagged) {
MetaInfo metadata = ((MetaTagged) downloadedFile).getMetaInfo();
metadata.setAuthor(ureq.getIdentity());
metadata.write();
}
} catch (IOException e) {
logError("", e);
showError("");
}
updateModel();
}
Aggregations