Example usage for com.liferay.portal.kernel.webdav WebDAVStorage getResource

List of usage examples for com.liferay.portal.kernel.webdav WebDAVStorage getResource

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.webdav WebDAVStorage getResource.

Prototype

public Resource getResource(WebDAVRequest webDAVRequest) throws WebDAVException;

Source Link

Usage

From source file:it.smc.calendar.sync.caldav.methods.BasePropMethodImpl.java

License:Open Source License

protected int writeResponseXML(WebDAVRequest webDAVRequest, Set<QName> props) throws Exception {

    WebDAVStorage storage = webDAVRequest.getWebDAVStorage();

    long depth = WebDAVUtil.getDepth(webDAVRequest.getHttpServletRequest());

    Document document = SAXReaderUtil.createDocument();

    Element multistatusElement = SAXReaderUtil.createElement(CalDAVProps.createQName("multistatus"));

    document.setRootElement(multistatusElement);

    Resource resource = storage.getResource(webDAVRequest);

    if (resource != null) {
        addResponse(storage, webDAVRequest, resource, props, multistatusElement, depth);

        String xml = document.formattedString(StringPool.FOUR_SPACES);

        if (_log.isDebugEnabled()) {
            _log.debug("Response XML\n" + xml);
        }// w  ww.j a v a  2  s . c o  m

        // Set the status prior to writing the XML

        int status = WebDAVUtil.SC_MULTI_STATUS;

        HttpServletResponse response = webDAVRequest.getHttpServletResponse();

        response.setContentType(ContentTypes.TEXT_XML_UTF8);
        response.setStatus(status);

        try {
            ServletResponseUtil.write(response, xml);

            response.flushBuffer();
        } catch (Exception e) {
            if (_log.isWarnEnabled()) {
                _log.warn(e);
            }
        }

        return status;
    } else {
        if (_log.isDebugEnabled()) {
            _log.debug("No resource found for " + storage.getRootPath() + webDAVRequest.getPath());
        }

        return HttpServletResponse.SC_NOT_FOUND;
    }
}

From source file:it.smc.calendar.sync.caldav.methods.GetMethodImpl.java

License:Open Source License

@Override
public int process(WebDAVRequest webDAVRequest) throws WebDAVException {
    InputStream is = null;//from   w w  w  .ja  v a 2  s.  com

    try {
        WebDAVStorage storage = webDAVRequest.getWebDAVStorage();
        HttpServletRequest request = webDAVRequest.getHttpServletRequest();
        HttpServletResponse response = webDAVRequest.getHttpServletResponse();

        Resource resource = storage.getResource(webDAVRequest);

        if (resource == null) {
            return HttpServletResponse.SC_NOT_FOUND;
        }

        try {
            is = resource.getContentAsStream();
        } catch (Exception e) {
            if (_log.isErrorEnabled()) {
                _log.error(e.getMessage());
            }
        }

        if (is != null) {
            try {
                ServletResponseUtil.sendFile(request, response, resource.getDisplayName(), is,
                        resource.getSize(), resource.getContentType());
            } catch (Exception e) {
                if (_log.isWarnEnabled()) {
                    _log.warn(e);
                }
            }

            return HttpServletResponse.SC_OK;
        }

        return HttpServletResponse.SC_NOT_FOUND;
    } catch (ResourceNotFoundException rnfe) {
        return HttpServletResponse.SC_NOT_FOUND;
    } catch (WebDAVException pe) {
        if (pe.getCause() instanceof PrincipalException) {
            return HttpServletResponse.SC_UNAUTHORIZED;
        } else if (pe.getCause() instanceof ResourceNotFoundException) {
            return HttpServletResponse.SC_NOT_FOUND;
        }

        throw pe;
    } catch (Exception e) {
        throw new WebDAVException(e);
    }
}

From source file:it.smc.calendar.sync.caldav.methods.ProppatchMethodImpl.java

License:Open Source License

protected WebDAVProps getStoredProperties(WebDAVRequest webDAVRequest) throws PortalException, SystemException {

    WebDAVStorage storage = webDAVRequest.getWebDAVStorage();

    Resource resource = storage.getResource(webDAVRequest);

    WebDAVProps webDavProps = null;/*from  w ww .  ja v  a2 s .com*/

    if (resource.getPrimaryKey() <= 0) {
        if (_log.isWarnEnabled()) {
            _log.warn("There is no primary key set for resource");
        }

        throw new InvalidRequestException();
    } else if (resource.isLocked()) {
        Lock lock = resource.getLock();

        if ((lock == null) || !lock.getUuid().equals(webDAVRequest.getLockUuid())) {

            throw new LockException();
        }
    }

    webDavProps = WebDAVPropsLocalServiceUtil.getWebDAVProps(webDAVRequest.getCompanyId(),
            resource.getClassName(), resource.getPrimaryKey());

    return webDavProps;
}