use of org.olat.core.util.vfs.lock.LockInfo in project OpenOLAT by OpenOLAT.
the class ListRenderer method appendRenderedFile.
// getRenderedDirectoryContent
/**
* Render a single file or folder.
*
* @param f The file or folder to render
* @param sb StringOutput to append generated html code
*/
private void appendRenderedFile(FolderComponent fc, VFSItem child, String currentContainerPath, StringOutput sb, URLBuilder ubu, Translator translator, boolean iframePostEnabled, boolean canContainerVersion, int pos) {
// assume full access unless security callback tells us something different.
boolean canWrite = child.getParentContainer().canWrite() == VFSConstants.YES;
// special case: virtual folders are always read only. parent of child =! the current container
canWrite = canWrite && !(fc.getCurrentContainer() instanceof VirtualContainer);
boolean isAbstract = (child instanceof AbstractVirtualContainer);
Versions versions = null;
if (canContainerVersion && child instanceof Versionable) {
Versionable versionable = (Versionable) child;
if (versionable.getVersions().isVersioned()) {
versions = versionable.getVersions();
}
}
boolean canVersion = versions != null && !versions.getRevisions().isEmpty();
boolean canAddToEPortfolio = FolderConfig.isEPortfolioAddEnabled();
VFSLeaf leaf = null;
if (child instanceof VFSLeaf) {
leaf = (VFSLeaf) child;
}
// if not a leaf, it must be a container...
boolean isContainer = (leaf == null);
MetaInfo metaInfo = null;
if (child instanceof MetaTagged) {
metaInfo = ((MetaTagged) child).getMetaInfo();
}
boolean lockedForUser = lockManager.isLockedForMe(child, fc.getIdentityEnvironnement().getIdentity(), fc.getIdentityEnvironnement().getRoles());
String name = child.getName();
boolean xssErrors = StringHelper.xssScanForErrors(name);
String pathAndName;
if (xssErrors) {
pathAndName = null;
} else {
pathAndName = currentContainerPath;
if (pathAndName.length() > 0 && !pathAndName.endsWith("/")) {
pathAndName += "/";
}
pathAndName += name;
}
// tr begin
sb.append("<tr><td>").append("<input type=\"checkbox\" name=\"").append(FileSelection.FORM_ID).append("\" value=\"");
if (xssErrors) {
sb.append(StringHelper.escapeHtml(name)).append("\" disabled=\"disabled\"");
} else {
sb.append(name).append("\" ");
}
sb.append("/> ");
// browse link pre
if (xssErrors) {
sb.append("<i class='o_icon o_icon-fw o_icon_banned'> </i> ");
sb.append(StringHelper.escapeHtml(name));
log.error("XSS Scan found something suspicious in: " + child);
} else {
sb.append("<a id='o_sel_doc_").append(pos).append("'");
if (isContainer) {
// for directories... normal module URIs
// needs encoding, not done in buildHrefAndOnclick!
// FIXME: SR: refactor encode: move to ubu.buildHrefAndOnclick
String pathAndNameEncoded = ubu.encodeUrl(pathAndName);
ubu.buildHrefAndOnclick(sb, pathAndNameEncoded, iframePostEnabled, false, true);
} else {
// for files, add PARAM_SERV command
sb.append(" href=\"");
ubu.buildURI(sb, new String[] { PARAM_SERV }, new String[] { "x" }, pathAndName, AJAXFlags.MODE_NORMAL);
sb.append("\"");
boolean download = FolderManager.isDownloadForcedFileType(name);
if (download) {
sb.append(" download=\"").append(StringHelper.escapeHtml(name)).append("\"");
} else {
sb.append(" target=\"_blank\"");
}
}
sb.append(">");
// icon css
sb.append("<i class=\"o_icon o_icon-fw ");
if (isContainer)
sb.append(CSSHelper.CSS_CLASS_FILETYPE_FOLDER);
else
sb.append(CSSHelper.createFiletypeIconCssClassFor(name));
sb.append("\"></i> ");
// name
if (isAbstract)
sb.append("<i>");
sb.append(StringHelper.escapeHtml(name));
if (isAbstract)
sb.append("</i>");
sb.append("</a>");
}
// file metadata as tooltip
if (metaInfo != null) {
boolean hasMeta = false;
sb.append("<div id='o_sel_doc_tooltip_").append(pos).append("' class='o_bc_meta' style='display:none;'>");
if (StringHelper.containsNonWhitespace(metaInfo.getTitle())) {
String title = StringHelper.escapeHtml(metaInfo.getTitle());
sb.append("<h5>").append(Formatter.escapeDoubleQuotes(title)).append("</h5>");
hasMeta = true;
}
if (StringHelper.containsNonWhitespace(metaInfo.getComment())) {
sb.append("<div class=\"o_comment\">");
String comment = StringHelper.escapeHtml(metaInfo.getComment());
sb.append(Formatter.escapeDoubleQuotes(comment));
sb.append("</div>");
hasMeta = true;
}
// boolean hasThumbnail = false;
if (metaInfo.isThumbnailAvailable() && !xssErrors) {
sb.append("<div class='o_thumbnail' style='background-image:url(");
ubu.buildURI(sb, new String[] { PARAM_SERV_THUMBNAIL }, new String[] { "x" }, pathAndName, AJAXFlags.MODE_NORMAL);
sb.append("); background-repeat:no-repeat; background-position:50% 50%;'></div>");
hasMeta = true;
// hasThumbnail = true;
}
// first try author info from metadata (creator)
// boolean hasMetaAuthor = false;
String author = metaInfo.getCreator();
// fallback use file author (uploader)
if (StringHelper.containsNonWhitespace(author)) {
// hasMetaAuthor = true;
} else {
author = metaInfo.getAuthor();
if (!"-".equals(author)) {
author = UserManager.getInstance().getUserDisplayName(author);
} else {
author = null;
}
}
author = StringHelper.escapeHtml(author);
if (StringHelper.containsNonWhitespace(author)) {
sb.append("<p class=\"o_author\">").append(Formatter.escapeDoubleQuotes(translator.translate("mf.author")));
sb.append(": ").append(Formatter.escapeDoubleQuotes(author)).append("</p>");
hasMeta = true;
}
sb.append("</div>");
if (hasMeta) {
// render tooltip only when it contains something
sb.append("<script type='text/javascript'>").append("/* <![CDATA[ */").append("jQuery(function() {\n").append(" jQuery('#o_sel_doc_").append(pos).append("').tooltip({\n").append(" html: true,\n").append(" container: 'body',\n").append(" title: function(){ return jQuery('#o_sel_doc_tooltip_").append(pos).append("').html(); }\n").append(" });\n").append(" jQuery('#o_sel_doc_").append(pos).append("').on('click', function(){\n").append(" jQuery('#o_sel_doc_").append(pos).append("').tooltip('hide');\n").append(" });\n").append("});").append("/* ]]> */").append("</script>");
}
}
sb.append("</td><td>");
// filesize
if (!isContainer) {
// append filesize
sb.append("<span class='text-muted small'>");
sb.append(Formatter.formatBytes(leaf.getSize()));
sb.append("</span>");
}
sb.append("</td><td>");
// last modified
long lastModified = child.getLastModified();
sb.append("<span class='text-muted small'>");
if (lastModified != VFSConstants.UNDEFINED)
sb.append(DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, translator.getLocale()).format(new Date(lastModified)));
else
sb.append("-");
sb.append("</span></td><td>");
// license
if (licensesEnabled) {
MetaInfoFactory metaInfoFactory = CoreSpringFactory.getImpl(MetaInfoFactory.class);
License license = metaInfoFactory.getLicense(metaInfo);
LicenseRenderer licenseRenderer = new LicenseRenderer(translator.getLocale());
licenseRenderer.render(sb, license, true);
sb.append("</td><td>");
}
if (canContainerVersion) {
if (canVersion)
if (versions != null) {
sb.append("<span class='text-muted small'>");
sb.append(versions.getRevisionNr());
sb.append("</span>");
}
sb.append("</td><td>");
}
// locked
boolean locked = lockManager.isLocked(child);
if (locked) {
LockInfo lock = lockManager.getLock(child);
sb.append("<i class=\"o_icon o_icon_locked\" title=\"");
if (lock != null && lock.getLockedBy() != null) {
String fullname = userManager.getUserDisplayName(lock.getLockedBy());
String date = "";
if (lock.getCreationDate() != null) {
date = fc.getDateTimeFormat().format(lock.getCreationDate());
}
String msg = translator.translate("Locked", new String[] { fullname, date });
if (lock.isWebDAVLock()) {
msg += " (WebDAV)";
}
sb.append(msg);
}
sb.append("\"> </i>");
}
sb.append("</td><td>");
// Info link
if (canWrite) {
int actionCount = 0;
if (canVersion) {
actionCount++;
}
String nameLowerCase = name.toLowerCase();
// OO-57 only display edit link if it's not a folder
boolean isLeaf = (child instanceof VFSLeaf);
boolean isEditable = (isLeaf && !lockedForUser && !xssErrors && (nameLowerCase.endsWith(".html") || nameLowerCase.endsWith(".htm") || nameLowerCase.endsWith(".txt") || nameLowerCase.endsWith(".css") || nameLowerCase.endsWith(".csv ")));
if (isEditable)
actionCount++;
boolean canEP = canAddToEPortfolio && !isContainer;
if (canEP)
actionCount++;
boolean canMetaData = canMetaInfo(child);
if (canMetaData)
actionCount++;
if (actionCount == 1 && canMetaData) {
// when only one action is available, don't render menu
sb.append("<a ");
ubu.buildHrefAndOnclick(sb, null, iframePostEnabled, false, false, new NameValuePair(PARAM_EDTID, pos)).append(" title=\"").append(StringHelper.escapeHtml(translator.translate("mf.edit"))).append("\"><i class=\"o_icon o_icon-fw o_icon_edit_metadata\"></i></a>");
} else if (actionCount > 1) {
// add actions to menu if multiple actions available
sb.append("<a id='o_sel_actions_").append(pos).append("' href='javascript:;'><i class='o_icon o_icon-lg o_icon_actions'></i></a>").append("<div id='o_sel_actions_pop_").append(pos).append("' style='display:none;'><ul class='list-unstyled'>");
// meta edit action (rename etc)
if (canMetaData) {
// Metadata edit link... also handles rename for non-OlatRelPathImpls
sb.append("<li><a ");
ubu.buildHrefAndOnclick(sb, null, iframePostEnabled, false, false, new NameValuePair(PARAM_EDTID, pos)).append("><i class=\"o_icon o_icon-fw o_icon_edit_metadata\"></i> ").append(StringHelper.escapeHtml(translator.translate("mf.edit"))).append("</a></li>");
}
// content edit action
if (isEditable) {
sb.append("<li><a ");
ubu.buildHrefAndOnclick(sb, null, iframePostEnabled, false, false, new NameValuePair(PARAM_CONTENTEDITID, pos)).append("><i class=\"o_icon o_icon-fw o_icon_edit_file\"></i> ").append(StringHelper.escapeHtml(translator.translate("editor"))).append("</a></li>");
}
// versions action
if (canVersion) {
// Versions link
sb.append("<li><a ");
ubu.buildHrefAndOnclick(sb, null, iframePostEnabled, false, false, new NameValuePair(PARAM_VERID, pos)).append("><i class=\"o_icon o_icon-fw o_icon_version\"></i> ").append(StringHelper.escapeHtml(translator.translate("versions"))).append("</a></li>");
}
// get a link for adding a file to ePortfolio, if file-owner is the current user
if (canEP) {
if (metaInfo != null) {
Identity author = metaInfo.getAuthorIdentity();
if (author != null && fc.getIdentityEnvironnement().getIdentity().getKey().equals(author.getKey())) {
sb.append("<li><a ");
ubu.buildHrefAndOnclick(sb, null, iframePostEnabled, false, false, new NameValuePair(PARAM_EPORT, pos)).append("><i class=\"o_icon o_icon-fw o_icon_eportfolio_add\"></i> ").append(StringHelper.escapeHtml(translator.translate("eportfolio"))).append("</a></li>");
}
}
}
sb.append("</ul></div>").append("<script type='text/javascript'>").append("/* <![CDATA[ */").append("jQuery(function() {\n").append(" o_popover('o_sel_actions_").append(pos).append("','o_sel_actions_pop_").append(pos).append("','left');\n").append("});").append("/* ]]> */").append("</script>");
}
}
sb.append("</td></tr>");
}
use of org.olat.core.util.vfs.lock.LockInfo in project OpenOLAT by OpenOLAT.
the class MetaInfoFormController method initForm.
@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
if (isSubform) {
setFormTitle("mf.metadata.title");
}
setFormContextHelp("Folders#_metadata");
MetaInfo meta = item instanceof OlatRelPathImpl ? metaInfoFactory.createMetaInfoFor((OlatRelPathImpl) item) : null;
// title
String titleVal = (meta != null ? meta.getTitle() : null);
title = uifactory.addTextElement("title", "mf.title", -1, titleVal, formLayout);
// filename
initialFilename = (item == null ? null : item.getName());
filename = uifactory.addTextElement("filename", "mf.filename", -1, initialFilename, formLayout);
filename.setEnabled(item == null || item.canRename() == VFSConstants.YES);
filename.setNotEmptyCheck("mf.error.empty");
filename.setMandatory(true);
// comment/description
String commentVal = (meta != null ? meta.getComment() : null);
comment = uifactory.addTextAreaElement("comment", "mf.comment", -1, 3, 1, true, commentVal, formLayout);
// license
if (licenseModule.isEnabled(licenseHandler)) {
License license = metaInfoFactory.getOrCreateLicense(meta, getIdentity());
LicenseSelectionConfig licenseSelectionConfig = LicenseUIFactory.createLicenseSelectionConfig(licenseHandler, license.getLicenseType());
licenseEl = uifactory.addDropdownSingleselect("mf.license", formLayout, licenseSelectionConfig.getLicenseTypeKeys(), licenseSelectionConfig.getLicenseTypeValues(getLocale()));
licenseEl.setMandatory(licenseSelectionConfig.isLicenseMandatory());
if (licenseSelectionConfig.getSelectionLicenseTypeKey() != null) {
licenseEl.select(licenseSelectionConfig.getSelectionLicenseTypeKey(), true);
}
licenseEl.addActionListener(FormEvent.ONCHANGE);
licensorEl = uifactory.addTextElement("mf.licensor", 1000, license.getLicensor(), formLayout);
String freetext = licenseService.isFreetext(license.getLicenseType()) ? license.getFreetext() : "";
licenseFreetextEl = uifactory.addTextAreaElement("mf.freetext", 4, 72, freetext, formLayout);
LicenseUIFactory.updateVisibility(licenseEl, licensorEl, licenseFreetextEl);
}
// creator
String creatorVal = (meta != null ? meta.getCreator() : null);
creator = uifactory.addTextElement("creator", "mf.creator", -1, creatorVal, formLayout);
// publisher
String publisherVal = (meta != null ? meta.getPublisher() : null);
publisher = uifactory.addTextElement("publisher", "mf.publisher", -1, publisherVal, formLayout);
// source/origin
String sourceVal = (meta != null ? meta.getSource() : null);
sourceEl = uifactory.addTextElement("source", "mf.source", -1, sourceVal, formLayout);
// city
String cityVal = (meta != null ? meta.getCity() : null);
city = uifactory.addTextElement("city", "mf.city", -1, cityVal, formLayout);
// publish date
String datePage = velocity_root + "/date.html";
FormLayoutContainer publicationDate = FormLayoutContainer.createCustomFormLayout("publicationDateLayout", getTranslator(), datePage);
publicationDate.setLabel("mf.publishDate", null);
formLayout.add(publicationDate);
String[] pubDate = (meta != null ? meta.getPublicationDate() : new String[] { "", "" });
publicationMonth = uifactory.addTextElement("publicationMonth", "mf.month", 2, StringHelper.escapeHtml(pubDate[1]), publicationDate);
publicationMonth.setDomReplacementWrapperRequired(false);
publicationMonth.setMaxLength(2);
publicationMonth.setDisplaySize(2);
publicationYear = uifactory.addTextElement("publicationYear", "mf.year", 4, StringHelper.escapeHtml(pubDate[0]), publicationDate);
publicationYear.setDomReplacementWrapperRequired(false);
publicationYear.setMaxLength(4);
publicationYear.setDisplaySize(4);
// number of pages
String pageVal = (meta != null ? meta.getPages() : null);
pages = uifactory.addTextElement("pages", "mf.pages", -1, pageVal, formLayout);
// language
String langVal = (meta != null ? meta.getLanguage() : null);
language = uifactory.addTextElement("language", "mf.language", -1, langVal, formLayout);
// url/link
String urlVal = (meta != null ? meta.getUrl() : null);
url = uifactory.addTextElement("url", "mf.url", -1, urlVal, formLayout);
/* static fields */
String sizeText, typeText;
if (item instanceof VFSLeaf) {
sizeText = Formatter.formatBytes(((VFSLeaf) item).getSize());
typeText = FolderHelper.extractFileType(item.getName(), getLocale());
} else {
sizeText = "-";
typeText = translate("mf.type.directory");
}
// Targets to hide
metaFields = new HashSet<>();
metaFields.add(creator);
metaFields.add(publisher);
metaFields.add(sourceEl);
metaFields.add(city);
metaFields.add(publicationDate);
metaFields.add(pages);
metaFields.add(language);
metaFields.add(url);
if (!hasMetadata(meta)) {
moreMetaDataLink = uifactory.addFormLink("mf.more.meta.link", formLayout, Link.LINK_CUSTOM_CSS);
setMetaFieldsVisible(false);
}
if (!isSubform) {
if (meta != null && !meta.isDirectory()) {
LockInfo lock = vfsLockManager.getLock(item);
// locked
String lockedTitle = getTranslator().translate("mf.locked");
String unlockedTitle = getTranslator().translate("mf.unlocked");
locked = uifactory.addRadiosHorizontal("locked", "mf.locked", formLayout, new String[] { "lock", "unlock" }, new String[] { lockedTitle, unlockedTitle });
locked.setHelpText(getTranslator().translate("mf.locked.help"));
if (vfsLockManager.isLocked(item)) {
locked.select("lock", true);
} else {
locked.select("unlock", true);
}
boolean lockForMe = vfsLockManager.isLockedForMe(item, getIdentity(), roles);
locked.setEnabled(!lockForMe);
// locked by
String lockedDetails = "";
if (lock != null) {
String user = userManager.getUserDisplayName(lock.getLockedBy());
user = StringHelper.escapeHtml(user);
String date = "";
if (lock.getCreationDate() != null) {
date = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, getLocale()).format(lock.getCreationDate());
}
lockedDetails = getTranslator().translate("mf.locked.description", new String[] { user, date });
} else {
lockedDetails = getTranslator().translate("mf.unlocked.description");
}
uifactory.addStaticTextElement("mf.lockedBy", lockedDetails, formLayout);
}
// username
String author = StringHelper.escapeHtml(meta == null ? "" : meta.getHTMLFormattedAuthor());
uifactory.addStaticTextElement("mf.author", author, formLayout);
// filesize
uifactory.addStaticTextElement("mf.size", StringHelper.escapeHtml(sizeText), formLayout);
// last modified date
String lastModified = meta == null ? "" : StringHelper.formatLocaleDate(meta.getLastModified(), getLocale());
uifactory.addStaticTextElement("mf.lastModified", lastModified, formLayout);
// file type
uifactory.addStaticTextElement("mf.type", StringHelper.escapeHtml(typeText), formLayout);
String downloads = meta == null ? "" : String.valueOf(meta.getDownloadCount());
uifactory.addStaticTextElement("mf.downloads", downloads, formLayout);
}
boolean xssErrors = false;
if (item != null) {
xssErrors = StringHelper.xssScanForErrors(item.getName());
}
if (StringHelper.containsNonWhitespace(resourceUrl) && !xssErrors) {
String externalUrlPage = velocity_root + "/external_url.html";
FormLayoutContainer extUrlCont = FormLayoutContainer.createCustomFormLayout("external.url", getTranslator(), externalUrlPage);
extUrlCont.setLabel("external.url", null);
extUrlCont.contextPut("resourceUrl", resourceUrl);
extUrlCont.setRootForm(mainForm);
formLayout.add(extUrlCont);
}
if (!isSubform && meta != null && meta.isDirectory()) {
// Don't show any meta data except title and comment if the item is
// a directory.
// Hide the metadata.
setMetaFieldsVisible(false);
if (moreMetaDataLink != null)
moreMetaDataLink.setVisible(false);
}
// save and cancel buttons
if (!isSubform) {
final FormLayoutContainer buttonLayout = FormLayoutContainer.createButtonLayout("buttonLayout", getTranslator());
formLayout.add(buttonLayout);
if (meta != null) {
uifactory.addFormSubmitButton("submit", buttonLayout);
}
uifactory.addFormCancelButton("cancel", buttonLayout, ureq, getWindowControl());
}
}
use of org.olat.core.util.vfs.lock.LockInfo in project OpenOLAT by OpenOLAT.
the class WebdavStatus method parseLockNullProperties.
/**
* Propfind helper method. Displays the properties of a lock-null resource.
*
* @param resources Resources object associated with this context
* @param generatedXML XML response to the Propfind request
* @param path Path of the current resource
* @param type Propfind type
* @param propertiesVector If the propfind type is find properties by
* name, then this Vector contains those properties
*/
private void parseLockNullProperties(HttpServletRequest req, XMLWriter generatedXML, final String path, int type, Vector<String> propertiesVector) {
// Exclude any resource in the /WEB-INF and /META-INF subdirectories
if (isSpecialPath(path))
return;
final WebResourceRoot resources = getResources(req);
final WebResource resource = resources.getResource(path);
// Retrieving the lock associated with the lock-null resource
LockInfo lock = lockManager.getResourceLock(resource);
if (lock == null)
return;
generatedXML.writeElement("D", "response", XMLWriter.OPENING);
String status = "HTTP/1.1 " + WebdavStatus.SC_OK + " " + WebdavStatus.getStatusText(WebdavStatus.SC_OK);
// Generating href element
generatedXML.writeElement("D", "href", XMLWriter.OPENING);
String absoluteUri = req.getRequestURI();
String relativePath = getRelativePath(req);
String toAppend = path.substring(relativePath.length());
if (!toAppend.startsWith("/"))
toAppend = "/" + toAppend;
String normalizedUrl = RequestUtil.normalize(absoluteUri + toAppend);
String nfcNormalizedUrl = Normalizer.normalize(normalizedUrl, Normalizer.Form.NFC);
generatedXML.writeText(rewriteUrl(nfcNormalizedUrl));
generatedXML.writeElement("D", "href", XMLWriter.CLOSING);
String resourceName = Normalizer.normalize(path, Normalizer.Form.NFC);
int lastSlash = path.lastIndexOf('/');
if (lastSlash != -1) {
resourceName = resourceName.substring(lastSlash + 1);
}
switch(type) {
case FIND_ALL_PROP:
generatedXML.writeElement("D", "propstat", XMLWriter.OPENING);
generatedXML.writeElement("D", "prop", XMLWriter.OPENING);
generatedXML.writeProperty("D", "creationdate", getISOCreationDate(lock.getCreationDate().getTime()));
generatedXML.writeElement("D", "displayname", XMLWriter.OPENING);
generatedXML.writeData(resourceName);
generatedXML.writeElement("D", "displayname", XMLWriter.CLOSING);
generatedXML.writeProperty("D", "getlastmodified", FastHttpDateFormat.formatDate(lock.getCreationDate().getTime(), null));
generatedXML.writeProperty("D", "getcontentlength", String.valueOf(0));
generatedXML.writeProperty("D", "getcontenttype", "");
generatedXML.writeProperty("D", "getetag", "");
generatedXML.writeElement("D", "resourcetype", XMLWriter.OPENING);
generatedXML.writeElement("D", "lock-null", XMLWriter.NO_CONTENT);
generatedXML.writeElement("D", "resourcetype", XMLWriter.CLOSING);
generatedXML.writeProperty("D", "source", "");
String supportedLocks = "<D:lockentry>" + "<D:lockscope><D:exclusive/></D:lockscope>" + "<D:locktype><D:write/></D:locktype>" + "</D:lockentry>" + "<D:lockentry>" + "<D:lockscope><D:shared/></D:lockscope>" + "<D:locktype><D:write/></D:locktype>" + "</D:lockentry>";
generatedXML.writeElement("D", "supportedlock", XMLWriter.OPENING);
generatedXML.writeText(supportedLocks);
generatedXML.writeElement("D", "supportedlock", XMLWriter.CLOSING);
generateLockDiscovery(resource, path, generatedXML);
generatedXML.writeElement("D", "prop", XMLWriter.CLOSING);
generatedXML.writeElement("D", "status", XMLWriter.OPENING);
generatedXML.writeText(status);
generatedXML.writeElement("D", "status", XMLWriter.CLOSING);
generatedXML.writeElement("D", "propstat", XMLWriter.CLOSING);
break;
case FIND_PROPERTY_NAMES:
generatedXML.writeElement("D", "propstat", XMLWriter.OPENING);
generatedXML.writeElement("D", "prop", XMLWriter.OPENING);
generatedXML.writeElement("D", "creationdate", XMLWriter.NO_CONTENT);
generatedXML.writeElement("D", "displayname", XMLWriter.NO_CONTENT);
generatedXML.writeElement("D", "getcontentlanguage", XMLWriter.NO_CONTENT);
generatedXML.writeElement("D", "getcontentlength", XMLWriter.NO_CONTENT);
generatedXML.writeElement("D", "getcontenttype", XMLWriter.NO_CONTENT);
generatedXML.writeElement("D", "getetag", XMLWriter.NO_CONTENT);
generatedXML.writeElement("D", "getlastmodified", XMLWriter.NO_CONTENT);
generatedXML.writeElement("D", "resourcetype", XMLWriter.NO_CONTENT);
generatedXML.writeElement("D", "source", XMLWriter.NO_CONTENT);
generatedXML.writeElement("D", "lockdiscovery", XMLWriter.NO_CONTENT);
generatedXML.writeElement("D", "prop", XMLWriter.CLOSING);
generatedXML.writeElement("D", "status", XMLWriter.OPENING);
generatedXML.writeText(status);
generatedXML.writeElement("D", "status", XMLWriter.CLOSING);
generatedXML.writeElement("D", "propstat", XMLWriter.CLOSING);
break;
case FIND_BY_PROPERTY:
Vector<String> propertiesNotFound = new Vector<>();
// Parse the list of properties
generatedXML.writeElement("D", "propstat", XMLWriter.OPENING);
generatedXML.writeElement("D", "prop", XMLWriter.OPENING);
Enumeration<String> properties = propertiesVector.elements();
while (properties.hasMoreElements()) {
String property = properties.nextElement();
if (property.equals("creationdate")) {
generatedXML.writeProperty("D", "creationdate", getISOCreationDate(lock.getCreationDate().getTime()));
} else if (property.equals("displayname")) {
generatedXML.writeElement("D", "displayname", XMLWriter.OPENING);
generatedXML.writeData(resourceName);
generatedXML.writeElement("D", "displayname", XMLWriter.CLOSING);
} else if (property.equals("getcontentlanguage")) {
generatedXML.writeElement("D", "getcontentlanguage", XMLWriter.NO_CONTENT);
} else if (property.equals("getcontentlength")) {
generatedXML.writeProperty("D", "getcontentlength", (String.valueOf(0)));
} else if (property.equals("getcontenttype")) {
generatedXML.writeProperty("D", "getcontenttype", "");
} else if (property.equals("getetag")) {
generatedXML.writeProperty("D", "getetag", "");
} else if (property.equals("getlastmodified")) {
generatedXML.writeProperty("D", "getlastmodified", FastHttpDateFormat.formatDate(lock.getCreationDate().getTime(), null));
} else if (property.equals("resourcetype")) {
generatedXML.writeElement("D", "resourcetype", XMLWriter.OPENING);
generatedXML.writeElement("D", "lock-null", XMLWriter.NO_CONTENT);
generatedXML.writeElement("D", "resourcetype", XMLWriter.CLOSING);
} else if (property.equals("source")) {
generatedXML.writeProperty("D", "source", "");
} else if (property.equals("supportedlock")) {
supportedLocks = "<D:lockentry>" + "<D:lockscope><D:exclusive/></D:lockscope>" + "<D:locktype><D:write/></D:locktype>" + "</D:lockentry>" + "<D:lockentry>" + "<D:lockscope><D:shared/></D:lockscope>" + "<D:locktype><D:write/></D:locktype>" + "</D:lockentry>";
generatedXML.writeElement("D", "supportedlock", XMLWriter.OPENING);
generatedXML.writeText(supportedLocks);
generatedXML.writeElement("D", "supportedlock", XMLWriter.CLOSING);
} else if (property.equals("lockdiscovery")) {
if (!generateLockDiscovery(resource, path, generatedXML))
propertiesNotFound.addElement(property);
} else {
propertiesNotFound.addElement(property);
}
}
generatedXML.writeElement("D", "prop", XMLWriter.CLOSING);
generatedXML.writeElement("D", "status", XMLWriter.OPENING);
generatedXML.writeText(status);
generatedXML.writeElement("D", "status", XMLWriter.CLOSING);
generatedXML.writeElement("D", "propstat", XMLWriter.CLOSING);
Enumeration<String> propertiesNotFoundList = propertiesNotFound.elements();
if (propertiesNotFoundList.hasMoreElements()) {
status = "HTTP/1.1 " + WebdavStatus.SC_NOT_FOUND + " " + WebdavStatus.getStatusText(WebdavStatus.SC_NOT_FOUND);
generatedXML.writeElement("D", "propstat", XMLWriter.OPENING);
generatedXML.writeElement("D", "prop", XMLWriter.OPENING);
while (propertiesNotFoundList.hasMoreElements()) {
generatedXML.writeElement("D", propertiesNotFoundList.nextElement(), XMLWriter.NO_CONTENT);
}
generatedXML.writeElement("D", "prop", XMLWriter.CLOSING);
generatedXML.writeElement("D", "status", XMLWriter.OPENING);
generatedXML.writeText(status);
generatedXML.writeElement("D", "status", XMLWriter.CLOSING);
generatedXML.writeElement("D", "propstat", XMLWriter.CLOSING);
}
break;
}
generatedXML.writeElement("D", "response", XMLWriter.CLOSING);
}
use of org.olat.core.util.vfs.lock.LockInfo in project OpenOLAT by OpenOLAT.
the class WebDAVCommandsTest method testLock_propfind_lockedInOpenOLAT.
/**
* @throws IOException
* @throws URISyntaxException
*/
@Test
public void testLock_propfind_lockedInOpenOLAT() throws IOException, URISyntaxException {
// create a user
Identity author = JunitTestHelper.createAndPersistIdentityAsAuthor("webdav-4-" + UUID.randomUUID().toString());
Identity assistant = JunitTestHelper.createAndPersistIdentityAsAuthor("webdav-5-" + UUID.randomUUID().toString());
RepositoryEntry re = deployTestCourse(author, assistant);
ICourse course = CourseFactory.loadCourse(re.getOlatResource());
Assert.assertNotNull(course);
// the assistant lock the file as in OpenOLAT GUI
VFSContainer folderContainer = course.getCourseFolderContainer();
createFile(folderContainer, "tolock.txt");
VFSItem itemToLock = folderContainer.resolve("tolock.txt");
Assert.assertNotNull(itemToLock);
boolean locked = lockManager.lock(itemToLock, assistant, new Roles(false, false, false, true, false, false, false));
Assert.assertTrue(locked);
// author make a propfind in the locked resource
WebDAVConnection conn = new WebDAVConnection();
conn.setCredentials(author.getName(), "A6B7C8");
URI toLockUri = conn.getBaseURI().path("webdav").path("coursefolders").path("_other").path("Kurs").path("tolock.txt").build();
String propfindXml = conn.propfind(toLockUri, 2);
// not really a test
Assert.assertTrue(propfindXml.indexOf("<D:lockscope><D:exclusive/></D:lockscope>") > 0);
Assert.assertTrue(propfindXml.indexOf("/Identity/" + assistant.getKey() + "</D:owner>") > 0);
Assert.assertTrue(propfindXml.indexOf("<D:locktoken><D:href>opaquelocktoken:") > 0);
LockInfo lock = lockManager.getLock(itemToLock);
Assert.assertNotNull(lock);
Assert.assertNotNull(lock.getScope());
Assert.assertNotNull(lock.getType());
Assert.assertNotNull(lock.getOwner());
Assert.assertTrue(lock.getOwner().length() > 0);
Assert.assertTrue(lock.isVfsLock());
Assert.assertFalse(lock.isWebDAVLock());
Assert.assertEquals(assistant.getKey(), lock.getLockedBy());
Assert.assertEquals(1, lock.getTokensSize());
IOUtils.closeQuietly(conn);
}
use of org.olat.core.util.vfs.lock.LockInfo in project openolat by klemens.
the class WebdavStatus method generateLockDiscovery.
/**
* Print the lock discovery information associated with a path.
*
* @param path Path
* @param generatedXML XML data to which the locks info will be appended
* @return true if at least one lock was displayed
*/
private boolean generateLockDiscovery(final WebResource resource, final String path, XMLWriter generatedXML) {
LockInfo resourceLock = lockManager.getResourceLock(resource);
Iterator<LockInfo> collectionLocksList = lockManager.getCollectionLocks();
boolean wroteStart = false;
if (resourceLock != null) {
wroteStart = true;
generatedXML.writeElement("D", "lockdiscovery", XMLWriter.OPENING);
resourceLock.toXML(generatedXML);
} else {
LockInfo ooLock = lockManager.getVFSLock(resource);
if (ooLock != null) {
wroteStart = true;
generatedXML.writeElement("D", "lockdiscovery", XMLWriter.OPENING);
ooLock.toXML(generatedXML);
}
}
while (collectionLocksList.hasNext()) {
LockInfo currentLock = collectionLocksList.next();
if (path.startsWith(currentLock.getWebPath())) {
if (!wroteStart) {
wroteStart = true;
generatedXML.writeElement("D", "lockdiscovery", XMLWriter.OPENING);
}
currentLock.toXML(generatedXML);
}
}
if (wroteStart) {
generatedXML.writeElement("D", "lockdiscovery", XMLWriter.CLOSING);
} else {
return false;
}
return true;
}
Aggregations