Java Code Examples for org.apache.jackrabbit.webdav.MultiStatusResponse#getProperties()

The following examples show how to use org.apache.jackrabbit.webdav.MultiStatusResponse#getProperties() . 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: HC4DavExchangeSession.java    From davmail with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Build Contact instance from multistatusResponse info
 *
 * @param multiStatusResponse response
 * @throws IOException      on error
 * @throws DavMailException on error
 */
public Contact(MultiStatusResponse multiStatusResponse) throws IOException, DavMailException {
    setHref(URIUtil.decode(multiStatusResponse.getHref()));
    DavPropertySet properties = multiStatusResponse.getProperties(HttpStatus.SC_OK);
    permanentUrl = getURLPropertyIfExists(properties, "permanenturl");
    etag = getPropertyIfExists(properties, "etag");
    displayName = getPropertyIfExists(properties, "displayname");
    for (String attributeName : CONTACT_ATTRIBUTES) {
        String value = getPropertyIfExists(properties, attributeName);
        if (value != null) {
            if ("bday".equals(attributeName) || "anniversary".equals(attributeName)
                    || "lastmodified".equals(attributeName) || "datereceived".equals(attributeName)) {
                value = convertDateFromExchange(value);
            } else if ("haspicture".equals(attributeName) || "private".equals(attributeName)) {
                value = "1".equals(value) ? "true" : "false";
            }
            put(attributeName, value);
        }
    }
}
 
Example 2
Source File: DavExchangeSession.java    From davmail with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Build Contact instance from multistatusResponse info
 *
 * @param multiStatusResponse response
 * @throws IOException      on error
 * @throws DavMailException on error
 */
public Contact(MultiStatusResponse multiStatusResponse) throws IOException, DavMailException {
    setHref(URIUtil.decode(multiStatusResponse.getHref()));
    DavPropertySet properties = multiStatusResponse.getProperties(HttpStatus.SC_OK);
    permanentUrl = getURLPropertyIfExists(properties, "permanenturl");
    etag = getPropertyIfExists(properties, "etag");
    displayName = getPropertyIfExists(properties, "displayname");
    for (String attributeName : CONTACT_ATTRIBUTES) {
        String value = getPropertyIfExists(properties, attributeName);
        if (value != null) {
            if ("bday".equals(attributeName) || "anniversary".equals(attributeName)
                    || "lastmodified".equals(attributeName) || "datereceived".equals(attributeName)) {
                value = convertDateFromExchange(value);
            } else if ("haspicture".equals(attributeName) || "private".equals(attributeName)) {
                value = "1".equals(value) ? "true" : "false";
            }
            put(attributeName, value);
        }
    }
}
 
Example 3
Source File: TestExchangePropfindMethod.java    From davmail with GNU General Public License v2.0 6 votes vote down vote up
public void testGetFolder() throws IOException {
    ExchangeSession.Folder folder = session.getFolder("INBOX");
    assertNotNull(folder);
    DavPropertyNameSet davPropertyNameSet = new DavPropertyNameSet();
       // davPropertyNameSet.add(Field.getPropertyName("displayname"));
    //PropFindMethod propFindMethod = new PropFindMethod(URIUtil.encodePath(((DavExchangeSession)session).getFolderPath(folder.folderPath)));
    //session.httpClient.executeMethod(propFindMethod);
    //propFindMethod.getResponseBodyAsMultiStatus();

    

    ExchangePropFindMethod exchangePropFindMethod = new ExchangePropFindMethod(URIUtil.encodePath(((DavExchangeSession)session).getFolderPath(folder.folderPath)), davPropertyNameSet, 0);
    //PropFindMethod propFindMethod = new PropFindMethod(URIUtil.encodePath(((DavExchangeSession)session).getFolderPath(folder.folderPath)));
    session.httpClient.executeMethod(exchangePropFindMethod);
     MultiStatusResponse response = exchangePropFindMethod.getResponse();
                DavPropertySet properties = response.getProperties(HttpStatus.SC_OK);
                System.out.println(properties);
}
 
Example 4
Source File: CtagHandler.java    From openmeetings with Apache License 2.0 6 votes vote down vote up
@Override
BaseDavRequest internalSyncItems() throws IOException, DavException {
	//Calendar already inited.

	DavPropertyNameSet properties = new DavPropertyNameSet();
	properties.add(DNAME_GETCTAG);

	HttpPropFindMethod method = new HttpPropFindMethod(path, properties, CalDAVConstants.DEPTH_0);
	HttpResponse httpResponse = client.execute(method, context);

	if (method.succeeded(httpResponse)) {
		for (MultiStatusResponse response : method.getResponseBodyAsMultiStatus(httpResponse).getResponses()) {
			DavPropertySet set = response.getProperties(SC_OK);
			String ctag = AppointmentManager.getTokenFromProperty(set.get(DNAME_GETCTAG));

			if (ctag != null && !ctag.equals(calendar.getToken())) {
				EtagsHandler etagsHandler = new EtagsHandler(path, calendar, client, context, appointmentDao, utils);
				etagsHandler.syncItems();
				calendar.setToken(ctag);
			}
		}
	} else {
		log.error("Error executing PROPFIND Method, with status Code: {}", httpResponse.getStatusLine().getStatusCode());
	}
	return method;
}
 
Example 5
Source File: WebdavFileObject.java    From commons-vfs with Apache License 2.0 6 votes vote down vote up
DavPropertySet getProperties(final URLFileName name, final int type, final DavPropertyNameSet nameSet,
        final boolean addEncoding) throws FileSystemException {
    try {
        final String urlStr = toUrlString(name);
        final PropFindMethod method = new PropFindMethod(urlStr, type, nameSet, DavConstants.DEPTH_0);
        setupMethod(method);
        execute(method);
        if (method.succeeded()) {
            final MultiStatus multiStatus = method.getResponseBodyAsMultiStatus();
            final MultiStatusResponse response = multiStatus.getResponses()[0];
            final DavPropertySet props = response.getProperties(HttpStatus.SC_OK);
            if (addEncoding) {
                final DavProperty prop = new DefaultDavProperty(RESPONSE_CHARSET, method.getResponseCharSet());
                props.add(prop);
            }
            return props;
        }
        return new DavPropertySet();
    } catch (final FileSystemException fse) {
        throw fse;
    } catch (final Exception e) {
        throw new FileSystemException("vfs.provider.webdav/get-property.error", e, getName(), name, type,
                nameSet.getContent(), addEncoding);
    }
}
 
Example 6
Source File: HC4DavExchangeSession.java    From davmail with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Build Event instance from response info.
 *
 * @param multiStatusResponse response
 * @throws IOException on error
 */
public Event(MultiStatusResponse multiStatusResponse) throws IOException {
    setHref(URIUtil.decode(multiStatusResponse.getHref()));
    DavPropertySet properties = multiStatusResponse.getProperties(HttpStatus.SC_OK);
    permanentUrl = getURLPropertyIfExists(properties, "permanenturl");
    etag = getPropertyIfExists(properties, "etag");
    displayName = getPropertyIfExists(properties, "displayname");
    subject = getPropertyIfExists(properties, "subject");
    instancetype = getPropertyIfExists(properties, "instancetype");
    contentClass = getPropertyIfExists(properties, "contentclass");
}
 
Example 7
Source File: HC4DavExchangeSession.java    From davmail with GNU General Public License v2.0 5 votes vote down vote up
protected Message buildMessage(MultiStatusResponse responseEntity) throws IOException {
    Message message = new Message();
    message.messageUrl = URIUtil.decode(responseEntity.getHref());
    DavPropertySet properties = responseEntity.getProperties(HttpStatus.SC_OK);

    message.permanentUrl = getURLPropertyIfExists(properties, "permanenturl");
    message.size = getIntPropertyIfExists(properties, "messageSize");
    message.uid = getPropertyIfExists(properties, "uid");
    message.contentClass = getPropertyIfExists(properties, "contentclass");
    message.imapUid = getLongPropertyIfExists(properties, "imapUid");
    message.read = "1".equals(getPropertyIfExists(properties, "read"));
    message.junk = "1".equals(getPropertyIfExists(properties, "junk"));
    message.flagged = "2".equals(getPropertyIfExists(properties, "flagStatus"));
    message.draft = (getIntPropertyIfExists(properties, "messageFlags") & 8) != 0;
    String lastVerbExecuted = getPropertyIfExists(properties, "lastVerbExecuted");
    message.answered = "102".equals(lastVerbExecuted) || "103".equals(lastVerbExecuted);
    message.forwarded = "104".equals(lastVerbExecuted);
    message.date = convertDateFromExchange(getPropertyIfExists(properties, "date"));
    message.deleted = "1".equals(getPropertyIfExists(properties, "deleted"));

    String lastmodified = convertDateFromExchange(getPropertyIfExists(properties, "lastmodified"));
    message.recent = !message.read && lastmodified != null && lastmodified.equals(message.date);

    message.keywords = getPropertyIfExists(properties, "keywords");

    if (LOGGER.isDebugEnabled()) {
        StringBuilder buffer = new StringBuilder();
        buffer.append("Message");
        if (message.imapUid != 0) {
            buffer.append(" IMAP uid: ").append(message.imapUid);
        }
        if (message.uid != null) {
            buffer.append(" uid: ").append(message.uid);
        }
        buffer.append(" href: ").append(responseEntity.getHref()).append(" permanenturl:").append(message.permanentUrl);
        LOGGER.debug(buffer.toString());
    }
    return message;
}
 
Example 8
Source File: DavExchangeSession.java    From davmail with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Build Event instance from response info.
 *
 * @param multiStatusResponse response
 * @throws URIException on error
 */
public Event(MultiStatusResponse multiStatusResponse) throws IOException {
    setHref(URIUtil.decode(multiStatusResponse.getHref()));
    DavPropertySet properties = multiStatusResponse.getProperties(HttpStatus.SC_OK);
    permanentUrl = getURLPropertyIfExists(properties, "permanenturl");
    etag = getPropertyIfExists(properties, "etag");
    displayName = getPropertyIfExists(properties, "displayname");
    subject = getPropertyIfExists(properties, "subject");
    instancetype = getPropertyIfExists(properties, "instancetype");
    contentClass = getPropertyIfExists(properties, "contentclass");
}
 
Example 9
Source File: DavExchangeSession.java    From davmail with GNU General Public License v2.0 5 votes vote down vote up
protected Message buildMessage(MultiStatusResponse responseEntity) throws IOException {
    Message message = new Message();
    message.messageUrl = URIUtil.decode(responseEntity.getHref());
    DavPropertySet properties = responseEntity.getProperties(HttpStatus.SC_OK);

    message.permanentUrl = getURLPropertyIfExists(properties, "permanenturl");
    message.size = getIntPropertyIfExists(properties, "messageSize");
    message.uid = getPropertyIfExists(properties, "uid");
    message.contentClass = getPropertyIfExists(properties, "contentclass");
    message.imapUid = getLongPropertyIfExists(properties, "imapUid");
    message.read = "1".equals(getPropertyIfExists(properties, "read"));
    message.junk = "1".equals(getPropertyIfExists(properties, "junk"));
    message.flagged = "2".equals(getPropertyIfExists(properties, "flagStatus"));
    message.draft = (getIntPropertyIfExists(properties, "messageFlags") & 8) != 0;
    String lastVerbExecuted = getPropertyIfExists(properties, "lastVerbExecuted");
    message.answered = "102".equals(lastVerbExecuted) || "103".equals(lastVerbExecuted);
    message.forwarded = "104".equals(lastVerbExecuted);
    message.date = convertDateFromExchange(getPropertyIfExists(properties, "date"));
    message.deleted = "1".equals(getPropertyIfExists(properties, "deleted"));

    String lastmodified = convertDateFromExchange(getPropertyIfExists(properties, "lastmodified"));
    message.recent = !message.read && lastmodified != null && lastmodified.equals(message.date);

    message.keywords = getPropertyIfExists(properties, "keywords");

    if (LOGGER.isDebugEnabled()) {
        StringBuilder buffer = new StringBuilder();
        buffer.append("Message");
        if (message.imapUid != 0) {
            buffer.append(" IMAP uid: ").append(message.imapUid);
        }
        if (message.uid != null) {
            buffer.append(" uid: ").append(message.uid);
        }
        buffer.append(" href: ").append(responseEntity.getHref()).append(" permanenturl:").append(message.permanentUrl);
        LOGGER.debug(buffer.toString());
    }
    return message;
}
 
Example 10
Source File: Webdav4FileObject.java    From commons-vfs with Apache License 2.0 5 votes vote down vote up
DavPropertySet getProperties(final GenericURLFileName name, final int type, final DavPropertyNameSet nameSet,
        final boolean addEncoding) throws FileSystemException {
    try {
        final String urlStr = toUrlString(name);
        final HttpPropfind request = new HttpPropfind(urlStr, type, nameSet, DavConstants.DEPTH_0);
        setupRequest(request);
        final HttpResponse res = executeRequest(request);
        if (request.succeeded(res)) {
            final MultiStatus multiStatus = request.getResponseBodyAsMultiStatus(res);
            final MultiStatusResponse response = multiStatus.getResponses()[0];
            final DavPropertySet props = response.getProperties(HttpStatus.SC_OK);
            if (addEncoding) {
                final ContentType resContentType = ContentType.getOrDefault(res.getEntity());
                final DavProperty prop = new DefaultDavProperty(RESPONSE_CHARSET,
                        resContentType.getCharset().name());
                props.add(prop);
            }
            return props;
        }
        return new DavPropertySet();
    } catch (final FileSystemException fse) {
        throw fse;
    } catch (final Exception e) {
        throw new FileSystemException("vfs.provider.webdav/get-property.error", e, getName(), name, type,
                nameSet.getContent(), addEncoding);
    }
}
 
Example 11
Source File: HC4DavExchangeSession.java    From davmail with GNU General Public License v2.0 4 votes vote down vote up
protected Folder buildFolder(MultiStatusResponse entity) throws IOException {
    String href = URIUtil.decode(entity.getHref());
    Folder folder = new Folder();
    DavPropertySet properties = entity.getProperties(HttpStatus.SC_OK);
    folder.displayName = getPropertyIfExists(properties, "displayname");
    folder.folderClass = getPropertyIfExists(properties, "folderclass");
    folder.hasChildren = "1".equals(getPropertyIfExists(properties, "hassubs"));
    folder.noInferiors = "1".equals(getPropertyIfExists(properties, "nosubs"));
    folder.count = getIntPropertyIfExists(properties, "count");
    folder.unreadCount = getIntPropertyIfExists(properties, "unreadcount");
    // fake recent value
    folder.recent = folder.unreadCount;
    folder.ctag = getPropertyIfExists(properties, "contenttag");
    folder.etag = getPropertyIfExists(properties, "lastmodified");

    folder.uidNext = getIntPropertyIfExists(properties, "uidNext");

    // replace well known folder names
    if (inboxUrl != null && href.startsWith(inboxUrl)) {
        folder.folderPath = href.replaceFirst(inboxUrl, INBOX);
    } else if (sentitemsUrl != null && href.startsWith(sentitemsUrl)) {
        folder.folderPath = href.replaceFirst(sentitemsUrl, SENT);
    } else if (draftsUrl != null && href.startsWith(draftsUrl)) {
        folder.folderPath = href.replaceFirst(draftsUrl, DRAFTS);
    } else if (deleteditemsUrl != null && href.startsWith(deleteditemsUrl)) {
        folder.folderPath = href.replaceFirst(deleteditemsUrl, TRASH);
    } else if (calendarUrl != null && href.startsWith(calendarUrl)) {
        folder.folderPath = href.replaceFirst(calendarUrl, CALENDAR);
    } else if (contactsUrl != null && href.startsWith(contactsUrl)) {
        folder.folderPath = href.replaceFirst(contactsUrl, CONTACTS);
    } else {
        int index = href.indexOf(mailPath.substring(0, mailPath.length() - 1));
        if (index >= 0) {
            if (index + mailPath.length() > href.length()) {
                folder.folderPath = "";
            } else {
                folder.folderPath = href.substring(index + mailPath.length());
            }
        } else {
            try {
                java.net.URI folderURI = new java.net.URI(href);
                folder.folderPath = folderURI.getPath();
                if (folder.folderPath == null) {
                    throw new DavMailException("EXCEPTION_INVALID_FOLDER_URL", href);
                }
            } catch (URISyntaxException e) {
                throw new DavMailException("EXCEPTION_INVALID_FOLDER_URL", href);
            }
        }
    }
    if (folder.folderPath.endsWith("/")) {
        folder.folderPath = folder.folderPath.substring(0, folder.folderPath.length() - 1);
    }
    return folder;
}
 
Example 12
Source File: DavExchangeSession.java    From davmail with GNU General Public License v2.0 4 votes vote down vote up
protected Folder buildFolder(MultiStatusResponse entity) throws IOException {
    String href = URIUtil.decode(entity.getHref());
    Folder folder = new Folder();
    DavPropertySet properties = entity.getProperties(HttpStatus.SC_OK);
    folder.displayName = getPropertyIfExists(properties, "displayname");
    folder.folderClass = getPropertyIfExists(properties, "folderclass");
    folder.hasChildren = "1".equals(getPropertyIfExists(properties, "hassubs"));
    folder.noInferiors = "1".equals(getPropertyIfExists(properties, "nosubs"));
    folder.count = getIntPropertyIfExists(properties, "count");
    folder.unreadCount = getIntPropertyIfExists(properties, "unreadcount");
    // fake recent value
    folder.recent = folder.unreadCount;
    folder.ctag = getPropertyIfExists(properties, "contenttag");
    folder.etag = getPropertyIfExists(properties, "lastmodified");

    folder.uidNext = getIntPropertyIfExists(properties, "uidNext");

    // replace well known folder names
    if (inboxUrl != null && href.startsWith(inboxUrl)) {
        folder.folderPath = href.replaceFirst(inboxUrl, INBOX);
    } else if (sentitemsUrl != null && href.startsWith(sentitemsUrl)) {
        folder.folderPath = href.replaceFirst(sentitemsUrl, SENT);
    } else if (draftsUrl != null && href.startsWith(draftsUrl)) {
        folder.folderPath = href.replaceFirst(draftsUrl, DRAFTS);
    } else if (deleteditemsUrl != null && href.startsWith(deleteditemsUrl)) {
        folder.folderPath = href.replaceFirst(deleteditemsUrl, TRASH);
    } else if (calendarUrl != null && href.startsWith(calendarUrl)) {
        folder.folderPath = href.replaceFirst(calendarUrl, CALENDAR);
    } else if (contactsUrl != null && href.startsWith(contactsUrl)) {
        folder.folderPath = href.replaceFirst(contactsUrl, CONTACTS);
    } else {
        int index = href.indexOf(mailPath.substring(0, mailPath.length() - 1));
        if (index >= 0) {
            if (index + mailPath.length() > href.length()) {
                folder.folderPath = "";
            } else {
                folder.folderPath = href.substring(index + mailPath.length());
            }
        } else {
            try {
                URI folderURI = new URI(href, false);
                folder.folderPath = folderURI.getPath();
                if (folder.folderPath == null) {
                    throw new URIException();
                }
            } catch (URIException e) {
                throw new DavMailException("EXCEPTION_INVALID_FOLDER_URL", href);
            }
        }
    }
    if (folder.folderPath.endsWith("/")) {
        folder.folderPath = folder.folderPath.substring(0, folder.folderPath.length() - 1);
    }
    return folder;
}