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();
}
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");
}
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);
}
}
}
}
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;
}
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);
}
}
Aggregations