Search in sources :

Example 71 with VFSLeaf

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

the class FeedFormController method formInnerEvent.

@Override
protected void formInnerEvent(UserRequest ureq, FormItem source, FormEvent event) {
    if (source == cancelButton && event.wasTriggerdBy(FormEvent.ONCLICK)) {
        fireEvent(ureq, Event.CANCELLED_EVENT);
    } else if (source == file && event.wasTriggerdBy(FormEvent.ONCHANGE)) {
        // display the uploaded file
        if (file.isUploadSuccess()) {
            String newFilename = file.getUploadFileName();
            boolean isValidFileType = newFilename.toLowerCase().matches(".*[.](png|jpg|jpeg|gif)");
            if (!isValidFileType) {
                file.setErrorKey("feed.form.file.type.error.images", null);
            } else {
                file.clearError();
            }
            deleteImage.setVisible(true);
        }
    } else if (source == deleteImage) {
        VFSLeaf img = FeedManager.getInstance().createFeedMediaFile(feed, feed.getImageName(), null);
        if (file.getUploadFile() != null && file.getUploadFile() != file.getInitialFile()) {
            file.reset();
            if (img == null) {
                deleteImage.setVisible(false);
                imageDeleted = true;
            } else {
                deleteImage.setVisible(true);
                imageDeleted = false;
            }
        } else if (img != null) {
            imageDeleted = true;
            deleteImage.setVisible(false);
            file.setInitialFile(null);
        }
        flc.setDirty(true);
    }
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf)

Example 72 with VFSLeaf

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

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 73 with VFSLeaf

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

the class SPCourseNodeIndexer method indexSubPages.

private void indexSubPages(SearchResourceContext courseNodeResourceContext, VFSContainer rootContainer, OlatFullIndexer indexWriter, VFSLeaf leaf, Set<String> alreadyIndexFileNames, int subPageLevel, String rootFilePath) throws IOException, InterruptedException {
    int mySubPageLevel = subPageLevel;
    // check deepness of recursion
    if (mySubPageLevel++ <= 5) {
        List<String> links = getLinkListFrom(leaf);
        for (String link : links) {
            if (log.isDebug())
                log.debug("link=" + link);
            if ((rootFilePath != null) && !rootFilePath.equals("")) {
                if (rootFilePath.endsWith("/")) {
                    link = rootFilePath + link;
                } else {
                    link = rootFilePath + "/" + link;
                }
            }
            if (!alreadyIndexFileNames.contains(link)) {
                VFSItem item = rootContainer.resolve(link);
                if ((item != null) && (item instanceof VFSLeaf)) {
                    VFSLeaf subPageLeaf = (VFSLeaf) item;
                    if (log.isDebug())
                        log.debug("subPageLeaf=" + subPageLeaf);
                    String filePath = getPathFor(subPageLeaf);
                    String newRootFilePath = filePath;
                    doIndexVFSLeafByMySelf(courseNodeResourceContext, subPageLeaf, indexWriter, filePath);
                    alreadyIndexFileNames.add(link);
                    indexSubPages(courseNodeResourceContext, rootContainer, indexWriter, subPageLeaf, alreadyIndexFileNames, mySubPageLevel, newRootFilePath);
                } else {
                    if (log.isDebug())
                        log.debug("Could not found sub-page for link=" + link);
                }
            } else {
                if (log.isDebug())
                    log.debug("sub-page already indexed, link=" + link);
            }
        }
    } else {
        if (log.isDebug())
            log.debug("Reach to many sub-page levels. Go not further with indexing sub-pages last leaf=" + leaf.getName());
    }
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) VFSItem(org.olat.core.util.vfs.VFSItem)

Example 74 with VFSLeaf

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

the class SPCourseNodeIndexer method doIndex.

@Override
public void doIndex(SearchResourceContext courseResourceContext, ICourse course, CourseNode courseNode, OlatFullIndexer indexWriter) throws IOException, InterruptedException {
    if (log.isDebug())
        log.debug("Index SinglePage...");
    SearchResourceContext courseNodeResourceContext = createSearchResourceContext(courseResourceContext, courseNode, TYPE);
    Document nodeDocument = CourseNodeDocument.createDocument(courseNodeResourceContext, courseNode);
    indexWriter.addDocument(nodeDocument);
    // The root of the configured single page. Depends on the configuration
    // whether to follow relative links or not. When relative links are
    // followed, the root is the course folder root, if not, it is folder
    // where the configured file is in
    VFSContainer rootContainer;
    // The filename of the configured file relative to the rootContainer
    String chosenFile;
    // Read the course node configuration
    VFSContainer courseFolderContainer = course.getCourseEnvironment().getCourseFolderContainer();
    boolean allowRelativeLinks = courseNode.getModuleConfiguration().getBooleanSafe(SPEditController.CONFIG_KEY_ALLOW_RELATIVE_LINKS);
    String fileName = (String) courseNode.getModuleConfiguration().get(SPEditController.CONFIG_KEY_FILE);
    // *** IF YOU CHANGE THIS LOGIC, do also change it in SinglePageController! ***
    if (allowRelativeLinks) {
        // Case 1: relative links are allowed. The root is the root of the
        // course, the file name is relative to the root
        rootContainer = courseFolderContainer;
        chosenFile = fileName;
    } else {
        // Case 2: relative links are NOT allowed. We have to calculate the
        // new root and remove the relative path to the course folder form
        // the file.
        String startURI = ((fileName.charAt(0) == '/') ? fileName.substring(1) : fileName);
        int sla = startURI.lastIndexOf('/');
        if (sla != -1) {
            // Some subfolder path is detected, create basecontainer from it
            String root = startURI.substring(0, sla);
            startURI = startURI.substring(sla + 1);
            // Create new root folder from the relative folder path
            VFSContainer newroot = (VFSContainer) courseFolderContainer.resolve(root);
            newroot.setParentContainer(null);
            rootContainer = newroot;
        } else {
            // No subpath detected, just use course base container
            rootContainer = courseFolderContainer;
        }
        chosenFile = startURI;
    }
    VFSLeaf leaf = (VFSLeaf) rootContainer.resolve(chosenFile);
    if (leaf != null) {
        String filePath = getPathFor(leaf);
        // Use inherited method from LeafIndexer for the actual indexing of the content
        SearchResourceContext fileContext = new SearchResourceContext(courseNodeResourceContext);
        doIndexVFSLeafByMySelf(fileContext, leaf, indexWriter, filePath);
        if (!indexOnlyChosenFile) {
            if (log.isDebug())
                log.debug("Index sub pages in SP.");
            Set<String> alreadyIndexFileNames = new HashSet<String>();
            alreadyIndexFileNames.add(chosenFile);
            // Check if page has links to subpages and index those as well
            indexSubPages(courseNodeResourceContext, rootContainer, indexWriter, leaf, alreadyIndexFileNames, 0, filePath);
        } else if (log.isDebug()) {
            log.debug("Index only chosen file in SP.");
        }
    } else if (log.isDebug()) {
        log.debug("Can not found choosen file in SP => Nothing indexed.");
    }
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) 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) HashSet(java.util.HashSet)

Example 75 with VFSLeaf

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

the class DialogCourseNodeIndexer method doIndexFile.

/**
 * Index a file of dialog-module.
 * @param filename
 * @param forumKey
 * @param leafResourceContext
 * @param indexWriter
 * @throws IOException
 * @throws InterruptedException
 */
private void doIndexFile(DialogElement element, SearchResourceContext leafResourceContext, OlatFullIndexer indexWriter) throws IOException, InterruptedException {
    DialogElementsManager dialogElmsMgr = CoreSpringFactory.getImpl(DialogElementsManager.class);
    VFSContainer dialogContainer = dialogElmsMgr.getDialogContainer(element);
    VFSLeaf leaf = (VFSLeaf) dialogContainer.getItems(new VFSLeafFilter()).get(0);
    if (isLogDebugEnabled())
        logDebug("Analyse VFSLeaf=" + leaf.getName());
    try {
        if (CoreSpringFactory.getImpl(FileDocumentFactory.class).isFileSupported(leaf)) {
            leafResourceContext.setFilePath(element.getFilename());
            leafResourceContext.setDocumentType(TYPE_FILE);
            Document document = CoreSpringFactory.getImpl(FileDocumentFactory.class).createDocument(leafResourceContext, leaf);
            indexWriter.addDocument(document);
        } else {
            if (isLogDebugEnabled())
                logDebug("Documenttype not supported. file=" + leaf.getName());
        }
    } catch (DocumentAccessException e) {
        if (isLogDebugEnabled())
            logDebug("Can not access document." + e.getMessage());
    } catch (IOException ioEx) {
        logWarn("IOException: Can not index leaf=" + leaf.getName(), ioEx);
    } catch (InterruptedException iex) {
        throw new InterruptedException(iex.getMessage());
    } catch (Exception ex) {
        logWarn("Exception: Can not index leaf=" + leaf.getName(), ex);
    }
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) VFSContainer(org.olat.core.util.vfs.VFSContainer) IOException(java.io.IOException) DialogElementsManager(org.olat.course.nodes.dialog.DialogElementsManager) Document(org.apache.lucene.document.Document) ForumMessageDocument(org.olat.search.service.document.ForumMessageDocument) CourseNodeDocument(org.olat.search.service.document.CourseNodeDocument) FileDocumentFactory(org.olat.search.service.document.file.FileDocumentFactory) IOException(java.io.IOException) DocumentAccessException(org.olat.search.service.document.file.DocumentAccessException) VFSLeafFilter(org.olat.core.util.vfs.filters.VFSLeafFilter) DocumentAccessException(org.olat.search.service.document.file.DocumentAccessException)

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