Search in sources :

Example 36 with VFSLeaf

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));
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) HashMap(java.util.HashMap) DateElement(org.olat.core.gui.components.date.DateElement) ArrayList(java.util.ArrayList) FormLink(org.olat.core.gui.components.form.flexible.elements.FormLink) InfoMessage(org.olat.commons.info.InfoMessage)

Example 37 with VFSLeaf

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;
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) LocalFileImpl(org.olat.core.util.vfs.LocalFileImpl) IOException(java.io.IOException) File(java.io.File)

Example 38 with VFSLeaf

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);
                }
            }
        }
    }
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) OlatRootFolderImpl(org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl) VFSContainer(org.olat.core.util.vfs.VFSContainer) VFSItem(org.olat.core.util.vfs.VFSItem) Identity(org.olat.core.id.Identity)

Example 39 with VFSLeaf

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;
}
Also used : Item(org.olat.ims.qti.editor.beecom.objects.Item) VFSItem(org.olat.core.util.vfs.VFSItem) QuestionItem(org.olat.modules.qpool.QuestionItem) VFSLeaf(org.olat.core.util.vfs.VFSLeaf) QuestionItemImpl(org.olat.modules.qpool.model.QuestionItemImpl) Element(org.dom4j.Element) VFSContainer(org.olat.core.util.vfs.VFSContainer) VFSItem(org.olat.core.util.vfs.VFSItem) Document(org.dom4j.Document)

Example 40 with VFSLeaf

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;
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) InputSource(org.xml.sax.InputSource) InputStream(java.io.InputStream) VFSContainer(org.olat.core.util.vfs.VFSContainer) VFSItem(org.olat.core.util.vfs.VFSItem) IMSEntityResolver(org.olat.ims.resources.IMSEntityResolver) XMLReader(org.xml.sax.XMLReader)

Aggregations

VFSLeaf (org.olat.core.util.vfs.VFSLeaf)642 VFSContainer (org.olat.core.util.vfs.VFSContainer)338 VFSItem (org.olat.core.util.vfs.VFSItem)280 File (java.io.File)114 InputStream (java.io.InputStream)96 IOException (java.io.IOException)92 Test (org.junit.Test)86 ArrayList (java.util.ArrayList)72 OutputStream (java.io.OutputStream)60 MetaInfo (org.olat.core.commons.modules.bc.meta.MetaInfo)58 MetaTagged (org.olat.core.commons.modules.bc.meta.tagged.MetaTagged)58 OlatRootFolderImpl (org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl)58 Identity (org.olat.core.id.Identity)54 LocalFileImpl (org.olat.core.util.vfs.LocalFileImpl)52 VFSMediaResource (org.olat.core.util.vfs.VFSMediaResource)46 URL (java.net.URL)40 Date (java.util.Date)40 RepositoryEntry (org.olat.repository.RepositoryEntry)36 URI (java.net.URI)34 MediaResource (org.olat.core.gui.media.MediaResource)34