// Exclude any resource in the /WEB-INF and /META-INF subdirectories
if (isSpecialPath(path))
return;
WebResource resource = resources.getResource(path);
if (!resource.exists()) {
// File is in directory listing but doesn't appear to exist
// Broken symlink or odd permission settings?
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 href = req.getContextPath() + req.getServletPath();
if ((href.endsWith("/")) && (path.startsWith("/")))
href += path.substring(1);
else
href += path;
if (resource.isDirectory() && (!href.endsWith("/")))
href += "/";
generatedXML.writeText(rewriteUrl(href));
generatedXML.writeElement("D", "href", XMLWriter.CLOSING);
String resourceName = path;
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(resource.getCreation()));
generatedXML.writeElement("D", "displayname", XMLWriter.OPENING);
generatedXML.writeData(resourceName);
generatedXML.writeElement("D", "displayname", XMLWriter.CLOSING);
if (resource.isFile()) {
generatedXML.writeProperty
("D", "getlastmodified", FastHttpDateFormat.formatDate
(resource.getLastModified(), null));
generatedXML.writeProperty
("D", "getcontentlength",
String.valueOf(resource.getContentLength()));
String contentType = getServletContext().getMimeType(
resource.getName());
if (contentType != null) {
generatedXML.writeProperty("D", "getcontenttype",
contentType);
}
generatedXML.writeProperty("D", "getetag",resource.getETag());
generatedXML.writeElement("D", "resourcetype",
XMLWriter.NO_CONTENT);
} else {
generatedXML.writeElement("D", "resourcetype",
XMLWriter.OPENING);
generatedXML.writeElement("D", "collection",
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(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);
if (resource.isFile()) {
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(resource.getCreation()));
} 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")) {
if (resource.isDirectory()) {
propertiesNotFound.addElement(property);
} else {
generatedXML.writeElement("D", "getcontentlanguage",
XMLWriter.NO_CONTENT);
}
} else if (property.equals("getcontentlength")) {
if (resource.isDirectory()) {
propertiesNotFound.addElement(property);
} else {
generatedXML.writeProperty
("D", "getcontentlength",
(String.valueOf(resource.getContentLength())));
}
} else if (property.equals("getcontenttype")) {
if (resource.isDirectory()) {
propertiesNotFound.addElement(property);
} else {
generatedXML.writeProperty
("D", "getcontenttype",
getServletContext().getMimeType
(resource.getName()));
}
} else if (property.equals("getetag")) {
if (resource.isDirectory()) {
propertiesNotFound.addElement(property);
} else {
generatedXML.writeProperty
("D", "getetag", resource.getETag());
}
} else if (property.equals("getlastmodified")) {
if (resource.isDirectory()) {
propertiesNotFound.addElement(property);
} else {
generatedXML.writeProperty
("D", "getlastmodified", FastHttpDateFormat.formatDate
(resource.getLastModified(), null));
}
} else if (property.equals("resourcetype")) {
if (resource.isDirectory()) {
generatedXML.writeElement("D", "resourcetype",
XMLWriter.OPENING);
generatedXML.writeElement("D", "collection",
XMLWriter.NO_CONTENT);
generatedXML.writeElement("D", "resourcetype",