mirror of
https://github.com/owncloud/android-library.git
synced 2025-06-08 00:16:09 +00:00
Allow conditional read of list of files in a folder based on ETag
This commit is contained in:
parent
e0f0416c9e
commit
5ff9062ea8
@ -62,7 +62,7 @@ import javax.net.ssl.SSLException;
|
|||||||
public class RemoteOperationResult implements Serializable {
|
public class RemoteOperationResult implements Serializable {
|
||||||
|
|
||||||
/** Generated - should be refreshed every time the class changes!! */;
|
/** Generated - should be refreshed every time the class changes!! */;
|
||||||
private static final long serialVersionUID = 1129130415603799707L;
|
private static final long serialVersionUID = -1909603208238358633L;
|
||||||
|
|
||||||
private static final String TAG = RemoteOperationResult.class.getSimpleName();
|
private static final String TAG = RemoteOperationResult.class.getSimpleName();
|
||||||
|
|
||||||
@ -112,7 +112,8 @@ public class RemoteOperationResult implements Serializable {
|
|||||||
WRONG_SERVER_RESPONSE,
|
WRONG_SERVER_RESPONSE,
|
||||||
INVALID_CHARACTER_DETECT_IN_SERVER,
|
INVALID_CHARACTER_DETECT_IN_SERVER,
|
||||||
DELAYED_FOR_WIFI,
|
DELAYED_FOR_WIFI,
|
||||||
LOCAL_FILE_NOT_FOUND
|
LOCAL_FILE_NOT_FOUND,
|
||||||
|
NOT_MODIFIED
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean mSuccess = false;
|
private boolean mSuccess = false;
|
||||||
@ -160,6 +161,8 @@ public class RemoteOperationResult implements Serializable {
|
|||||||
case HttpStatus.SC_FORBIDDEN:
|
case HttpStatus.SC_FORBIDDEN:
|
||||||
mCode = ResultCode.FORBIDDEN;
|
mCode = ResultCode.FORBIDDEN;
|
||||||
break;
|
break;
|
||||||
|
case HttpStatus.SC_NOT_MODIFIED:
|
||||||
|
mCode = ResultCode.NOT_MODIFIED;
|
||||||
default:
|
default:
|
||||||
mCode = ResultCode.UNHANDLED_HTTP_CODE;
|
mCode = ResultCode.UNHANDLED_HTTP_CODE;
|
||||||
Log_OC.d(TAG, "RemoteOperationResult has processed UNHANDLED_HTTP_CODE: " +
|
Log_OC.d(TAG, "RemoteOperationResult has processed UNHANDLED_HTTP_CODE: " +
|
||||||
@ -410,6 +413,9 @@ public class RemoteOperationResult implements Serializable {
|
|||||||
|
|
||||||
} else if (mCode == ResultCode.SYNC_CONFLICT) {
|
} else if (mCode == ResultCode.SYNC_CONFLICT) {
|
||||||
return "Synchronization conflict";
|
return "Synchronization conflict";
|
||||||
|
|
||||||
|
} else if (mCode == ResultCode.NOT_MODIFIED) {
|
||||||
|
return "Resource in server was not modified";
|
||||||
}
|
}
|
||||||
|
|
||||||
return "Operation finished with HTTP status code " + mHttpCode + " (" +
|
return "Operation finished with HTTP status code " + mHttpCode + " (" +
|
||||||
|
@ -49,7 +49,10 @@ public class ReadRemoteFolderOperation extends RemoteOperation {
|
|||||||
|
|
||||||
private static final String TAG = ReadRemoteFolderOperation.class.getSimpleName();
|
private static final String TAG = ReadRemoteFolderOperation.class.getSimpleName();
|
||||||
|
|
||||||
|
private static final String IF_NONE_MATCH_HEADER = "If-None-Match";
|
||||||
|
|
||||||
private String mRemotePath;
|
private String mRemotePath;
|
||||||
|
private String mETagToNotMatch;
|
||||||
private ArrayList<Object> mFolderAndFiles;
|
private ArrayList<Object> mFolderAndFiles;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -59,6 +62,17 @@ public class ReadRemoteFolderOperation extends RemoteOperation {
|
|||||||
*/
|
*/
|
||||||
public ReadRemoteFolderOperation(String remotePath) {
|
public ReadRemoteFolderOperation(String remotePath) {
|
||||||
mRemotePath = remotePath;
|
mRemotePath = remotePath;
|
||||||
|
mETagToNotMatch = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor
|
||||||
|
*
|
||||||
|
* @param remotePath Remote path of the file.
|
||||||
|
*/
|
||||||
|
public ReadRemoteFolderOperation(String remotePath, String eTagToNotMatch) {
|
||||||
|
mRemotePath = remotePath;
|
||||||
|
mETagToNotMatch = (eTagToNotMatch == null) ? "" : eTagToNotMatch;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -76,6 +90,10 @@ public class ReadRemoteFolderOperation extends RemoteOperation {
|
|||||||
query = new PropFindMethod(client.getWebdavUri() + WebdavUtils.encodePath(mRemotePath),
|
query = new PropFindMethod(client.getWebdavUri() + WebdavUtils.encodePath(mRemotePath),
|
||||||
WebdavUtils.getAllPropSet(), // PropFind Properties
|
WebdavUtils.getAllPropSet(), // PropFind Properties
|
||||||
DavConstants.DEPTH_1);
|
DavConstants.DEPTH_1);
|
||||||
|
if (mETagToNotMatch.length() > 0) {
|
||||||
|
query.addRequestHeader(IF_NONE_MATCH_HEADER, "\"" + mETagToNotMatch + "\"");
|
||||||
|
}
|
||||||
|
|
||||||
int status = client.executeMethod(query);
|
int status = client.executeMethod(query);
|
||||||
|
|
||||||
// check and process response
|
// check and process response
|
||||||
@ -95,7 +113,7 @@ public class ReadRemoteFolderOperation extends RemoteOperation {
|
|||||||
result.setData(mFolderAndFiles);
|
result.setData(mFolderAndFiles);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// synchronization failed
|
// synchronization failed, or no change in folder (mETagToNotMatch matched)
|
||||||
client.exhaustResponse(query.getResponseBodyAsStream());
|
client.exhaustResponse(query.getResponseBodyAsStream());
|
||||||
result = new RemoteOperationResult(false, status, query.getResponseHeaders());
|
result = new RemoteOperationResult(false, status, query.getResponseHeaders());
|
||||||
}
|
}
|
||||||
@ -122,10 +140,6 @@ public class ReadRemoteFolderOperation extends RemoteOperation {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isMultiStatus(int status) {
|
|
||||||
return (status == HttpStatus.SC_MULTI_STATUS);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Read the data retrieved from the server about the contents of the target folder
|
* Read the data retrieved from the server about the contents of the target folder
|
||||||
*
|
*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user