use of org.olat.core.util.vfs.VFSContainer in project OpenOLAT by OpenOLAT.
the class VFSResourceRoot method mkdir.
@Override
public boolean mkdir(String path) {
// remove trailing /
if (path.endsWith("/")) {
path = path.substring(0, path.length() - 1);
}
int lastSlash = path.lastIndexOf('/');
if (lastSlash == -1)
return false;
String parentPath = path.substring(0, lastSlash);
VFSItem parentItem = resolveFile(parentPath);
if (parentItem instanceof VFSLeaf) {
return false;
} else if (parentItem instanceof VFSContainer) {
String name = path.substring(lastSlash + 1);
VFSContainer folder = (VFSContainer) parentItem;
if (folder.canWrite() == VFSConstants.YES) {
VFSContainer dir = folder.createChildContainer(name);
return dir != null && dir.exists();
}
}
return false;
}
use of org.olat.core.util.vfs.VFSContainer in project OpenOLAT by OpenOLAT.
the class VFSResourceRoot method canWrite.
@Override
public boolean canWrite(String name) {
// resolve item if it already exists
VFSItem item = resolveFile(name);
if (item == null) {
// try to resolve parent in case the item does not yet exist
int lastSlash = name.lastIndexOf("/");
if (lastSlash > 0) {
String containerName = name.substring(0, lastSlash);
item = resolveFile(containerName);
}
}
if (item == null) {
return false;
}
VFSStatus status;
if (item instanceof VFSContainer) {
status = item.canWrite();
} else {
// read/write is not defined on item level, only on directory level
status = item.getParentContainer().canWrite();
}
return VFSConstants.YES.equals(status);
}
use of org.olat.core.util.vfs.VFSContainer in project OpenOLAT by OpenOLAT.
the class VFSResourceRoot method write.
@Override
public boolean write(String path, InputStream is, boolean overwrite, WebResource movedFrom) throws QuotaExceededException {
VFSLeaf childLeaf;
VFSItem file = resolveFile(path);
if (file instanceof VFSLeaf) {
if (overwrite) {
// overwrite the file
childLeaf = (VFSLeaf) file;
// versioning
if (childLeaf instanceof Versionable && ((Versionable) childLeaf).getVersions().isVersioned()) {
if (childLeaf.getSize() == 0) {
VersionsManager.getInstance().createVersionsFor(childLeaf, true);
} else {
VersionsManager.getInstance().addToRevisions((Versionable) childLeaf, identity, "");
}
}
} else {
return false;
}
} else if (file instanceof VFSContainer) {
return false;
} else {
// create a new file
int lastSlash = path.lastIndexOf('/');
if (lastSlash == -1)
return false;
String parentPath = path.substring(0, lastSlash);
VFSItem parentItem = resolveFile(parentPath);
if (parentItem instanceof VFSContainer) {
VFSContainer folder = (VFSContainer) parentItem;
String name = path.substring(lastSlash + 1);
childLeaf = folder.createChildLeaf(name);
} else {
return false;
}
}
if (childLeaf == null) {
return false;
}
try {
copyVFS(childLeaf, is);
} catch (QuotaExceededException e) {
throw e;
} catch (Exception e) {
log.error("", e);
return false;
}
VFSContainer inheritingCont = VFSManager.findInheritingSecurityCallbackContainer(childLeaf.getParentContainer());
if (inheritingCont != null) {
VFSSecurityCallback callback = inheritingCont.getLocalSecurityCallback();
if (callback != null && callback.getSubscriptionContext() != null) {
SubscriptionContext subContext = callback.getSubscriptionContext();
NotificationsManager.getInstance().markPublisherNews(subContext, null, true);
}
}
if (childLeaf instanceof MetaTagged && identity != null) {
MetaInfo infos = ((MetaTagged) childLeaf).getMetaInfo();
if (infos != null && !infos.hasAuthorIdentity()) {
infos.setAuthor(identity);
addLicense(infos, identity);
infos.clearThumbnails();
// infos.write(); the clearThumbnails call write()
}
}
if (movedFrom instanceof VFSResource) {
VFSResource vfsResource = (VFSResource) movedFrom;
if (vfsResource.getItem() instanceof Versionable && ((Versionable) vfsResource.getItem()).getVersions().isVersioned()) {
VFSLeaf currentVersion = (VFSLeaf) vfsResource.getItem();
VersionsManager.getInstance().move(currentVersion, childLeaf, identity);
}
}
return true;
}
use of org.olat.core.util.vfs.VFSContainer in project OpenOLAT by OpenOLAT.
the class HtmlStaticPageComponent method setCurrentURI.
/**
* Sets the start html page, may be null
*
* @param currentURI The currentURI to set
*/
public void setCurrentURI(String currentURI) {
if (!isFileTypeSupported(currentURI)) {
throw new AssertException("can only accept files which are inline renderable(.html, .htm, .txt), but given filename is:" + currentURI);
}
this.currentURI = currentURI;
setDirty(true);
VFSItem sourceItem = null;
if (rootContainer != null)
sourceItem = rootContainer.resolve(currentURI);
if (sourceItem == null || (sourceItem instanceof VFSContainer)) {
jsOnLoad = null;
htmlHead = null;
htmlContent = "File not found: " + currentURI;
return;
}
getFileContent((VFSLeaf) sourceItem);
}
use of org.olat.core.util.vfs.VFSContainer in project OpenOLAT by OpenOLAT.
the class GlossaryTermMapper method handle.
/**
* @see org.olat.core.dispatcher.mapper.Mapper#handle(java.lang.String,
* javax.servlet.http.HttpServletRequest)
*/
public MediaResource handle(String relPath, HttpServletRequest request) {
GlossaryItemManager gIM = GlossaryItemManager.getInstance();
// security checks are done by MapperRegistry
String[] parts = relPath.split("/");
String glossaryId = parts[1];
String glossaryFolderString = FolderConfig.getCanonicalRoot() + FolderConfig.getRepositoryHome() + "/" + glossaryId + "/" + GlossaryMarkupItemController.INTERNAL_FOLDER_NAME;
File glossaryFolderFile = new File(glossaryFolderString);
if (!glossaryFolderFile.isDirectory()) {
logWarn("GlossaryTerms delivery failed; path to glossaryFolder not existing: " + relPath, null);
return new NotFoundMediaResource();
}
VFSContainer glossaryFolder = new LocalFolderImpl(glossaryFolderFile);
if (!gIM.isFolderContainingGlossary(glossaryFolder)) {
logWarn("GlossaryTerms delivery failed; glossaryFolder doesn't contain a valid Glossary: " + glossaryFolder, null);
return new NotFoundMediaResource();
}
// Create a media resource
StringMediaResource resource = new StringMediaResource() {
@Override
public void prepare(HttpServletResponse hres) {
// don't use normal string media headers which prevent caching,
// use standard browser caching based on last modified timestamp
}
};
resource.setLastModified(gIM.getGlossaryLastModifiedTime(glossaryFolder));
resource.setContentType("text/javascript");
// Get data
String glossaryArrayData = TextMarkerJsGenerator.loadGlossaryItemListAsJSArray(glossaryFolder);
resource.setData(glossaryArrayData);
// UTF-8 encoding used in this js file since explicitly set in the ajax
// call (usually js files are 8859-1)
resource.setEncoding("utf-8");
return resource;
}
Aggregations