Search in sources :

Example 91 with LocalFolderImpl

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

the class RepositoryManager method setImage.

public boolean setImage(VFSLeaf newImageFile, RepositoryEntry re) {
    VFSLeaf currentImage = getImage(re);
    if (currentImage != null) {
        if (currentImage instanceof MetaTagged) {
            MetaInfo info = ((MetaTagged) currentImage).getMetaInfo();
            if (info != null) {
                info.clearThumbnails();
            }
        }
        currentImage.delete();
    }
    if (newImageFile == null || !newImageFile.exists() || newImageFile.getSize() <= 0) {
        return false;
    }
    String targetExtension = ".png";
    String extension = FileUtils.getFileSuffix(newImageFile.getName());
    if ("jpg".equalsIgnoreCase(extension) || "jpeg".equalsIgnoreCase(extension)) {
        targetExtension = ".jpg";
    }
    VFSContainer repositoryHome = new LocalFolderImpl(new File(FolderConfig.getCanonicalRepositoryHome()));
    VFSLeaf repoImage = repositoryHome.createChildLeaf(re.getResourceableId() + targetExtension);
    if (targetExtension.equals(".png") || targetExtension.equals(".jpg")) {
        Size newImageSize = imageHelper.getSize(newImageFile, extension);
        if (newImageSize != null && newImageSize.getWidth() <= PICTURE_WIDTH && newImageSize.getHeight() <= PICTURE_HEIGHT) {
            boolean success = VFSManager.copyContent(newImageFile, repoImage);
            return success;
        }
    }
    Size size = imageHelper.scaleImage(newImageFile, repoImage, PICTURE_WIDTH, PICTURE_WIDTH, false);
    return size != null;
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) Size(org.olat.core.commons.services.image.Size) VFSContainer(org.olat.core.util.vfs.VFSContainer) MetaTagged(org.olat.core.commons.modules.bc.meta.tagged.MetaTagged) MetaInfo(org.olat.core.commons.modules.bc.meta.MetaInfo) File(java.io.File) LocalFolderImpl(org.olat.core.util.vfs.LocalFolderImpl)

Example 92 with LocalFolderImpl

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

the class RepositoryManager method copyImage.

/**
 * Copy the repo entry image from the source to the target repository entry.
 * If the source repo entry does not exists, nothing will happen
 *
 * @param src
 * @param target
 * @return
 */
public boolean copyImage(RepositoryEntry source, RepositoryEntry target) {
    VFSLeaf srcFile = getImage(source);
    if (srcFile == null) {
        return false;
    }
    VFSLeaf targetFile = getImage(target);
    if (targetFile != null) {
        targetFile.delete();
    }
    String sourceImageSuffix = FileUtils.getFileSuffix(srcFile.getName());
    VFSContainer repositoryHome = new LocalFolderImpl(new File(FolderConfig.getCanonicalRepositoryHome()));
    VFSLeaf newImage = repositoryHome.createChildLeaf(target.getResourceableId() + "." + sourceImageSuffix);
    if (newImage != null) {
        return VFSManager.copyContent(srcFile, newImage);
    }
    return false;
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) VFSContainer(org.olat.core.util.vfs.VFSContainer) File(java.io.File) LocalFolderImpl(org.olat.core.util.vfs.LocalFolderImpl)

Example 93 with LocalFolderImpl

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

the class ScormRepositoryIndexer method doIndex.

protected void doIndex(SearchResourceContext resourceContext, OlatFullIndexer indexWriter, File cpRoot) throws IOException, InterruptedException {
    VFSContainer container = new LocalFolderImpl(cpRoot);
    VFSLeaf fManifest = (VFSLeaf) container.resolve("imsmanifest.xml");
    if (fManifest != null) {
        Element rootElement = IMSLoader.loadIMSDocument(fManifest).getRootElement();
        Document manfiestDoc = createManifestDocument(fManifest, rootElement, resourceContext);
        indexWriter.addDocument(manfiestDoc);
        ScormFileAccess accessRule = new ScormFileAccess();
        doIndexVFSContainer(resourceContext, container, indexWriter, "", accessRule);
    }
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) VFSContainer(org.olat.core.util.vfs.VFSContainer) Element(org.dom4j.Element) Document(org.apache.lucene.document.Document) IMSMetadataDocument(org.olat.search.service.document.file.IMSMetadataDocument) LocalFolderImpl(org.olat.core.util.vfs.LocalFolderImpl)

Example 94 with LocalFolderImpl

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

the class TACourseNodeIndexer method doIndex.

@Override
public void doIndex(SearchResourceContext repositoryResourceContext, ICourse course, CourseNode courseNode, OlatFullIndexer indexWriter) throws IOException, InterruptedException {
    SearchResourceContext courseNodeResourceContext = createSearchResourceContext(repositoryResourceContext, courseNode, null);
    Document nodeDocument = CourseNodeDocument.createDocument(courseNodeResourceContext, courseNode);
    indexWriter.addDocument(nodeDocument);
    // Index Task
    File fTaskfolder = new File(FolderConfig.getCanonicalRoot() + TACourseNode.getTaskFolderPathRelToFolderRoot(course.getCourseEnvironment(), courseNode));
    VFSContainer taskRootContainer = new LocalFolderImpl(fTaskfolder);
    courseNodeResourceContext.setDocumentType(TYPE_TASK);
    doIndexVFSContainer(courseNodeResourceContext, taskRootContainer, indexWriter, "", FolderIndexerAccess.FULL_ACCESS);
    // Index Dropbox
    String dropboxFilePath = FolderConfig.getCanonicalRoot() + DropboxController.getDropboxPathRelToFolderRoot(course.getCourseEnvironment(), courseNode);
    File fDropboxFolder = new File(dropboxFilePath);
    VFSContainer dropboxRootContainer = new LocalFolderImpl(fDropboxFolder);
    courseNodeResourceContext.setDocumentType(TYPE_DROPBOX);
    doIndexVFSContainer(courseNodeResourceContext, dropboxRootContainer, indexWriter, "", FolderIndexerAccess.FULL_ACCESS);
    // Index Returnbox
    String returnboxFilePath = FolderConfig.getCanonicalRoot() + ReturnboxController.getReturnboxPathRelToFolderRoot(course.getCourseEnvironment(), courseNode);
    File fResturnboxFolder = new File(returnboxFilePath);
    VFSContainer returnboxRootContainer = new LocalFolderImpl(fResturnboxFolder);
    courseNodeResourceContext.setDocumentType(TYPE_RETURNBOX);
    doIndexVFSContainer(courseNodeResourceContext, returnboxRootContainer, indexWriter, "", FolderIndexerAccess.FULL_ACCESS);
    // Index Solutionbox
    String solutionFilePath = FolderConfig.getCanonicalRoot() + SolutionController.getSolutionPathRelToFolderRoot(course.getCourseEnvironment(), courseNode);
    File fSolutionFolder = new File(solutionFilePath);
    VFSContainer solutionRootContainer = new LocalFolderImpl(fSolutionFolder);
    courseNodeResourceContext.setDocumentType(TYPE_SOLUTIONBOX);
    doIndexVFSContainer(courseNodeResourceContext, solutionRootContainer, indexWriter, "", FolderIndexerAccess.FULL_ACCESS);
}
Also used : SearchResourceContext(org.olat.search.service.SearchResourceContext) VFSContainer(org.olat.core.util.vfs.VFSContainer) Document(org.apache.lucene.document.Document) CourseNodeDocument(org.olat.search.service.document.CourseNodeDocument) File(java.io.File) LocalFolderImpl(org.olat.core.util.vfs.LocalFolderImpl)

Example 95 with LocalFolderImpl

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

the class RepositoryServiceImpl method getIntroductionImage.

@Override
public VFSLeaf getIntroductionImage(RepositoryEntry re) {
    VFSContainer repositoryHome = new LocalFolderImpl(new File(FolderConfig.getCanonicalRepositoryHome()));
    String imageName = re.getResourceableId() + ".jpg";
    VFSItem image = repositoryHome.resolve(imageName);
    if (image instanceof VFSLeaf) {
        return (VFSLeaf) image;
    }
    imageName = re.getResourceableId() + ".png";
    image = repositoryHome.resolve(imageName);
    if (image instanceof VFSLeaf) {
        return (VFSLeaf) image;
    }
    return null;
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) VFSContainer(org.olat.core.util.vfs.VFSContainer) 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