org.apache.jackrabbit.webdav.DavMethods Java Examples

The following examples show how to use org.apache.jackrabbit.webdav.DavMethods. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestCaldavHttpClient4.java    From davmail with GNU General Public License v2.0 6 votes vote down vote up
public void testReportInbox() throws IOException {
    String buffer = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
            "<C:calendar-query xmlns:C=\"urn:ietf:params:xml:ns:caldav\" xmlns:D=\"DAV:\">" +
            "<D:prop>" +
            "<C:calendar-data/>" +
            "</D:prop>" +
            "<C:filter>" +
            "</C:filter>" +
            "</C:calendar-query>";
    BaseDavRequest method = new BaseDavRequest(URI.create("/users/" + session.getEmail() + "/inbox/")) {
        @Override
        public String getMethod() {
            return DavMethods.METHOD_REPORT;
        }
    };
    method.setEntity(new StringEntity(buffer, ContentType.create("text/xml", "UTF-8")));
    httpClient.executeDavRequest(method);
}
 
Example #2
Source File: TestCaldavHttpClient4.java    From davmail with GNU General Public License v2.0 6 votes vote down vote up
public void testReportTasks() throws IOException {
    String buffer = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
            "<C:calendar-query xmlns:C=\"urn:ietf:params:xml:ns:caldav\" xmlns:D=\"DAV:\">" +
            "<D:prop>" +
            "<C:calendar-data/>" +
            "</D:prop>" +
            "<C:comp-filter name=\"VCALENDAR\">" +
            "<C:comp-filter name=\"VTODO\"/>" +
            "</C:comp-filter>" +
            "<C:filter>" +
            "</C:filter>" +
            "</C:calendar-query>";
    BaseDavRequest method = new BaseDavRequest(URI.create("/users/" + session.getEmail() + "/calendar/")) {
        @Override
        public String getMethod() {
            return DavMethods.METHOD_REPORT;
        }
    };
    method.setEntity(new StringEntity(buffer, ContentType.create("text/xml", "UTF-8")));

    httpClient.executeDavRequest(method);
}
 
Example #3
Source File: TestCaldavHttpClient4.java    From davmail with GNU General Public License v2.0 6 votes vote down vote up
public void testReportEventsOnly() throws IOException {
    String buffer = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
            "<C:calendar-query xmlns:C=\"urn:ietf:params:xml:ns:caldav\" xmlns:D=\"DAV:\">" +
            "<D:prop>" +
            "<C:calendar-data/>" +
            "</D:prop>" +
            "<C:comp-filter name=\"VCALENDAR\">" +
            "<C:comp-filter name=\"VEVENT\"/>" +
            "</C:comp-filter>" +
            "<C:filter>" +
            "</C:filter>" +
            "</C:calendar-query>";
    BaseDavRequest method = new BaseDavRequest(URI.create("/users/" + session.getEmail() + "/calendar/")) {
        @Override
        public String getMethod() {
            return DavMethods.METHOD_REPORT;
        }
    };
    method.setEntity(new StringEntity(buffer, ContentType.create("text/xml", "UTF-8")));

    httpClient.executeDavRequest(method);
}
 
Example #4
Source File: TestCaldavHttpClient4.java    From davmail with GNU General Public License v2.0 6 votes vote down vote up
public void testInvalidDavRequest() {
    BaseDavRequest method = new BaseDavRequest(URI.create("/users/" + session.getEmail() + "/calendar/")) {
        @Override
        public String getMethod() {
            return DavMethods.METHOD_REPORT;
        }
    };
    method.setEntity(new StringEntity("invalid", ContentType.create("text/xml", "UTF-8")));

    try {
        httpClient.executeDavRequest(method);
        fail("Should fail");
    } catch (IOException e) {
        assertNotNull(e.getMessage());
        assertEquals(503, ((DavException)e.getCause()).getErrorCode());

    }

}
 
Example #5
Source File: VersionControlledResourceImpl.java    From document-management-software with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Return a comma separated string listing the supported method names
 * 
 * @return the supported method names
 * 
 * @see org.apache.jackrabbit.webdav.DavResource#getSupportedMethods()
 */
public String getSupportedMethods() {
	StringBuffer sb = new StringBuffer(super.getSupportedMethods());
	// Versioning support
	sb.append(", ").append(VersionableResource.METHODS);
	if (isVersionControlled()) {
		sb.append(", ").append(DavMethods.METHOD_CHECKOUT);
		sb.append(", ").append(DavMethods.METHOD_UNCHECKOUT);
		sb.append(", ").append(DavMethods.METHOD_LABEL);
		sb.append(", ").append(DavMethods.METHOD_CHECKIN);
	}
	return sb.toString();
}
 
Example #6
Source File: DavResourceFactoryImpl.java    From document-management-software with GNU Lesser General Public License v3.0 5 votes vote down vote up
public DavResource createResource(DavResourceLocator locator, DavServletRequest request, DavSession session)
		throws DavException {

	try {
		String resourcePath = locator.getResourcePath();
		Matcher matcher = versionRequestPattern.matcher(locator.getResourcePath());

		String version = null;
		if (matcher.matches() == true) {
			version = matcher.group(1);
			resourcePath = resourcePath.replaceFirst("/vstore/" + version, "");
		}

		DavResource resource;

		Resource repositoryResource = resourceService.getResource(resourcePath, session);

		if (repositoryResource == null) {
			boolean isCollection = DavMethods.isCreateCollectionRequest(request);
			resource = createNullResource(locator, session, isCollection);
		} else {
			repositoryResource.setVersionLabel(version);
			repositoryResource.setRequestedPerson(Long.parseLong(session.getObject("id").toString()));
			resource = new VersionControlledResourceImpl(locator, this, session, resourceConfig, repositoryResource);
		}

		putInCache(session, resource);
		return resource;
	} catch (Exception e) {
		log.error(e.getMessage(), e);
		throw new DavException(DavServletResponse.SC_INTERNAL_SERVER_ERROR, e);
	}
}
 
Example #7
Source File: TestCaldavHttpClient4.java    From davmail with GNU General Public License v2.0 5 votes vote down vote up
public void testReportCalendar() throws IOException {
    SimpleDateFormat formatter = ExchangeSession.getZuluDateFormat();
    Calendar cal = Calendar.getInstance();
    Date end = cal.getTime();
    cal.add(Calendar.MONTH, -1);
    Date start = cal.getTime();

    BaseDavRequest method = new BaseDavRequest(URI.create("/users/" + session.getEmail() + "/calendar/")) {
        @Override
        public String getMethod() {
            return DavMethods.METHOD_REPORT;
        }
    };
    String buffer = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
            "<C:calendar-query xmlns:C=\"urn:ietf:params:xml:ns:caldav\" xmlns:D=\"DAV:\">" +
            "<D:prop>" +
            "<C:calendar-data/>" +
            "</D:prop>" +
            "<C:comp-filter name=\"VCALENDAR\">" +
            "<C:comp-filter name=\"VEVENT\">" +
            "<C:time-range start=\"" + formatter.format(start) + "\" end=\"" + formatter.format(end) + "\"/>" +
            //"<C:time-range start=\"" + formatter.format(start) + "\"/>" +
            "</C:comp-filter>" +
            "</C:comp-filter>" +
            "<C:filter>" +
            "</C:filter>" +
            "</C:calendar-query>";
    method.setEntity(new StringEntity(buffer, ContentType.create("text/xml", "UTF-8")));

    MultiStatus multiStatus = httpClient.executeDavRequest(method);
    MultiStatusResponse[] responses = multiStatus.getResponses();
    List<ExchangeSession.Event> events = session.searchEvents("/users/" + session.getEmail() + "/calendar/",
            ExchangeSession.getZuluDateFormat().format(start),
            ExchangeSession.getZuluDateFormat().format(end)
    );

    assertEquals(events.size(), responses.length);
}
 
Example #8
Source File: CosmoDavMethods.java    From cosmo with Apache License 2.0 5 votes vote down vote up
/**
 * Augments superclass method to also return <code>true</code> for
 * <code>MKCALENDAR</code> requests.
 * @param request DavServletRequest.
 * @return If the request is created or not.
 */
public static boolean isCreateRequest(DavServletRequest request) {
    if (getMethodCode(request.getMethod()) == DAV_MKCALENDAR) {
        return true;
    }
    return DavMethods.isCreateRequest(request);
}
 
Example #9
Source File: CosmoDavMethods.java    From cosmo with Apache License 2.0 5 votes vote down vote up
/**
 * Augments superclass method to also return <code>true</code> for
 * <code>MKCALENDAR</code> requests.
 * @param request DavServletRequest.
 * @return If the collection request is created.
 */
public static boolean isCreateCollectionRequest(DavServletRequest request) {
    if (getMethodCode(request.getMethod()) == DAV_MKCALENDAR) {
        return true;
    }
    return DavMethods.isCreateCollectionRequest(request);
}
 
Example #10
Source File: AbstractWebdavServlet.java    From document-management-software with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Executes the respective method in the given webdav context
 * 
 * @param request the HTTP request
 * @param response the server's response
 * @param method the HTTP method
 * 
 * @param resource the DAV resource
 * 
 * @throws ServletException error inside the servlet container
 * @throws IOException generic I/O error
 * @throws DavException generic error in the WebDAV communication
 */
protected boolean execute(WebdavRequest request, WebdavResponse response, int method, DavResource resource)
		throws ServletException, IOException, DavException {

	switch (method) {
	case DavMethods.DAV_GET:
		doGet(request, response, resource);
		break;
	case DavMethods.DAV_HEAD:
		doHead(request, response, resource);
		break;
	case DavMethods.DAV_PROPFIND:
		doPropFind(request, response, resource);
		break;
	case DavMethods.DAV_PROPPATCH:
		doPropPatch(request, response, resource);
		break;
	case DavMethods.DAV_POST:
		doPost(request, response, resource);
		break;
	case DavMethods.DAV_PUT:
		doPut(request, response, resource);
		break;
	case DavMethods.DAV_DELETE:
		doDelete(request, response, resource);
		break;
	case DavMethods.DAV_COPY:
		doCopy(request, response, resource);
		break;
	case DavMethods.DAV_MOVE:
		doMove(request, response, resource);
		break;
	case DavMethods.DAV_MKCOL:
		doMkCol(request, response, resource);
		break;
	case DavMethods.DAV_OPTIONS:
		doOptions(request, response, resource);
		break;
	case DavMethods.DAV_LOCK:
		doLock(request, response, resource);
		break;
	case DavMethods.DAV_UNLOCK:
		doUnlock(request, response, resource);
		break;
	case DavMethods.DAV_CHECKOUT:
		doCheckout(request, response, resource);
		break;
	case DavMethods.DAV_CHECKIN:
		doCheckin(request, response, resource);
		break;
	case DavMethods.DAV_REPORT:
		doReport(request, response, resource);
		break;
	case DavMethods.DAV_VERSION_CONTROL:
		doVersionControl(request, response, resource);
		break;
	case DavMethods.DAV_UNCHECKOUT:
		doUncheckout(request, response, resource);
		break;
	default:
		// any other method
		return false;
	}
	return true;
}
 
Example #11
Source File: SyncMethod.java    From openmeetings with Apache License 2.0 4 votes vote down vote up
/**
 * Implements the Report Method.
 */
@Override
public String getMethod() {
	return DavMethods.METHOD_REPORT;
}