List of usage examples for com.liferay.portal.kernel.webdav WebDAVRequest getWebDAVStorage
public WebDAVStorage getWebDAVStorage();
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); }//from w ww . j a v a 2s . co 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.DeleteMethodImpl.java
License:Open Source License
@Override public int process(WebDAVRequest webDAVRequest) throws WebDAVException { WebDAVStorage storage = webDAVRequest.getWebDAVStorage(); return storage.deleteResource(webDAVRequest); }
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;//w w w . j a v a2 s .c om 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.OptionsMethodImpl.java
License:Open Source License
@Override public int process(WebDAVRequest webDAVRequest) throws WebDAVException { HttpServletResponse response = webDAVRequest.getHttpServletResponse(); StringBuilder sb = new StringBuilder(); if (webDAVRequest.getWebDAVStorage().isSupportsClassTwo()) { sb.append("1,2, "); } else {/*from w w w. jav a 2s. c om*/ sb.append("1, "); } sb.append("calendar-access"); response.addHeader("DAV", sb.toString()); response.addHeader("Allow", SUPPORTED_CALDAV_METHODS_NAMES); response.addHeader("MS-Author-Via", "DAV"); response.addHeader(HttpHeaders.CONTENT_LENGTH, "0"); return HttpServletResponse.SC_OK; }
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 w w .j a v a2 s .c om*/ 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; }
From source file:it.smc.calendar.sync.caldav.methods.PutMethodImpl.java
License:Open Source License
@Override public int process(WebDAVRequest webDAVRequest) throws WebDAVException { WebDAVStorage storage = webDAVRequest.getWebDAVStorage(); return storage.putResource(webDAVRequest); }
From source file:it.smc.calendar.sync.caldav.util.CalDAVUtil.java
License:Open Source License
public static Set<QName> getRequestDAVProps(WebDAVRequest webDAVRequest) throws InvalidRequestException { try {/*w w w . j ava 2s .co m*/ Set<QName> props = new HashSet<QName>(); Resource resource = webDAVRequest.getWebDAVStorage().getResource(webDAVRequest); Document document = CalDAVRequestThreadLocal.getRequestDocument(); if (document == null) { if (resource.isCollection()) { return CalDAVProps.getAllCollectionProps(); } else { return CalDAVProps.getAllResourceProps(); } } Element rootElement = document.getRootElement(); if (rootElement.element("allprop") != null) { if (resource.isCollection()) { return CalDAVProps.getAllCollectionProps(); } else { return CalDAVProps.getAllResourceProps(); } } Element propElement = rootElement.element("prop"); List<Element> elements = propElement.elements(); for (Element element : elements) { String prefix = element.getNamespacePrefix(); String uri = element.getNamespaceURI(); Namespace namespace = WebDAVUtil.createNamespace(prefix, uri); props.add(SAXReaderUtil.createQName(element.getName(), namespace)); } return props; } catch (Exception e) { throw new InvalidRequestException(e); } }