Search in sources :

Example 1 with PropFindHelper

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();
}
Also used : Element(org.w3c.dom.Element) Document(org.w3c.dom.Document) LinkedList(java.util.LinkedList) Date(java.util.Date) SAXException(org.xml.sax.SAXException) GenericEntityException(org.apache.ofbiz.entity.GenericEntityException) PropFindHelper(org.apache.ofbiz.webapp.webdav.PropFindHelper) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) Writer(java.io.Writer)

Aggregations

Writer (java.io.Writer)1 Date (java.util.Date)1 LinkedList (java.util.LinkedList)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 GenericEntityException (org.apache.ofbiz.entity.GenericEntityException)1 PropFindHelper (org.apache.ofbiz.webapp.webdav.PropFindHelper)1 Document (org.w3c.dom.Document)1 Element (org.w3c.dom.Element)1 SAXException (org.xml.sax.SAXException)1