use of org.olat.core.util.vfs.VFSItem in project OpenOLAT by OpenOLAT.
the class FileCopyController method finishSuccessfullUpload.
private void finishSuccessfullUpload(String fileName, UserRequest ureq) {
VFSContainer currentContainer = folderComponent.getCurrentContainer();
VFSItem item = currentContainer.resolve(fileName);
if (item instanceof OlatRootFileImpl) {
OlatRootFileImpl relPathItem = (OlatRootFileImpl) item;
// create meta data
MetaInfo meta = CoreSpringFactory.getImpl(MetaInfoFactory.class).createMetaInfoFor(relPathItem);
meta.setAuthor(ureq.getIdentity());
// if overwrite an older file
meta.clearThumbnails();
meta.write();
}
ThreadLocalUserActivityLogger.log(FolderLoggingAction.FILE_COPIED, getClass(), CoreLoggingResourceable.wrapUploadFile(fileName));
// Notify listeners about upload
fireEvent(ureq, new FolderEvent(FolderEvent.NEW_FILE_EVENT, newFile.getName()));
fireEvent(ureq, FolderCommand.FOLDERCOMMAND_FINISHED);
}
use of org.olat.core.util.vfs.VFSItem in project OpenOLAT by OpenOLAT.
the class FileCopyController method proposedRenamedFilename.
private String proposedRenamedFilename(VFSLeaf file) {
String currentName = file.getName();
for (int i = 1; i < 999; i++) {
String proposition = FileUtils.appendNumberAtTheEndOfFilename(currentName, i);
VFSItem item = folderComponent.getCurrentContainer().resolve(proposition);
if (item == null) {
return proposition;
}
}
return null;
}
use of org.olat.core.util.vfs.VFSItem in project OpenOLAT by OpenOLAT.
the class FolderCommandHelper method tryDoubleDecoding.
/**
* The moduleURI from the UserRequest has been decoded (URL decoded). Which means that
* encoded character as + came as %B2, decoded from Tomcat as + and by OpenOLAT after
* as blank.
* @param ureq
* @param folderComponent
* @return
*/
public static VFSItem tryDoubleDecoding(UserRequest ureq, FolderComponent folderComponent) {
VFSItem vfsfile = null;
// double decoding of ++
String requestUri = ureq.getHttpReq().getRequestURI();
String uriPrefix = ureq.getUriPrefix();
if (uriPrefix.length() < requestUri.length()) {
requestUri = requestUri.substring(uriPrefix.length());
int nextPath = requestUri.indexOf('/');
if (nextPath > 0 && nextPath < requestUri.length()) {
String path = requestUri.substring(nextPath + 1, requestUri.length());
vfsfile = folderComponent.getRootContainer().resolve(path);
}
}
return vfsfile;
}
use of org.olat.core.util.vfs.VFSItem in project OpenOLAT by OpenOLAT.
the class FolderComponentRenderer method renderList.
private void renderList(StringOutput target, FolderComponent fc, URLBuilder ubu, Translator translator, boolean iframePostEnabled) {
VFSContainer currentContainer = fc.getCurrentContainer();
boolean canWrite = currentContainer.canWrite() == VFSConstants.YES;
boolean canCreateFolder = true;
if (currentContainer.getLocalSecurityCallback() != null && !currentContainer.getLocalSecurityCallback().canCreateFolder()) {
canCreateFolder = false;
}
boolean canDelete = false;
boolean canVersion = FolderConfig.versionsEnabled(fc.getCurrentContainer());
boolean canMail = fc.isCanMail();
for (Iterator<VFSItem> iter = fc.getCurrentContainerChildren().iterator(); iter.hasNext(); ) {
VFSItem child = iter.next();
if (child.canDelete() == VFSConstants.YES) {
canDelete = true;
break;
}
}
String formName = "folder" + CodeHelper.getRAMUniqueID();
target.append("<form method=\"post\" id=\"").append(formName).append("\" action=\"");
ubu.buildURI(target, new String[] { VelocityContainer.COMMAND_ID }, new String[] { FolderRunController.FORM_ACTION }, iframePostEnabled ? AJAXFlags.MODE_TOBGIFRAME : AJAXFlags.MODE_NORMAL);
target.append("\" ");
if (iframePostEnabled) {
// add ajax iframe target
target.append("\" onsubmit=\"o_XHRSubmit('").append(formName).append("');\">");
target.append("<input id=\"o_mai_").append(formName).append("\" type=\"hidden\" name=\"multi_action_identifier\" value=\"\"").append(" />");
} else {
target.append("\" onsubmit=\"if ( b_briefcase_isChecked('").append(formName).append("', '").append(Formatter.escapeSingleAndDoubleQuotes(StringHelper.escapeHtml(translator.translate("alert")).toString())).append("')) { if(o_info.linkbusy) return false; else o_beforeserver(); return true; } else {return false; }\">");
}
target.append("<div class=\"o_bc_createactions clearfix\"><ul class='nav navbar-nav navbar-right'>");
if (canWrite) {
if (canVersion) {
// deleted files
target.append("<li><a class=\"o_bc_deletedfiles\"");
ubu.buildHrefAndOnclick(target, null, iframePostEnabled, false, false, new NameValuePair(VelocityContainer.COMMAND_ID, "dfiles")).append("><i class='o_icon o_icon_recycle o_icon-fw'></i> ").append(translator.translate("dfiles")).append("</a></li>");
}
if (canWrite) {
if (fc.getExternContainerForCopy() != null && (fc.getExternContainerForCopy().getLocalSecurityCallback() == null || fc.getExternContainerForCopy().getLocalSecurityCallback().canCopy())) {
// option copy file
target.append("<li><a class=\"o_bc_copy\" ");
ubu.buildHrefAndOnclick(target, null, iframePostEnabled, false, false, new NameValuePair(VelocityContainer.COMMAND_ID, "copyfile")).append("><i class='o_icon o_icon_copy o_icon-fw'></i> ").append(translator.translate("copyfile")).append("</a></li>");
}
// option upload
target.append("<li><a class='o_bc_upload' ");
ubu.buildHrefAndOnclick(target, null, iframePostEnabled, false, false, new NameValuePair(VelocityContainer.COMMAND_ID, "ul")).append("><i class='o_icon o_icon_upload o_icon-fw'></i> ").append(translator.translate("ul")).append("</a></li>");
if (canCreateFolder) {
// option new folder
target.append("<li><a class=\"b_bc_newfolder\" ");
ubu.buildHrefAndOnclick(target, null, iframePostEnabled, false, false, new NameValuePair(VelocityContainer.COMMAND_ID, "cf")).append("><i class='o_icon o_icon_new_folder o_icon-fw'></i> ").append(translator.translate("cf")).append("</a></li>");
}
// option new file
target.append("<li><a class=\"b_bc_newfile\" ");
ubu.buildHrefAndOnclick(target, null, iframePostEnabled, false, false, new NameValuePair(VelocityContainer.COMMAND_ID, "cfile")).append("><i class='o_icon o_icon_new_document o_icon-fw'></i> ").append(translator.translate("cfile")).append("</a></li>");
}
}
// placeholder for the search
target.append("</ul></div>");
// add current file bread crumb path
crumbRenderer.render(fc, target, ubu, iframePostEnabled);
// add file listing for current folder
target.append("<div class='o_table_wrapper'>");
listRenderer.render(fc, target, ubu, translator, iframePostEnabled);
if (fc.getCurrentContainerChildren().size() > 0) {
target.append("<div class='o_table_footer'>").append("<div class=\"o_table_checkall input-sm\">").append("<label class='checkbox-inline'><a href=\"#\" onclick=\"javascript:b_briefcase_toggleCheck('").append(formName).append("', true)\">").append("<input type=\"checkbox\" checked=\"checked\" disabled=\"disabled\" />").append(translator.translate("checkall")).append("</a></label> <label class='checkbox-inline'><a href=\"#\" onclick=\"javascript:b_briefcase_toggleCheck('").append(formName).append("', false)\">").append("<input type=\"checkbox\" disabled=\"disabled\" />").append(translator.translate("uncheckall")).append("</a></label></div>").append("<div class='o_table_buttons'>");
if (canMail) {
target.append("<button type=\"button\" class='btn btn-default' onclick=\"o_TableMultiActionEvent('").append(formName).append("','").append(FolderRunController.ACTION_PRE).append(FolderCommandFactory.COMMAND_MAIL).append("');\"><span>").append(StringHelper.escapeHtml(translator.translate("send"))).append("</span></button>");
}
target.append(" <button type=\"button\" class='btn btn-default' onclick=\"o_TableMultiActionEvent('").append(formName).append("','").append(FolderRunController.ACTION_PRE).append(FolderCommandFactory.COMMAND_DOWNLOAD_ZIP).append("');\"><span>").append(StringHelper.escapeHtml(translator.translate("download"))).append("</span></button>");
if (canDelete) {
// delete
target.append(" <button type=\"button\" class='btn btn-default' onclick=\"o_TableMultiActionEvent('").append(formName).append("','").append(FolderRunController.ACTION_PRE).append(FolderCommandFactory.COMMAND_DEL).append("');\"><span>").append(StringHelper.escapeHtml(translator.translate("del"))).append("</span></button>");
}
if (canWrite) {
// move
target.append(" <button type=\"button\" class='btn btn-default' onclick=\"o_TableMultiActionEvent('").append(formName).append("','").append(FolderRunController.ACTION_PRE).append(FolderCommandFactory.COMMAND_MOVE).append("');\"><span>").append(StringHelper.escapeHtml(translator.translate("move"))).append("</span></button>");
// copy
target.append(" <button type=\"button\" class='btn btn-default' onclick=\"o_TableMultiActionEvent('").append(formName).append("','").append(FolderRunController.ACTION_PRE).append(FolderCommandFactory.COMMAND_COPY).append("');\"><span>").append(StringHelper.escapeHtml(translator.translate("copy"))).append("</span></button>");
// zip
target.append(" <button type=\"button\" class='btn btn-default' onclick=\"o_TableMultiActionEvent('").append(formName).append("','").append(FolderRunController.ACTION_PRE).append(FolderCommandFactory.COMMAND_ZIP).append("');\"><span>").append(StringHelper.escapeHtml(translator.translate("zip"))).append("</span></button>");
// unzip
target.append(" <button type=\"button\" class='btn btn-default' onclick=\"o_TableMultiActionEvent('").append(formName).append("','").append(FolderRunController.ACTION_PRE).append(FolderCommandFactory.COMMAND_UNZIP).append("');\"><span>").append(StringHelper.escapeHtml(translator.translate("unzip"))).append("</span></button>");
}
target.append("</div></div>");
}
target.append("</div></form>");
}
use of org.olat.core.util.vfs.VFSItem in project OpenOLAT by OpenOLAT.
the class WebdavStatus method doPropfind.
/**
* PROPFIND Method.
*/
public void doPropfind(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String path = getRelativePath(req);
if (path.length() > 1 && path.endsWith("/"))
path = path.substring(0, path.length() - 1);
// Properties which are to be displayed.
Vector<String> properties = null;
// Propfind depth
int depth = maxDepth;
// Propfind type
int type = FIND_ALL_PROP;
String depthStr = req.getHeader("Depth");
if (depthStr == null) {
depth = maxDepth;
} else {
if (depthStr.equals("0")) {
depth = 0;
} else if (depthStr.equals("1")) {
depth = 1;
} else if (depthStr.equals("infinity")) {
depth = maxDepth;
}
}
Node propNode = null;
if (req.getContentLength() > 0) {
DocumentBuilder documentBuilder = getDocumentBuilder(req);
try {
Document document = documentBuilder.parse(new InputSource(req.getInputStream()));
// Get the root element of the document
Element rootElement = document.getDocumentElement();
NodeList childList = rootElement.getChildNodes();
for (int i = 0; i < childList.getLength(); i++) {
Node currentNode = childList.item(i);
switch(currentNode.getNodeType()) {
case Node.TEXT_NODE:
break;
case Node.ELEMENT_NODE:
if (currentNode.getNodeName().endsWith("prop")) {
type = FIND_BY_PROPERTY;
propNode = currentNode;
}
if (currentNode.getNodeName().endsWith("propname")) {
type = FIND_PROPERTY_NAMES;
}
if (currentNode.getNodeName().endsWith("allprop")) {
type = FIND_ALL_PROP;
}
break;
}
}
} catch (SAXException e) {
// Something went wrong - bad request
resp.sendError(WebdavStatus.SC_BAD_REQUEST);
return;
} catch (IOException e) {
// Something went wrong - bad request
resp.sendError(WebdavStatus.SC_BAD_REQUEST);
return;
}
}
if (type == FIND_BY_PROPERTY) {
properties = new Vector<>();
// propNode must be non-null if type == FIND_BY_PROPERTY
NodeList childList = propNode.getChildNodes();
for (int i = 0; i < childList.getLength(); i++) {
Node currentNode = childList.item(i);
switch(currentNode.getNodeType()) {
case Node.TEXT_NODE:
break;
case Node.ELEMENT_NODE:
String nodeName = currentNode.getNodeName();
String propertyName = null;
if (nodeName.indexOf(':') != -1) {
propertyName = nodeName.substring(nodeName.indexOf(':') + 1);
} else {
propertyName = nodeName;
}
// href is a live property which is handled differently
properties.addElement(propertyName);
break;
}
}
}
WebResourceRoot resources = getResources(req);
WebResource resource = resources.getResource(path);
if (!resource.exists()) {
int slash = path.lastIndexOf('/');
if (slash != -1) {
String parentPath = path.substring(0, slash);
WebResource parentResource = resources.getResource(parentPath);
Vector<String> currentLockNullResources = lockManager.getLockNullResource(parentResource);
if (currentLockNullResources != null) {
Enumeration<String> lockNullResourcesList = currentLockNullResources.elements();
while (lockNullResourcesList.hasMoreElements()) {
String lockNullPath = lockNullResourcesList.nextElement();
if (lockNullPath.equals(path)) {
resp.setStatus(WebdavStatus.SC_MULTI_STATUS);
resp.setContentType("text/xml; charset=UTF-8");
// Create multistatus object
XMLWriter generatedXML = new XMLWriter(resp.getWriter());
generatedXML.writeXMLHeader();
generatedXML.writeElement("D", DEFAULT_NAMESPACE, "multistatus", XMLWriter.OPENING);
parseLockNullProperties(req, generatedXML, lockNullPath, type, properties);
generatedXML.writeElement("D", "multistatus", XMLWriter.CLOSING);
generatedXML.sendData();
return;
}
}
}
}
}
if (!resource.exists()) {
resp.sendError(HttpServletResponse.SC_NOT_FOUND, path);
return;
}
resp.setStatus(WebdavStatus.SC_MULTI_STATUS);
resp.setContentType("text/xml; charset=UTF-8");
// Create multistatus object
XMLWriter generatedXML = new XMLWriter(resp.getWriter());
generatedXML.writeXMLHeader();
generatedXML.writeElement("D", DEFAULT_NAMESPACE, "multistatus", XMLWriter.OPENING);
if (depth == 0) {
parseProperties(req, generatedXML, path, type, properties);
} else {
// The stack always contains the object of the current level
Stack<String> stack = new Stack<String>();
stack.push(path);
// Stack of the objects one level below
Stack<String> stackBelow = new Stack<String>();
while ((!stack.isEmpty()) && (depth >= 0)) {
final String currentPath = stack.pop();
parseProperties(req, generatedXML, currentPath, type, properties);
resource = resources.getResource(currentPath);
if (resource.isDirectory() && (depth > 0)) {
Collection<VFSItem> entries = resources.list(currentPath);
for (VFSItem entry : entries) {
String newPath = currentPath;
if (!(newPath.endsWith("/")))
newPath += "/";
newPath += entry.getName();
stackBelow.push(newPath);
}
// Displaying the lock-null resources present in that
// collection
String lockPath = currentPath;
if (lockPath.endsWith("/")) {
lockPath = lockPath.substring(0, lockPath.length() - 1);
}
Vector<String> currentLockNullResources = lockManager.getLockNullResource(resource);
if (currentLockNullResources != null) {
Enumeration<String> lockNullResourcesList = currentLockNullResources.elements();
while (lockNullResourcesList.hasMoreElements()) {
String lockNullPath = lockNullResourcesList.nextElement();
parseLockNullProperties(req, generatedXML, lockNullPath, type, properties);
}
}
}
if (stack.isEmpty()) {
depth--;
stack = stackBelow;
stackBelow = new Stack<String>();
}
generatedXML.sendData();
}
}
generatedXML.writeElement("D", "multistatus", XMLWriter.CLOSING);
generatedXML.sendData();
}
Aggregations