use of org.apache.ofbiz.webapp.webdav.PropFindHelper in project ofbiz-framework by apache.
the class ICalWorker method handlePropFindRequest.
public static void handlePropFindRequest(HttpServletRequest request, HttpServletResponse response, ServletContext context) throws IOException {
if (!isValidRequest(request, response)) {
return;
}
String workEffortId = (String) request.getAttribute("workEffortId");
Debug.logInfo("[handlePropFindRequest] workEffortId = " + workEffortId, module);
try {
Document requestDocument = WebDavUtil.getDocumentFromRequest(request);
if (Debug.verboseOn()) {
Debug.logVerbose("[handlePropFindRequest] PROPFIND body:\r\n" + UtilXml.writeXmlDocument(requestDocument), module);
}
PropFindHelper helper = new PropFindHelper(requestDocument);
if (!helper.isAllProp() && !helper.isPropName()) {
Document responseDocument = helper.getResponseDocument();
List<Element> supportedProps = new LinkedList<>();
List<Element> unSupportedProps = new LinkedList<>();
List<Element> propElements = helper.getFindPropsList(ResponseHelper.DAV_NAMESPACE_URI);
for (Element propElement : propElements) {
if ("getetag".equals(propElement.getNodeName())) {
Element etagElement = helper.createElementSetValue("D:getetag", String.valueOf(System.currentTimeMillis()));
supportedProps.add(etagElement);
continue;
}
if ("getlastmodified".equals(propElement.getNodeName())) {
Date lastModified = getLastModifiedDate(request);
Element lmElement = helper.createElementSetValue("D:getlastmodified", WebDavUtil.formatDate(WebDavUtil.getRFC1123DateFormat(), lastModified));
supportedProps.add(lmElement);
continue;
}
unSupportedProps.add(responseDocument.createElementNS(propElement.getNamespaceURI(), propElement.getTagName()));
}
Element responseElement = helper.createResponseElement();
responseElement.appendChild(helper.createHrefElement("/" + workEffortId + "/"));
if (supportedProps.size() > 0) {
Element propElement = helper.createPropElement(supportedProps);
responseElement.appendChild(helper.createPropStatElement(propElement, ResponseHelper.STATUS_200));
}
if (unSupportedProps.size() > 0) {
Element propElement = helper.createPropElement(unSupportedProps);
responseElement.appendChild(helper.createPropStatElement(propElement, ResponseHelper.STATUS_404));
}
Element rootElement = helper.createMultiStatusElement();
rootElement.appendChild(responseElement);
responseDocument.appendChild(rootElement);
if (Debug.verboseOn()) {
Debug.logVerbose("[handlePropFindRequest] PROPFIND response:\r\n" + UtilXml.writeXmlDocument(responseDocument), module);
}
ResponseHelper.prepareResponse(response, 207, "Multi-Status");
try (Writer writer = response.getWriter()) {
helper.writeResponse(response, writer);
}
return;
}
} catch (RuntimeException | GenericEntityException | SAXException | ParserConfigurationException e) {
Debug.logError(e, "PROPFIND error: ", module);
}
response.setStatus(HttpServletResponse.SC_OK);
response.flushBuffer();
}
Aggregations