Search in sources :

Example 66 with VFSItem

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

the class WikiToZipUtils method createIndexPageForExport.

/**
 * creates an html page with the mappings between the pagename and the Base64
 * encoded filename.
 *
 * @param vfsLeaves
 * @return
 */
private static String createIndexPageForExport(List<VFSItem> vfsLeaves) {
    boolean hasProperties = false;
    StringBuilder sb = new StringBuilder();
    sb.append("<html><head>");
    sb.append("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">");
    sb.append("</head><body><ul>");
    for (Iterator<VFSItem> iter = vfsLeaves.iterator(); iter.hasNext(); ) {
        VFSLeaf element = (VFSLeaf) iter.next();
        // destination.copyFrom(element);
        if (element.getName().endsWith(WikiManager.WIKI_PROPERTIES_SUFFIX)) {
            hasProperties = true;
            Properties p = new Properties();
            try {
                p.load(element.getInputStream());
            } catch (IOException e) {
                throw new AssertException("Wiki propterties couldn't be read! ", e);
            }
            sb.append("<li>");
            sb.append(p.getProperty(WikiManager.PAGENAME));
            sb.append(" ----> ");
            sb.append(element.getName().substring(0, element.getName().indexOf(".")));
            sb.append("</li>");
        }
    }
    sb.append("</ul></body></html>");
    if (!hasProperties)
        return null;
    return sb.toString();
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) AssertException(org.olat.core.logging.AssertException) VFSItem(org.olat.core.util.vfs.VFSItem) IOException(java.io.IOException) Properties(java.util.Properties)

Example 67 with VFSItem

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

the class WikiToZipUtils method getWikiAsZip.

/**
 * get the whole wiki as a zip file for export, content is unparsed!
 * @param rootContainer
 * @return
 */
public static VFSLeaf getWikiAsZip(VFSContainer rootContainer) {
    List<VFSItem> folders = rootContainer.getItems();
    VFSLeaf indexLeaf = (VFSLeaf) rootContainer.resolve("index.html");
    if (indexLeaf != null)
        indexLeaf.delete();
    List<VFSItem> filesTozip = new ArrayList<VFSItem>();
    for (Iterator<VFSItem> iter = folders.iterator(); iter.hasNext(); ) {
        VFSItem item = iter.next();
        if (item instanceof VFSContainer) {
            VFSContainer folder = (VFSContainer) item;
            List<VFSItem> items = folder.getItems();
            String overviewPage = WikiToZipUtils.createIndexPageForExport(items);
            if (overviewPage != null) {
                VFSLeaf overview = rootContainer.createChildLeaf("index.html");
                // items.add(overview); take care not to have duplicate entries in the list
                FileUtils.save(overview.getOutputStream(false), overviewPage, "utf-8");
            }
            // reload list, maybe there is a new index.html file
            items = folder.getItems();
            filesTozip.addAll(items);
        }
    }
    VFSLeaf zipFile = (VFSLeaf) rootContainer.resolve("wiki.zip");
    if (rootContainer.resolve("wiki.zip") != null)
        zipFile.delete();
    ZipUtil.zip(filesTozip, rootContainer.createChildLeaf("wiki.zip"), true);
    return (VFSLeaf) rootContainer.resolve("wiki.zip");
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) VFSContainer(org.olat.core.util.vfs.VFSContainer) ArrayList(java.util.ArrayList) VFSItem(org.olat.core.util.vfs.VFSItem)

Example 68 with VFSItem

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

the class WikiToZipUtils method wikiToZip.

public static void wikiToZip(VFSContainer rootContainer, String currentPath, ZipOutputStream exportStream) throws IOException {
    for (VFSItem item : rootContainer.getItems()) {
        if (item instanceof VFSContainer) {
            VFSContainer folder = (VFSContainer) item;
            List<VFSItem> items = folder.getItems();
            String overviewPage = WikiToZipUtils.createIndexPageForExport(items);
            if (overviewPage != null) {
                exportStream.putNextEntry(new ZipEntry(currentPath + "/index.html"));
                IOUtils.write(overviewPage, exportStream, "UTF-8");
                exportStream.closeEntry();
            }
            for (VFSItem wikiItem : items) {
                ZipUtil.addToZip(wikiItem, currentPath, exportStream);
            }
        }
    }
}
Also used : VFSContainer(org.olat.core.util.vfs.VFSContainer) ZipEntry(java.util.zip.ZipEntry) VFSItem(org.olat.core.util.vfs.VFSItem)

Example 69 with VFSItem

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

the class Wiki method getMediaFileList.

protected List<VFSItem> getMediaFileList() {
    List<VFSItem> allFiles = mediaContainer.getItems();
    List<VFSItem> mediaFilesOnly = new ArrayList<VFSItem>();
    for (Iterator<VFSItem> iter = allFiles.iterator(); iter.hasNext(); ) {
        VFSItem element = iter.next();
        if (!element.getName().endsWith(WikiMainController.METADATA_SUFFIX))
            mediaFilesOnly.add(element);
    }
    return mediaFilesOnly;
}
Also used : ArrayList(java.util.ArrayList) VFSItem(org.olat.core.util.vfs.VFSItem)

Example 70 with VFSItem

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

the class BCCourseNodeIndexer method doIndex.

@Override
public void doIndex(SearchResourceContext repositoryResourceContext, ICourse course, CourseNode courseNode, OlatFullIndexer indexWriter) throws IOException, InterruptedException {
    if (isLogDebugEnabled())
        logDebug("Index Briefcase...");
    BCCourseNode bcNode = (BCCourseNode) courseNode;
    SearchResourceContext courseNodeResourceContext = createSearchResourceContext(repositoryResourceContext, bcNode, TYPE);
    Document document = CourseNodeDocument.createDocument(courseNodeResourceContext, bcNode);
    indexWriter.addDocument(document);
    VFSContainer bcContainer = null;
    if (bcNode.getModuleConfiguration().getBooleanSafe(BCCourseNodeEditController.CONFIG_AUTO_FOLDER)) {
        bcContainer = BCCourseNode.getNodeFolderContainer(bcNode, course.getCourseEnvironment());
    } else {
        String subpath = courseNode.getModuleConfiguration().getStringValue(BCCourseNodeEditController.CONFIG_SUBPATH);
        if (subpath != null) {
            VFSItem item = course.getCourseEnvironment().getCourseFolderContainer().resolve(subpath);
            if (item instanceof VFSContainer) {
                bcContainer = new NamedContainerImpl(courseNode.getShortTitle(), (VFSContainer) item);
            }
        }
    }
    if (bcContainer != null) {
        doIndexVFSContainer(courseNodeResourceContext, bcContainer, indexWriter, "", FolderIndexerAccess.FULL_ACCESS);
    }
}
Also used : BCCourseNode(org.olat.course.nodes.BCCourseNode) SearchResourceContext(org.olat.search.service.SearchResourceContext) VFSContainer(org.olat.core.util.vfs.VFSContainer) VFSItem(org.olat.core.util.vfs.VFSItem) Document(org.apache.lucene.document.Document) CourseNodeDocument(org.olat.search.service.document.CourseNodeDocument) NamedContainerImpl(org.olat.core.util.vfs.NamedContainerImpl)

Aggregations

VFSItem (org.olat.core.util.vfs.VFSItem)546 VFSContainer (org.olat.core.util.vfs.VFSContainer)356 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)272 File (java.io.File)78 Test (org.junit.Test)68 OlatRootFolderImpl (org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl)68 ArrayList (java.util.ArrayList)64 InputStream (java.io.InputStream)52 MetaInfo (org.olat.core.commons.modules.bc.meta.MetaInfo)52 Identity (org.olat.core.id.Identity)50 MetaTagged (org.olat.core.commons.modules.bc.meta.tagged.MetaTagged)48 IOException (java.io.IOException)42 Date (java.util.Date)40 URI (java.net.URI)38 LocalFolderImpl (org.olat.core.util.vfs.LocalFolderImpl)38 SystemItemFilter (org.olat.core.util.vfs.filters.SystemItemFilter)34 OutputStream (java.io.OutputStream)30 VFSMediaResource (org.olat.core.util.vfs.VFSMediaResource)28 HttpResponse (org.apache.http.HttpResponse)22 URL (java.net.URL)20