use of org.olat.core.util.vfs.VFSLeaf in project OpenOLAT by OpenOLAT.
the class InfoDisplayController method loadMessages.
/**
* This is the main method which push the messages in the layout container,
* and clean-up old links.
*/
protected void loadMessages() {
// first clear the current message if any
for (Long key : previousDisplayKeys) {
flc.contextRemove("info.date." + key);
if (flc.getComponent("info.delete." + key) != null) {
flc.remove("info.delete." + key);
}
if (flc.getComponent("info.edit." + key) != null) {
flc.remove("info.edit." + key);
}
}
previousDisplayKeys.clear();
deleteLinks.clear();
List<InfoMessage> msgs = infoMessageManager.loadInfoMessageByResource(ores, resSubPath, businessPath, after, null, 0, maxResults);
List<InfoMessageForDisplay> infoDisplays = new ArrayList<>(msgs.size());
Map<Long, VFSLeaf> keyToDisplay = new HashMap<>();
for (InfoMessage info : msgs) {
previousDisplayKeys.add(info.getKey());
InfoMessageForDisplay infoDisplay = createInfoMessageForDisplay(info);
infoDisplays.add(infoDisplay);
if (infoDisplay.getAttachment() != null) {
keyToDisplay.put(info.getKey(), infoDisplay.getAttachment());
}
String dateCmpName = "info.date." + info.getKey();
DateElement dateEl = DateComponentFactory.createDateElementWithYear(dateCmpName, info.getCreationDate());
flc.add(dateCmpName, dateEl);
if (secCallback.canEdit(info)) {
String editName = "info.edit." + info.getKey();
FormLink link = uifactory.addFormLink(editName, "edit", "edit", flc, Link.BUTTON_SMALL);
link.setElementCssClass("o_sel_info_edit_msg");
link.setUserObject(info);
editLinks.add(link);
flc.add(link);
}
if (secCallback.canDelete()) {
String delName = "info.delete." + info.getKey();
FormLink link = uifactory.addFormLink(delName, "delete", "delete", flc, Link.BUTTON_SMALL);
link.setElementCssClass("o_sel_info_delete_msg");
link.setUserObject(info);
deleteLinks.add(link);
flc.add(link);
}
}
flc.contextPut("infos", infoDisplays);
infoKeyToAttachment = keyToDisplay;
int numOfInfos = infoMessageManager.countInfoMessageByResource(ores, resSubPath, businessPath, null, null);
oldMsgsLink.setVisible((msgs.size() < numOfInfos));
newMsgsLink.setVisible((msgs.size() == numOfInfos) && (numOfInfos > maxResultsConfig) && (maxResultsConfig > 0));
}
use of org.olat.core.util.vfs.VFSLeaf in project OpenOLAT by OpenOLAT.
the class ImpressumAdminController method checkContent.
private boolean checkContent(VFSItem file) {
boolean check = false;
if (file instanceof VFSLeaf && file.exists()) {
if (file instanceof LocalFileImpl) {
File f = ((LocalFileImpl) file).getBasefile();
try {
String content = FileUtils.readFileToString(f);
content = FilterFactory.getHtmlTagAndDescapingFilter().filter(content);
if (content.length() > 0) {
content = content.trim();
}
if (content.length() > 0) {
check = true;
}
} catch (IOException e) {
logError("", e);
}
} else {
check = true;
}
}
return check;
}
use of org.olat.core.util.vfs.VFSLeaf in project OpenOLAT by OpenOLAT.
the class ConvertToGTACourseNode method convertDropbox.
private void convertDropbox(TaskList taskList, TACourseNode sourceNode, GTACourseNode gtaNode, CourseEnvironment courseEnv) {
String dropbox = DropboxController.getDropboxPathRelToFolderRoot(courseEnv, sourceNode);
OlatRootFolderImpl dropboxContainer = new OlatRootFolderImpl(dropbox, null);
for (VFSItem userDropbox : dropboxContainer.getItems()) {
if (userDropbox instanceof VFSContainer) {
VFSContainer userDropContainer = (VFSContainer) userDropbox;
String username = userDropContainer.getName();
Identity assessedIdentity = securityManager.findIdentityByName(username);
if (assessedIdentity != null) {
VFSContainer sumbitContainer = gtaManager.getSubmitContainer(courseEnv, gtaNode, assessedIdentity);
boolean dropped = false;
for (VFSItem dropppedItem : userDropContainer.getItems()) {
if (dropppedItem instanceof VFSLeaf) {
VFSLeaf submittedDocument = sumbitContainer.createChildLeaf(dropppedItem.getName());
VFSManager.copyContent((VFSLeaf) dropppedItem, submittedDocument);
convertMetada(userDropContainer, sumbitContainer, dropppedItem.getName(), null, null);
dropped = true;
}
}
if (dropped) {
setTaskStatus(taskList, assessedIdentity, TaskProcess.submit, gtaNode);
}
}
}
}
}
use of org.olat.core.util.vfs.VFSLeaf in project OpenOLAT by OpenOLAT.
the class QTIQPoolServiceProvider method importBeecomItem.
public QuestionItemImpl importBeecomItem(Identity owner, ItemAndMetadata itemAndMetadata, VFSContainer sourceDir, Locale defaultLocale) {
QTIImportProcessor processor = new QTIImportProcessor(owner, defaultLocale);
String editor = null;
String editorVersion = null;
Item item = itemAndMetadata.getItem();
if (!item.isAlient()) {
editor = "OpenOLAT";
editorVersion = Settings.getVersion();
}
Document doc = QTIEditHelper.itemToXml(item);
Element itemEl = (Element) doc.selectSingleNode("questestinterop/item");
QuestionItemImpl qitem = processor.processItem(itemEl, "", null, editor, editorVersion, null, itemAndMetadata);
// save to file System
VFSContainer baseDir = qpoolFileStorage.getContainer(qitem.getDirectory());
VFSLeaf leaf = baseDir.createChildLeaf(qitem.getRootFilename());
QTIEditHelper.serialiazeDoc(doc, leaf);
if (sourceDir != null) {
List<String> materials = processor.getMaterials(itemEl);
// copy materials
for (String material : materials) {
VFSItem sourceItem = sourceDir.resolve(material);
if (sourceItem instanceof VFSLeaf) {
VFSLeaf targetItem = baseDir.createChildLeaf(material);
VFSManager.copyContent((VFSLeaf) sourceItem, targetItem);
}
}
}
return qitem;
}
use of org.olat.core.util.vfs.VFSLeaf in project OpenOLAT by OpenOLAT.
the class QTIQPoolServiceProvider method extractTextContent.
@Override
public String extractTextContent(QuestionItemFull item) {
String content = null;
if (item.getRootFilename() != null) {
String dir = item.getDirectory();
VFSContainer container = qpoolFileStorage.getContainer(dir);
VFSItem file = container.resolve(item.getRootFilename());
if (file instanceof VFSLeaf) {
VFSLeaf leaf = (VFSLeaf) file;
InputStream is = leaf.getInputStream();
QTI12SAXHandler handler = new QTI12SAXHandler();
try {
XMLReader parser = XMLReaderFactory.createXMLReader();
parser.setContentHandler(handler);
parser.setEntityResolver(new IMSEntityResolver());
parser.setFeature("http://xml.org/sax/features/validation", false);
parser.parse(new InputSource(is));
} catch (Exception e) {
log.error("", e);
} finally {
FileUtils.closeSafely(is);
}
return handler.toString();
}
}
return content;
}
Aggregations