Search in sources :

Example 76 with LocalFolderImpl

use of org.olat.core.util.vfs.LocalFolderImpl in project OpenOLAT by OpenOLAT.

the class CheckListStepRunnerCallback method execute.

@Override
public Step execute(UserRequest ureq, WindowControl wControl, StepsRunContext runContext) {
    GeneratorData data = (GeneratorData) runContext.get("data");
    List<Checkbox> templateCheckbox = data.getCheckboxList();
    ModuleConfiguration templateConfig = data.getModuleConfiguration();
    ICourse course = CourseFactory.getCourseEditSession(courseOres.getResourceableId());
    CourseEnvironment courseEnv = course.getCourseEnvironment();
    CheckboxManager checkboxManager = CoreSpringFactory.getImpl(CheckboxManager.class);
    CourseNode structureNode = createCourseNode(data.getStructureShortTitle(), data.getStructureTitle(), data.getStructureObjectives(), "st");
    CourseEditorTreeNode parentNode = (CourseEditorTreeNode) course.getEditorTreeModel().getRootNode();
    course.getEditorTreeModel().addCourseNode(structureNode, parentNode.getCourseNode());
    List<CheckListNode> nodes = data.getNodes();
    List<String> nodesIdent = new ArrayList<>();
    for (CheckListNode node : nodes) {
        String title = node.getTitle();
        CheckListCourseNode checkNode = (CheckListCourseNode) createCourseNode(title, title, null, "checklist");
        nodesIdent.add(checkNode.getIdent());
        ModuleConfiguration config = checkNode.getModuleConfiguration();
        config.putAll(templateConfig);
        CheckboxList checkboxList = new CheckboxList();
        List<Checkbox> boxes = new ArrayList<>();
        for (Checkbox templateBox : templateCheckbox) {
            Checkbox checkbox = templateBox.clone();
            boxes.add(checkbox);
            if (StringHelper.containsNonWhitespace(templateBox.getFilename())) {
                File path = new File(FolderConfig.getCanonicalTmpDir(), templateBox.getCheckboxId());
                VFSContainer tmpContainer = new LocalFolderImpl(path);
                VFSItem item = tmpContainer.resolve(templateBox.getFilename());
                if (item instanceof VFSLeaf) {
                    VFSContainer container = checkboxManager.getFileContainer(courseEnv, checkNode);
                    VFSManager.copyContent(tmpContainer, container);
                    tmpContainer.deleteSilently();
                }
            }
        }
        checkboxList.setList(boxes);
        config.set(CheckListCourseNode.CONFIG_KEY_CHECKBOX, checkboxList);
        boolean dueDate = node.getDueDate() != null;
        if (dueDate) {
            config.set(CheckListCourseNode.CONFIG_KEY_DUE_DATE, node.getDueDate());
        }
        config.set(CheckListCourseNode.CONFIG_KEY_CLOSE_AFTER_DUE_DATE, new Boolean(dueDate));
        course.getEditorTreeModel().addCourseNode(checkNode, structureNode);
    }
    setScoreCalculation(data, (STCourseNode) structureNode, nodesIdent);
    return StepsMainRunController.DONE_MODIFIED;
}
Also used : CheckboxList(org.olat.course.nodes.cl.model.CheckboxList) VFSLeaf(org.olat.core.util.vfs.VFSLeaf) ModuleConfiguration(org.olat.modules.ModuleConfiguration) CourseEnvironment(org.olat.course.run.environment.CourseEnvironment) VFSContainer(org.olat.core.util.vfs.VFSContainer) CourseEditorTreeNode(org.olat.course.tree.CourseEditorTreeNode) ArrayList(java.util.ArrayList) VFSItem(org.olat.core.util.vfs.VFSItem) ICourse(org.olat.course.ICourse) CheckListCourseNode(org.olat.course.nodes.CheckListCourseNode) LocalFolderImpl(org.olat.core.util.vfs.LocalFolderImpl) CheckboxManager(org.olat.course.nodes.cl.CheckboxManager) Checkbox(org.olat.course.nodes.cl.model.Checkbox) CourseNode(org.olat.course.nodes.CourseNode) CheckListCourseNode(org.olat.course.nodes.CheckListCourseNode) STCourseNode(org.olat.course.nodes.STCourseNode) File(java.io.File)

Example 77 with LocalFolderImpl

use of org.olat.core.util.vfs.LocalFolderImpl in project OpenOLAT by OpenOLAT.

the class GlossaryItemManager method upgradeAndDeleteOldGlossary.

/**
 * upgrades the old textmarker-format into the new DocBook-glossary-format
 *
 * @param folderContainingGlossary
 * @param textMarkerFile
 */
protected void upgradeAndDeleteOldGlossary(VFSContainer folderContainingGlossary, VFSLeaf textMarkerFile) {
    // check if a new glossary exists, warn
    if (folderContainingGlossary.resolve(GLOSSARY_FILENAME) != null) {
        logError("Upgrading Glossary in " + folderContainingGlossary.toString() + ": There is already a new glossary-file. There can't be an old and a new version in the same directory!", null);
    } else {
        // upgrade it
        TextMarkerManager textMarkerManager = TextMarkerManagerImpl.getInstance();
        List<TextMarker> textMarkerList = textMarkerManager.loadTextMarkerList(textMarkerFile);
        Collections.sort(textMarkerList);
        ArrayList<GlossaryItem> glossaryItemArr = new ArrayList<GlossaryItem>();
        for (TextMarker tm : textMarkerList) {
            String glossTerm = tm.getMarkedMainText();
            String glossDef = tm.getHooverText();
            GlossaryItem glossItem = new GlossaryItem(glossTerm, glossDef);
            // handle alias -> save as synonyms
            String aliasString = tm.getMarkedAliasText();
            if (StringHelper.containsNonWhitespace(aliasString)) {
                String[] aliasArr = aliasString.split(";");
                ArrayList<String> glossSynonyms = new ArrayList<String>();
                glossSynonyms.addAll(Arrays.asList(aliasArr));
                glossItem.setGlossSynonyms(glossSynonyms);
            }
            glossaryItemArr.add(glossItem);
        }
        VFSLeaf glossaryFile = folderContainingGlossary.createChildLeaf(GLOSSARY_FILENAME);
        saveToFile(glossaryFile, glossaryItemArr);
        // keep a backup in debug mode:
        if (Settings.isDebuging()) {
            File tmFile = ((LocalFileImpl) textMarkerFile).getBasefile();
            File tmCont = ((LocalFolderImpl) folderContainingGlossary).getBasefile();
            FileUtils.copyFileToDir(tmFile, new File(tmCont + "/bkp"), "backup old glossary");
        }
        textMarkerFile.delete();
    }
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) ArrayList(java.util.ArrayList) LocalFileImpl(org.olat.core.util.vfs.LocalFileImpl) TextMarkerManager(org.olat.core.gui.control.generic.textmarker.TextMarkerManager) TextMarker(org.olat.core.gui.control.generic.textmarker.TextMarker) LocalFolderImpl(org.olat.core.util.vfs.LocalFolderImpl) File(java.io.File)

Example 78 with LocalFolderImpl

use of org.olat.core.util.vfs.LocalFolderImpl in project OpenOLAT by OpenOLAT.

the class FileElementImpl method moveUploadFileTo.

@Override
public VFSLeaf moveUploadFileTo(VFSContainer destinationContainer, boolean crop) {
    VFSLeaf targetLeaf = null;
    if (tempUploadFile != null && tempUploadFile.exists()) {
        // Check if such a file does already exist, if yes rename new file
        VFSItem existsChild = destinationContainer.resolve(uploadFilename);
        if (existsChild != null) {
            // Use standard rename policy
            uploadFilename = VFSManager.rename(destinationContainer, uploadFilename);
        }
        // Create target leaf file now and delete original temp file
        if (destinationContainer instanceof LocalFolderImpl) {
            // Optimize for local files (don't copy, move instead)
            LocalFolderImpl folderContainer = (LocalFolderImpl) destinationContainer;
            File destinationDir = folderContainer.getBasefile();
            File targetFile = new File(destinationDir, uploadFilename);
            Crop cropSelection = previewEl == null ? null : previewEl.getCropSelection();
            if (crop && cropSelection != null) {
                CoreSpringFactory.getImpl(ImageService.class).cropImage(tempUploadFile, targetFile, cropSelection);
                targetLeaf = (VFSLeaf) destinationContainer.resolve(targetFile.getName());
            } else if (FileUtils.copyFileToFile(tempUploadFile, targetFile, true)) {
                targetLeaf = (VFSLeaf) destinationContainer.resolve(targetFile.getName());
            } else {
                log.error("Error after copying content from temp file, cannot copy file::" + (tempUploadFile == null ? "NULL" : tempUploadFile) + " - " + (targetFile == null ? "NULL" : targetFile), null);
            }
            if (targetLeaf == null) {
                log.error("Error after copying content from temp file, cannot resolve copied file::" + (tempUploadFile == null ? "NULL" : tempUploadFile) + " - " + (targetFile == null ? "NULL" : targetFile), null);
            }
        } else {
            // Copy stream in case the destination is a non-local container
            VFSLeaf leaf = destinationContainer.createChildLeaf(uploadFilename);
            boolean success = false;
            try {
                success = VFSManager.copyContent(new FileInputStream(tempUploadFile), leaf);
            } catch (FileNotFoundException e) {
                log.error("Error while copying content from temp file::" + (tempUploadFile == null ? "NULL" : tempUploadFile.getAbsolutePath()), e);
            }
            if (success) {
                // Delete original temp file after copy to simulate move
                // behavior
                tempUploadFile.delete();
                targetLeaf = leaf;
            }
        }
    } else if (log.isDebug()) {
        log.debug("Error while copying content from temp file, no temp file::" + (tempUploadFile == null ? "NULL" : tempUploadFile.getAbsolutePath()));
    }
    return targetLeaf;
}
Also used : Crop(org.olat.core.commons.services.image.Crop) VFSLeaf(org.olat.core.util.vfs.VFSLeaf) FileNotFoundException(java.io.FileNotFoundException) VFSItem(org.olat.core.util.vfs.VFSItem) File(java.io.File) ImageService(org.olat.core.commons.services.image.ImageService) FileInputStream(java.io.FileInputStream) LocalFolderImpl(org.olat.core.util.vfs.LocalFolderImpl)

Example 79 with LocalFolderImpl

use of org.olat.core.util.vfs.LocalFolderImpl in project OpenOLAT by OpenOLAT.

the class GlossaryDefinitionMapper method handle.

/**
 * @see org.olat.core.dispatcher.mapper.Mapper#handle(java.lang.String,
 *      javax.servlet.http.HttpServletRequest)
 */
public MediaResource handle(String relPath, HttpServletRequest request) {
    GlossaryItemManager gIM = GlossaryItemManager.getInstance();
    String[] parts = relPath.split("/");
    String glossaryId = parts[1];
    String glossaryFolderString = FolderConfig.getCanonicalRoot() + FolderConfig.getRepositoryHome() + "/" + glossaryId + "/" + GlossaryMarkupItemController.INTERNAL_FOLDER_NAME;
    File glossaryFolderFile = new File(glossaryFolderString);
    if (!glossaryFolderFile.isDirectory()) {
        logWarn("GlossaryDefinition delivery failed; path to glossaryFolder not existing: " + relPath, null);
        return new NotFoundMediaResource();
    }
    VFSContainer glossaryFolder = new LocalFolderImpl(glossaryFolderFile);
    if (!gIM.isFolderContainingGlossary(glossaryFolder)) {
        logWarn("GlossaryDefinition delivery failed; glossaryFolder doesn't contain a valid Glossary: " + glossaryFolder, null);
        return new NotFoundMediaResource();
    }
    String glossaryMainTerm = parts[2];
    if (parts.length > 2) {
        // this handle / or \ in a term
        for (int i = 3; i < parts.length; i++) {
            glossaryMainTerm += "/" + parts[i];
        }
    }
    // cut away ".html" if necessary
    if (glossaryMainTerm.endsWith(".html")) {
        glossaryMainTerm = glossaryMainTerm.substring(0, glossaryMainTerm.length() - 5);
    }
    glossaryMainTerm = glossaryMainTerm.toLowerCase();
    Set<String> alternatives = new HashSet<>();
    prepareAlternatives(glossaryMainTerm, alternatives);
    // Create a media resource
    StringMediaResource resource = new StringMediaResource() {

        @Override
        public void prepare(HttpServletResponse hres) {
        // don't use normal string media headers which prevent caching,
        // use standard browser caching based on last modified timestamp
        }
    };
    resource.setLastModified(gIM.getGlossaryLastModifiedTime(glossaryFolder));
    resource.setContentType("text/html");
    List<GlossaryItem> glossItems = gIM.getGlossaryItemListByVFSItem(glossaryFolder);
    GlossaryItem foundItem = null;
    for (GlossaryItem glossaryItem : glossItems) {
        String item = glossaryItem.getGlossTerm().toLowerCase();
        if (alternatives.contains(item)) {
            foundItem = glossaryItem;
            break;
        }
    }
    if (foundItem == null) {
        return new NotFoundMediaResource();
    }
    StringBuilder sb = new StringBuilder();
    sb.append("<dd><dt>").append(foundItem.getGlossTerm()).append("</dt><dl>").append(foundItem.getGlossDef()).append("</dl></dd>");
    resource.setData(sb.toString());
    resource.setEncoding("utf-8");
    if (isLogDebugEnabled())
        logDebug("loaded definition for " + glossaryMainTerm, null);
    return resource;
}
Also used : NotFoundMediaResource(org.olat.core.gui.media.NotFoundMediaResource) VFSContainer(org.olat.core.util.vfs.VFSContainer) HttpServletResponse(javax.servlet.http.HttpServletResponse) LocalFolderImpl(org.olat.core.util.vfs.LocalFolderImpl) GlossaryItemManager(org.olat.core.commons.modules.glossary.GlossaryItemManager) StringMediaResource(org.olat.core.gui.media.StringMediaResource) File(java.io.File) HashSet(java.util.HashSet) GlossaryItem(org.olat.core.commons.modules.glossary.GlossaryItem)

Example 80 with LocalFolderImpl

use of org.olat.core.util.vfs.LocalFolderImpl in project OpenOLAT by OpenOLAT.

the class CourseLayoutHelper method getCourseThemeTemplates.

/**
 * get a list of system wide course theme templates
 * they need to be in webapp/static/coursethemes/XY
 * @return
 */
public static List<VFSItem> getCourseThemeTemplates() {
    List<VFSItem> courseThemes = new ArrayList<VFSItem>();
    // 1. add the system-defaults
    String staticAbsPath = WebappHelper.getContextRealPath("/static");
    File themesFile = new File(staticAbsPath);
    VFSContainer cThemeCont = new LocalFolderImpl(themesFile);
    cThemeCont = (VFSContainer) cThemeCont.resolve("/coursethemes");
    if (cThemeCont != null) {
        courseThemes = cThemeCont.getItems(themeNamesFilter);
    }
    // 2. now add the additional Templates from the current Theme
    VFSContainer addThCont = CourseLayoutHelper.getOLATThemeCourseLayoutFolder();
    if (addThCont != null) {
        List<VFSItem> additionalThemes = addThCont.getItems(themeNamesFilter);
        courseThemes.addAll(additionalThemes);
    }
    return courseThemes;
}
Also used : VFSContainer(org.olat.core.util.vfs.VFSContainer) ArrayList(java.util.ArrayList) VFSItem(org.olat.core.util.vfs.VFSItem) File(java.io.File) LocalFolderImpl(org.olat.core.util.vfs.LocalFolderImpl)

Aggregations

LocalFolderImpl (org.olat.core.util.vfs.LocalFolderImpl)122 File (java.io.File)82 VFSContainer (org.olat.core.util.vfs.VFSContainer)76 VFSItem (org.olat.core.util.vfs.VFSItem)38 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)30 ArrayList (java.util.ArrayList)14 IOException (java.io.IOException)10 Document (org.dom4j.Document)10 RepositoryEntry (org.olat.repository.RepositoryEntry)10 CloseableModalController (org.olat.core.gui.control.generic.closablewrapper.CloseableModalController)8 DeliveryOptions (org.olat.core.gui.control.generic.iframe.DeliveryOptions)8 OLATResource (org.olat.resource.OLATResource)8 Date (java.util.Date)6 Document (org.apache.lucene.document.Document)6 Element (org.dom4j.Element)6 OlatRootFolderImpl (org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl)6 LocalFileImpl (org.olat.core.util.vfs.LocalFileImpl)6 CourseEnvironment (org.olat.course.run.environment.CourseEnvironment)6 CPPackageConfig (org.olat.ims.cp.ui.CPPackageConfig)6 SearchResourceContext (org.olat.search.service.SearchResourceContext)6