String path,
int type,
Vector<String> propertiesVector,
String mimeType ) throws WebdavException {
StoredObject so = store.getStoredObject(transaction, path);
if (so == null) return;
boolean isFolder = so.isFolder();
final String creationdate = creationDateFormat(so.getCreationDate());
final String lastModified = lastModifiedDateFormat(so.getLastModified());
String resourceLength = String.valueOf(so.getResourceLength());
// ResourceInfo resourceInfo = new ResourceInfo(path, resources);
generatedXML.writeElement("DAV::response", XMLWriter.OPENING);
String status = "HTTP/1.1 " + WebdavStatus.SC_OK + " " + WebdavStatus.getStatusText(WebdavStatus.SC_OK);
// Generating href element
generatedXML.writeElement("DAV::href", XMLWriter.OPENING);
String href = req.getContextPath();
String servletPath = req.getServletPath();
if (servletPath != null) {
if ((href.endsWith("/")) && (servletPath.startsWith("/"))) {
href += servletPath.substring(1);
} else {
href += servletPath;
}
}
if ((href.endsWith("/")) && (path.startsWith("/"))) {
href += path.substring(1);
} else {
href += path;
}
if ((isFolder) && (!href.endsWith("/"))) {
href += "/";
}
generatedXML.writeText(rewriteUrl(href));
generatedXML.writeElement("DAV::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("DAV::propstat", XMLWriter.OPENING);
generatedXML.writeElement("DAV::prop", XMLWriter.OPENING);
writeCustomProperties(transaction, generatedXML, path, true, propertiesVector);
generatedXML.writeProperty("DAV::creationdate", creationdate);
generatedXML.writeElement("DAV::displayname", XMLWriter.OPENING);
generatedXML.writeData(resourceName);
generatedXML.writeElement("DAV::displayname", XMLWriter.CLOSING);
if (!isFolder) {
generatedXML.writeProperty("DAV::getlastmodified", lastModified);
generatedXML.writeProperty("DAV::getcontentlength", resourceLength);
if (mimeType != null) {
generatedXML.writeProperty("DAV::getcontenttype", mimeType);
}
generatedXML.writeProperty("DAV::getetag", getETag(so));
generatedXML.writeElement("DAV::resourcetype", XMLWriter.NO_CONTENT);
} else {
generatedXML.writeElement("DAV::resourcetype", XMLWriter.OPENING);
generatedXML.writeElement("DAV::collection", XMLWriter.NO_CONTENT);
generatedXML.writeElement("DAV::resourcetype", XMLWriter.CLOSING);
}
writeSupportedLockElements(transaction, generatedXML, path);
writeLockDiscoveryElements(transaction, generatedXML, path);
generatedXML.writeProperty("DAV::source", "");
generatedXML.writeElement("DAV::prop", XMLWriter.CLOSING);
generatedXML.writeElement("DAV::status", XMLWriter.OPENING);
generatedXML.writeText(status);
generatedXML.writeElement("DAV::status", XMLWriter.CLOSING);
generatedXML.writeElement("DAV::propstat", XMLWriter.CLOSING);
break;
case FIND_PROPERTY_NAMES:
generatedXML.writeElement("DAV::propstat", XMLWriter.OPENING);
generatedXML.writeElement("DAV::prop", XMLWriter.OPENING);
writeCustomProperties(transaction, generatedXML, path, false, propertiesVector);
generatedXML.writeElement("DAV::creationdate", XMLWriter.NO_CONTENT);
generatedXML.writeElement("DAV::displayname", XMLWriter.NO_CONTENT);
if (!isFolder) {
generatedXML.writeElement("DAV::getcontentlanguage", XMLWriter.NO_CONTENT);
generatedXML.writeElement("DAV::getcontentlength", XMLWriter.NO_CONTENT);
generatedXML.writeElement("DAV::getcontenttype", XMLWriter.NO_CONTENT);
generatedXML.writeElement("DAV::getetag", XMLWriter.NO_CONTENT);
generatedXML.writeElement("DAV::getlastmodified", XMLWriter.NO_CONTENT);
}
generatedXML.writeElement("DAV::resourcetype", XMLWriter.NO_CONTENT);
generatedXML.writeElement("DAV::supportedlock", XMLWriter.NO_CONTENT);
generatedXML.writeElement("DAV::source", XMLWriter.NO_CONTENT);
generatedXML.writeElement("DAV::prop", XMLWriter.CLOSING);
generatedXML.writeElement("DAV::status", XMLWriter.OPENING);
generatedXML.writeText(status);
generatedXML.writeElement("DAV::status", XMLWriter.CLOSING);
generatedXML.writeElement("DAV::propstat", XMLWriter.CLOSING);
break;
case FIND_BY_PROPERTY:
Vector<String> propertiesNotFound = new Vector<String>();
// Parse the list of properties
generatedXML.writeElement("DAV::propstat", XMLWriter.OPENING);
generatedXML.writeElement("DAV::prop", XMLWriter.OPENING);
writeCustomProperties(transaction, generatedXML, path, true, propertiesVector);
Enumeration<String> properties = propertiesVector.elements();
while (properties.hasMoreElements()) {
String property = properties.nextElement();
if (property.equals("DAV::creationdate")) {
generatedXML.writeProperty("DAV::creationdate", creationdate);
} else if (property.equals("DAV::displayname")) {
generatedXML.writeElement("DAV::displayname", XMLWriter.OPENING);
generatedXML.writeData(resourceName);
generatedXML.writeElement("DAV::displayname", XMLWriter.CLOSING);
} else if (property.equals("DAV::getcontentlanguage")) {
if (isFolder) {
propertiesNotFound.addElement(property);
} else {
generatedXML.writeElement("DAV::getcontentlanguage", XMLWriter.NO_CONTENT);
}
} else if (property.equals("DAV::getcontentlength")) {
if (isFolder) {
propertiesNotFound.addElement(property);
} else {
generatedXML.writeProperty("DAV::getcontentlength", resourceLength);
}
} else if (property.equals("DAV::getcontenttype")) {
if (isFolder) {
propertiesNotFound.addElement(property);
} else {
generatedXML.writeProperty("DAV::getcontenttype", mimeType);
}
} else if (property.equals("DAV::getetag")) {
if (isFolder || so.isNullResource()) {
propertiesNotFound.addElement(property);
} else {
generatedXML.writeProperty("DAV::getetag", getETag(so));
}
} else if (property.equals("DAV::getlastmodified")) {