use of org.olat.core.util.vfs.VFSItem in project OpenOLAT by OpenOLAT.
the class VFSWebservice method resolveContainer.
protected VFSContainer resolveContainer(List<PathSegment> path, boolean create) {
VFSContainer directory = container;
boolean notFound = false;
// remove trailing segment if a trailing / is used
if (path.size() > 0 && !StringHelper.containsNonWhitespace(path.get(path.size() - 1).getPath())) {
path = path.subList(0, path.size() - 1);
}
a_a: for (PathSegment seg : path) {
String segPath = seg.getPath();
for (VFSItem item : directory.getItems(new SystemItemFilter())) {
if (item instanceof VFSLeaf) {
//
} else if (item instanceof VFSContainer && normalize(item.getName()).equals(segPath)) {
directory = (VFSContainer) item;
continue a_a;
}
}
if (create) {
directory = directory.createChildContainer(segPath);
} else if (path.get(path.size() - 1) == seg) {
break a_a;
} else {
notFound = true;
}
}
if (notFound) {
return null;
}
return directory;
}
use of org.olat.core.util.vfs.VFSItem in project OpenOLAT by OpenOLAT.
the class BulkAssessmentTask method processReturnFile.
private void processReturnFile(AssessableCourseNode courseNode, BulkAssessmentRow row, UserCourseEnvironment uce, File assessedFolder) {
String assessedId = row.getAssessedId();
Identity identity = uce.getIdentityEnvironment().getIdentity();
VFSContainer returnBox = getReturnBox(uce, courseNode, identity);
if (returnBox != null) {
for (String returnFilename : row.getReturnFiles()) {
File returnFile = new File(assessedFolder, returnFilename);
VFSItem currentReturnLeaf = returnBox.resolve(returnFilename);
if (currentReturnLeaf != null) {
// remove the current file (delete make a version if it is enabled)
currentReturnLeaf.delete();
}
VFSLeaf returnLeaf = returnBox.createChildLeaf(returnFilename);
if (returnFile.exists()) {
try {
InputStream inStream = new FileInputStream(returnFile);
VFSManager.copyContent(inStream, returnLeaf);
} catch (FileNotFoundException e) {
log.error("Cannot copy return file " + returnFilename + " from " + assessedId, e);
}
}
}
}
}
use of org.olat.core.util.vfs.VFSItem in project OpenOLAT by OpenOLAT.
the class FileCreatorController method validateFormLogic.
@Override
protected boolean validateFormLogic(UserRequest ureq) {
boolean isFileNmaeValid = true;
boolean isSubDirValid = true;
// 1: Check sub path
String subPath = targetSubPath.getValue();
if (subPath != null) {
// Cleanup first
subPath = subPath.toLowerCase().trim();
if (!validSubPathPattern.matcher(subPath).matches()) {
targetSubPath.setErrorKey("subpath.error.characters", null);
isSubDirValid = false;
} else {
// Fix mess with slashes and dots
// reduce doubled slashes with single slash
subPath = subPath.replaceAll("\\.*\\/+\\.*", "\\/");
// do it a second time to catch the double slashes created by previous replacement
subPath = subPath.replaceAll("\\/+", "\\/");
// remove slash at end
if (subPath.endsWith("/")) {
subPath = subPath.substring(0, subPath.length() - 1);
}
// single slash means no sub-directory
if (subPath.length() == 1 && subPath.startsWith("/")) {
subPath = "";
}
// fix missing slash at start
if (subPath.length() > 0 && !subPath.startsWith("/")) {
subPath = "/" + subPath;
}
// update in GUI so user sees how we optimized
targetSubPath.setValue(subPath);
}
// Now check if this path does not already exist
if (isSubDirValid && StringHelper.containsNonWhitespace(subPath)) {
// Try to resolve given rel path from current container
VFSItem uploadDir = baseContainer.resolve(subPath);
if (uploadDir != null) {
// already exists. this is fine, as long as it is a directory and not a file
if (!(uploadDir instanceof VFSContainer)) {
// error
targetSubPath.setErrorKey("subpath.error.dir.is.file", new String[] { subPath });
isSubDirValid = false;
}
}
}
if (isSubDirValid) {
targetSubPath.clearError();
}
}
// 2: Check file name
String fileName = fileNameElement.getValue();
if (!StringHelper.containsNonWhitespace(fileName)) {
fileNameElement.setErrorKey("mf.error.filename.empty", new String[0]);
isFileNmaeValid = false;
} else {
fileName = fileName.toLowerCase().trim();
if (!FileUtils.validateFilename(fileName)) {
fileNameElement.setErrorKey("mf.error.filename.invalidchars", new String[0]);
isFileNmaeValid = false;
} else if (!fileName.endsWith(".html") && !fileName.endsWith(".htm")) {
fileName = fileName + ".html";
}
// update in GUI so user sees how we optimized
fileNameElement.setValue(fileName);
// check if it already exists
String filePath = fileName;
if (filePath.startsWith("/")) {
filePath = "/" + filePath;
}
if (StringHelper.containsNonWhitespace(targetSubPath.getValue())) {
filePath = targetSubPath.getValue() + filePath;
}
VFSItem vfsItem = baseContainer.resolve(filePath);
if (vfsItem != null) {
fileNameElement.setErrorKey("mf.error.filename.exists", new String[] { filePath });
isFileNmaeValid = false;
}
}
if (isFileNmaeValid) {
fileNameElement.clearError();
}
return isFileNmaeValid && isSubDirValid;
}
use of org.olat.core.util.vfs.VFSItem in project OpenOLAT by OpenOLAT.
the class ImpressumAdminController method doDelete.
private void doDelete(VFSContainer rootDir, String lang) {
String filePath = "index_" + lang + ".html";
VFSItem file = rootDir.resolve(filePath);
if (file != null) {
file.delete();
}
}
use of org.olat.core.util.vfs.VFSItem in project OpenOLAT by OpenOLAT.
the class ExportManager method createLogFile.
/**
* Create the actual log file.
* <p>
* Note: vfsContainer and dir must point to the very same directory. This is necessary to allow
* converting of the resulting file into a VFSLeaf (which is required by the zip util class)
* and to have the absolute path name of the vfsContainer for the sql export (there's no
* getter on the VFSContainer for the absolute path - this is core reason why).
* This 'hack' is not very nice but we'll live with it for the moment.
* <p>
* @param oresID
* @param begin
* @param end
* @param charset
* @param vfsContainer
* @param dir
* @param filename
* @param resourceAdminAction
* @param anonymize
* @return
*/
private VFSItem createLogFile(Long oresID, Date begin, Date end, String charset, VFSContainer vfsContainer, File dir, String filename, boolean resourceAdminAction, boolean anonymize) {
File outFile = new File(dir, filename);
// trigger the course log exporter - it will store the file to outFile
log_.info("createLogFile: start exporting course log file " + outFile.getAbsolutePath());
courseLogExporter.exportCourseLog(outFile, charset, oresID, begin, end, resourceAdminAction, anonymize);
log_.info("createLogFile: finished exporting course log file " + outFile.getAbsolutePath());
VFSItem logFile = vfsContainer.resolve(filename);
if (logFile == null) {
log_.warn("createLogFile: could not resolve " + filename);
}
return logFile;
}
Aggregations