use of org.olat.core.util.vfs.VFSLeaf in project OpenOLAT by OpenOLAT.
the class CPManagerImpl method writeToZip.
/**
* @see org.olat.ims.cp.CPManager#writeToZip(org.olat.ims.cp.ContentPackage)
*/
public VFSLeaf writeToZip(ContentPackage cp) {
OLATResourceable ores = cp.getResourcable();
VFSContainer cpRoot = cp.getRootDir();
VFSContainer oresRoot = FileResourceManager.getInstance().getFileResourceRootImpl(ores);
RepositoryEntry repoEntry = RepositoryManager.getInstance().lookupRepositoryEntry(ores, false);
String zipFileName = "imscp.zip";
if (repoEntry != null) {
String zipName = repoEntry.getResourcename();
if (zipName != null && zipName.endsWith(".zip")) {
zipFileName = zipName;
}
}
// delete old archive and create new one
VFSItem oldArchive = oresRoot.resolve(zipFileName);
if (oldArchive != null) {
// don't versioned the zip
oldArchive.deleteSilently();
}
ZipUtil.zip(cpRoot.getItems(), oresRoot.createChildLeaf(zipFileName), true);
VFSLeaf zip = (VFSLeaf) oresRoot.resolve(zipFileName);
return zip;
}
use of org.olat.core.util.vfs.VFSLeaf in project OpenOLAT by OpenOLAT.
the class ContentPackage method updatePage.
protected void updatePage(CPPage page) {
DefaultElement ele = cpcore.getElementByIdentifier(page.getIdentifier());
if (ele instanceof CPItem) {
CPItem item = (CPItem) ele;
item.setTitle(page.getTitle());
item.setMetadata(page.getMetadata());
String itemIdentifierRef = item.getIdentifierRef();
if (itemIdentifierRef == null || itemIdentifierRef.equals("")) {
// This item has no linked resource yet. Add one if there is a page file
// attached.
VFSLeaf pageFile = page.getPageFile();
if (pageFile != null) {
CPResource res = new CPResource();
CPFile file = new CPFile(pageFile);
res.addFile(file);
// TODO:GW Set type according to file
res.setType("text/html");
res.setHref(file.getHref());
item.setIdentifierRef(res.getIdentifier());
cpcore.getRootNode().getResources().addResource(res);
}
} else {
// this item has already a linked resource
// this is not supported, we don't change linked resources...
}
} else if (ele instanceof CPOrganization) {
CPOrganization organization = (CPOrganization) ele;
organization.setTitle(page.getTitle());
} else {
// ERROR: this shouldn't be
throw new OLATRuntimeException("Error while updating manifest with new Page-Data. Invalid identifier " + page.getIdentifier(), null);
}
}
use of org.olat.core.util.vfs.VFSLeaf in project OpenOLAT by OpenOLAT.
the class ContentPackage method writeToFile.
/**
* writes the manifest.xml
*/
void writeToFile() {
String filename = "imsmanifest.xml";
OutputFormat format = OutputFormat.createPrettyPrint();
try {
VFSLeaf outFile;
// file may exist
outFile = (VFSLeaf) cpcore.getRootDir().resolve("/" + filename);
if (outFile == null) {
// if not, create it
outFile = cpcore.getRootDir().createChildLeaf("/" + filename);
}
DefaultDocument manifestDocument = cpcore.buildDocument();
XMLWriter writer = new XMLWriter(outFile.getOutputStream(false), format);
writer.write(manifestDocument);
} catch (Exception e) {
log.error("imsmanifest for ores " + ores.getResourceableId() + "couldn't be written to file.", e);
throw new OLATRuntimeException(CPOrganizations.class, "Error writing imsmanifest-file", new IOException());
}
}
use of org.olat.core.util.vfs.VFSLeaf in project OpenOLAT by OpenOLAT.
the class CPFileImportController method containsItemsToAdd.
/**
* Breadth-first search for leafs inside the container that are to be added to
* the tree.
*
* @param container
* @param menuItemTypes
* @return true if there is a leaf inside container that should be added
*/
private boolean containsItemsToAdd(VFSContainer container, Collection<String> menuItemTypes) {
LinkedList<VFSItem> queue = new LinkedList<VFSItem>();
// enqueue root node
queue.add(container);
do {
// dequeue and exmaine
VFSItem item = queue.poll();
if (item instanceof VFSLeaf) {
if (isToBeAdded((VFSLeaf) item, menuItemTypes)) {
// node found, return
return true;
}
} else {
// enqueue successors
VFSContainer parent = (VFSContainer) item;
queue.addAll(parent.getItems());
}
} while (!queue.isEmpty());
return false;
}
use of org.olat.core.util.vfs.VFSLeaf in project OpenOLAT by OpenOLAT.
the class CPTreeController method addNewHTMLPage.
/**
* Adds a new page to the CP
*
* @return
*/
protected String addNewHTMLPage() {
String newId = CPManager.getInstance().addBlankPage(cp, translate("cptreecontroller.newpage.title"), currentPage.getIdentifier());
CPPage newPage = new CPPage(newId, cp);
// Create an html file
VFSContainer root = cp.getRootDir();
VFSLeaf htmlFile = root.createChildLeaf(newId + ".html");
newPage.setFile(htmlFile);
updatePage(newPage);
updateTree();
return newId;
}
Aggregations