Java Code Examples for com.github.sardine.DavResource#getModified()

The following examples show how to use com.github.sardine.DavResource#getModified() . 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: MicrosoftIISDAVAttributesFinderFeature.java    From cyberduck with GNU General Public License v3.0 5 votes vote down vote up
protected PathAttributes toAttributes(final DavResource resource) {
    final PathAttributes attributes = super.toAttributes(resource);
    final Map<QName, String> properties = resource.getCustomPropsNS();
    if(null != properties && properties.containsKey(MicrosoftIISDAVTimestampFeature.LAST_MODIFIED_WIN32_CUSTOM_NAMESPACE)) {
        final String value = properties.get(MicrosoftIISDAVTimestampFeature.LAST_MODIFIED_WIN32_CUSTOM_NAMESPACE);
        if(StringUtils.isNotBlank(value)) {
            try {
                attributes.setModificationDate(rfc1123.parse(value).getTime());
            }
            catch(InvalidDateException e) {
                log.warn(String.format("Failure parsing property %s with value %s", MicrosoftIISDAVTimestampFeature.LAST_MODIFIED_WIN32_CUSTOM_NAMESPACE, value));
                if(resource.getModified() != null) {
                    attributes.setModificationDate(resource.getModified().getTime());
                }
            }
        }
        else {
            if(log.isDebugEnabled()) {
                log.debug(String.format("Missing value for property %s", MicrosoftIISDAVTimestampFeature.LAST_MODIFIED_WIN32_CUSTOM_NAMESPACE));
            }
            if(resource.getModified() != null) {
                attributes.setModificationDate(resource.getModified().getTime());
            }
        }
    }
    return attributes;
}
 
Example 2
Source File: CSVParser.java    From substitution-schedule-parser with Mozilla Public License 2.0 5 votes vote down vote up
@Override
public SubstitutionSchedule getSubstitutionSchedule() throws IOException, JSONException,
        CredentialInvalidException {
    String url = data.getString(PARAM_URL);
    SubstitutionSchedule schedule = SubstitutionSchedule.fromData(scheduleData);

    if (url.startsWith("webdav")) {
        UserPasswordCredential credential = (UserPasswordCredential) this.credential;
        try {
            Sardine client = getWebdavClient(credential);
            String httpUrl = url.replaceFirst("webdav", "http");
            List<DavResource> files = client.list(httpUrl);
            for (DavResource file : files) {
                if (!file.isDirectory() && !file.getName().startsWith(".")) {
                    LocalDateTime modified = new LocalDateTime(file.getModified());
                    if (schedule.getLastChange() == null || schedule.getLastChange().isBefore(modified)) {
                        schedule.setLastChange(modified);
                    }
                    InputStream stream = client.get(new URI(httpUrl).resolve(file.getHref()).toString());
                    parseCSV(IOUtils.toString(stream, "UTF-8"), schedule);
                }
            }
            return schedule;
        } catch (GeneralSecurityException | URISyntaxException e) {
            throw new IOException(e);
        }
    } else {
        new LoginHandler(scheduleData, credential, cookieProvider).handleLogin(executor, cookieStore);
        String response = httpGet(url);
        return parseCSV(response, schedule);
    }
}
 
Example 3
Source File: DAVAttributesFinderFeature.java    From cyberduck with GNU General Public License v3.0 4 votes vote down vote up
protected PathAttributes toAttributes(final DavResource resource) {
    final PathAttributes attributes = new PathAttributes();
    final Map<QName, String> properties = resource.getCustomPropsNS();
    if(null != properties && properties.containsKey(DAVTimestampFeature.LAST_MODIFIED_CUSTOM_NAMESPACE)) {
        final String value = properties.get(DAVTimestampFeature.LAST_MODIFIED_CUSTOM_NAMESPACE);
        if(StringUtils.isNotBlank(value)) {
            try {
                if(properties.containsKey(DAVTimestampFeature.LAST_MODIFIED_SERVER_CUSTOM_NAMESPACE)) {
                    final String svalue = properties.get(DAVTimestampFeature.LAST_MODIFIED_SERVER_CUSTOM_NAMESPACE);
                    if(StringUtils.isNotBlank(svalue)) {
                        final Date server = rfc1123.parse(svalue);
                        if(server.equals(resource.getModified())) {
                            // file not touched with a different client
                            attributes.setModificationDate(
                                rfc1123.parse(value).getTime());
                        }
                        else {
                            // file touched with a different client, use default modified date from server
                            if(resource.getModified() != null) {
                                attributes.setModificationDate(resource.getModified().getTime());
                            }
                        }
                    }
                    else {
                        if(log.isDebugEnabled()) {
                            log.debug(String.format("Missing value for property %s", DAVTimestampFeature.LAST_MODIFIED_SERVER_CUSTOM_NAMESPACE));
                        }
                        if(resource.getModified() != null) {
                            attributes.setModificationDate(resource.getModified().getTime());
                        }
                    }
                }
                else {
                    attributes.setModificationDate(
                        rfc1123.parse(value).getTime());
                }
            }
            catch(InvalidDateException e) {
                log.warn(String.format("Failure parsing property %s with value %s", DAVTimestampFeature.LAST_MODIFIED_CUSTOM_NAMESPACE, value));
                if(resource.getModified() != null) {
                    attributes.setModificationDate(resource.getModified().getTime());
                }
            }
        }
        else {
            if(log.isDebugEnabled()) {
                log.debug(String.format("Missing value for property %s", DAVTimestampFeature.LAST_MODIFIED_CUSTOM_NAMESPACE));
            }
            if(resource.getModified() != null) {
                attributes.setModificationDate(resource.getModified().getTime());
            }
        }
    }
    else if(resource.getModified() != null) {
        attributes.setModificationDate(resource.getModified().getTime());
    }
    if(resource.getCreation() != null) {
        attributes.setCreationDate(resource.getCreation().getTime());
    }
    if(resource.getContentLength() != null) {
        attributes.setSize(resource.getContentLength());
    }
    if(StringUtils.isNotBlank(resource.getEtag())) {
        attributes.setETag(resource.getEtag());
    }
    if(StringUtils.isNotBlank(resource.getDisplayName())) {
        attributes.setDisplayname(resource.getDisplayName());
    }
    if(StringUtils.isNotBlank(resource.getDisplayName())) {
        attributes.setDisplayname(resource.getDisplayName());
    }
    attributes.setLockId(resource.getLockToken());
    return attributes;
}